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 ['q', 'Q', chr(27)] in c:
            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
dataset/ETHPy150Open fatcloud/PyCV-time/opencv-official-samples/2.4.9/video_dmtx.py/data_matrix_demo/swapped operands of `in`