Onboard OpenCV camera python capture

I really need some help cracking the OpenCV onboard camera capture…

I have spend really long time and tried many different approaches, but it always fails

The TX2 is flashed with the latest Nvidia package and all cpp samples works

I want to capture using python, and really need the simplest example that should work on a “out of the box” installation from the latest TX2 SDK manager software

I have tried with “gst-launch-1.0 nvarguscamerasrc …” producer
and all of these examples in versus combinations.

def open_cam_onboard(width, height):
# On versions of L4T previous to L4T 28.1, flip-method=2
# Use Jetson onboard camera
gst_str = ("nvarguscamerasrc ! "
"video/x-raw(memory:NVMM), width=(int)1280, height=(int)720, format=(string)I420, framerate=(fraction)30/1 ! "
"nvvidconv ! video/x-raw, width=(int){}, height=(int){}, format=(string)BGRx ! "
“videoconvert ! appsink”).format(width, height)
return cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

cap = open_cam_onboard(1280, 720)

#cap = cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, format=(string)$

#cap = cv2.VideoCapture(0)

#cap = cv2.VideoCapture(“nvcamerasrc”)

if not cap.isOpened():
print(“No Cam”)
exit()

System info
thr@TX2:~/python$ cat /etc/nv_tegra_release
R32 (release), REVISION: 4.3, GCID: 21589087, BOARD: t186ref, EABI: aarch64, DATE: Fri Jun 26 04:34:27 UTC 2020

thr@TX2:~/python$ sudo apt-cache show nvidia-jetpack
Package: nvidia-jetpack
Version: 4.4-b186

thr@TX2:~/python$ opencv_version
OpenCV 4.1.1 - with GStreamer support

@teddy_roskvist

I hope this link would be helpful in your case:

Hi,
We have OpenCV + gstreamer samples in
https://developer.nvidia.com/embedded/L4T/r32_Release_v4.3/Sources/T186/public_sources.tbz2

Please download it and give it a try.

Hi and thanks for the try.

I have actually already been there and tried that example, with no success.
You might recognize the code above

Just to be sure - Am i required to first start an gstreamer producer from another console before running the python script ?

Thanks DaneLLL

But it seems to be only C++ examples, and the C++ examples in the SDK works

I’m having problems with Python

@teddy_roskvist,

If you need to activate a CSI camera with Python on Jetson TX2,
you may try like this :
** I tested following code at Jetson Nano

import cv2

def open_cam_onboard(width, height):
   # On versions of L4T previous to L4T 28.1, flip-method=2
   # Use Jetson onboard camera
   gst_str = ("nvarguscamerasrc ! video/x-raw(memory:NVMM)," \
              "width=(int)1920, height=(int)1080, format=(string)NV12, " \
              "framerate=(fraction)30/1 ! nvvidconv ! video/x-raw, " \
              "width=(int){}, height=(int){}, format=(string)BGRx ! " \
              "videoconvert ! video/x-raw, format=(string)BGR !" \
              "appsink").format(width, height)

   return cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

cap = open_cam_onboard(1280, 720)

#cap = cv2.VideoCapture("nvcamerasrc ! video/x-raw(memory:NVMM), width=(int)1280, height=(int)720,format=(string)I420, framerate=(fraction)30/1 ! nvvidconv flip-method=0 ! video/x-raw, format=(string)$

#cap = cv2.VideoCapture(0)

#cap = cv2.VideoCapture(“nvcamerasrc”)

if cap is None:
   print("No Cam")

while True:
    _, frame = cap.read()

    cv2.imshow("frame", frame)
    key = cv2.waitKey(1) & 0xFF
    if key == ord("q"):
        break

cap.stop()
cv2.destroyAllWindows()

@MtHiker

Thanks.
It works now.
I think that i have been creating problems in the system when trying in many different ways, and thereby made a “block”

After a reboot the jkjung script worked

Thanks very much

1 Like

That’s great!