Can I Use My Laptop Camera Instead of an External Camera for Arduino Q Board Human Detection Project?

Hello everyone,

I am currently working on a human detection interface project using:

  • Arduino Q board
  • My laptop
  • App Lab (for interface development)

Instead of using an external camera module connected to the Arduino, I would like to know:

:backhand_index_pointing_right: Can I use my laptop’s built-in camera to perform human detection and then send signals/data to the Arduino Q board?

thinking aloud here - totally untested - this is how I would think about your problem:

The Arduino UNO Q runs Linux and executes your Python process locally. The VideoObjectDetection component relies on the Linux video stack when you plug a USB webcam into the UNO Q, the camera is enumerated by the Linux kernel on the board itself, and frames are captured locally.

When you connect the UNO Q to a Mac or PC over USB, that link is a USB device connection, not a USB host connection in the reverse direction. Your computer acts as USB host and the UNO Q acts as a USB device. Standard laptops do not expose their built-in webcam as a USB device that can be consumed by another machine over a USB cable. The internal camera is attached to the host’s internal bus and is only accessible through the host operating system. TYo my knowledge there is no standard mechanism that makes the Mac or PC appear as a USB UVC camera to the UNO Q.

➜ Thus I would conclude that you can't directly “reuse” the built-in webcam of the Mac or PC over the same USB cable that is linked to the UNO Q.

So now we need to dig a bit more in the code to see where the USB Webcam is actually chosen. So you search GitHub and have a look at the video_objectdetection class

they mention live stream. So this might be something to explore/

Source code for the brick is available and you can see it does rely on a directly accessible camera object

The Camera peripheral source code is also available and there is a file in there called IPCamera which sounds interesting as it inherits from BaseCamera

As the VideoObjectDetection constructor accepts a camera argument of type BaseCamera and since IPCamera inherits from BaseCamera, it satisfies that interface.

That opens up something to explore : If you want to use the computer’s webcam as a source for the UNO Q, an approach could be to have a program on the computer that streams video over IP. The UNO Q, being a Linux machine, can then connect as a client to that network stream and read frames from a URL instead of from /dev/video0 and as the IPCamera class is designed to consume a remote stream (say HTTP or RTSP) then with minimum code modification I would think you could instantiate IPCamera with the appropriate stream URL and pass it explicitly...

You just now need to find a good example to work from and there is a recent example from a French member of the forum @philippe86220 here) where we see he depends on the default behavior:

Because he does not pass a camera argument, it creates a local Camera() internally (which will find the one on the USB bus).

So what I would test if I wanted to use an IPCamera instead, I would just import it from arduino.app_peripherals.camera, instantiate it with the URL of my network stream, and pass it explicitly to VideoObjectDetection.

Conceptually, the only change is replacing the implicit Camera() with something like:

from arduino.app_utils import App, Bridge
from arduino.app_bricks.video_objectdetection import VideoObjectDetection
from arduino.app_peripherals.camera import IPCamera
import time
import threading

# Replace with the actual stream URL exposed by your Mac/PC
camera = IPCamera("http://192.168.1.100:8080/video")

video_detector = VideoObjectDetection(
  camera=camera,
  confidence=0.4,
  debounce_sec=1.5
)
...

I think software like VLC Media Player can capture your Mac or PC webcam and publish it as an RTSP stream over the local network so that would be it the missing link to expose your computer's camera to the UNO-Q as long as it sits on the same LAN.

I have no clue if that works but worth exploring. Direct benefit of open source is that everything you need is just one GitHub click away !

Something to note is that Arduino App Lab (or to be more specific, its Arduino App CLI helper tool) currently uses version 0.6.4 of the arduino Python package. The IP camera functionality mentioned by @J-M-L was added in version 0.7.0 of the package. So it won't be available until the next release of Arduino App CLI comes out.

Version 0.8.3 of Arduino App CLI has now been released, which brings version 0.7.3 of the Bricks and arduino Python package. Arduino App Lab will offer to install the update the next time you use it. After completing the update, you will be able to use these new features in your Arduino Apps.

There are some examples here: