I've been trying to write a Python application for the Pinephone that needs access to the camera.
1. My first iteration was using python-opencv, but that doesn't work out of the box.
The simple first two lines:
```
import cv2
cap = cv2.VideoCapture(0)
```
produce the following error:
```
[ WARN:0@18.736] global ./modules/videoio/src/cap_gstreamer.cpp (2401) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Device '/dev/video0' is not a capture device.
[ WARN:0@18.739] global ./modules/videoio/src/cap_gstreamer.cpp (1356) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0@18.740] global ./modules/videoio/src/cap_gstreamer.cpp (862) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:0@18.758] global ./modules/videoio/src/cap_v4l.cpp (902) open VIDEOIO(V4L2:/dev/video0): can't open camera by index
```
There is some discussion about this problem in a manjaro forum: https://forum.manjaro.org/t/access-pinep...encv/94593
but there are no conclusive solutions.
I have two possible work-around to this issue:
2. I could build a python library reusing "megapixels" code (https://gitlab.com/postmarketOS/megapixels). By the way, there is a very interesting description of the pinephone camera interface in the README in that repository.
3. Or I could call an external command from my python executable that gets me the actual camera data, for example `ffmpeg` similarly to this blog post: https://blog.brixit.nl/camera-on-the-pinephone/
In my opinion, solution 3 is ugly and probably under-performant, while 2 seems overkill.
There should be a simple way to read the camera data natively from Python.
If anyone can give me a solution or a hint, I would really appreciate it.
1. My first iteration was using python-opencv, but that doesn't work out of the box.
The simple first two lines:
```
import cv2
cap = cv2.VideoCapture(0)
```
produce the following error:
```
[ WARN:0@18.736] global ./modules/videoio/src/cap_gstreamer.cpp (2401) handleMessage OpenCV | GStreamer warning: Embedded video playback halted; module v4l2src0 reported: Device '/dev/video0' is not a capture device.
[ WARN:0@18.739] global ./modules/videoio/src/cap_gstreamer.cpp (1356) open OpenCV | GStreamer warning: unable to start pipeline
[ WARN:0@18.740] global ./modules/videoio/src/cap_gstreamer.cpp (862) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:0@18.758] global ./modules/videoio/src/cap_v4l.cpp (902) open VIDEOIO(V4L2:/dev/video0): can't open camera by index
```
There is some discussion about this problem in a manjaro forum: https://forum.manjaro.org/t/access-pinep...encv/94593
but there are no conclusive solutions.
I have two possible work-around to this issue:
2. I could build a python library reusing "megapixels" code (https://gitlab.com/postmarketOS/megapixels). By the way, there is a very interesting description of the pinephone camera interface in the README in that repository.
3. Or I could call an external command from my python executable that gets me the actual camera data, for example `ffmpeg` similarly to this blog post: https://blog.brixit.nl/camera-on-the-pinephone/
In my opinion, solution 3 is ugly and probably under-performant, while 2 seems overkill.
There should be a simple way to read the camera data natively from Python.
If anyone can give me a solution or a hint, I would really appreciate it.