Refined Identification Node

This commit is contained in:
Nicole Rappe 2025-02-26 01:27:08 -07:00
parent 981d5cb573
commit c10fc1ba6d
2 changed files with 22 additions and 4 deletions

View File

@ -3,7 +3,7 @@
Identification Overlay Node: Identification Overlay Node:
- Creates an OCR region in data_collector with a blue overlay. - Creates an OCR region in data_collector with a blue overlay.
- Detects instances of a specified word and draws adjustable overlays. - Detects instances of a specified word and draws adjustable overlays.
- Users can configure offset and margin dynamically. - Users can configure offset, margin, and polling frequency dynamically.
""" """
import re import re
@ -22,8 +22,9 @@ class IdentificationOverlayNode(BaseNode):
# User-configurable options # User-configurable options
self.add_text_input("search_term", "Search Term", text="Aibatt") 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("offset_value", "Offset Value (X,Y)", text="0,0") # X,Y Offset
self.add_text_input("margin", "Margin", text="5") # New input self.add_text_input("margin", "Margin", text="5") # Box Margin
self.add_text_input("polling_freq", "Polling Frequency (ms)", text="500") # New input
self.region_id = "identification_overlay" 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.create_ocr_region(self.region_id, x=250, y=50, w=300, h=200, color=(0, 0, 255))
@ -34,7 +35,21 @@ class IdentificationOverlayNode(BaseNode):
# Timer for updating overlays # Timer for updating overlays
self.timer = QTimer() self.timer = QTimer()
self.timer.timeout.connect(self.update_overlay) self.timer.timeout.connect(self.update_overlay)
self.timer.start(500) # Update every 500ms
# Set initial polling frequency
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(100, int(polling_text)) # Minimum 100ms to avoid overloading
except ValueError:
polling_interval = 500 # Default to 500ms
self.timer.start(polling_interval)
def update_overlay(self): def update_overlay(self):
""" """
@ -44,6 +59,9 @@ class IdentificationOverlayNode(BaseNode):
offset_text = self.get_property("offset_value") offset_text = self.get_property("offset_value")
margin_text = self.get_property("margin") margin_text = self.get_property("margin")
# Read and apply polling frequency updates
self.update_polling_frequency()
# Parse user-defined offset # Parse user-defined offset
try: try:
offset_x, offset_y = map(int, offset_text.split(",")) offset_x, offset_y = map(int, offset_text.split(","))