Browse Source

add: Bildbearbeitung in camera_playground

Your Name 3 months ago
parent
commit
764044d4e9

+ 4 - 2
playgrounds/camera_playground.py

@@ -6,14 +6,16 @@ def main():
     picam2.configure(picam2.create_preview_configuration(main={"format": "BGR888", "size": (640, 480)}))
     picam2.start()
 
-    x, y, w, h = [290, 260, 240, 170]
+
+    x, y, w, h = [290, 140, 240, 170]
 
     print("Type 's' to save a still image. Type 'q' to quit.")
     while True:
         cmd = input("Command [s/q]: ").strip().lower()
         if cmd == 's':
             frame = picam2.capture_array()
-            frame = frame[y:y+h, x:x+w]
+            # Draw a green rectangle on the image
+            cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
             cv2.imwrite("still_image.jpg", frame)
             print("Saved still_image.jpg")
         elif cmd == 'q':

+ 9 - 9
playgrounds/integration_test.py

@@ -107,15 +107,15 @@ class LoaderSystem:
     async def _loader_loop(self):
         while True:
 
-            await wait_for_enter()
-            # Feeding with MagDistributor
-            ###########################
-            self.logger.info("Homing the Magazin Distributor Axis...")
-            await self.mag_distributor.home()
-            self.logger.info("Picking up a cell from magazine and placing it into feeder using MagDistributor...")
-            self.mag_distributor.mag_to_feeder()
-            await self.feeder_queue.put(1)
-            self.logger.info("Done.")
+            # await wait_for_enter()
+            # # Feeding with MagDistributor
+            # ###########################
+            # self.logger.info("Homing the Magazin Distributor Axis...")
+            # await self.mag_distributor.home()
+            # self.logger.info("Picking up a cell from magazine and placing it into feeder using MagDistributor...")
+            # self.mag_distributor.mag_to_feeder()
+            # await self.feeder_queue.put(1)
+            # self.logger.info("Done.")
 
             await wait_for_enter()
             # Prepare Feeder Cell

+ 1 - 1
robot_control/config/config.yaml

@@ -101,7 +101,7 @@ vision:
   frame_rate: 30
   exposure: 0.1
   gain: 1.0
-  bbox: [290, 260, 240, 170]  # (x, y, width, height)
+  bbox: [290, 140, 240, 170]  # (x, y, width, height)
 
 vacuum:
   min_pressure_bar: 0.13

+ 1 - 0
robot_control/requirements.txt

@@ -12,4 +12,5 @@ httpx==0.25.0
 paho-mqtt<2
 pyserial-asyncio>=0.6
 pigpio
+picamera2
 smbus2

+ 2 - 2
robot_control/src/robot/controller.py

@@ -465,8 +465,8 @@ class RobotController:
         """
         io_conf = self.config.gpio
         while not self.next_cell_id:
-            #self.next_cell_id = self.vision.read_datamatrix() commented out for test purposes Y
-            self.next_cell_id = 1
+            self.next_cell_id = self.vision.read_datamatrix() # commented out for test purposes Y
+            # self.next_cell_id = 1
             if not self.next_cell_id:
                 logger.debug("No cell detected")
                 return False  # No cell detected

+ 9 - 2
robot_control/src/vision/datamatrix.py

@@ -82,8 +82,15 @@ class DataMatrixReader:
         if self.bbox:
             x, y, w, h = self.bbox
             frame = frame[y:y+h, x:x+w]
-        
-        decoded = decode(frame)
+            # Convert to grayscale, apply histogram equalization, blur, and adaptive thresholding
+            frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
+            frame = cv2.equalizeHist(frame)
+            # frame = cv2.medianBlur(frame, 3)
+            # frame = cv2.adaptiveThreshold(frame, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
+            #           cv2.THRESH_BINARY, 21, 2)
+            # kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3))
+            # frame = cv2.morphologyEx(frame, cv2.MORPH_CLOSE, kernel)
+            decoded = decode(frame, timeout=5000, gap_size=20, shape="square", max_count=1)
         if not decoded:
             logger.info("No datamatrix found")
             return None

BIN
still_image.jpg