Exemple #1
0
def Video():
    cap = cv2.VideoCapture(0)
    while not cap.isOpened():
        cap = cv2.VideoCapture(0)
        cv2.waitKey(1000)
    label = ''
    cntr = 1
    while True:
        flag, frame = cap.read()
        if flag:
            frame = cv2.flip(frame, 1)
            cv2.rectangle(frame, (400, 100), (600, 300), (255, 0, 0), 2)
            annotated_frame = write_text(frame, label)
            cv2.imshow('input', annotated_frame)
            #cv2.imshow('input',frame[100:300,400:600])

        else:
            cv2.waitKey(1000)
        k = cv2.waitKey(5)
        if k == 27:
            break
        elif k == ord('c'):
            start = timeit.default_timer()
            #o_frame = trancsform(frame[100:300,400:600])
            label = predict_label_svm(frame[100:300, 400:600])
            print(label)
            stop = timeit.default_timer()
            rt = stop - start
            print('Time: ', rt)
            #cv2.imshow('output',o_frame)
        elif k == ord('s'):
            cv2.imwrite('images/' + str(cntr) + '.jpg', frame[100:300,
                                                              400:600])
            cntr += 1
Exemple #2
0
def Video():
    capture = cv2.VideoCapture(0)
    while not capure.isOpened():
        capture = cv2.VideoCapture(0)
        cv2.waitKey(1000)
    label = ''
    cntr = 1
    while not False:
        flag = capture.read()
        frame = capture.read()
        if flag is not None:
            try:
                frame = cv2.flip(frame, 1)
                cv2.rectangle(frame, (400, 100), (600, 300), (255, 0, 0), 2)
                annotated_frame = write_text(frame, label)
                cv2.imshow('input', annotated_frame)
            except:
                print('Something went wrong')
        #cv2.imshow('input',frame[100:300,400:600])

        else:
            cv2.waitKey(800)
        key = cv2.waitKey(5)
        if key == 27:
            #Escape key pressed
            break
        elif key == 99 or key == ord('c'):
            #o_frame = transform(frame[100:300,400:600])
            label = predict_label_svm(frame[100:300, 400:600])
            print(label)
            #cv2.imshow('output',o_frame)
        elif key == ord('s'):
            cv2.imwrite('images/' + str(cntr) + '.jpg', frame[100:300,
                                                              400:600])
            cntr += 1
Exemple #3
0
def Image(path):
    frame = cv2.imread(path)
    o_frame = transform(frame)
    label = predict_label_svm(frame)
    annotated_img = write_text(frame, label)
    print(label)
    cv2.imshow('input', annotated_img)
    cv2.imshow('output', o_frame)
    cv2.waitKey(0)
Exemple #4
0
def Video():
    # code for sentence
    word = ' '

    cap = cv2.VideoCapture(0)
    while not cap.isOpened():
        cap = cv2.VideoCapture(0)
        cv2.waitKey(1000)
    label = ''
    blank = ''
    cntr = 1
    while True:
        flag, frame = cap.read()
        # label = predict_label_svm(frame[100:300,400:600])
        if flag:
            frame = cv2.flip(frame, 1)
            cv2.rectangle(frame, (400, 100), (600, 300), (255, 0, 0), 2)
            annotated_frame = write_text(frame, blank)
            cv2.imshow('input', annotated_frame)

        else:
            cv2.waitKey(1000)
        k = cv2.waitKey(5)
        #    tab breaks the flow -> text+audio
        if k == 27:
            return word
            break

        elif k == 9:
            label = predict_label_svm(frame[100:300, 400:600])
            word = word + label

        elif k == ord('s'):
            cv2.imwrite('images/' + str(cntr) + '.jpg', frame[100:300,
                                                              400:600])
            cntr += 1
            # adding a space with enter
        elif k == 13:
            label = " "
            word = word + label