GStreamer error with python3

Hello, I have an error while trying to use pi camera on jetson nano, using python 3.6:

import cv2

camSet="nvarguscamerasrc ! video/x-raw(memory:NVMM),format=NV12,width=640,height=480,framerate=30/1 ! nvvidconv ! video/x-raw,format=BGRx ! videoconvert ! video/x-raw,format=BGR ! appsink drop=1 "
cam= cv2.VideoCapture(camSet,cv2.CAP_GSTREAMER)


# Capture frame-by-frame
ret,frame =
if cv2.waitKey(1) == ord(‘q’):

The error:

Traceback (most recent call last):
File “”, line 21, in
cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-zuuo394f/opencv/modules/highgui/src/window.cpp:376: error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘imshow’

But while running the code using python 2.7, the camera works normally and after some help it was recognized that GStreamer is “yes” for python 2 and “No” for python 3:

Python 3
Video I/O:

GStreamer: NO

Python 2
Video I/O:

GStreamer: YES (1.14.5)

So the question is how to install GStreamer for python 3 also?

Gstreamer should already be installed in pyhton3. In python3, type the following for checking:

import gi
gi.require_version('Gst', '1.0')
from gi.repository import Gst
print("Using Gst: {}.{}.{}.{}".format(*Gst.version()))

If this is ok (gstreamer is available from python3), the question may rather be: what is the opencv package used by python3 and does it match with where does my opencv install step as installed the python3 library, as said here.

I tried the mentioned code and this is the output:

corki@corki:~$ python
Python 3.6.9 (default, Jan 26 2021, 15:33:00)
[GCC 8.4.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
import gi
gi.require_version(‘Gst’, ‘1.0’)
from gi.repository import Gst
print(“Using Gst: {}.{}.{}.{}”.format(*Gst.version()))
Using Gst:

OK, so gstreamer is available from your python 3.6.9 setup.
You may try to check which opencv lib is used by your python3.6.9 install and where the opencv build script did install its new version including gstreamer support (for opencv).

1 Like

is there any hints how can I figure this out?

You may get details about the one running from python3 with:

import cv2

Note the path where python3 cv2 lib has been installed.

Check (or rerun) opencv install step (sudo make install in opencv build directory) logs for checking where it has installed opencv lib.

I’d suspect both paths to be different.

Python 3.6.9 (default, Jan 26 2021, 15:33:00)
[GCC 8.4.0] on linux
Type “help”, “copyright”, “credits” or “license” for more information.

import cv2

General configuration for OpenCV 4.5.1 =====================================
Version control: 4.5.1-dirty

Timestamp: 2021-01-02T12:47:39Z
Host: Linux 5.4.0-54-generic aarch64
CMake: 3.18.4
CMake generator: Unix Makefiles
CMake build tool: /bin/gmake
Configuration: Release

CPU/HW features:
Baseline: NEON FP16

Built as dynamic libs?: NO
C++ standard: 11
C++ Compiler: /opt/rh/devtoolset-9/root/usr/bin/c++ (ver 9.3.1)
C++ flags (Release): -Wl,-strip-all -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -Wl,-strip-all -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: /opt/rh/devtoolset-9/root/usr/bin/cc
C flags (Release): -Wl,-strip-all -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -Wl,-strip-all -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release): -L/root/ffmpeg_build/lib -Wl,–gc-sections -Wl,–as-needed
Linker flags (Debug): -L/root/ffmpeg_build/lib -Wl,–gc-sections -Wl,–as-needed
ccache: YES
Precompiled headers: NO
Extra dependencies: ade Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test Qt5::Concurrent /lib64/ /lib64/ dl m pthread rt
3rdparty dependencies: ittnotify libprotobuf libjpeg-turbo libwebp libtiff libopenjp2 IlmImf quirc tegra_hal

OpenCV modules:
To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching video videoio
Disabled: world
Disabled by dependency: -
Unavailable: java python2 ts
Applications: -
Documentation: NO
Non-free algorithms: NO

QT: YES (ver 5.15.0)
QT OpenGL support: NO
VTK support: NO

Media I/O:
ZLib: /lib64/ (ver 1.2.7)
JPEG: libjpeg-turbo (ver 2.0.6-62)
WEBP: build (ver encoder: 0x020f)
PNG: /lib64/ (ver 1.5.13)
TIFF: build (ver 42 - 4.0.10)
JPEG 2000: build (ver 2.3.1)
OpenEXR: build (ver 2.3.0)

Video I/O:
DC1394: NO
avcodec: YES (58.112.103)
avformat: YES (58.64.100)
avutil: YES (56.60.100)
swscale: YES (5.8.100)
avresample: NO
GStreamer: NO
v4l/v4l2: YES (linux/videodev2.h)

Parallel framework: pthreads

Trace: YES (with Intel ITT)

Other third-party libraries:
Lapack: NO
Eigen: NO
Custom HAL: YES (carotene (ver 0.0.1))
Protobuf: build (3.5.1)

OpenCL: YES (no extra features)
Include path: /tmp/pip-req-build-zuuo394f/opencv/3rdparty/include/opencl/1.2
Link libraries: Dynamic load

Python 3:
Interpreter: /opt/python/cp36-cp36m/bin/python (ver 3.6.12)
Libraries: libpython3.6m.a (ver 3.6.12)
numpy: /tmp/pip-build-env-c03ewnak/overlay/lib/python3.6/site-packages/numpy/core/include (ver 1.19.3)
install path: python

Python (for build): /bin/python2.7

ant: NO
Java wrappers: NO
Java tests: NO

Install to: /tmp/pip-req-build-zuuo394f/_skbuild/linux-aarch64-3.6/cmake-install

would you suggest to reformat the jetson nano and reinstall a clean version? if yes, could you please tell what are the steps to install the packages correctly ( python3, opencv and Gstreamer)

Someone more skilled about python environment may be able to help you further, I can’t.

Reflashing would loose any data on Jeston (you may save important work if any before), but it can save hours of debugging if you’re unsure about what you’ve installed and custom configured.
From a clean jetson install, using one of these scripts should be ok for both python2 and 3:

1 Like

I really appreciate your time and effort, thanks a lot.
so after installing a new image on the SD card, should Ijust run one of these scripts? even before installing python 3 or any other packages like tensorflow, numpy…etc?

First be sure to update your Jetson with apt.
Then I think it should be ok to install opencv.