Python 3 and opencv

Before I start to compile openCV3.1 for python 3.4, does anyone know if there is a possibility to use apt-get ?
I only found for Python2…

I’m afraid you will have to compile it: https://gist.github.com/willprice/c216fcbeba8d14ad1138

Could you share you binary after that please? :smiley:

Not working at the moment.
@Pierre import cv2 is working but cv2.VideoCapture(-1) return False . The camera works with picamera module and cv2 basic feature works.

Any ideas ?

If you are looking for a binary of opencv3 for linux-64, OSX or Windows, there is a conda package.

1 Like

I guess conda package won’t work with Raspbian. Anyway I fixed the issue :slight_smile: . It was because the V4L drivers was not loaded.

~$ sudo modprobe bcm2835-v4l2

I have now an ergo working on RPI 3 and python 3.4.

Sure I will share the binary, but at the moment a truck destroyed the Internet cable in my road and I have to wait until they repair my cable connexion (not reasonable to upload this on my 3G connexion).

Enjoy your week-end.

2 Likes

Can you get image acquisition with an higher definition than 640*480 with v4l2 ?

The image under my eyes is 640 x 480. I didn’t investigate if it is possible to change this. But what I understood is that the feature cv2.videoCapture() implemented in Pypot absolutely need the V4L2 drivers.

But there are other way to access the camera and some people recommend not using cv2 but picamera module to get an image.

from : http://docs.opencv.org/master/dd/d43/tutorial_py_video_display.html#gsc.tab=0
For example, I can check the frame width and height by cap.get(3) and cap.get(4). It gives me 640x480 by default. But I want to modify it to 320x240. Just use ret = cap.set(3,320) and ret = cap.set(4,240).

Few tests but it seems that I can not change the resolution…

It could be better to start the camera with the picamera module :

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))

We are using VL42 driver to be independant of Raspberry Pi camera. You can plug any USB cameras and it will work in the same way that the picamera.

1 Like

Yes, this is the advantage but do you know how to change resolution with a picamera plugged ?

Yes the advantage with the picamera is that you master the camera. With v4l2 it seems there is a bug with opencv 2.4. but with picamera, there is also a bug with opencv… I do not understand why there are so many bugs.
When you want to use ROS above that…

Note that you have to release and re-instanciate VideoCapture if you want to change the resolution while capturing frames.

1 Like

It should work but it doesn’t with my setup.

in : cam.get(cv2.CAP_PROP_FRAME_WIDTH)
out : 640
in : cam.set(cv2.CAP_PROP_FRAME_WIDTH,320)
out : False

Is it working with your setup ?

For my setup (Raspberry Pi + opencv) it works even if cam.set return False ; but It works only if I haven’t called readmethod before.

Right,
It works even returning False. Below, a Jupyter code to test camera.

import cv2
cam = cv2.VideoCapture(-1)
cam.set(3,1296)
cam.set(4,730)
res, img = cam.read()
%matplotlib inline
from matplotlib import pyplot as plt
plt.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))

My home in high def :slight_smile:

1 Like

Ok thank you, I was also lost when it returned False. :slight_smile:

Here are the binary :

Build directory (opencv 3.1 using python 3.4) on RPI 3

Full Iso image for RPI 3 with ergo JR on it.

1 Like

Genius. 10/10
Helped me fix my problems