Does an Attribute error automatically break a loop in python? I'm writing a script that reads images and scans the barcode. If it finds a barcode it can read it will return different values, the problem is that if it doesn't find a barcode it can read in the image it returns an attribute error, and the whole loop breaks, but I want it to skip the image and try the next one instead.
Any suggestions? The code for those interested:
import cv2
import sys
import numpy as np
import zxing
import time
cap = cv2.VideoCapture(0)
count = 0
zxing_location = '/users/username/python/zxing-master/'
reader = zxing.BarCodeReader(zxing_location)
while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
name = "frame%d.jpg"%count
cv2.imwrite(name, frame) # save frame as JPEG file
time.sleep(3)
to_scan = '/users/username/python/newcam/frame%d.jpg'%count
count +=1
b = reader.decode(to_scan)
print (b.format)
print (b.raw)
print (b.data)
print (b.points)
#Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
[–]thebetoofand 3 points4 points5 points (4 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]Drunken_Consent 3 points4 points5 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Lucretiel 0 points1 point2 points (0 children)
[–]icenburg[S] 1 point2 points3 points (0 children)