luxonis / depthai-python

DepthAI Python Library
MIT License
359 stars 193 forks source link

IR led not switching ON using standalone mode (http stream) in "OAK-D Pro W PoE" #1080

Open Vishnu-Karthikeyan opened 2 weeks ago

Vishnu-Karthikeyan commented 2 weeks ago

Am creating a dap package and installing it to OAK-D Pro W PoE using device manager. Am getting the video feed on link, but the IR led does not switch on. Tested it on dark room environment. Checked IR led on phone cam nut no glow.

Following is the code.

#!/usr/bin/env python3

import depthai as dai
import time

pipeline = dai.Pipeline()

monoRight = pipeline.create(dai.node.MonoCamera)
monoRight.setCamera("right")
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
monoRight.setFps(120)

jpeg = pipeline.create(dai.node.VideoEncoder)
jpeg.setDefaultProfilePreset(monoRight.getFps(), dai.VideoEncoderProperties.Profile.MJPEG)
jpeg.setQuality(100)

monoRight.out.link(jpeg.input)

script = pipeline.create(dai.node.Script)
script.setProcessor(dai.ProcessorType.LEON_CSS)

script.setScript("""
    import time
    import socket
    import fcntl
    import struct
    from socketserver import ThreadingMixIn
    from http.server import BaseHTTPRequestHandler, HTTPServer
    Device.setIrFloodLightIntensity(1)
    PORT = 80

    def get_ip_address(ifname):
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        return socket.inet_ntoa(fcntl.ioctl(
            s.fileno(),
            -1071617759,  # SIOCGIFADDR
            struct.pack('256s', ifname[:15].encode())
        )[20:24])

    class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):
        pass

    class HTTPHandler(BaseHTTPRequestHandler):
        def do_GET(self):
            if self.path == '/':
                self.send_response(200)
                self.end_headers()
                self.wfile.write(b'<h1 style="text-align: center;">OAK TEST</h1><p style="text-align: center;">TEST</p><p style="text-align: center;">Click <a href="img">here</a> for Stream</p>')             
            elif self.path == '/img':
                try:
                    self.send_response(200)
                    self.send_header('Content-type', 'multipart/x-mixed-replace; boundary=--jpgboundary')
                    self.end_headers()
                    fpsCounter = 0
                    timeCounter = time.time()

                    while True:

                        jpegImage = node.io['jpeg'].get()
                        self.wfile.write("--jpgboundary".encode())
                        self.wfile.write(bytes([13, 10]))
                        self.send_header('Content-type', 'image/jpeg')
                        self.send_header('Content-length', str(len(jpegImage.getData())))
                        self.end_headers()
                        self.wfile.write(jpegImage.getData())
                        self.end_headers()

                        fpsCounter = fpsCounter + 1
                        if time.time() - timeCounter > 1:
                            node.warn(f'FPS: {fpsCounter}')
                            fpsCounter = 0
                            timeCounter = time.time()
                except Exception as ex:
                    node.warn(str(ex))

    with ThreadingSimpleServer(("", PORT), HTTPHandler) as httpd:
        node.warn(f"Serving at {get_ip_address('re0')}:{PORT}")
        httpd.serve_forever()
""")

jpeg.bitstream.link(script.inputs['jpeg'])

(f, bl) = dai.DeviceBootloader.getFirstAvailableDevice()
bootloader = dai.DeviceBootloader(bl)
bootloader.saveDepthaiApplicationPackage(pipeline=pipeline, path="D:/mono_ir_led.dap")
Erol444 commented 2 weeks ago

Hi @Vishnu-Karthikeyan , Does it also not turn on when not in standalone mode (so just standard/peripheral mode)?

Vishnu-Karthikeyan commented 2 weeks ago

I tried using the following standard preview example. The IR led turns on as soon as feed windows shows up and then gets turned off automatically within 3-4 seconds, the window feed however continues.

!/usr/bin/env python3

import cv2 import depthai as dai

Create pipeline

pipeline = dai.Pipeline()

Define sources and outputs

monoLeft = pipeline.create(dai.node.MonoCamera) monoRight = pipeline.create(dai.node.MonoCamera) xoutLeft = pipeline.create(dai.node.XLinkOut) xoutRight = pipeline.create(dai.node.XLinkOut)

xoutLeft.setStreamName('left') xoutRight.setStreamName('right')

Properties

monoLeft.setCamera("left") monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P) monoRight.setCamera("right") monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)

Linking

monoRight.out.link(xoutRight.input) monoLeft.out.link(xoutLeft.input)

Connect to device and start pipeline

with dai.Device(pipeline) as device: device.setIrFloodLightIntensity(0.9) # in %, from 0 to 1

Output queues will be used to get the grayscale frames from the outputs defined above

qLeft = device.getOutputQueue(name="left", maxSize=4, blocking=False)
qRight = device.getOutputQueue(name="right", maxSize=4, blocking=False)

while True:
    device.setIrFloodLightIntensity(0.9) # in %, from 0 to 1
    # Instead of get (blocking), we use tryGet (non-blocking) which will return the available data or None otherwise
    inLeft = qLeft.tryGet()
    inRight = qRight.tryGet()

    if inLeft is not None:
        cv2.imshow("left", inLeft.getCvFrame())

    if inRight is not None:
        cv2.imshow("right", inRight.getCvFrame())

    if cv2.waitKey(1) == ord('q'):
        break
Erol444 commented 2 weeks ago

@Vishnu-Karthikeyan I mean setting it once inside the Scirpt node (not inside a while True loop). Does that work?

Vishnu-Karthikeyan commented 2 weeks ago

Yes i tried that first itself. It glowed for first 3 seconds then got turned off by itself, I thought it was executing only once in program so kept it in while loop later (the one that i posted here). Anyways both the methods gave same result.

Vishnu-Karthikeyan commented 2 weeks ago

Following is the code i used for inside script led intensity setting

#!/usr/bin/env python3

import cv2
import depthai as dai

# Create pipeline
pipeline = dai.Pipeline()

# Define sources and outputs
monoLeft = pipeline.create(dai.node.MonoCamera)
monoRight = pipeline.create(dai.node.MonoCamera)
xoutLeft = pipeline.create(dai.node.XLinkOut)
xoutRight = pipeline.create(dai.node.XLinkOut)

xoutLeft.setStreamName('left')
xoutRight.setStreamName('right')

# Properties
monoLeft.setCamera("left")
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
monoRight.setCamera("right")
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)

# Create a Script node
script = pipeline.create(dai.node.Script)
script.setProcessor(dai.ProcessorType.LEON_CSS)
script.setScript("""

    Device.setIrFloodLightIntensity(0.9) 

""")

# Linking
monoRight.out.link(xoutRight.input)
monoLeft.out.link(xoutLeft.input)

# Connect to device and start pipeline
with dai.Device(pipeline) as device:
    # Output queues will be used to get the grayscale frames from the outputs defined above
    qLeft = device.getOutputQueue(name="left", maxSize=4, blocking=False)
    qRight = device.getOutputQueue(name="right", maxSize=4, blocking=False)

    while True:
        # Instead of get (blocking), we use tryGet (non-blocking) which will return the available data or None otherwise
        inLeft = qLeft.tryGet()
        inRight = qRight.tryGet()

        if inLeft is not None:
            cv2.imshow("left", inLeft.getCvFrame())

        if inRight is not None:
            cv2.imshow("right", inRight.getCvFrame())

        if cv2.waitKey(1) == ord('q'):
            break

@Vishnu-Karthikeyan I mean setting it once inside the Scirpt node (not inside a while True loop). Does that work?

Erol444 commented 2 weeks ago

@jakaskerl , could you try to repro this?

jakaskerl commented 1 week ago

@Vishnu-Karthikeyan Does it work in normal operation (setting it on host using device.setIrFloodLightBrightness(0.9)). I tested on Pro W POE and it does not work in any mode. Tested the same code on it's USB variant and had no issue both inside Script as well as on host.

Vishnu-Karthikeyan commented 1 week ago

Yes i tried the following methods 1) with dai.Device(pipeline) as device: ____device.setIrFloodLightBrightness(0.9) in host mode 2) Device.setIrFloodLightIntensity(0.9) within script in host mode 3) Device.setIrFloodLightIntensity(0.9) within script in standalone mode

RESULT: The ir led light switches on for first 2-3 seconds and turns off automatically. No problems with video stream however.

Vishnu-Karthikeyan commented 3 days ago

Do we have any solution for this ?

Erol444 commented 3 days ago

I apologize for the delay @Vishnu-Karthikeyan. The code above works as expected for me. image So very likely there's a hardware issue (which I haven't seen yet for LED). Please send an email to support@luxonis.com together with this ticket URL and we'll replace the device asap.

Vishnu-Karthikeyan commented 3 days ago

Thanks @Erol444, I have 2 unit of same hardware. But same problem for both which are installed at two different sites. Do you think this would still be a hardware problem. I think @jakaskerl also has the same problem as mentioned in his comment.

Erol444 commented 2 days ago

@Vishnu-Karthikeyan that's interesting.. Are you using the latest depthai? Are you powering the device with sufficient POE injector/switch?