Esempio n. 1
0
def data_matrix_demo(cap):
    window_name = "Data Matrix Detector"
    frame_number = 0
    need_to_save = False

    while 1:
        ret, frame = cap.read()
        if not ret:
            break

        gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
        codes, corners, dmtx = cv2.findDataMatrix(gray)

        cv2.drawDataMatrixCodes(frame, codes, corners)
        cv2.imshow(window_name, frame)

        key = cv2.waitKey(30)
        c = chr(key & 255)
        if c in ['q', 'Q', chr(27)]:
            break

        if c == ' ':
            need_to_save = True

        if need_to_save and codes:
            filename = ("datamatrix%03d.jpg" % frame_number)
            cv2.imwrite(filename, frame)
            print "Saved frame to " + filename
            need_to_save = False

        frame_number += 1
Esempio n. 2
0
def data_matrix_demo(cap):
    window_name = "Data Matrix Detector"
    frame_number = 0
    need_to_save = False

    while 1:
        ret, frame = cap.read()
        if not ret:
            break

        gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
        codes, corners, dmtx = cv2.findDataMatrix(gray)

        cv2.drawDataMatrixCodes(frame, codes, corners)
        cv2.imshow(window_name, frame)

        key = cv2.waitKey(30)
        c = chr(key & 255)
        if c in ['q', 'Q', chr(27)]:
            break

        if c == ' ':
            need_to_save = True

        if need_to_save and codes:
            filename = ("datamatrix%03d.jpg" % frame_number)
            cv2.imwrite(filename, frame)
            print "Saved frame to " + filename
            need_to_save = False

        frame_number += 1
        print 'Cannot initialize vide capture'
        sys.exit(-1)

    while(1):
        count += 1
        ret, frame1 = cap.read()
        if not ret:
            break;

        ret, frame2 = cap.read()
        if not ret:
            break;

        gray = cv2.cvtColor(frame1, cv2.COLOR_RGB2GRAY)
        codes, corners, dmtx = cv2.findDataMatrix(gray)
        cv2.drawDataMatrixCodes(frame1, codes, corners)

        cv2.imshow('ShowFrame', frame1)
        absFrame = cv2.absdiff(frame1, frame2)

        cv2.imshow('absFrame', absFrame)
        ret, thresholdFrame = cv2.threshold(absFrame, sensitivity_value
                                       ,255, cv2.THRESH_BINARY)

        for i in xrange(1,6,2):
            thresholdFrame =  cv2.blur(thresholdFrame,(i,i))

        ret, thresholdFrame = cv2.threshold(absFrame, sensitivity_value
                                       ,255, cv2.THRESH_BINARY)