PiCapture Using Python picamera and opencv

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #763
    mike101video
    Participant

    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, Mike

    #764
    mwlinder
    Keymaster

    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.

    #765
    mike101video
    Participant

    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.start_preview()
    # Camera warm-up time
    print “camera ready”
    sleep(2)
    camera.start_recording(‘/media/pi/USB20FD/current/testvid.h264’)
    print “Video Cap Underway”
    sleep(10)
    camera.stop_recording()
    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.

    Thanks

    #766
    mwlinder
    Keymaster

    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.

    Marshal

    • This reply was modified 3 years, 10 months ago by mwlinder.
    #768
    mike101video
    Participant

    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.

    #772
    mike101video
    Participant

    Just checking if there has been any progress in fixing this???? Thanks.

    #773
    mwlinder
    Keymaster

    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.

    Marshal

    • This reply was modified 3 years, 10 months ago by mwlinder.
    #805
    mwlinder
    Keymaster

    Mike,

    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.

    Marshal

    • This reply was modified 3 years, 10 months ago by mwlinder.
    #809
    mike101video
    Participant

    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….

    #1050
    alee.hydr
    Participant

    Hi mike101video,
    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.

    #1051
    mwlinder
    Keymaster

    One thing you might try is setting the Region of Interest” (ROI) in OpenCV to exclude the “junk” in the buffer.

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.
mike101videoUsing Python picamera and opencv