Skip to content

Commit 7acb2dc

Browse files
committed
Added try-except to account for diff opencv versions
1 parent d2ea367 commit 7acb2dc

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

core/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ def recognize_plate(img, coords):
3636
#cv2.imshow("Dilation", dilation)
3737
#cv2.waitKey(0)
3838
# find contours of regions of interest within license plate
39-
contours, hierarchy = cv2.findContours(dilation, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
39+
try:
40+
contours, hierarchy = cv2.findContours(dilation, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
41+
except:
42+
ret_img, contours, hierarchy = cv2.findContours(dilation, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
4043
# sort contours left-to-right
4144
sorted_contours = sorted(contours, key=lambda ctr: cv2.boundingRect(ctr)[0])
4245
# create copy of gray image

license_plate_recognizer.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
#cv2.imshow("dilation", dilation)
2525
#cv2.waitKey(0)
2626
# find contours
27-
contours, hierarchy = cv2.findContours(dilation, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
27+
try:
28+
contours, hierarchy = cv2.findContours(dilation, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
29+
except:
30+
ret_img, contours, hierarchy = cv2.findContours(dilation, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
2831
sorted_contours = sorted(contours, key=lambda ctr: cv2.boundingRect(ctr)[0])
2932

3033
# create copy of image

0 commit comments

Comments
 (0)