Skip to content

Commit 4d8b8de

Browse files
committed
diff - box - rect
1 parent 5ffb6e8 commit 4d8b8de

File tree

1 file changed

+57
-4
lines changed

1 file changed

+57
-4
lines changed

src/ocr_opencv/src/test_ocr_1.py

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ def get_contours(image_init,img_edged,img_name):
290290
"""
291291
Contours extraction
292292
# TODO - uses - imutils
293+
294+
Wrapper Func for -- get_order_points_1()
293295
"""
294296
# find contours in the edge map
295297
img_edged_1 = img_edged.copy()
@@ -300,7 +302,7 @@ def get_contours(image_init,img_edged,img_name):
300302
(cnts, _) = contours.sort_contours(cnts)
301303
colors = ((0, 0, 255), (240, 0, 159), (255, 0, 0), (255, 255, 0))
302304
# loop over the contours individually
303-
for (i, c) in enumerate(cnts):
305+
for (iter_k, c) in enumerate(cnts):
304306
# if the contour is not sufficiently large, ignore it
305307
if cv2.contourArea(c) < 100:
306308
continue
@@ -310,9 +312,56 @@ def get_contours(image_init,img_edged,img_name):
310312
box = np.array(box, dtype="int")
311313
cv2.drawContours(image_init, [box], -1, (0, 255, 0), 2)
312314
# show the original coordinates
313-
print("Object #{}:".format(i + 1))
314-
print(box)
315+
print("Object #{}:".format(iter_k + 1))
316+
print(box) ## BBOX Coordinates -- printed into the terminal Log Files
317+
print(" ---box--Above --- "*90)
318+
# TODO -- get_cropped_mask( -->
319+
# for the Number Plate images - get only CNTRS that are a CERTAIN DISTANCE from IMAGE TOP and BOTTOM
315320
cv2.imwrite("./data_dir/output_dir/img_skew/img_contours_"+str(img_name)+"_.png", image_init)
321+
get_order_points_1(image_init,img_name,box,iter_k)
322+
323+
324+
def get_order_points_1(image_init,img_name,box,iter_k):
325+
"""
326+
How diff from -- ls_rect_coords = get_order_points(img_init,image_points)
327+
328+
#Ordering coordinates clockwise with Python and OpenCV
329+
# order the points in the contour such that they appear
330+
# in top-left, top-right, bottom-right, and bottom-left
331+
# order, then draw the outline of the rotated bounding
332+
# box
333+
334+
"""
335+
colors = ((0, 0, 255), (240, 0, 159), (255, 0, 0), (255, 255, 0))
336+
337+
#rect = order_points_old(box) ## OLd -- Deprecated
338+
# Dont check to see if the new method should be used for ordering the coordinates
339+
# Use New here
340+
rect = perspective.order_points(box)
341+
# show the re-ordered coordinates
342+
print(rect.astype("int"))
343+
print(" ---RECT--Above --- "*90)
344+
"""
345+
TODO -- for certain OBJECTS in the Images
346+
The 2 Vals are DIFF -
347+
The ndArray---> box
348+
is DIFF from
349+
The ndArray---> rect
350+
Identify such OBJ's and print somewhere asto why this DIFF
351+
"""
352+
# loop over the original points and draw them
353+
for ((x, y), color) in zip(rect, colors):
354+
cv2.circle(image_init, (int(x), int(y)), 5, color, -1)
355+
# draw the object num at the top-left corner
356+
cv2.putText(image_init, "Object #{}".format(iter_k + 1),
357+
(int(rect[0][0] - 15), int(rect[0][1] - 15)),
358+
cv2.FONT_HERSHEY_SIMPLEX, 0.55, (255, 255, 255), 2)
359+
# # show the image
360+
# cv2.imshow("Image", image_init)
361+
# cv2.waitKey(0)
362+
cv2.imwrite("./data_dir/output_dir/img_skew/img_cntr_pts_"+str(img_name)+"_.png", image_init)
363+
364+
316365

317366
def get_img_blur():
318367
"""
@@ -365,7 +414,11 @@ def get_cropped_mask(image_init,crop_coord,img_name):
365414
# path_img2 = "./data_dir/input_dir/warped_img_img_skw_2_.png"
366415
# path_img3 = "./data_dir/input_dir/warped_img_img_skw_3_.png"
367416

368-
ls_imgs = [path_img1,path_img2,path_img3]
417+
path_img2 = "./data_dir/input_dir/mh_0.png"
418+
path_img3 = "./data_dir/input_dir/mh_1.png"
419+
420+
#ls_imgs = [path_img1,path_img2,path_img3]
421+
ls_imgs = [path_img2,path_img3]
369422

370423
for iter_img in range(len(ls_imgs)):
371424
img_name = str(ls_imgs[iter_img]).rsplit("/",1)[1]

0 commit comments

Comments
 (0)