emilianavt / OpenSeeFace

Robust realtime face and facial landmark tracking on CPU with Unity integration
BSD 2-Clause "Simplified" License
1.44k stars 151 forks source link

Trying to open the wrong camera #71

Closed Melechtna closed 2 months ago

Melechtna commented 2 months ago
[ WARN:0@0.032] global cap_v4l.cpp:999 open VIDEOIO(V4L2:/dev/video0): can't open camera by index
[ERROR:0@0.140] global obsensor_uvc_stream_channel.cpp:158 getStreamChannelGroup Camera index out of range

The camera is on device video1, not 0, but there doesn't seem to be any way for me to modify what cv2 selects without straight up modifying the code. I read that setting it to -1 can help, but this runs the risk of it selecting the wrong input, but perhaps simply providing a flag in facetracker.py to select the camera would be a better option?

emilianavt commented 2 months ago

-1 is used for camera settings with DirectShow based video capture, so it's not relevant to Linux. On Linux, only OpenCV is supported and the camera ID you specify is passed through directly to the library. You can specify it with the -c argument. I don't think passing a device name is possible.

Melechtna commented 2 months ago

-1 is used for camera settings with DirectShow based video capture, so it's not relevant to Linux. On Linux, only OpenCV is supported and the camera ID you specify is passed through directly to the library. You can specify it with the -c argument. I don't think passing a device name is possible.

Well, I've been working on a script to launch VSeeFace with OpenSeeFace through lutris to make the experience virtually seamless.

#!/bin/bash

# Directory where OpenSeeFace is located
OPENSEEFACE_DIR=~/src/OpenSeeFace/

# Command to execute in the new terminal
CMD="cd $OPENSEEFACE_DIR && python -m venv . && source ./bin/activate && python facetracker.py"

# Function to open a new terminal and run the command
open_terminal() {
    if command -v konsole &> /dev/null; then
        konsole --noclose -e bash -c "$CMD"
    elif command -v gnome-terminal &> /dev/null; then
        gnome-terminal -- bash -c "$CMD; exec bash"
    elif command -v mate-terminal &> /dev/null; then
        mate-terminal -- bash -c "$CMD; exec bash"
    elif command -v lxterminal &> /dev/null; then
        lxterminal --command="$CMD"
    elif command -v xfce4-terminal &> /dev/null; then
        xfce4-terminal --hold --command="$CMD"
    elif command -v xterm &> /dev/null; then
        xterm -hold -e "$CMD"
    else
        echo "No compatible terminal emulator found. Please install one of the following: konsole, gnome-terminal, mate-terminal, lxterminal, xfce4-terminal, xterm."
        exit 1
    fi
}

# Open the terminal and run the command
open_terminal

is there a good way to make it go through each device until it gets a positive result you're aware of in bash? I could likely kick around a python script to perform the check and pass the correct variable to select the correct camera, or possibly even have it offer the user the choice of which camera to select, but I'd need a better understanding for how that -c flag works, if you could elaborate please?

Edit: after messing with it for a bit, seems it's as simple as simply passing the device number (I.E. -c 1 selects device video 1), so I likely just need to find a reliable way to scrape the cameras and pass this into the existing script, and prompt the user for which camera they want to use. Thank you.