New Text Document (2) 22
New Text Document (2) 22
import cv2
import numpy as np
import pytesseract
# Convert the frame to HSV and threshold the yellow color range
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(hsv, yellow_lower, yellow_upper)
# Set a minimum size for the yellow boxes (adjust these values as needed)
min_box_area = 1000 # minimum area of the box (in pixels)
min_box_width = 50 # minimum width of the box (in pixels)
min_box_height = 50 # minimum height of the box (in pixels)
# Iterate through the contours and draw rectangles around the yellow boxes
for contour in contours:
x, y, w, h = cv2.boundingRect(contour)
area = w * h
if area > min_box_area and w > min_box_width and h > min_box_height:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
# Optionally, you can add more logic to confirm successful merging, or repeat the
process as needed