From 24d531af6a1d91129a84d32415957a0023b3b1a9 Mon Sep 17 00:00:00 2001
From: gg
Date: Thu, 6 Feb 2025 13:49:03 +0100
Subject: [PATCH 1/2] smart camera ok memory tbt
---
src/components/hikrobot_sc/hikrobot_sc.py | 67 ++++++++++++++---------
1 file changed, 42 insertions(+), 25 deletions(-)
diff --git a/src/components/hikrobot_sc/hikrobot_sc.py b/src/components/hikrobot_sc/hikrobot_sc.py
index 880bdf6..4b8d6d1 100644
--- a/src/components/hikrobot_sc/hikrobot_sc.py
+++ b/src/components/hikrobot_sc/hikrobot_sc.py
@@ -19,6 +19,9 @@ class HikrobotSmartCamera(Component):
self.simulate = "--sim-camera" in sys.argv
self.num_cameras=1
self.connected = False
+ self.ok_memory = True
+ self.ok_frames = []
+ self.ok_results =[]
def config_changed(self):
self.connected = False
@@ -99,32 +102,42 @@ class HikrobotSmartCamera(Component):
for cam_idx in range(self.num_cameras):
cam = self.cam_list[cam_idx]
self.log.info(f"GET FRAME CAMERA # {cam_idx}")
-
- # Trigger acquisition & test execution
- nRet = mv_lib.MV_VS_SetCommandValue(cam["handle"], b"AcquisitionStart")
- if nRet != MV_VS_OK:
- self.log.error(f"CAM{cam_idx} AcquisitionStart failed! [{nRet&0xFFFFFFFF:#x}]")
- self.connected = False
- # get frame
- frame_res = MV_VS_GetFrame(cam["handle"])
- if frame_res is not None:
- res = frame_res["res"]["ScDeviceSolutionRunningResult"]
- frame = frame_res["frame"]
- # rotate frame
- if rot[cam_idx] == "1":
- frame = cv2.rotate(frame, cv2.ROTATE_90_CLOCKWISE)
- if rot[cam_idx] == "2":
- frame = cv2.rotate(frame, cv2.ROTATE_90_COUNTERCLOCKWISE)
- if rot[cam_idx] == "3":
- frame = cv2.rotate(frame, cv2.ROTATE_180)
-
- if concat_frame is None:
- concat_frame = copy.deepcopy(frame)
- else:
- concat_frame = cv2.hconcat([concat_frame, frame])
- concat_results.append(not res)
+ if self.ok_results[cam_idx]:
+ # keep last good result
+ frame = self.ok_frames[cam_idx]
+ res = False
else:
- self.connected = False
+ # Trigger acquisition & test execution
+ nRet = mv_lib.MV_VS_SetCommandValue(cam["handle"], b"AcquisitionStart")
+ if nRet != MV_VS_OK:
+ self.log.error(f"CAM{cam_idx} AcquisitionStart failed! [{nRet&0xFFFFFFFF:#x}]")
+ self.connected = False
+ frame_res = None
+ else:
+ # get frame
+ frame_res = MV_VS_GetFrame(cam["handle"])
+
+ if frame_res is not None:
+ res = frame_res["res"]["ScDeviceSolutionRunningResult"]
+ frame = frame_res["frame"]
+ # rotate frame
+ if rot[cam_idx] == "1":
+ frame = cv2.rotate(frame, cv2.ROTATE_90_CLOCKWISE)
+ if rot[cam_idx] == "2":
+ frame = cv2.rotate(frame, cv2.ROTATE_90_COUNTERCLOCKWISE)
+ if rot[cam_idx] == "3":
+ frame = cv2.rotate(frame, cv2.ROTATE_180)
+ else:
+ self.connected = False
+ if concat_frame is None:
+ concat_frame = copy.deepcopy(frame)
+ else:
+ concat_frame = cv2.hconcat([concat_frame, frame])
+ concat_results.append(not res)
+ if res:
+ self.ok_results[cam_idx] = True
+ self.ok_frames[cam_idx] = copy.deepcopy(frame)
+
super()._get([concat_frame, concat_results])
def resume(self):
@@ -132,6 +145,10 @@ class HikrobotSmartCamera(Component):
if not self.connected:
self.config_changed()
if self.connected:
+ # init OK result memory
+ self.ok_frames = [None for n in range(self.num_cameras)]
+ self.ok_results = [False for n in range(self.num_cameras)]
+
if len(self.cam_list) == self.num_cameras:
# Dummy acquisition for each camera to avoid reading past images
for cam_idx in range(self.num_cameras):
From d6c0534db62d37b5590ac354a9110605d8a6e0fc Mon Sep 17 00:00:00 2001
From: gg
Date: Thu, 6 Feb 2025 15:05:50 +0100
Subject: [PATCH 2/2] smart camera ok memory tbt
---
src/components/hikrobot_sc/hikrobot_sc.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/components/hikrobot_sc/hikrobot_sc.py b/src/components/hikrobot_sc/hikrobot_sc.py
index 4b8d6d1..1b643e0 100644
--- a/src/components/hikrobot_sc/hikrobot_sc.py
+++ b/src/components/hikrobot_sc/hikrobot_sc.py
@@ -134,11 +134,11 @@ class HikrobotSmartCamera(Component):
else:
concat_frame = cv2.hconcat([concat_frame, frame])
concat_results.append(not res)
- if res:
+ if not res:
self.ok_results[cam_idx] = True
self.ok_frames[cam_idx] = copy.deepcopy(frame)
- super()._get([concat_frame, concat_results])
+ super()._get([concat_frame, self.ok_results])
def resume(self):
self.log.info(f"RESUMING")