Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Vishnu-Karthikeyan opened this issue Oct 18, 2024 · 6 comments

Comments

@Vishnu-Karthikeyan
Copy link

Vishnu-Karthikeyan commented Oct 18, 2024

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
Copy link
Member

Erol444 commented Oct 18, 2024

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

@Vishnu-Karthikeyan
Copy link
Author

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
Copy link
Member

Erol444 commented Oct 18, 2024

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

@Vishnu-Karthikeyan
Copy link
Author

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
Copy link
Author

Vishnu-Karthikeyan commented Oct 18, 2024

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
Copy link
Member

Erol444 commented Oct 19, 2024

@jakaskerl , could you try to repro this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants