Opencv with Raspberry Pi Cam (Rock Pi 4B)


#1

Is there a combination that works?

First i tried Ubuntu, installed the OpenCV 4 package, but with ubuntu I got errors when accessing the camera (do I have to install an additional driver? I just add the v4l2-ctl lib) .

After that, I used the Debian Desktop img. But there is no Opencv Package and a build from the opencv source get me various errors.

So, what is a working combination with a driver for the raspi cam (v2) and a OpenCV Installation?


#2

Hello,
can I look for answers in the forum for you?

Raspberry Pi Cam

OpenCV 4



#3

Hello,

Both opencv and raspi cam V2 can work seperately on debian.
But, only gstreamer is confirmed to work well with raspi cam v2, because “raspi cam v2” is only supported via the gstreamer elements, now.

rkcamsrc
rkximagesink

Hoping some easy library can be released soon.

Crash happens, when opening camera via opencv4, on latest kernel.

> import cv2
>cv2.__version__
‘4.0.1’
>cam = cv2.VideoCapture(0)
Using mplane plugin for capture

^C
(python:1154): GStreamer-CRITICAL **:
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.
(python:1154): GStreamer-CRITICAL **: gst_element_get_state: assertion ‘GST_IS_ELEMENT (element)’ failed
VIDEOIO ERROR: V4L2: Unable to capture video memory.VIDEOIO ERROR: V4L: can’t open camera by index 0


#4

I have read all these forum posts. But if I can only use the Rapi Cam on the Debian desktop, I need an OpenCV package for that. But currently there seems to be only one for Ubuntu right?

We have made a pre-built openCV 4.0 package for ROCK Pi. Please refer: https://wiki.radxa.com
/Rockpi4>/Ubuntu Basically


#5

Ok, then I try it with this driver and Debian Desktop. Is there an OpenCV 3 or 4 deb package for this?


#6

i didn’t found pre-built openCV 4.0 for Debian as well.
Although Radxa Apt says there it is…

I searched a lot, before I built opencv4.0 from source code.

btw, If you want to build it from source code on rockpi4, please have a check of your gcc version and spec.
because current gcc in debian image, is not built with support of NEON nor VFP, which is required by opencv.


#7

Did you check this?

https://wiki.radxa.com/Rockpi4/dev/install-opencv


#8

Thanks for your tip. Before I start, you’ve also successfully built Opencv from the Source and used it with the standard RockPi driver and the Rpi Cam?

sorry for the question, but the last time I built OpenCv, I needed a whole weekend for it

Is it enough if I get the gcc 7 from the debian experimental deb list (for NEON und VFP support)?
deb http://deb.debian.org/debian experimental main


#9

Yes, I had checked that. But this only works for Ubuntu and unfortunately you do not have a driver for the Raspi Cam for Ubuntu.


#10

I checked. But, this only works on Ubuntu…


#11

OpenCv under Ubuntu it is not a problem (OpenCV 4 or 3 both work) but, the Pi-Cam does not work under Ubuntu. It works only on the Debian desktop. Or which driver do you use with Ubuntu?


#12

I failed to make Pi Cam work on ubuntu.

It only works on debian, i think.


#13

That’s exactly my problem. Under Ubuntu the Pi Cam does not work and under Debian Desktop OpenCV does not work. Unfortunately I can not use the Rock Pi 4 for our project. I was very interested in the high performance of the Rock Pi. Now I hope that Radxa helps here.


#14

Hello jack. What is your recommendation to use OpenCV with the Pi Cam? Ubuntu does not work (no Cam driver), Debian does not work (no OpenCV package and compiler is also not up to date)?


#15

Hi wozuying

Last weekend I compiled the gcc 8.3 for debian on the Rock Pi. After that I was able to build OpenCV 4.0.1. Unfortunately there are still bugs with the opencv_python bindings (the python dist on the Rock Pi Image ist too old (3.5.X). The next problem, the image quality with the current rock-chip driver is very bad.

This script from the forum helped me with the gcc
https://www.raspberrypi.org/forums/viewtopic.php?t=212636


#16

It’s true that the IMX219 is not tunned for the Rockchip ISP. If you can tune the sensor, we can provide tool and documents. Please send me a PM.


#17

Here is all about the commit history in kernel about imx219, the imaging sensor.
Maybe you can find some hint of how to modify.
Just for your reference.

But, the author, Jacob Chen, has quit rock-chipis.com.
For further detail, you have to read code…


#18

According my researching of kernel and gstreamer-rockchip-extra oss in github,

In gstreamer-rockchip-extra , you can find rkcamsrc, which is the middle ware containing most wrapper functions of v4l2 and UNOPENED functions, that is implemented in librk_aiq.so.

In kernel, all imx219-related functions are implemented in imx219.c. And that will not be a big problem to understand it, with the help of imx219 datasheet document referenced here.

So, there are 2 ways for tuning imx219 imaging sensor on RockPI 4.

  1. Asking radxa for helping, to get the details of librk_aiq.so.
  2. Modifying the kernel source, imx219.c, to extend the existed v4l2 method.

ANOUNCEMENT!!
All these above is just my opinion from the github OSS.

Thanks!


#19

the modification here can be used to change some of the camera parameters, after re-building kernel.

For example, the configure of camera brightness

$ sudo echo 2000 > /sys/module/imx219/parameters/__imx219_exposure__

And then, excute gst command.

$ gst-launch-1.0 rkcamsrc device=/dev/video0 io-mode=4 isp-mode=0A ! videoconvert ! video/x-raw,format=NV12,width=640,height=480 ! rkximagesink

Have a fun!
Good luck!