找回密码
 立即注册
001 该用户已被删除
发表于 2017-1-17 13:56:46
49077
问题1描述:使用jetpack2.3.1自带的opencv2.4.13苦 编写驱动板上摄像头的代码(如图1),能编译通过,但执行时并不能打开板上的csi摄像头(如图2),但改了代码中的摄像头号来驱动usb摄像头时候,能驱动usb摄像头,且在板上使用nvgstcapture1.0指令也能驱动板上csi摄像头,那么请问要如何才能在opencv代码中使用tx1上的csi摄像头? 谢谢

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
使用道具 举报 回复
发表于 2017-1-19 10:55:00
problem with TX1 usb camera
ccchen
I am a newer TX1.I am trying to use a USB camera on tx1 boardwith opencv2.4.10. Here is the c++ code.
  1. 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,
  1. 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!

I am a newer TX1.I am trying to use a USB camera on tx1 boardwith opencv2.4.10. Here is the c++ code.
1.        int main()
2.        {
3.        
4.        //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";
5.        
6.          //  VideoCapture cap(gst);
7.        
8.        //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");
9.        VideoCapture cap(0);
10.        
11.        Mat frame;
12.        if(cap.isOpened())
13.        {cout<<"1"<<endl;
14.        while(1)
15.        {
16.        namedWindow("1",1);
17.        cap>>frame;
18.        imshow("1",frame);
19.        waitKey(30);
20.        
21.        }
22.        
23.        }
24.        
25.        return 0;
26.        
27.        }



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,
1.        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!
#1
Posted 08/31/2016 01:59 PM   
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





-----------------------------------------------------------------------------------------------------------------------------------
jachen
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
#2
Posted 09/02/2016 08:18 AM   
ccchen
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

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
#3
Posted 09/03/2016 02:36 AM   
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,
  1. (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

jachen
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,
1.        (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
#4
Posted 09/05/2016 02:44 AM   
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 640*480 to 1920*1080 by set
  1. 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

ccchen
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 640*480 to 1920*1080 by set
1.        cap.set(CV_CAP_PROP_FRAME_WIDTH,1920);
2.                cap.set(CV_CAP_PROP_FRAME_HEIGHT,1080);

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

ccchen
#5
Posted 09/28/2016 12:59 PM   
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:pen call. Thanks

kayccc
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:pen call.

Thanks
#6
Posted 09/30/2016 02:00 AM   
[quote="kayccc"]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:pen call. Thanks[/quote] Hi kayccc, Thank you for your advice.I have tried to set resolution from 640*480 to 1920*1080 by set
  1. 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:pen 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 ,
  1. 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

ccchen
kayccc said: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:pen call.

Thanks


Hi kayccc,

Thank you for your advice.I have tried to set resolution from 640*480 to 1920*1080 by set
1.        VideoCapture cap(0);
2.        
3.                Mat frame;
4.                if(cap.isOpened())
5.                {
6.                cout<<"1"<<endl;
7.               
8.                cap.set(CV_CAP_PROP_FRAME_WIDTH,1920);
9.                cap.set(CV_CAP_PROP_FRAME_HEIGHT,1080);
after cv::VideoCapture:pen 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 ,
1.        VideoCapture cap("video0.avi");
2.        
3.                Mat frame;
4.                if(cap.isOpened())
5.                {
6.                cout<<"1"<<endl;
7.               
8.                cap.set(CV_CAP_PROP_FRAME_WIDTH,1920);
9.                cap.set(CV_CAP_PROP_FRAME_HEIGHT,1080);

but it did't have any change.

Thanks
#7
Posted 10/07/2016 02:16 AM   
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

jachen
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
#8
Posted 10/14/2016 02:31 AM   
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

ccchen
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
#9
Posted 10/17/2016 03:32 AM   
Hello, ccchen: That part of code is open-source. You can compile openCV package and track down the code. br Chenjian

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

br
Chenjian
#10
Posted 10/17/2016 06:35 AM   
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:
  1. 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

jachen
Answer Accepted by Forum Admin
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:
1.        int width = 1280;
2.            int height = 720;
3.            printf("Set width to %d\n", width);
4.            cap.set(CV_CAP_PROP_FRAME_WIDTH, width);
5.            printf("Set height to %d\n", height);
6.            cap.set(CV_CAP_PROP_FRAME_HEIGHT, height);


br
Chenjian
#11
Posted 10/19/2016 07:12 AM   
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:
  1. ../../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

ccchen
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:
1.        ../../lib/libopencv_imgcodecs.so.3.1.0: undefined reference to `png_init_filter_functions_neon'
2.        collect2: error: ld returned 1 exit status
3.        apps/annotation/CMakeFiles/opencv_annotation.dir/build.make:100: recipe for target 'bin/opencv_annotation' failed
4.        make[2]: *** [bin/opencv_annotation] Error 1
5.        CMakeFiles/Makefile2:6170: recipe for target 'apps/annotation/CMakeFiles/opencv_annotation.dir/all' failed
6.        make[1]: *** [apps/annotation/CMakeFiles/opencv_annotation.dir/all] Error 2
7.        make[1]: *** Waiting for unfinished jobs....

Do you know some ways to solve it?

br
ccchen
#12
Posted 10/21/2016 07:44 AM   
it looks like libpng is missed. please install some dependencies for openCV br Chenjian

jachen
it looks like libpng is missed. please install some dependencies for openCV
使用道具 举报 回复 支持 1 反对 0
发表于 2017-1-18 14:49:21
您好,已经去帮您转技术工作人员啦
使用道具 举报 回复 支持 反对
发表于 2017-1-19 10:51:16
你好@001, 我看了一些资料,以下方案供您参考:It could mean that your camera (camera driver) is generating images in a format OpenCV doesn't understand, such as compressed video or YUV video instead of RGB, etc. First thing I recommend is that if you built or installed public OpenCV or any v4l or camera or multimedia libraries yourself then perhaps start from a clean system (ie: flash your board and install Grinch and OpenCV4Tegra), then see if your OpenCV install works with your camera, and if not then try 1 or 2 different webcams, because it is probably an issue with your webcam compatibility.

If so, you might decide to use V4L or Gstreamer or a similar API directly and see if they can access your camera, and if so then use that API to obtain camera images and then access the image from OpenCVAttachments

另外,还有一份资料(L4T Multimedia API Reference)您可以参考:
L4TMultimedia API Reference

楼下我转载的交流请您参考^^如果读英文有困难请您告诉我~



使用道具 举报 回复 支持 反对
发表于 2017-1-21 16:02:06
emily 发表于 2017-1-19 10:55
problem with TX1 usb camera
ccchen
I am a newer TX1.I am trying to use a USB camera on tx1 boardw ...

好东西
使用道具 举报 回复 支持 反对
发表于 2017-1-21 16:21:00

谢谢,但是上述的交流都是讨论usb camera的,在usb camera opencv那边我的设备能正常驱动usb 摄像头,但是并不能正常驱动板上mipi摄像头,我也找到了一些文档博客,采用VideoCapture cap(&quot;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 !..),有一个用户能打开板上mipi摄像头,但是也有一些用户和我一样,采用了上述代码也是不能打开摄像头,采用的opencv版本号也是2.4.13 。 具体我看看你发给我的那份文档,谢谢你的回复,真心暖心,谢谢对菜鸟的支持,支持NV。
使用道具 举报 回复 支持 反对
发表于 2017-1-21 16:22:11
emily 发表于 2017-1-19 10:55
problem with TX1 usb camera
ccchen
I am a newer TX1.I am trying to use a USB camera on tx1 boardw ...

谢谢,但是上述的交流都是讨论usb camera的,在usb camera opencv那边我的设备能正常驱动usb 摄像头,但是并不能正常驱动板上mipi摄像头,我也找到了一些文档博客,采用VideoCapture cap(&quot;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 !..),有一个用户能打开板上mipi摄像头,但是也有一些用户和我一样,采用了上述代码也是不能打开摄像头,采用的opencv版本号也是2.4.13 。 具体我看看你发给我的那份文档,谢谢你的回复,真心暖心,谢谢对菜鸟的支持,支持NV。
使用道具 举报 回复 支持 反对
发表于 2017-2-3 10:59:22
001 发表于 2017-1-21 16:22
谢谢,但是上述的交流都是讨论usb camera的,在usb camera opencv那边我的设备能正常驱动usb 摄像头,但 ...

表客气,如果有新的心得或者领悟,还请来回复一下,让以后的小盆友们也能学习参考^^
使用道具 举报 回复 支持 反对
发新帖
您需要登录后才可以回帖 登录 | 立即注册

zzczczxczxczx