Access TX2 onboard camera from host: Cannot connect to X server


I’m trying to use NSight on a host machine running Ubuntu 16.04 to access the onboard camera of the Jetson TX2 developer module. I’m also using OpenCV 3.4 with GStreamer enabled. I have my host machine connected via ethernet to the TX2. I can successfully run the cross-compilation example at

Now I want to try and control the camera. From the host, I can ssh into the device and run the following command from the terminal fine.

gst-launch-1.0 nvcamerasrc ! nvvidconv ! xvimagesink

A video image appears on the host. So then I wrote the simple program below in NSight:

int main()
   std::cout << cv::getBuildInformation() << std::endl;
   cv::Mat img;

   std::string gst = "nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)640, height=(int)480, format=(string)I420, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, format=(string)I420 ! videoconvert ! video/x-raw, format(string)BGR ! appsink";

   cv::VideoCapture input(gst);

   for (;;)
      if (!

      cv::imshow("img", img);
      char c = cv::waitKey(30);
      if (c == ' ')


I can run this directly on the device itself and it works. When I try to compile it on the host and run it remotely, it seems like it starts to access the camera because I get the message

“NvCameraSrc: Trying to Set Default Camera Resolution. Selected sensorModeIndex = 1 WxH = 2592x1458 FrameRate = 30.000000 …”

But then I get a “cannot connect to X server” message immediately after. Looking around, it seems like it might have to do with X forwarding not being enabled when Nsight connects remotely to the device. But I’m not sure how to resolve this. Can anyone help me out? Thanks in advance.

You may try to check DISPLAY environment variable (you may use getenv/setenv in your app).
If you want to display on a local monitor attached to Jetson you may use DISPLAY=:0. If you want display on your host, you may use DISPLAY=$HOSTIP:0 where $HOSTIP is the IP of your host. You may have to allow external access to your host X server with command xhost.

Yes, that was it! I’m now able to display the video on a local monitor. Thank you!