<jupyter_start><jupyter_text>library<jupyter_code>import cv2
from keras.models import load_model
import numpy as np
import os
from PIL import Image
import time
import pickle
import datetime
datetime.datetime.now()<jupyter_output>Using TensorFlow backend.<jupyter_text>input<jupyter_code>a = input("input:")
pixel=28
pixel=int(pixel)
mx=20
mx=int(mx)
my=mx
count=6
count=int(count)
tangle=80
tangle=int(tangle)<jupyter_output>input:PD003<jupyter_text>detection<jupyter_code>MODEL_FILENAME1 = "D:/Work/Picture/multy/"+a+"/code/X_model.hdf5"
MODEL_LABELS_FILENAME1 = "D:/Work/Picture/multy/"+a+"/code/X_model_labels.dat"
with open(MODEL_LABELS_FILENAME1, "rb") as f:
    lb1 = pickle.load(f)

# Load the trained neural network
model1 = load_model(MODEL_FILENAME1)

MODEL_FILENAME2 = "D:/Work/Picture/multy/"+a+"/code/Y_model.hdf5"
MODEL_LABELS_FILENAME2 = "D:/Work/Picture/multy/"+a+"/code/Y_model_labels.dat"
with open(MODEL_LABELS_FILENAME2, "rb") as f:
    lb2 = pickle.load(f)

# Load the trained neural network
model2 = load_model(MODEL_FILENAME2)

MODEL_FILENAME3 = "D:/Work/Picture/multy/"+a+"/code/Z_model.hdf5"
MODEL_LABELS_FILENAME3 = "D:/Work/Picture/multy/"+a+"/code/Z_model_labels.dat"
with open(MODEL_LABELS_FILENAME3, "rb") as f:
    lb3 = pickle.load(f)

# Load the trained neural network
model3 = load_model(MODEL_FILENAME3)



outputFolder = "D:/Work/Picture/multy/" + a + "/CI_1"

# 自動建立目錄
if not os.path.exists(outputFolder):
    os.makedirs(outputFolder)

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 480)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 512)
outputCounter = 0
count=0


while (outputCounter < 10):
    predictions = []

    # get a frameq
    ret, frame = cap.read(0)
    frame = frame[41:441, 57:457]
    r = 1000.0 / frame.shape[1]
    dim = (1000, int(frame.shape[0] * r))
    frame = cv2.resize(frame, dim, interpolation=cv2.INTER_AREA)
    # show a frame

    cv2.imwrite("%s/PICTURE.jpeg" % (outputFolder), frame)
    time.sleep(0.05)
    test_img = np.array(
        Image.open(outputFolder + "/PICTURE.jpeg").resize([pixel, pixel]))
    test_img = np.expand_dims(test_img, axis=0)
    prediction1 = model1.predict(test_img)
    prediction2 = model2.predict(test_img)
    prediction3 = model3.predict(test_img)
    x = lb1.inverse_transform(prediction1)[0]
    y = lb2.inverse_transform(prediction2)[0]
    Z = lb3.inverse_transform(prediction3)[0]
    predictions.append(x)
    predictions.append(y)
    predictions.append(Z)
    Predicted_Probability1 = model1.predict(test_img / 255.0)
    c = max(Predicted_Probability1[0])
    Predicted_Probability2 = model2.predict(test_img / 255.0)
    d = max(Predicted_Probability2[0])

    x = str(x)[35:]
    y = str(y)[35:]
    z = str(0)
    d_a = (1000 // (1000 - int(z) * 100) * tangle - tangle//2) // 2
    d_b = (1000 - 2 * d_a) // (mx+1)
    text = (x + ',' + y+ ',' + z)
    cv2.namedWindow('capture', cv2.WINDOW_NORMAL)
    cv2.rectangle(frame, (d_b * (mx - int(x)) + d_a, d_b * (my - int(y)) 
+ d_a),(d_b * (mx - int(x)) + tangle//2 + d_a, d_b * (my - int(y)) + tangle//2 + d_a),
                  (0, 255, 255), 3)
    
    cv2.putText(frame, text, (11 * (mx - int(x)) , 11 * (my - int(y)) ), cv2.FONT_HERSHEY_SIMPLEX,
                1, (0, 0, 255), 1, cv2.LINE_AA)
    cv2.imshow("capture", frame)

    
    localtime = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S_")
    ResultFolder = "D:/Work/Picture/result/"+a
    if not os.path.exists(ResultFolder):
        os.makedirs(ResultFolder)
    if count>=0:
        cv2.imwrite("D:/Work/Picture/Result/"+a+"/"+localtime+str(count)+".jpeg", frame)
        count+=1
    
    print(localtime)
    print(count)
    print(x, y)
    

    k = cv2.waitKey(30) & 0xff

    if k == 27:  # press 'ESC' to quit

        break
cap.release()
cv2.destroyAllWindows()<jupyter_output>2020-05-06_18-32-56_
1
3 20 3
2020-05-06_18-32-57_
2
3 8 3
2020-05-06_18-32-57_
3
3 10 3
2020-05-06_18-32-57_
4
3 8 3
2020-05-06_18-32-57_
5
3 9 3
2020-05-06_18-32-57_
6
3 9 3
2020-05-06_18-32-58_
7
3 10 3
2020-05-06_18-32-58_
8
3 19 3
2020-05-06_18-32-58_
9
20 20 3
2020-05-06_18-32-58_
10
20 20 3
2020-05-06_18-32-58_
11
20 20 3
2020-05-06_18-32-59_
12
2 20 3
2020-05-06_18-32-59_
13
1 20 3
2020-05-06_18-32-59_
14
1 20 3
2020-05-06_18-32-59_
15
1 20 3
2020-05-06_18-32-59_
16
1 20 3
2020-05-06_18-33-00_
17
5 20 3
2020-05-06_18-33-00_
18
4 20 3
2020-05-06_18-33-00_
19
1 20 3
2020-05-06_18-33-00_
20
17 20 3
2020-05-06_18-33-00_
21
14 20 3
2020-05-06_18-33-01_
22
12 20 3
2020-05-06_18-33-01_
23
12 20 3
2020-05-06_18-33-01_
24
15 20 3
2020-05-06_18-33-01_
25
16 20 3
2020-05-06_18-33-01_
26
1 20 3
2020-05-06_18-33-02_
27
3 20 3
2020-05-06_18-33-02_
28
3 20 3
2020-05-06_18-33-02_
29
3 19 3
2020-05-06_18-33-02_
30
3 19 3
2020-05-06_18-33-02_
31
3 19 3
2020-05-06_18-33-03_
32
3 18 3
2020-05-06_1[...]
{'fraction_non_alphanumeric': 0.15317739598426827, 'fraction_numerical': 0.1684951355826951, 'mean_word_length': 3.3649503161698284, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '249179', 'license': 'Apache-2.0', 'n_tokens_mistral': 2670, 'n_tokens_neox': 2169, 'n_words': 424, 'path': 'Object Coordinate Detector/Detection.ipynb', 'repo_name': 'ntutindustry40/One-Shot-II', 'size': '4831'}