Fully Customizable GPU Accelerated Identification Nodes
This commit is contained in:
Binary file not shown.
@ -45,10 +45,10 @@ def _ensure_qapplication():
|
||||
app_instance = QApplication(sys.argv) # Start in main thread
|
||||
|
||||
|
||||
def create_ocr_region(region_id, x=250, y=50, w=DEFAULT_WIDTH, h=DEFAULT_HEIGHT, color=(255, 255, 0)):
|
||||
def create_ocr_region(region_id, x=250, y=50, w=DEFAULT_WIDTH, h=DEFAULT_HEIGHT, color=(255, 255, 0), thickness=2):
|
||||
"""
|
||||
Creates an OCR region with a visible, resizable box on the screen.
|
||||
The color parameter allows customization (default yellow, blue for overlays).
|
||||
Allows setting custom color (RGB) and line thickness.
|
||||
"""
|
||||
|
||||
_ensure_qapplication()
|
||||
@ -60,7 +60,7 @@ def create_ocr_region(region_id, x=250, y=50, w=DEFAULT_WIDTH, h=DEFAULT_HEIGHT,
|
||||
regions[region_id] = {
|
||||
'bbox': [x, y, w, h],
|
||||
'raw_text': "",
|
||||
'widget': OCRRegionWidget(x, y, w, h, region_id, color)
|
||||
'widget': OCRRegionWidget(x, y, w, h, region_id, color, thickness)
|
||||
}
|
||||
collector_mutex.unlock()
|
||||
|
||||
@ -179,19 +179,19 @@ def find_word_positions(region_id, word, offset_x=0, offset_y=0, margin=5, ocr_e
|
||||
return []
|
||||
|
||||
|
||||
def draw_identification_boxes(region_id, positions, color=(0, 0, 255)):
|
||||
def draw_identification_boxes(region_id, positions, color=(0, 0, 255), thickness=2):
|
||||
"""
|
||||
Draws non-interactive rectangles at specified positions within the given OCR region.
|
||||
"""
|
||||
collector_mutex.lock()
|
||||
if region_id in regions and 'widget' in regions[region_id]:
|
||||
widget = regions[region_id]['widget']
|
||||
widget.set_draw_positions(positions, color)
|
||||
widget.set_draw_positions(positions, color, thickness)
|
||||
collector_mutex.unlock()
|
||||
|
||||
|
||||
class OCRRegionWidget(QWidget):
|
||||
def __init__(self, x, y, w, h, region_id, color):
|
||||
def __init__(self, x, y, w, h, region_id, color, thickness):
|
||||
super().__init__()
|
||||
|
||||
self.setGeometry(x, y, w, h)
|
||||
@ -203,6 +203,7 @@ class OCRRegionWidget(QWidget):
|
||||
self.selected_handle = None
|
||||
self.region_id = region_id
|
||||
self.box_color = QColor(*color)
|
||||
self.line_thickness = thickness
|
||||
self.draw_positions = []
|
||||
|
||||
self.show()
|
||||
@ -210,31 +211,23 @@ class OCRRegionWidget(QWidget):
|
||||
def paintEvent(self, event):
|
||||
painter = QPainter(self)
|
||||
pen = QPen(self.box_color)
|
||||
pen.setWidth(5)
|
||||
pen.setWidth(self.line_thickness)
|
||||
painter.setPen(pen)
|
||||
|
||||
# Draw main rectangle
|
||||
painter.drawRect(0, 0, self.width(), self.height())
|
||||
|
||||
# Draw detected word overlays
|
||||
pen.setWidth(2)
|
||||
pen.setColor(QColor(0, 0, 255))
|
||||
painter.setPen(pen)
|
||||
|
||||
for x, y, w, h in self.draw_positions:
|
||||
painter.drawRect(x, y, w, h)
|
||||
|
||||
# Draw resize handles
|
||||
painter.setBrush(self.box_color)
|
||||
for handle in self._resize_handles():
|
||||
painter.drawRect(handle)
|
||||
|
||||
def set_draw_positions(self, positions, color):
|
||||
def set_draw_positions(self, positions, color, thickness):
|
||||
"""
|
||||
Update the positions where identification boxes should be drawn.
|
||||
Updates the overlay positions and visual settings.
|
||||
"""
|
||||
self.draw_positions = positions
|
||||
self.box_color = QColor(*color)
|
||||
self.line_thickness = thickness
|
||||
self.update()
|
||||
|
||||
def _resize_handles(self):
|
||||
|
Reference in New Issue
Block a user