simplify autosetup_capture_mode_v4l2 by using a for loop
This commit is contained in:
parent
5525cc4d09
commit
588eba3b37
@ -422,24 +422,20 @@ try_palette(int fd,
|
|||||||
|
|
||||||
#ifdef HAVE_CAMV4L2
|
#ifdef HAVE_CAMV4L2
|
||||||
|
|
||||||
static int try_palette_v4l2(CvCaptureCAM_V4L* capture, unsigned long colorspace)
|
static bool try_palette_v4l2(CvCaptureCAM_V4L* capture)
|
||||||
{
|
{
|
||||||
CLEAR (capture->form);
|
CLEAR (capture->form);
|
||||||
|
|
||||||
capture->form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
capture->form.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||||
capture->form.fmt.pix.pixelformat = colorspace;
|
capture->form.fmt.pix.pixelformat = capture->palette;
|
||||||
capture->form.fmt.pix.field = V4L2_FIELD_ANY;
|
capture->form.fmt.pix.field = V4L2_FIELD_ANY;
|
||||||
capture->form.fmt.pix.width = capture->width;
|
capture->form.fmt.pix.width = capture->width;
|
||||||
capture->form.fmt.pix.height = capture->height;
|
capture->form.fmt.pix.height = capture->height;
|
||||||
|
|
||||||
if (-1 == ioctl (capture->deviceHandle, VIDIOC_S_FMT, &capture->form))
|
if (-1 == ioctl (capture->deviceHandle, VIDIOC_S_FMT, &capture->form))
|
||||||
return -1;
|
return false;
|
||||||
|
|
||||||
|
return capture->palette == capture->form.fmt.pix.pixelformat;
|
||||||
if (colorspace != capture->form.fmt.pix.pixelformat)
|
|
||||||
return -1;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* HAVE_CAMV4L2 */
|
#endif /* HAVE_CAMV4L2 */
|
||||||
@ -547,67 +543,34 @@ static int try_init_v4l2(CvCaptureCAM_V4L* capture, char *deviceName)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int autosetup_capture_mode_v4l2(CvCaptureCAM_V4L* capture)
|
static int autosetup_capture_mode_v4l2(CvCaptureCAM_V4L* capture) {
|
||||||
{
|
__u32 try_order[] = {
|
||||||
if (try_palette_v4l2(capture, V4L2_PIX_FMT_BGR24) == 0)
|
V4L2_PIX_FMT_BGR24,
|
||||||
{
|
V4L2_PIX_FMT_YVU420,
|
||||||
capture->palette = V4L2_PIX_FMT_BGR24;
|
V4L2_PIX_FMT_YUV411P,
|
||||||
}
|
|
||||||
else
|
|
||||||
if (try_palette_v4l2(capture, V4L2_PIX_FMT_YVU420) == 0)
|
|
||||||
{
|
|
||||||
capture->palette = V4L2_PIX_FMT_YVU420;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
if (try_palette_v4l2(capture, V4L2_PIX_FMT_YUV411P) == 0)
|
|
||||||
{
|
|
||||||
capture->palette = V4L2_PIX_FMT_YUV411P;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
|
|
||||||
#ifdef HAVE_JPEG
|
#ifdef HAVE_JPEG
|
||||||
if (try_palette_v4l2(capture, V4L2_PIX_FMT_MJPEG) == 0 ||
|
V4L2_PIX_FMT_MJPEG,
|
||||||
try_palette_v4l2(capture, V4L2_PIX_FMT_JPEG) == 0)
|
V4L2_PIX_FMT_JPEG,
|
||||||
{
|
|
||||||
capture->palette = V4L2_PIX_FMT_MJPEG;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
#endif
|
||||||
|
V4L2_PIX_FMT_YUYV,
|
||||||
|
V4L2_PIX_FMT_UYVY,
|
||||||
|
V4L2_PIX_FMT_SN9C10X,
|
||||||
|
V4L2_PIX_FMT_SBGGR8,
|
||||||
|
V4L2_PIX_FMT_SGBRG8,
|
||||||
|
V4L2_PIX_FMT_RGB24
|
||||||
|
};
|
||||||
|
|
||||||
if (try_palette_v4l2(capture, V4L2_PIX_FMT_YUYV) == 0)
|
for (size_t i = 0; i < sizeof(try_order) / sizeof(__u32); i++) {
|
||||||
{
|
capture->palette = try_order[i];
|
||||||
capture->palette = V4L2_PIX_FMT_YUYV;
|
if (try_palette_v4l2(capture)) {
|
||||||
}
|
return 0;
|
||||||
else if (try_palette_v4l2(capture, V4L2_PIX_FMT_UYVY) == 0)
|
}
|
||||||
{
|
}
|
||||||
capture->palette = V4L2_PIX_FMT_UYVY;
|
|
||||||
}
|
fprintf(stderr,
|
||||||
else
|
"VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV\n");
|
||||||
if (try_palette_v4l2(capture, V4L2_PIX_FMT_SN9C10X) == 0)
|
|
||||||
{
|
|
||||||
capture->palette = V4L2_PIX_FMT_SN9C10X;
|
|
||||||
} else
|
|
||||||
if (try_palette_v4l2(capture, V4L2_PIX_FMT_SBGGR8) == 0)
|
|
||||||
{
|
|
||||||
capture->palette = V4L2_PIX_FMT_SBGGR8;
|
|
||||||
} else
|
|
||||||
if (try_palette_v4l2(capture, V4L2_PIX_FMT_SGBRG8) == 0)
|
|
||||||
{
|
|
||||||
capture->palette = V4L2_PIX_FMT_SGBRG8;
|
|
||||||
}
|
|
||||||
else if (try_palette_v4l2(capture, V4L2_PIX_FMT_RGB24) == 0)
|
|
||||||
{
|
|
||||||
capture->palette = V4L2_PIX_FMT_RGB24;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV\n");
|
|
||||||
icvCloseCAM_V4L(capture);
|
icvCloseCAM_V4L(capture);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* HAVE_CAMV4L2 */
|
#endif /* HAVE_CAMV4L2 */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user