<s> '''<STR_LIT>''' <EOL> import cv2 <EOL> import numpy as np <EOL> import sys <EOL> def data_matrix_demo ( cap ) : <EOL> window_name = "<STR_LIT>" <EOL> frame_number = <NUM_LIT:0> <EOL> need_to_save = False <EOL> while <NUM_LIT:1> : <EOL> ret , frame = cap . read ( ) <EOL> if not ret : <EOL> break <EOL> gray = cv2 . cvtColor ( frame , cv2 . COLOR_RGB2GRAY ) <EOL> codes , corners , dmtx = cv2 . findDataMatrix ( gray ) <EOL> cv2 . drawDataMatrixCodes ( frame , codes , corners ) <EOL> cv2 . imshow ( window_name , frame ) <EOL> key = cv2 . waitKey ( <NUM_LIT:30> ) <EOL> c = chr ( key & <NUM_LIT:255> ) <EOL> if c in [ '<STR_LIT:q>' , '<STR_LIT>' , chr ( <NUM_LIT> ) ] : <EOL> break <EOL> if c == '<STR_LIT:U+0020>' : <EOL> need_to_save = True <EOL> if need_to_save and codes : <EOL> filename = ( "<STR_LIT>" % frame_number ) <EOL> cv2 . imwrite ( filename , frame ) <EOL> print "<STR_LIT>" + filename <EOL> need_to_save = False <EOL> frame_number += <NUM_LIT:1> <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print __doc__ <EOL> if len ( sys . argv ) == <NUM_LIT:1> : <EOL> cap = cv2 . VideoCapture ( <NUM_LIT:0> ) <EOL> else : <EOL> cap = cv2 . VideoCapture ( sys . argv [ <NUM_LIT:1> ] ) <EOL> if not cap . isOpened ( ) : <EOL> cap = cv2 . VideoCapture ( int ( sys . argv [ <NUM_LIT:1> ] ) ) <EOL> if not cap . isOpened ( ) : <EOL> print '<STR_LIT>' <EOL> sys . exit ( - <NUM_LIT:1> ) <EOL> data_matrix_demo ( cap ) </s>
