Updated by Alexander Shishkov about 13 years ago
On Linux if you grab something from a not jpeg camera the frame appears with a dark rectangle on the left and on the top. The problem is in the "icvSetVideoSize" function. The crop capability is not right implemented. I have modify the function to resolve the problem. See below:
static int icvSetVideoSize( CvCaptureCAM_V4L* [[CvCaptureCAM]]_V4L* capture, int w, int h) {
#ifdef HAVE_CAMV4L2
if (V4L2_SUPPORT == 1)
{
CLEAR (capture->cropcap);
capture->cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (xioctl (capture->deviceHandle, VIDIOC_CROPCAP, &capture->cropcap) < 0) {
fprintf(stderr, "HIGHGUI ERROR: V4L/V4L2: VIDIOC_CROPCAP\n");
} else {
CLEAR (capture->crop);
capture->crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
capture->crop.c= capture->cropcap.defrect;
//http://v4l2spec.bytesex.org/spec-single/v4l2.html#CROP
/*capture->crop.c.left = 0;
capture->crop.c.top = 0;
capture->crop.c.height = h*24;
capture->crop.c.width = w*24;*/
/* set the crop area, but don't exit if the device don't support croping */
if (xioctl (capture->deviceHandle, VIDIOC_S_CROP, &capture->crop) < 0) {
fprintf(stderr, "HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP\n");
}
}
CLEAR (capture->form);
capture->form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
/* read the current setting, mainly to retreive the pixelformat information */
...
static int icvSetVideoSize( CvCaptureCAM_V4L* [[CvCaptureCAM]]_V4L* capture, int w, int h) {
#ifdef HAVE_CAMV4L2
if (V4L2_SUPPORT == 1)
{
CLEAR (capture->cropcap);
capture->cropcap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
if (xioctl (capture->deviceHandle, VIDIOC_CROPCAP, &capture->cropcap) < 0) {
fprintf(stderr, "HIGHGUI ERROR: V4L/V4L2: VIDIOC_CROPCAP\n");
} else {
CLEAR (capture->crop);
capture->crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
capture->crop.c= capture->cropcap.defrect;
//http://v4l2spec.bytesex.org/spec-single/v4l2.html#CROP
/*capture->crop.c.left = 0;
capture->crop.c.top = 0;
capture->crop.c.height = h*24;
capture->crop.c.width = w*24;*/
/* set the crop area, but don't exit if the device don't support croping */
if (xioctl (capture->deviceHandle, VIDIOC_S_CROP, &capture->crop) < 0) {
fprintf(stderr, "HIGHGUI ERROR: V4L/V4L2: VIDIOC_S_CROP\n");
}
}
CLEAR (capture->form);
capture->form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
/* read the current setting, mainly to retreive the pixelformat information */
...