anikde commited on
Commit
c6cad64
1 Parent(s): 00975db

poly2rectangle bbox

Browse files
Files changed (1) hide show
  1. IndicPhotoOCR/ocr.py +9 -3
IndicPhotoOCR/ocr.py CHANGED
@@ -54,9 +54,15 @@ class OCR:
54
  for box in detections:
55
  # Convert list of points to a numpy array with int type
56
  points = np.array(box, np.int32)
57
- points = points.reshape((-1, 1, 2)) # Reshape for cv2.polylines
58
- # Draw the polygon
59
- cv2.polylines(image, [points], isClosed=True, color=(0, 255, 0), thickness=3)
 
 
 
 
 
 
60
 
61
  # Show the image if 'show' is True
62
  if show:
 
54
  for box in detections:
55
  # Convert list of points to a numpy array with int type
56
  points = np.array(box, np.int32)
57
+
58
+ # Compute the top-left and bottom-right corners of the bounding box
59
+ x_min = np.min(points[:, 0])
60
+ y_min = np.min(points[:, 1])
61
+ x_max = np.max(points[:, 0])
62
+ y_max = np.max(points[:, 1])
63
+
64
+ # Draw the rectangle
65
+ cv2.rectangle(image, (x_min, y_min), (x_max, y_max), color=(0, 255, 0), thickness=3)
66
 
67
  # Show the image if 'show' is True
68
  if show: