RTSP with OpenCV (VideoCapture) on python3.7

Hi all,
I’ll take the occasion to present myself since this is my very first post in the forums - great community, people!!!

I have a problem with OpenCV and gstreamer to collect frames from an IP Camera via RTSP.

My need: I need to collect frames from an IP Camera over RTSP using OpenCV (standard JetPack) and Python3.7 using the VideoCapture API.
This is a very straightforward method that I always use with other platforms - it’s a one liner actually:
cap = cv2.VideoCapture("rtsp://*********@<camera_ip>:<camera_port>/<stream_path>")
My problem: I am not able to collect IP camera frames using Python3.7 and OpenCV 4.5.1, but I can do it only with pre-installed Python3.6 + OpenCV

My tests and results: I built OpenCV for Py3.7 following the post here: https://forums.developer.nvidia.com/t/jetson-nano-opencv-4-1-0/77367 and for testing purposes, I’m using the tegra-cam.py script from https://gist.github.com/jkjung-avt/86b60a7723b97da19f7bfa3cb7d2690e

If I try running the script through python3.7 - It fails me:
$python3.7 tegra-cam.py --rtsp --uri rtsp://****:****@192.168.1.65:554/stream2
...... OpenCV version: 4.5.1 / Failed to open camera!

while if I try running the same script using python3.6, it shows me my stream without any problem.
$python3.6 tegra-cam.py --rtsp --uri rtsp://****:****@192.168.1.65:554/stream2
I can see my camera frames with this


How can I enable RTSP frame collection with OpenCV using python3.7??? Has anyone had the same problem?

Thanks

Hi,
Please try this sample with python3.7:

You would need to enable gstreamer in building OpenCV4.5.1.

Thanks @DaneLLL ,

I tested your example but I get an rtsp open failure (CAP_IMAGES can’t find starting number)

please note that this example is not compatible with Python3.7 syntax, and I had to correct the print statement to make it work. Have you tried it using Python3.7 ?

You mentioned building OpenCV 4.5.1 enabling gstreamer, but I couldn’t find any documentation to guide me through that - do you have any reference docs to do that and to link the right libraries in python3.7?

Hi,
By default is 3.6.9. We are able to run the script with this version.

nvidia@nvidia-desktop:~$ python3
Python 3.6.9 (default, Oct  8 2020, 12:12:24)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.