Failed to open TX1 on-board camera

I’d suggest to remove the 2.4.9 version, or move it elsewhere if you need to keep it. Be sure anyway to know what software you’ve developed that might depend on it before removing it, of course.
Have you installed it through a package or self built and installed ? If it was through package, you may use the package tool (apt, dpkg,…) for removing package.

I’m not familiar with python, someone with better knowledge may share.

Maybe reconfiguring an opencv3.2.0 library with gstreamer and python (2 or 3) enabled for your case, setting CMAKE_INSTALL_PREFIX to /usr/local/opencv-3.2.0, build with make and (after cleaning old traces from /usr/local/include and /usr/local/lib) install with:

sudo make install

then retry after adding path /usr/local/opencv-3.2.0/lib to environment variable LD_LIBRARY_PATH in the shell you launch python from, or set it in python configuration if this exists.

One extra thing to know is that pkg-config is sometimes used to provide flags or libs in toolchains. Check also if

pkg-config --modversion opencv
pkg-config --cflags --libs opencv

returns the expected version and paths.
If not, you might remove (or rename) file /usr/lib/pkgconfig/opencv.pc and make there instead a symlink to /usr/local/opencv-3.2.0/lib/pkgconfig/opencv.pc.

What gives

sudo apt search opencv | grep installed

Hi honey_Patouceul ,

sorry for reponse so later , I have finished a business travel just ,

I try to uninstall python2.7 and reinstall ,and now ,the system status is following:

ubuntu@tegra-ubuntu:~/test$ pkg-config --modversion opencv
3.2.0
ubuntu@tegra-ubuntu:~/test$ pkg-config --cflags --libs opencv
-I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_cudabgsegm -lopencv_cudaobjdetect -lopencv_cudastereo -lopencv_shape -lopencv_stitching -lopencv_cudafeatures2d -lopencv_superres -lopencv_cudacodec -lopencv_videostab -lopencv_cudaoptflow -lopencv_cudalegacy -lopencv_calib3d -lopencv_features2d -lopencv_objdetect -lopencv_highgui -lopencv_videoio -lopencv_photo -lopencv_imgcodecs -lopencv_cudawarping -lopencv_cudaimgproc -lopencv_cudafilters -lopencv_video -lopencv_ml -lopencv_imgproc -lopencv_flann -lopencv_cudaarithm -lopencv_core -lopencv_cudev
ubuntu@tegra-ubuntu:~/test$ sudo apt search opencv | grep installed

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libopencv-calib3d-dev/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-calib3d2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,automatic]
libopencv-contrib2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,automatic]
libopencv-core-dev/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-core2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,automatic]
libopencv-features2d-dev/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-features2d2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,automatic]
libopencv-flann-dev/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-flann2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,automatic]
libopencv-gpu-dev/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-gpu2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-highgui2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,automatic]
libopencv-imgproc-dev/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-imgproc2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,automatic]
libopencv-legacy2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,automatic]
libopencv-ml-dev/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-ml2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,automatic]
libopencv-objdetect2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,automatic]
libopencv-ocl2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-photo-dev/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-photo2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,automatic]
libopencv-stitching-dev/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-stitching2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-superres2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-ts-dev/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-ts2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-video-dev/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv-video2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,automatic]
libopencv-videostab2.4v5/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
libopencv2.4-java/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 all [installed,auto-removable]
libopencv2.4-jni/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed,auto-removable]
opencv-data/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 all [installed,auto-removable]
python-opencv/xenial,now 2.4.9.1+dfsg-1.5ubuntu1 arm64 [installed]
ubuntu@tegra-ubuntu:~/test$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

import cv2
Traceback (most recent call last):
File “”, li

I can not import cv2.so corrected ? what is wrong with me?

It seems you still have a 2.4.9 version installed.
You may remove any version installed through apt with:

sudo apt purge libopencv*

I’m not familiar with python, but you may have to import sys before importing cv2.

Hi honey_Patouceul ,

thanks alot . thank you for  helping me find the root cause .I have already gotten  the video through on_board camera .

B/R

Hi lgz3308,
I have met the same issue with you on TX2 which installs opencv 3.2.0. A problem come around when I use cv2.VideoCapture(0), the tips as followed:

nvidia@tegra-ubuntu:~/opencv/build$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'3.2.0'
>>> vs = cv2.VideoCapture(0)
VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV

Then I change cv2.VideoCapture(0) as followed:

>>> cap = cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)640, height=(int)480, format=(string)I420, framerate=(fraction)24/1 ! nvvidconv flip-method=6 ! video/x-raw, format=(string)I420 ! videoconvert ! video/x-raw, format=(string)BGR ! appsink")
>>> retval, frame = cap.read()
>>> frame
>>> frame.shape
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'shape'
>>> cap.isOpened()
False

As above, we can see that the onboard camera remains closed. Any help will be appreciated.

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”);

pls use the above forma,opencv can not get the video with device id 0.

maybe you can try the following python code:

import cv2
import numpy as np
cv2.namedWindow(“test”)
#cap=cv2.VideoCapture(0)
#cap = cv2.VideoCapture(“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”)
cap = cv2.VideoCapture(“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”)
#cap = cv2.VideoCapture(“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”)

#cap = cv2.VideoCapture(“rtsp://admin:admin12345@192.168.10.214:554/h264/ch1/main/av_stream”)
success, frame = cap.read()
color = (0,0,0)
classfier=cv2.CascadeClassifier(“haarcascade_frontalface_alt.xml”)
while success:
success, frame = cap.read()
size=frame.shape[:2]
image=np.zeros(size,dtype=np.float16)
#image = cv2.cvtColor(frame, cv2.cv.CV_BGR2GRAY)
#cv2.equalizeHist(image, image)
divisor=8
h, w = size
minSize=(w/divisor, h/divisor)
#faceRects = classfier.detectMultiScale(image, 1.2, 2, cv2.CASCADE_SCALE_IMAGE,minSize)
cv2.imshow(“test”, frame)
key=cv2.waitKey(10)
c = chr(key & 255)
if c in [‘q’, ‘Q’, chr(27)]:
break
cv2.destroyWindow(“test”)

Hi aspirinkb,
I have met the same issue with you on TX2 which installs opencv 3.2.0 too.
build opencv3.2 [url]http://www.jetsonhacks.com/2017/04/05/build-opencv-nvidia-jetson-tx2/[/url]

Did you solve the problem?

I have written a pretty detailed guide about how to do this on Jetson TX2. I think the procedure also works for Jetson TX1. Just remember to set CUDA_ARCH_BIN to 5.3 when doing cmake on opencv-3.3.0, and probably set nvvidconv ‘flip-method=2’ in the GStreamer pipeline for Jetson onboard camera.

“How to Install OpenCV (3.3.0) on Jetson TX2”: [url]https://jkjung-avt.github.io/opencv3-on-tx2/[/url]
“How to Capture and Display Camera Video with Python on Jetson TX2”: [url]https://jkjung-avt.github.io/tx2-camera-with-python/[/url]

it’s my method.
to setting opencv.
opencv3.2.0 on tx2
[url]Open CV camera error jetson tx2 - Jetson TX2 - NVIDIA Developer Forums

import numpy as np
import cv2

#cap = cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)640, height=(int)480, format=(string)I420, framerate=(fraction)30/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)I420 ! videoconvert ! video/x-raw, format=(string)BGR ! appsink")
gst = "nvarguscamerasrc  ! video/x-raw(memory:NVMM), width=(int)640, height=(int)480, format=(string)I420, framerate=(fraction)30/1 ! nvvidconv flip-method=2 ! video/x-raw, format=(string)I420 ! videoconvert ! video/x-raw, format=(string)BGR ! appsink"

cap = cv2.VideoCapture(gst)
while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

    # Our operations on the frame come here
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY, 3)

    # Display the resulting frame
    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

Lab5@tegra-ubuntu:~/Desktop/SEM_VII/TermProject$ python Video.py
GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected…
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 2592 x 1944 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 34000, max 550385000;

GST_ARGUS: 2592 x 1458 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 34000, max 550385000;

GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 16.000000; Exposure Range min 22000, max 358733000;

GST_ARGUS: Running with following settings:
Camera index = 0
Camera mode = 1
Output Stream W = 2592 H = 1458
seconds to Run = 0
Frame Rate = 29.999999
GST_ARGUS: PowerService: requested_clock_Hz=13608000
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
GST_ARGUS: Cleaning up
CONSUMER: Done Success
GST_ARGUS: Done Success

[b]OpenCV Error: Unspecified error (GStreamer: unable to start pipeline
) in cvCaptureFromCAM_GStreamer, file /home/nvidia/build_opencv/opencv/modules/videoio/src/cap_gstreamer.cpp, line 887
VIDEOIO(cvCreateCapture_GStreamer (CV_CAP_GSTREAMER_FILE, filename)): raised OpenCV exception:

/home/nvidia/build_opencv/opencv/modules/videoio/src/cap_gstreamer.cpp:887: error: (-2) GStreamer: unable to start pipeline
in function cvCaptureFromCAM_GStreamer
[/b]
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /home/nvidia/build_opencv/opencv/modules/imgproc/src/color.cpp, line 11048
Traceback (most recent call last):
File “Video.py”, line 13, in
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY, 3)
cv2.error: /home/nvidia/build_opencv/opencv/modules/imgproc/src/color.cpp:11048: error: (-215) scn == 3 || scn == 4 in function cvtColor

GST_ARGUS:
PowerServiceHwVic::cleanupResources

I want to access on-board camera using opencv-python and hence I have used the above program.
I have consistently receiving the error(mentioned in bold letters) whether I am using this particular code or any other code.
The on-board is working properly.(Checked using :

gst-launch-1.0 -ev nvcamerasrc ! nvvidconv ! ximagesink)

Please help me to resolve this issue.