#!/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 and margin dynamically. """ import re from OdenGraphQt import BaseNode from PyQt5.QtWidgets import QMessageBox from PyQt5.QtCore import QTimer from Modules import data_manager, data_collector class IdentificationOverlayNode(BaseNode): __identifier__ = "bunny-lab.io.identification_overlay_node" NODE_NAME = "Identification Overlay" def __init__(self): super(IdentificationOverlayNode, self).__init__() # User-configurable options self.add_text_input("search_term", "Search Term", text="Aibatt") self.add_text_input("offset_value", "Offset Value (X,Y)", text="0,0") # New input self.add_text_input("margin", "Margin", text="5") # New input 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)) data_collector.start_collector() self.set_name("Identification Overlay") # Timer for updating overlays self.timer = QTimer() self.timer.timeout.connect(self.update_overlay) self.timer.start(500) # Update every 500ms 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") # 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 # Parse user-defined margin try: margin = int(margin_text) except ValueError: margin = 5 # Default margin if invalid input if not search_term: return # Get detected word positions detected_positions = data_collector.find_word_positions(self.region_id, search_term, offset_x, offset_y, margin) # Draw detected word boxes data_collector.draw_identification_boxes(self.region_id, detected_positions, color=(0, 0, 255))