PiCapture › Using Python picamera and opencv
Tagged: picamera python opencv
October 23, 2016 at 4:49 pm #763
I can use raspistill and raspivid to get still and video. But I wish to use python picamera and opencv. I have working software with the Raspberry Pi camera – but using python picamera withe PiCapture does NOT work. I get an image is top left hand corner and then “junk” in the rest. I can provide example python code and outputs. I am assuming that the PiCapture should work with picamera and v4l2 driver for opencv. Am I right in this? thanks, MikeOctober 23, 2016 at 7:11 pm #764
We have used picamera with PiCapture with no issues at all, and so I’m sure it works.
From your description, it sounds as if you are not setting up picamera to expect “Mode 6” video (640×480) resolution, which is what the SD1 produces. The image you are seeing in the corner is the data being supplied by PiCapture to the GPU, and the rest is junk from the video buffer.
If you have problems resolving this, please provide the python code and I’ll take a look at it.October 26, 2016 at 1:31 pm #765
Thanks for getting back to me. I’m sure I must be doing something wrong. The code I’m testing with is:
from time import sleep
from picamera import PiCamera
camera = PiCamera( sensor_mode = 6, resolution=(640,480))
# Camera warm-up time
print “camera ready”
print “Video Cap Underway”
print “End of recoding”
Playing it back with omxplayer shows the size as 640×5480 – but with the actual image is top Left hand corner.
Any example code would be appricated.
ThanksOctober 27, 2016 at 9:26 am #766
Mike, I have looked into this and recreated the problem you are seeing. I found that the exact same python code is behaving differently now with the Raspberry Pi camera and the PiCapture, and so something must have changed either in our software or on the Raspberry Pi side.
The behavior is the same as when there is a mismatch because the Raspberry Pi is requesting a camera mode that the PiCapture does not support (for example, if you try running raspivid with “mode 5” specified with the PiCapture SD1), which shows the supplied video in the corner along with the garbage in the GPU buffer that is not being filled, and so I jumped to that conclusion. What you are doing works fine with the camera, and should be working with PiCapture.
I will investigate what is going on, and expect to be able to provide a software update for this issue. This may take some time, and in the interim there is a workaround that I hope will be usable for you. If you specify the “region of interest” (ROI) with picamera it will exclude the garbage. Something like:
camera.zoom = (0.01, 0.01, 0.48, 0.48)
We also suggest turning off some of the video processing intended for the camera. Adding these commands to your code will turn off automatic white balance and exposure compensation that can cause unwanted changes to the picture:
camera.exposure_mode = ‘off’
camera.awb_mode = ‘off’
camera.awb_gains = (1.0,1.0)
Also, the “sleep” to wait for the camera to wake up is not required for PiCapture.
I’m sorry for the problem you ran in to, and hope that this fix works in the interim.
October 27, 2016 at 10:18 am #768
- This reply was modified 4 years, 6 months ago by mwlinder.
Thanks for the update. I have been modifying code to capture a 640×480 image and the use numpy to extract a 320×240 with a good image. To give you some background (which might or might not be interesting) I am capturing input from a sony xr-500 camera (daylight and IR at night) and then using the sony LANC protocol to start/stop recording in the camera in hi-def. I also use to start/stop xr-500 and VG-20 photo images. This is for wildlife photo/video. I was using a windows notebook, but am planning on replacing with the Raspberry Pi. I have time/resources to do additional testing if this is useful for you.November 11, 2016 at 11:05 am #772
Just checking if there has been any progress in fixing this???? Thanks.November 14, 2016 at 9:57 am #773
Sorry – no answers yet for the root cause. I think that something may have changed in the RPi firmware and tracking it down is complicated….
Is the workaround of setting the Region of Interest working for you?
We are spending much of our time right now wrapping up the HD-1 version, but I hope to be able to focus more on this problem soon.
November 17, 2016 at 2:35 pm #805
- This reply was modified 4 years, 5 months ago by mwlinder.
I believe that I’ve found the solution to this issue.
There appears to be a problem in the way that picamera deals with camera mode setting. The data rate for video coming from the PiCapture SD1 is 60fps, which is higher than than the default data rate for the camera (30fps). For some reason, this is confusing the current release of picamera and it is overriding the sensor_mode setting and trying to treat it like Mode 4.
Please try specifying a framerate of 60fps, and let me know if that resolves what you are seeing – it fixed it on my system:
camera.framerate = 60
Thanks for your patience as we work through these issues.
November 17, 2016 at 5:06 pm #809
- This reply was modified 4 years, 5 months ago by mwlinder.
Thanks for the update. I ran the python code (that I sent to you) with the framerate change and it seems to be working just fine – full picture with no noise.
BTW I just pre-ordered the HDMI version…….. Thanks for fixing this. I did find (not surprisingly) that my motion detection with opencv works much faster when analysing a smaller image DUH….March 15, 2017 at 5:41 am #1050alee.hydrParticipant
I am facing the same problem (“junk” in the right hand corner) with HD1 as you but with openCV(C++) instead of picamera. I know that this is because PiCapture HD1 expects “mode 5” (1296×730–720p) which is obviously not the mode that openCV is using for capturing. This is not a problem with picamera as there is an option of sensor_mode available in picamera but I cannot figure out a similar option in openCV. Do you know how to select “mode” in openCV? I have tried CV_CAP_PROP_MODE but it changes the color space instead of resolution.March 15, 2017 at 11:58 am #1051
One thing you might try is setting the Region of Interest” (ROI) in OpenCV to exclude the “junk” in the buffer.
- You must be logged in to reply to this topic.