problem with TX1 usb camera

I am a newer TX1.I am trying to use a USB camera on tx1 boardwith opencv2.4.10. Here is the c++ code.

int main()
{

//char* gst = "nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)320, height=(int)240, format=(string)I420, framerate=(fraction)120/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)I420 ! videoconvert ! video/x-raw, format=(string)BGR ! appsink";

  //  VideoCapture cap(gst);

//VideoCapture cap("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)320, height=(int)240, format=(string)I420, framerate=(fraction)120/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)I420 ! videoconvert ! video/x-raw, format=(string)BGR ! appsink");
VideoCapture cap(0);

Mat frame;
if(cap.isOpened())
{cout<<"1"<<endl;
while(1)
{
namedWindow("1",1);
cap>>frame;
imshow("1",frame);
waitKey(30);

}

}

return 0;

}

and there is the error:
(DEBUG) try_init_v4l2 VIDIOC_ENUMINPUT “/dev/video0”: Inappropriate ioctl for device
Unable to stop the stream.: Device or resource busy
Unable to stop the stream.: Bad file descriptor
1
VIDIOC_STREAMON: Inappropriate ioctl for device

I also try with gstreamer and nvgstcapture-1.0-sample,

gst-launch-1.0 nvcamerasrc fpsRange="30.0 30.0" ! 'video/x-raw(memory:NVMM), width=(int)1920, height=(int)1080, format=(string)I420, framerate=(fraction)30/1' ! nvtee ! nvvidconv flip-method=2 ! 'video/x-raw(memory:NVMM), format=(string)I420' ! nvoverlaysink -e

Also the error:
Invalid FPSRange Input
Setting pipeline to PAUSED …
Inside NvxLiteH264DecoderLowLatencyInitNvxLiteH264DecoderLowLatencyInit set DPB and MjstreamingInside NvxLiteH265DecoderLowLatencyInitNvxLiteH265DecoderLowLatencyInit set DPB and MjstreamingSocket read error. Camera Daemon stopped functioning…
gst_nvcamera_open() failed ret=0
ERROR: Pipeline doesn’t want to pause.
Setting pipeline to NULL …
Freeing pipeline …

And still cannot get the stream from camera,please help me!
Thanks!

Hello, ccchen:
Please search a tool called ‘yavta’, which can capture images from V4L2 device (usb camera in your case), to test your usb camera first.

If yavta works well, opencv should work as well.

as to GST, please use v4l2src plugin.

br
ChenJian

Hi ChenJian:
I don’t find ‘yavta’,but I use ‘cheese’ to test my usb camera and it can work well.
But my opencv can’t work.I wonder if I miss something when I install opencv,cuda .Do you have the guide to install opencv2.4.10, ubuntu14.04 and cuda7.0 or newer version on my tx1 board.
Thank you very much!

br

ccchen

Hello, ccchen:
For opencv4tegra, You can check docs/packages @ https://developer.nvidia.com/embedded/downloads#?search=opencv

USB camera should work in opencv. You can build the source code can track down why it reports error.
(For the error log you pasted,

(DEBUG) try_init_v4l2 VIDIOC_ENUMINPUT "/dev/video0": Inappropriate ioctl for device

it should have nothing to do with CUDA. You build openCV from source by yourself? if so, that looks more like the openCV is not configured correctly.)

br
ChenJian

Hi,jachen:
Thank you for your advice.
I try to flash the os with Jetpack2.2.1 and install opencv2.4.13 .It really works and I can grab the frame from usb camera,but I want to change the resolution from 640480 to 19201080 by set

cap.set(CV_CAP_PROP_FRAME_WIDTH,1920);
        cap.set(CV_CAP_PROP_FRAME_HEIGHT,1080);

and it doesn’t have any change.
how can I solve this problem?

ccchen

Hi ccchen,

V4L2 camera support level depends on kernel driver mostly. We do not exclude OpenCV issue for the particular case, but most probably, some IOCTLs are not implemented for particular camera and that’s why you cannot change camera resolution.

As possible solution, please, try to set resolution before or after cv::VideoCapture::open call.

Thanks

Hi kayccc,

Thank you for your advice.I have tried to set resolution from 640480 to 19201080 by set

VideoCapture cap(0);

	Mat frame;
	if(cap.isOpened())
	{
	cout<<"1"<<endl;
	
        cap.set(CV_CAP_PROP_FRAME_WIDTH,1920);
        cap.set(CV_CAP_PROP_FRAME_HEIGHT,1080);

after cv::VideoCapture::open call,but I cannot make any change.Can you give some advice about how to set resolution before open call?
Also,I tried to change resolution of a video ,

VideoCapture cap("video0.avi");

	Mat frame;
	if(cap.isOpened())
	{
	cout<<"1"<<endl;
	
        cap.set(CV_CAP_PROP_FRAME_WIDTH,1920);
        cap.set(CV_CAP_PROP_FRAME_HEIGHT,1080);

but it did’t have any change.

Thanks

Hello, ccchen:
For USB camera support, it’s provided by openCV. You can track down the related code to dig why resolution-changing does not work.
Per my point, such functions are device-related. USB camera has capabilities for its own. Some support low-resolution with raw format like RGB, and high-resolution with compressed format like JPG.

I think you can find the answer by tracking down openCV core.

br
Chenjian

Hi jachen:
When I run my code ,it got the error:

highgui error :v4l/v4l2:vidioc_s_crop

and how can I fix it ?

Thanks.

br

ccchen

Hello, ccchen:
That part of code is open-source. You can compile openCV package and track down the code.

br
Chenjian

I just tried openCV 3.1.0 for usb camera resolution change. It works well.
First please confirm that usb camera can support frame size like 1920x1080. (v4l2-ctl --list-formats-ext -d /dev/video1)
Compile the openCV 3.1.0.
Compile the test program and link against openCV 3.1.0, the following code clip can change the resolution:

int width = 1280;
    int height = 720;
    printf("Set width to %d\n", width);
    cap.set(CV_CAP_PROP_FRAME_WIDTH, width);
    printf("Set height to %d\n", height);
    cap.set(CV_CAP_PROP_FRAME_HEIGHT, height);

br
Chenjian

Thank you for your advice.
I will try openCV 3.1.0,but when I compile the openCV 3.1.0,
there are some errors listed:

../../lib/libopencv_imgcodecs.so.3.1.0: undefined reference to `png_init_filter_functions_neon'
collect2: error: ld returned 1 exit status
apps/annotation/CMakeFiles/opencv_annotation.dir/build.make:100: recipe for target 'bin/opencv_annotation' failed
make[2]: *** [bin/opencv_annotation] Error 1
CMakeFiles/Makefile2:6170: recipe for target 'apps/annotation/CMakeFiles/opencv_annotation.dir/all' failed
make[1]: *** [apps/annotation/CMakeFiles/opencv_annotation.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

Do you know some ways to solve it?

br
ccchen

it looks like libpng is missed. please install some dependencies for openCV

br
Chenjian