I have an Oak4S that I connect using PoE to linux PC using a static IP address (192.168.1.220). I noticed that the examples use context manager using with in python that helps in clean resource cleanup. https://docs.luxonis.com/software-v3/depthai/examples/april_tags/april_tags/ However, for my application, I can't use the context manager and I initialize the device/ node/ pipeline using
self.device = dai.Device(target_device_info)
self.pipeline = dai.Pipeline(self.device)
self.hostCamera = self.pipeline.create(dai.node.Camera).build()
self.aprilTagNode = self.pipeline.create(dai.node.AprilTag)
self.resolution = (640, 480)
self.fps = 50
self.videoOutput = self.hostCamera.requestOutput(size=self.resolution, fps=self.fps)
self.videoOutput.link(self.aprilTagNode.inputImage)
self.passthroughOutputQueue = self.aprilTagNode.passthroughInputImage.createOutputQueue()
self.AprilTagNodeOutQueue = self.aprilTagNode.out.createOutputQueue()
# Image manipulation node to convert RGB image to GRAY to feed to Script node self.manipNode = self.pipeline.create(dai.node.ImageManip) self.manipNode.initialConfig.setFrameType(dai.ImgFrame.Type.GRAY8) self.videoOutput.link(self.manipNode.inputImage) #Input set to the manipNode
#Script node for Laplacian variance check self.scriptNode = self.pipeline.create(dai.node.Script)
self.manipNode.out.link(self.scriptNode.inputs["image"]) #manipNode output is input for the Script node
self.lensCheckQueue = self.scriptNode.outputs["laplacianVar"].createOutputQueue() self.scriptNode.setScript("""import cv2import struct
out = Buffer(4)
PACK = struct.Struct("f")
while True:
grayImage = node.io['image'].get().getCvFrame()
laplacianVar = cv2.Laplacian(grayImage, cv2.CV_64F).var()
out.setData(PACK.pack(laplacianVar))
node.io['laplacianVar'].send(out)""")
self.pipeline.start()
This is how I read data from the camera in a while loop. Please ignore the indentation issue.
while True:
aprilTagMessage = self.AprilTagNodeOutQueue.tryGet()
if aprilTagMessage is None:
time.sleep(0.002) # tiny yield so SIGINT handler runs
continue
self.image = self.passthroughOutputQueue.tryGet()
if self.image is None:
time.sleep(0.002) # tiny yield so SIGINT handler runs
continue
imageQuality = self.lensCheckQueue.tryGet()
if imageQuality is None:
time.sleep(0.002) # tiny yield so SIGINT handler runs
continue
Upon CTRL+C, I handle the Keyboard interrupt and call below in order to close the connection gracefully.
self.hostCamera.stopPipeline()
self.device.close()
The same script can run multiple times when the camera does not detect any april tags. But if it detects april tags, it fails to run next time and oakctl list says No devices found.
I need to power cycle the device in order to make it work again.
Below is the oakctl list output when its working fine.
+---+---------------+-------------------------+---------------+------------------------+---------------+-------+
| # | Serial Number | Device | Connection | OS | Agent Version | Setup |
+==============================================================================================================+
| 1 | Hidden intentionally | Luxonis, Inc. OAK4-S R9 | 192.168.1.220 | Luxonis OS RVC4 1.24.0 | 0.17.0 | OK |
+---+---------------+-------------------------+---------------+------------------------+---------------+-------+
Please help!