Successfully implemented multi-core OCR functionality.

This commit is contained in:
2025-02-26 03:36:59 -07:00
parent 5c23653d59
commit b6ef14b559
5 changed files with 176 additions and 65 deletions

View File

@ -1,9 +1,7 @@
#!/usr/bin/env python3
"""
Identification Overlay Node:
- Creates an OCR region in data_collector with a blue overlay.
- Detects instances of a specified word and draws adjustable overlays.
- Users can configure offset, margin, polling frequency, overlay color, and thickness.
- Users can configure threads/slices for parallel processing.
"""
import re
@ -31,6 +29,7 @@ class IdentificationOverlayNode(BaseNode):
# Custom overlay options
self.add_text_input("overlay_color", "Overlay Color (RGB)", text="0,0,255") # Default blue
self.add_text_input("thickness", "Line Thickness", text="2") # Default 2px
self.add_text_input("threads_slices", "Threads / Slices", text="8") # Default 8 threads/slices
self.region_id = "identification_overlay"
data_collector.create_ocr_region(self.region_id, x=250, y=50, w=300, h=200, color=(0, 0, 255), thickness=2)
@ -46,62 +45,59 @@ class IdentificationOverlayNode(BaseNode):
self.update_polling_frequency()
def update_polling_frequency(self):
"""
Reads the user-defined polling frequency and updates the timer interval.
"""
polling_text = self.get_property("polling_freq")
try:
polling_interval = max(50, int(polling_text)) # Minimum 50ms for near real-time
polling_interval = max(50, int(polling_text))
except ValueError:
polling_interval = 500 # Default to 500ms
polling_interval = 500
self.timer.start(polling_interval)
def update_overlay(self):
"""
Updates the overlay with detected word positions.
"""
search_term = self.get_property("search_term")
offset_text = self.get_property("offset_value")
margin_text = self.get_property("margin")
ocr_engine = self.get_property("ocr_engine")
threads_slices_text = self.get_property("threads_slices")
# Read and apply polling frequency updates
self.update_polling_frequency()
# Parse user-defined offset
try:
offset_x, offset_y = map(int, offset_text.split(","))
except ValueError:
offset_x, offset_y = 0, 0 # Default to no offset if invalid input
offset_x, offset_y = 0, 0
# Parse user-defined margin
try:
margin = int(margin_text)
except ValueError:
margin = 5 # Default margin if invalid input
margin = 5
# Parse overlay color
color_text = self.get_property("overlay_color")
try:
color = tuple(map(int, color_text.split(","))) # Convert "255,0,0" -> (255,0,0)
color = tuple(map(int, color_text.split(",")))
except ValueError:
color = (0, 0, 255) # Default to blue if invalid input
color = (0, 0, 255)
# Parse thickness
thickness_text = self.get_property("thickness")
try:
thickness = max(1, int(thickness_text)) # Ensure at least 1px thickness
thickness = max(1, int(thickness_text))
except ValueError:
thickness = 2 # Default thickness
thickness = 2
try:
num_slices = max(1, int(threads_slices_text)) # Ensure at least 1 slice
except ValueError:
num_slices = 1
if not search_term:
return
# Get detected word positions using the selected OCR engine
detected_positions = data_collector.find_word_positions(
self.region_id, search_term, offset_x, offset_y, margin, ocr_engine
self.region_id, search_term, offset_x, offset_y, margin, ocr_engine, num_slices
)
# Draw detected word boxes with custom color & thickness
# Ensure slice count is updated visually in the region widget
data_collector.update_region_slices(self.region_id, num_slices)
data_collector.draw_identification_boxes(self.region_id, detected_positions, color=color, thickness=thickness)