0% found this document useful (0 votes)
7 views

roiiii

The CameraRoiInterface class manages camera frames and regions of interest (ROI) in a graphical interface. It initializes the frame, restores ROI from a database if available, updates the camera list, and displays the current camera frame on a canvas. The class handles errors during ROI restoration and camera list updates, ensuring a smooth user experience.

Uploaded by

elimelech03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

roiiii

The CameraRoiInterface class manages camera frames and regions of interest (ROI) in a graphical interface. It initializes the frame, restores ROI from a database if available, updates the camera list, and displays the current camera frame on a canvas. The class handles errors during ROI restoration and camera list updates, ensuring a smooth user experience.

Uploaded by

elimelech03
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

class CameraRoiInterface(CTkFrame):

def __init__(self, master, root_width=None, root_height=None, **kwargs):


# ... (keep existing initialization code until self.camera_manager =
CameraStateManager())

# Add this after self.camera_manager initialization


self._initialized = False
self.pending_roi_restore = False

def initialize_frame_and_roi(self):
"""Initialize the frame and restore ROI if available"""
# Clear any existing ROI
if hasattr(self, 'canvas'):
self.canvas.delete("all")

# If we have a current camera, try to restore its ROI


if self.current_camera:
# Try to get ROI data from the database
try:
roi_data =
self.obj_Core.obj_Camera.get_roi_coordinates(self.current_camera)
if roi_data and not roi_data.get("str_error_msg"):
coordinates = roi_data.get("coordinates", {})
if coordinates:
# Extract coordinates
x1, y1 = coordinates["point1"]
x2, y2 = coordinates["point4"]
self.roi_coords = (int(x1), int(y1), int(x2), int(y2))
self.roi_selected = True
self._roi_state[self.current_camera] = {
"coords": self.roi_coords,
"selected": True
}
self.pending_roi_restore = True
except Exception as e:
print(f"Error restoring ROI from database: {e}")

if not self._initialized:
# Create a message on the canvas
canvas_width = self.canvas.winfo_width()
canvas_height = self.canvas.winfo_height()
self.canvas.create_text(
canvas_width / 2,
canvas_height / 2,
font=("Arial", 14),
fill="#666666"
)
self._initialized = True

def update_camera_list(self, new_camera_list):


"""Update the camera list and dropdown with new values from database"""
try:
self.camera_list = new_camera_list
print("Updating camera list with:", new_camera_list)

# Update dropdown values with checkbox symbols


self.dropdown_values = [f"☐ {camera}" for camera in
self.camera_list.keys()]
# If we have a current camera, restore its state
if self.current_camera in self.camera_list:
self.change_camera(self.current_camera)
elif self.camera_list:
# Select first camera if current_camera is not in list
first_camera = list(self.camera_list.keys())[0]
self.change_camera(first_camera)

if not self.dropdown_values:
self.status_label.configure(text="No cameras available",
text_color="#FF0000")

except Exception as e:
print(f"Error updating camera list: {e}")
self.status_label.configure(text="Error updating camera list",
text_color="#FF0000")

def display_frame(self):
"""Display the current frame on the canvas"""
if self.frame is not None:
# Get current canvas dimensions
canvas_width = self.canvas.winfo_width()
canvas_height = self.canvas.winfo_height()

# Ensure frame matches canvas size


if self.frame.shape[1] != canvas_width or self.frame.shape[0] !=
canvas_height:
self.frame = cv2.resize(self.frame, (canvas_width, canvas_height),
interpolation=cv2.INTER_LANCZOS4)

frame_rgb = cv2.cvtColor(self.frame, cv2.COLOR_BGR2RGB)


image = Image.fromarray(frame_rgb)
photo = ImageTk.PhotoImage(image=image)
self.canvas.delete("all") # Clear canvas before creating new image
self.canvas.create_image(0, 0, image=photo, anchor="nw")
self.canvas.image = photo

# If there's a pending ROI restore, do it now


if self.pending_roi_restore and self.roi_selected and self.roi_coords:
self.restore_roi()
self.pending_roi_restore = False

You might also like