super.termografo
Posts: 1
Joined: Wed Mar 05, 2014 7:32 pm

Resolution Error openCV with PiCam

Wed Mar 05, 2014 7:50 pm

Hi there,

I'm trying to reduce the resolution of a video streaming got it from the Pi Camera (using uv4l driver).
Now, it seems that when trying to modify default resolution, there is some kind of problem or conflict produced by V4L.
Here's the critical part of the code:

Code: Select all

#!/usr/bin/env python

CAMERAID=1
HAARCASCADE="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml"
MOVIE="/home/gijs/Work/uva/afstuderen/data/movie/heiligenacht.mp4"
STORE=False
OUTPUT="/home/gijs/testje.mp4"
FPS = 1000/15
SCALING = 2
THRESH = 80
XWINDOWS = 2
FACE_BORDER = 0.2
HUEBINS = 30
SATBINS = 32

import cv
import time
import sys
import math

class GetHands:
    def __init__(self):
        self.threshold_value = THRESH # value associated with slider bar
        self.capture = cv.CaptureFromCAM(0)
     [b]   cv.SetCaptureProperty( self.capture, cv.CV_CAP_PROP_FRAME_WIDTH, 320 );
        cv.SetCaptureProperty( self.capture, cv.CV_CAP_PROP_FRAME_HEIGHT, 200 );[/b]

        self.hc = cv.Load(HAARCASCADE)
        self.ms = cv.CreateMemStorage()

        [b]self.orig = cv.QueryFrame(self.capture)[/b]
        if not self.orig:
            print "can't get frame, check camera"
            sys.exit(2)

        self.width = self.orig.width
        self.height = self.orig.height
        self.size = (self.width, self.height)
        self.smallwidth = int(self.width/SCALING)
        self.smallheight = int(self.height/SCALING)
        self.smallsize = (self.smallwidth, self.smallheight)
I've realized that the error comes after executing cv.QueryFrame instruction. However, I've also realized that this error is produced by changing the Resolution of the video through cv.SetCaptureProperty.
When not defining the resolution of the video, there are no errors on the execution, however, the video runs by default resolution, which 640x480 (which doesn't work for me, the video must be defined @ 320x240 and below).

Here is the error:

pi@raspberrypi ~/Desktop $ sudo python skin.py

/dev/video0 does not support memory mapping
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
Unable to stop the stream.: Bad file descriptor
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
HIGHGUI ERROR: V4L: Initial Capture Error: Unable to load initial memory buffers.
can't get frame, check camera
*** glibc detected *** python: double free or corruption (!prev): 0x01082e68 ***

Any help will be very much appreciate it.
Thank you very much,
Marco

kkannan
Posts: 4
Joined: Sat Apr 14, 2012 12:47 pm

Re: Resolution Error openCV with PiCam

Mon Apr 14, 2014 7:13 am

same here, it is really frustrating (:

s0ck3t
Posts: 1
Joined: Sun Oct 12, 2014 5:15 pm

Re: Resolution Error openCV with PiCam

Sun Oct 12, 2014 5:19 pm

I too had this error. In the end I removed uv4l

Code: Select all

sudo apt-get remove uv4l uv4l-raspicam
I then followed the instructions at http://www.ics.com/blog/raspberry-pi-ca ... DqccvldX6U in the sction Official V4L2 Driver.

This I understand is an alternative to UV4L. There is a mistake though that happens during build. Make sure to also follow
http://stackoverflow.com/questions/2563 ... a-makefile to edit two Makefiles and build properly.

And voila - you can now use Raspicam, OpenCV, Python and change the input resolution of the video. Good luck with your projects!

Return to “Graphics, sound and multimedia”