Skip to content

Support for V4L2_PIX_FMT_Y16 and setting CV_CAP_PROP_FOURCC for v4l2 - #7293

Merged
opencv-pushbot merged 2 commits into
opencv:masterfrom
Algomorph:master
Sep 16, 2016
Merged

opencv-pushbot merged 2 commits into
opencv:masterfrom
Algomorph:master

Conversation

@Algomorph

Copy link
Copy Markdown
Contributor

Resolves #7194

  1. Changed cap_v4l.cpp so the backend tries to use V4L2_PIX_FMT_Y16 (adapted from @stbnps in Added support for V4L2_PIX_FMT_Y16 #7196).
  2. Unlike Added support for V4L2_PIX_FMT_Y16 #7196, Cameras started with Y16 (V4L2_PIX_FMT_Y16) format via v4l2 backend will now exhibit default camera behavior, i.e. convert the 16-bit image to BGR as with all other formats. 16-bit 1-channel output will now only be produced for Y16 if CV_CAP_PROP_CONVERT_RGB is explicitly set to "false" using VideoCap::set method.
  3. v4l2 videoio backend now supports setting CV_CAP_PROP_FOURCC explicitly (icvSetPropertyCAM_V4L function in cap_v4l.cpp), allowing users to manually set the codec on cameras that support multiple codecs.

Comment thread modules/videoio/src/cap_v4l.cpp Outdated
break;
case CV_CAP_PROP_FOURCC:
{
__u32 old_palette = capture->palette;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove tab here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that, IDE feature for converting indentation tabs to spaces misfired here somehow. Fixed now.

break;
case V4L2_PIX_FMT_Y16:
if(!capture->convert_rgb){
depth = IPL_DEPTH_16U;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

channels = 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, it is above: channels = v4l2_num_channels(...)

1) Cameras started with Y16 (V4L2_PIX_FMT_Y16) format via v4l2 backend will now exhibit default camera behavior, i.e. convert the 16-bit image to BGR as with all other formats. 16-bit 1-channel output will now only be produced for Y16 if CV_CAP_PROP_CONVERT_RGB is set to "false" using VideoCap::set method.
2) v4l2 videoio backend now supports setting CV_CAP_PROP_FOURCC explicitly (icvSetPropertyCAM_V4L function in cap_v4l.cpp), allowing users to manually set the codec on cameras that support multiple codecs.
@Algomorph

Copy link
Copy Markdown
Contributor Author

@alalek , should be good now.

@alalek

alalek commented Sep 16, 2016

Copy link
Copy Markdown
Member

Looks good to me!
👍

@opencv-pushbot
opencv-pushbot merged commit 0d626c8 into opencv:master Sep 16, 2016
opencv-pushbot pushed a commit that referenced this pull request Sep 16, 2016
@gterren

gterren commented Jun 28, 2017

Copy link
Copy Markdown

Hi, I changed file cap_v4l.cpp as you said, and set the property CV_CAP_PROP_CONVERT_RGB to False but it is still not working. I read 8 bits depth pixels. Thank you!

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

#include <iostream>
#include <conio.h>

using namespace cv;
using namespace std;


int main()
{
	char keyPressed;
	VideoCapture _CameraDevice;
	Mat InputImage;

	_CameraDevice.open(1);

	_CameraDevice.set(CV_CAP_PROP_CONVERT_RGB, false);
	//_CameraDevice.set(CV_CAP_PROP_FOURCC,1);

	while (1)
	{
		_CameraDevice >> InputImage; //Read the input image

		if (InputImage.empty()) //Check for the vlid image
		{
			cout << "No frame grabbed!!, check whether the camera is free!!" << endl;
			break;
		}

		//cout << InputImage << endl;

		namedWindow("Camera Frame", WINDOW_AUTOSIZE);
		imshow("Camera Frame", InputImage);

		keyPressed = waitKey(1); //Waits for a user input to quit the application

		if (keyPressed == 27 || keyPressed == 'q' || keyPressed == 'Q')
		{
			destroyAllWindows();
			break;
		}
	}

	//Release the devices
	_CameraDevice.release();

	cout << endl << "Press any Key to exit the application" << endl << endl;
	_getch();

	return 0;
}

screen_shot

@alalek

alalek commented Jun 28, 2017

Copy link
Copy Markdown
Member

@Guille129 This patch is about V2L, than means "Video for Linux". But your problem is Windows-related.
You should post your question on Users OpenCV Q/A forum: http://answers.opencv.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants