Accessing the camera from Python
#1
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.
  Reply


Messages In This Thread
Accessing the camera from Python - by lagrang3 - 07-13-2023, 01:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Stupid Question] Where is the phone camera software?! newusername 5 3,633 10-10-2022, 03:58 AM
Last Post: newusername
  basic and ugly mpc-python-GTK3 mpd remote alexandre 0 1,206 08-22-2021, 11:35 AM
Last Post: alexandre
Question Pinephone camera & Megapixels - Bug report and question danimations 0 1,470 08-10-2021, 05:43 AM
Last Post: danimations
  Is there a sound card input on the Pinephone which can be used by Python software? Peter Gamma 5 7,579 06-24-2020, 06:08 AM
Last Post: wibble

Forum Jump:


Users browsing this thread: 1 Guest(s)