Spaces:
Runtime error
Runtime error
Update utility/utils.py
Browse files110 unmodified lines111112113114115116117118119120121122123124125126127128129130131132133134135136110 unmodified lines# Check if img is a file path or an image arrayif isinstance(img, str):# If img is a file path, load the imageimg = cv2.imread(img)# Perform OCR (Note: You might need to adapt this based on how PaddleOCR handles input images)result = ocr.ocr(img)# Iterate through OCR resultsfor line in result[0]:box, text, _ = linefinal_text += ' ' + textboxes.append(box) # Save the bounding box coordinates# Convert points to integer and draw the bounding boxpoints = [(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 neededreturn final_text, boxes, img_with_boxes# Function to draw bounding boxes around text#def draw_boxes(image, boxes):110 unmodified lines111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141110 unmodified lines# Check if img is a file path or an image arrayif isinstance(img, str):img = cv2.imread(img)# Perform OCRresult = ocr.ocr(img)# Iterate through the OCR resultfor line in result[0]:# Check how many values are returned (2 or 3) and unpack accordinglyif len(line) == 3:box, text, _ = line # When 3 values are returnedelif len(line) == 2:box, text = line # When only 2 values are returned# Store the recognized text and bounding boxesfinal_text += ' ' + textboxes.append(box)# Draw the bounding boxpoints = [(int(point[0]), int(point[1])) for point in box]cv2.polylines(img, [np.array(points)], isClosed=True, color=(0, 255, 0), thickness=2)# Store the image with bounding boxes in a variableimg_with_boxes = imgreturn final_text, img_with_boxes# Function to draw bounding boxes around text#def draw_boxes(image, boxes):
utility/utils.py+15-10