Spaces:
Runtime error
Runtime error
Update utility/utils.py
Browse files110 unmodified lines111112113114114116117115116117118120119120122121122123124125126127128124129130126131132133134130131135136137133138139140141110 unmodified lines
# Check if img is a file path or an image array if isinstance(img, str): # If img is a file path, load the image img = cv2.imread(img) # Perform OCR (Note: You might need to adapt this based on how PaddleOCR handles input images)
# Perform OCR result = ocr.ocr(img)
# Iterate through OCR results # Iterate through the OCR result for line in result[0]: box, text, _ = line # Check how many values are returned (2 or 3) and unpack accordingly if len(line) == 3: box, text, _ = line # When 3 values are returned elif len(line) == 2: box, text = line # When only 2 values are returned
# Store the recognized text and bounding boxes final_text += ' ' + text boxes.append(box) # Save the bounding box coordinates boxes.append(box)
# Convert points to integer and draw the bounding box # Draw the bounding box points = [(int(point[0]), int(point[1])) for point in box] cv2.polylines(img, [np.array(points)], isClosed=True, color=(0, 255, 0), thickness=2)
# Save the image with drawn boxes in memory (as a variable) img_with_boxes = img # This image can be used later or saved to disk if needed # Store the image with bounding boxes in a variable img_with_boxes = img
return final_text, boxes, img_with_boxes return final_text, img_with_boxes
# Function to draw bounding boxes around text#def draw_boxes(image, boxes):utility/utils.py+15-10