sieuwe1 / PS4-eye-camera-for-linux-with-python-and-OpenCV

Use the PS4 camera as an cheap yet powerfull 3D depth and RGB camera for use with OpenCV and python in Linux
49 stars 15 forks source link

Scripts seemingly hang doing nothing #1

Closed parkerlreed closed 3 years ago

parkerlreed commented 3 years ago

Arch Linux opencv 4.5.2-2

Video feed from /dev/video2 works

image

Whenever I try the scripts they hang on no output and I get this after Ctrl C

[parker@ryzen5 OpenCV_viewer]$ python View_RGB.py   
^C
(python:11650): GStreamer-CRITICAL **: 16:37:32.692: 
Trying to dispose element pipeline0, but it is in PAUSED instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.

[ WARN:0] global /build/opencv/src/opencv-4.5.2/modules/videoio/src/cap_gstreamer.cpp (1034) open OpenCV | GStreamer warning: unable to start pipeline

(python:11650): GStreamer-CRITICAL **: 16:37:32.692: 
Trying to dispose element videoconvert0, but it is in PLAYING instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.

[ WARN:0] global /build/opencv/src/opencv-4.5.2/modules/videoio/src/cap_gstreamer.cpp (597) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

(python:11650): GStreamer-CRITICAL **: 16:37:32.692: 
Trying to dispose element appsink0, but it is in READY instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.

[ WARN:0] global /build/opencv/src/opencv-4.5.2/modules/videoio/src/cap_v4l.cpp (890) open VIDEOIO(V4L2:/dev/video2): can't open camera by index
Traceback (most recent call last):
  File "/home/parker/build/PS4-eye-camera-for-linux-with-python-and-OpenCV/OpenCV_viewer/View_RGB.py", line 5, in <module>
    cap = cv2.VideoCapture(2)
KeyboardInterrupt
parkerlreed commented 3 years ago

Was missing gst-libav. Got me a little more output but still nothing visually.

[parker@ryzen5 OpenCV_viewer]$ python View_RGB.py   
[ WARN:0] global /build/opencv/src/opencv-4.5.2/modules/videoio/src/cap_gstreamer.cpp (1081) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
^C
(python:11975): GStreamer-CRITICAL **: 16:40:09.228: 
Trying to dispose element videoconvert0, but it is in PLAYING instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.

(python:11975): GStreamer-CRITICAL **: 16:40:09.228: 
Trying to dispose element pipeline0, but it is in PAUSED instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.

[ WARN:0] global /build/opencv/src/opencv-4.5.2/modules/videoio/src/cap_gstreamer.cpp (632) startPipeline OpenCV | GStreamer warning: unable to start pipeline
Traceback (most recent call last):
  File "/home/parker/build/PS4-eye-camera-for-linux-with-python-and-OpenCV/OpenCV_viewer/View_RGB.py", line 7, in <module>
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, 3448)
KeyboardInterrupt
[ WARN:0] global /build/opencv/src/opencv-4.5.2/modules/videoio/src/cap_gstreamer.cpp (597) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created

(python:11975): GStreamer-CRITICAL **: 16:40:09.236: 
Trying to dispose element appsink0, but it is in READY instead of the NULL state.
You need to explicitly set elements to the NULL state before
dropping the final reference, to allow them to clean up.
This problem may also be caused by a refcounting bug in the
application or some element.
parkerlreed commented 3 years ago

My V2 camera is seemingly initializing as V1...

[parker@ryzen5 Firmware_loader]$ sudo python ps4eye_init.py 
PS4 camera Version 1 already initialized

Does not come up with the V2 USB ID. Could this be causing issues?

sieuwe1 commented 3 years ago

Hi

That your V2 camera is initializing as a v1 is not an issue. I forgot to remove that part from the code. Previous there where 2 firmware versions. However now there is only 1 that works for v1 and V2. So it does not matter. Also because of that there is only one device id which is the same for v1 and V2. The fact that you can use it in Linux means that it is not a firmware problem.

It is a gstreamer problem. Sometimes if you don't close the pipeline correctly then gstreamer will still keep the pipeline open. Just try to restart your computer that could solve your issue.

Also make sure you use the correct opencv version.

As last maybe try reinstalling gstreamer.

I did not have this issue so I don't have a exact answer for you.

Greetings

Sieuwe

parkerlreed commented 3 years ago

Thanks. Yeah just using the latest version of both

opencv 4.5.2-2 gst-libav 1.18.4-1 gst-plugin-gtk 1.18.4-2 gst-plugin-pipewire 1:0.3.25-1 gst-plugins-bad 1.18.4-4 gst-plugins-bad-libs 1.18.4-4 gst-plugins-base 1.18.4-1 gst-plugins-base-libs 1.18.4-1 gst-plugins-good 1.18.4-2

When you were using this, was it an older opencv?

parkerlreed commented 3 years ago

Oh ok then. Tried on another computer. Worked right away. Seems the lighting isn't being picked up the best. Will have to play with it. Thanks.

image

parkerlreed commented 3 years ago

I assume to get better lighting I have to lower the resolution and adjust the cropping values?

parkerlreed commented 3 years ago

Or alternatively drop the FPS. I'll poke around to see how to do that in OpenCV/Python. Thanks for the help!

parkerlreed commented 3 years ago

Much better with

cap.set(cv2.CAP_PROP_FPS, 15)
sieuwe1 commented 3 years ago

Hi

Different lighting conditions is one problem I also faced while working with this camera. The thing is that the Ps4 camera is made to be used in a stationary environment. Because of that it is not that great at adjusting to changing conditions like when on a moving vehicle.

I have added in the readme a section on how to change camera settings like exposure using a command tool.

Feel free to to experiment with those settings to find a good balance.

Just let me know if you found a good setting so that I can add it to the readme.

I still needed to work on this project, mainly by fixing this lighting issue but sadly did not had time to do so yet.

Greetings

Sieuwe

parkerlreed commented 3 years ago

Got it! Was actually a lot more simple than I imagined.

[parker@wolfcola ~]$ v4l2-ctl -d /dev/video1 -l
                     brightness 0x00980900 (int)    : min=0 max=8 step=1 default=4 value=4
                       contrast 0x00980901 (int)    : min=0 max=8 step=1 default=4 value=4
                     saturation 0x00980902 (int)    : min=0 max=8 step=1 default=4 value=4
                            hue 0x00980903 (int)    : min=0 max=11 step=1 default=0 value=0
 white_balance_temperature_auto 0x0098090c (bool)   : default=1 value=1
                           gain 0x00980913 (int)    : min=0 max=8 step=1 default=4 value=4
           power_line_frequency 0x00980918 (menu)   : min=0 max=2 default=1 value=1
      white_balance_temperature 0x0098091a (int)    : min=2800 max=6500 step=100 default=4600 value=4600 flags=inactive
                      sharpness 0x0098091b (int)    : min=0 max=8 step=1 default=4 value=4
                  exposure_auto 0x009a0901 (menu)   : min=0 max=3 default=2 value=2
              exposure_absolute 0x009a0902 (int)    : min=1 max=5000 step=1 default=1000 value=1000 flags=inactive
[parker@wolfcola ~]$ v4l2-ctl -d /dev/video1 -c exposure_auto=0
[parker@wolfcola ~]$ 

image

parkerlreed commented 3 years ago

Setting exposure_auto BACK to 2 actually improves it even more. It seems the default firmware/UVC initialization just isn't triggering it automatically.