Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#Get system camera in index 0
source = ImageSource(args.camera)
w, h = source.get_size()
#Set document processing parameters and initialize scanner
scanner = TestScanner(w, h, args.exams_file, show_image=True, double_check=True, debug = args.debug, poll = args.poll)
tests = {}
#While user does not press the q key
while cv2.waitKey(1) & 0xFF != ord('q'):
#Get the scan report of the source image
report = scanner.scan(source)
#if test recognized OK
if report.success:
if not report.test.id in tests:
beep.beep()
tests[report.test.id] = report.test
print "Test ID:", unicode(report.test.id).encode("utf8")
for i, q in enumerate(report.test.questions):
print "%d. %s"%(i+1, q)
if len(report.test.warnings)>0:
print "Warnings:"
for w in report.test.warnings:
print "\t", w
else:
print "The test '%d' was already scanned."%report.test.id
#if recognition went wrong print the reasons
else:
# show only the question detection errors and the
# errors in the format of the qrcodes
for e in [x for x in report.errors
if isinstance(x, QuestionError) or
while True:
#While user does not press the q key if it is a camera
if source.is_camera:
if (cv2.waitKey(100) & 0xFF) == ord('q'):
print('Camera finished!')
break
elif source.finished:
print('Folder finished!')
break
#Get the scan report of the source image
report = scanner.scan(source)
#if test recognized OK
if report.success:
if not report.test.id in tests:
beep.beep()
tests[report.test.id] = report.test
print "Test ID:", unicode(report.test.id).encode("utf8")
for i, q in enumerate(report.test.questions):
print "%d. %s" % (i+1, q)
if len(report.test.warnings) > 0:
print "Warnings:"
for w in report.test.warnings:
print "\t", w
# on_scan(report)
#this method appends the test results if the file exists...
if args.autowrite:
scanresults.dump(tests, args.outfile, overwrite=False)
stats = get_stats(args.outfile)
stats_path = os.path.join(os.path.dirname(os.path.realpath(args.outfile)), "stats.json")
with open(stats_path, "wb") as stats_file:
json.dump(stats, stats_file, indent=4)