# Can not open the camera on TX1 via OpenCV

**URL:** <https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945>\
**Category:** Jetson TX1\
**Tags:** opencv\
**Created:** [March 22, 2016, 9:13am UTC](https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945 "2016-03-22T09:13:45Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jackwang](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Jackwang](https://forums.developer.nvidia.com/u/Jackwang)\
**Post date:** [March 22, 2016, 9:13am UTC](https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945/1 "2016-03-22T09:13:45Z")

</div>

Hi,  
I am trying to open the camera on Jetson TX1 developmen kit via OpenCV and I can compile the code.But when I run it,I got nothing.someone said “OpenCV is not using Gstreamer path and pipeline string is being interpreted as V4L2 device”,but I do not konow how to do it.The code is like that:

```
#include <stdio.h>
#include <opencv2/opencv.hpp>

using namespace cv;
using namespace std;

int main(int argc, char** argv )
{
        VideoCapture cap("nvcamerasrc ! video/x-raw(memory:NVMM), 
width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=2 
! video/x-raw, format=(string)BGRx ! videoconvert ! 'video/x-raw, format=(string)BGR' ! appsink"); // open the camera

    if(!cap.isOpened()){ 
 // check if we succeeded
        return -1;
}

    Mat edges;
    namedWindow("edges",1);
    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        cvtColor(frame, edges, COLOR_BGR2GRAY);
        GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
        Canny(edges, edges, 0, 30, 3);
        imshow("edges", edges);
       // if(waitKey(30) >= 0) break;
    }
    return 0;
}

```

I have got the code from the website：[https://devtalk.nvidia.com/default/topic/904949/how-to-get-tx1-camera-in-opencv/](https://devtalk.nvidia.com/default/topic/904949/how-to-get-tx1-camera-in-opencv/)  
Any suggestion will be appreciated,  
Thanks

---

<div class="post-metadata">

**Author:** ![kayccc](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/kayccc/32/14043_2.png) [@kayccc](https://forums.developer.nvidia.com/u/kayccc)\
**Post date:** [March 23, 2016, 1:52am UTC](https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945/2 "2016-03-23T01:52:25Z")

</div>

Hi Jackwang,

It seems geoffreywall could make it work, see [https://devtalk.nvidia.com/default/topic/904949/jetson-tx1/how-to-get-tx1-camera-in-opencv/post/4787122/#4787122](https://devtalk.nvidia.com/default/topic/904949/jetson-tx1/how-to-get-tx1-camera-in-opencv/post/4787122/#4787122)

Please change your code:

```auto
VideoCapture cap("nvcamerasrc ! video/x-raw(memory:NVMM), 
width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=2 
! video/x-raw, format=(string)BGRx ! videoconvert ! 'video/x-raw, format=(string)BGR' ! appsink"); // open the camera

```

To following:

```auto
char* gst = "nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=2 ! videoconvert ! appsink";

    VideoCapture cap(gst);

```

And see if it can work.

Thanks

---

<div class="post-metadata">

**Author:** ![Jackwang](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Jackwang](https://forums.developer.nvidia.com/u/Jackwang)\
**Post date:** [March 24, 2016, 9:31am UTC](https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945/3 "2016-03-24T09:31:24Z")

</div>

Hi kayccc，  
Thanks for your response.I had modified my code as what you said.But It did not work.I got nothing just as before.By the way.I have flashed my board with tegra 23.2.

---

<div class="post-metadata">

**Author:** ![GinDiamond](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@GinDiamond](https://forums.developer.nvidia.com/u/GinDiamond)\
**Post date:** [March 28, 2016, 2:31pm UTC](https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945/4 "2016-03-28T14:31:30Z")

</div>

I followed this thread’s instructions and had to add in a

```auto
if (!frame.empty())
{
    continue;
}

```

in the for(;;) to keep it from throwing scn == 3 || scn == 4 errors.

Now it just hangs in an infinite loop, waiting for an image to be passed (it hangs because all images being passed are empty)

How do I fix it?

**EDIT**

The terminal says that there is an error near unexpected token ‘(’ in this command:

```auto
nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=2 ! videoconvert ! appsink

```

when run from the command line

---

<div class="post-metadata">

**Author:** ![Leow](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@Leow](https://forums.developer.nvidia.com/u/Leow)\
**Post date:** [April 1, 2016, 8:17am UTC](https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945/5 "2016-04-01T08:17:00Z")

</div>

Hi,

You may want to try this:

```auto
VideoCapture capture("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");

```

I took the code from [https://devtalk.nvidia.com/default/topic/904949/jetson-tx1/how-to-get-tx1-camera-in-opencv/post/4823344/#4823344](https://devtalk.nvidia.com/default/topic/904949/jetson-tx1/how-to-get-tx1-camera-in-opencv/post/4823344/#4823344)  
It works for me. However, I lowered the resolution to avoid delay.

Thanks.

-Leow

---

<div class="post-metadata">

**Author:** ![SeunghyunLee](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@SeunghyunLee](https://forums.developer.nvidia.com/u/SeunghyunLee)\
**Post date:** [April 8, 2016, 1:35pm UTC](https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945/6 "2016-04-08T13:35:41Z")

</div>

Well, I’m currently getting stuck with this same situation even after updating JetPack to 2.1.  
I’m trying to use the embedded CSI sensor with OpenCV.

After I could successfully run the pre-installed application ‘nvgstcapture-1.0’ with an option ‘-m 2’, and then type ‘gcdn’, it returns

‘/dev/video0’ but actually there is no ‘video0’ under ‘dev’ folder(only ‘nvgstcapture-1.0’ works, ‘nvgstcapture’ and ‘nvgstcapture-0.1’

don’t work, I don’t know why).

I tried to apply the newly released patch provided by dusty\_nv([https://devtalk.nvidia.com/default/topic/920739/jetson-tx1/l4t-r23-2-](https://devtalk.nvidia.com/default/topic/920739/jetson-tx1/l4t-r23-2-)

for-jetson-tx1-released/post/4824232/#4824232), but I think JetPack 2.1 already provides drivers or kernel sources that the patch is

applied.

Then I also tried to apply GST\_EXPORT := 3, but still same situation.

I thought it would be better to use “nvcamerasrc” pipeline instead of the default OpenCV cam value(-1 or 0).  
So I tried to use the above line

VideoCapture cap("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)

24/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)BGRx ! videoconvert ! ‘video/x-raw, format=(string)BGR’ ! appsink");

or just cap(0), cap(-1 ) or cap(1) but it always fails to find the camera.

Is it real that everybody doen not see this problem anymore and only me is the one facing this embarrassing situation? do I need to

remove the exisitng Opencv4Tegra and install the common openCV 2.4 as geoffreyall did?

Please if someone has any advice, let me know it.

---

<div class="post-metadata">

**Author:** ![kayccc](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/kayccc/32/14043_2.png) [@kayccc](https://forums.developer.nvidia.com/u/kayccc)\
**Post date:** [April 11, 2016, 7:13am UTC](https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945/7 "2016-04-11T07:13:51Z")

</div>

Hi SeunghyunLee,

Actually, the OpenCV4Tegra is not well optimized to support camera on Jetson TX1 at present version to cause the video capturing (live streaming) problem.  
We’re working this issue, and going to have an update version in coming release soon.

Instead of using OpenCV4Tegra, you could try to remove the exisitng Opencv4Tegra and install the common openCV 2.4 as geoffreyall did or to compile and install OpenCV 3.1.0 by referring the below thread:  
[url][https://devtalk.nvidia.com/default/topic/917386/jetson-tx1/usb-3-0-port-unstable-on-jetson-tx1-/post/4835793/#4835793[/url]](https://devtalk.nvidia.com/default/topic/917386/jetson-tx1/usb-3-0-port-unstable-on-jetson-tx1-/post/4835793/#4835793%5B/url%5D)

This should work as temporary solution on your case.

Thanks

---

<div class="post-metadata">

**Author:** ![BrianOrb](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@BrianOrb](https://forums.developer.nvidia.com/u/BrianOrb)\
**Post date:** [April 13, 2016, 10:44pm UTC](https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945/8 "2016-04-13T22:44:30Z")

</div>

I’m having this issue as well. I’m working on a time critical demo. The camera works fine with the v4l-2 interface but openCV fails sometimes with error, sometimes without error.

Can you provide a time line on the fix to the NVidia optimized openCV? I need to figure out if I’m going to have to use lib4vl for my demo.

Thanks,

Brian

---

<div class="post-metadata">

**Author:** ![ccchen](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ccchen](https://forums.developer.nvidia.com/u/ccchen)\
**Post date:** [September 1, 2016, 2:32am UTC](https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945/9 "2016-09-01T02:32:46Z")

</div>

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

```auto
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,

```auto
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!

---

<div class="post-metadata">

**Author:** ![ccchen](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@ccchen](https://forums.developer.nvidia.com/u/ccchen)\
**Post date:** [September 1, 2016, 2:35am UTC](https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945/10 "2016-09-01T02:35:01Z")

</div>

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

```auto
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,

```auto
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!

---

<div class="post-metadata">

**Author:** ![Gary\_4001](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/gary_4001/32/12639_2.png) [@Gary\_4001](https://forums.developer.nvidia.com/u/Gary_4001)\
**Post date:** [September 6, 2016, 9:55pm UTC](https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945/11 "2016-09-06T21:55:59Z")

</div>

same here, could nvidia really fix this annoying thing? We already wait for 3 months! NV keeps saying there will be an upgrade, there will be an upgrade, now where is it? 24.2 got even more bug! Seriously, we all hope NV could comes up with some new system, or release a step-by-step tutorial about how to load default Ubuntu and how to install those CUDA and things like them, how to set up so we can optimized CPU and GPU power.

---

<div class="post-metadata">

**Author:** ![kayccc](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/kayccc/32/14043_2.png) [@kayccc](https://forums.developer.nvidia.com/u/kayccc)\
**Post date:** [September 9, 2016, 3:01am UTC](https://forums.developer.nvidia.com/t/can-not-open-the-camera-on-tx1-via-opencv/41945/12 "2016-09-09T03:01:40Z")

</div>

Hi Gary\_4001,

Regarding the issue that met, we ave answered in another topic 961154:  
[url][https://devtalk.nvidia.com/default/topic/961154/problem-with-tx1-usb-camera-/?offset=1#4963564[/url]](https://devtalk.nvidia.com/default/topic/961154/problem-with-tx1-usb-camera-/?offset=1#4963564%5B/url%5D)

The USB camera should work with L4T 24.1 + OpenCV4Tegra 2.4.13.

About the onboard camera, assuming you’re using L4T 24.1, installing OpenCV 3.1.0 may work around this issue. See this thread: [url][https://devtalk.nvidia.com/default/topic/943129/jetson-tx1/highgui-error-v4l-v4l2-while-opening-camera-with-opencv4tegra-l4t-r24/post/4921383/#4921383[/url]](https://devtalk.nvidia.com/default/topic/943129/jetson-tx1/highgui-error-v4l-v4l2-while-opening-camera-with-opencv4tegra-l4t-r24/post/4921383/#4921383%5B/url%5D)

Would you please file another topic with specific issue you met?

Thanks
