Here is another rtsp cv2.VideoCapture onvif camera Nonmatching transport and -215:Assertion failed size and width > 0
Am I missing something in trying to get frames from my ip camera over a network. The solution did not work at "Nonmatching transport in server reply" when cv2.VideoCapture rtsp onvif camera, how to fix? did not work for me.
Is there something missing in what I am doing? Background information:
OS Win 7 64-bit
Python - using both IDLE and DOS/cmd version, v3.8.5 - to show the error codes.
Open cv - version 4.4.0
Router, with address 192.168.1.1
Wireless adapter with address 192.168.1.100
Schematic diagram: IP Camera -> RJ45 into wireless router (192.168.1.1) -> air -> PC's wireless adapter (192.168.1.100) -> python computer program trying to decode the program. NOTE again: I can use other applications but cannot use opencv.
Where my IPCamera works:
The camera does communicate with VLC (v3.0.11 Vetinari) player's video stream setting with URL = rtsp://user:[email protected]:554/onvif1 from the menu: Media -> Open Network Stream -> enter URL. That's with VLC.
The camera does communicate with other Media Player Classic (1.9.8.21) which uses FFMPEG. From the menu: File -> Open File/URL, and enter the URL = rtsp://user:[email protected]:554/onvif1.
Furthermore, I can use 'any' application on my PC to connect to the IPCamera via the router - for example ISpy. Since the IPCamera's signal goes through a router, my smartphone's Android v5.1.1 with WiFi set to on, I can use any ONVIF application installed on my smartphone.
A python program can be successfully connected to the IPCamera using VLC :
import vlc player = vlc.MediaPlayer('rtsp://user:[email protected]:554/onvif1') player.play() player.stop()
In sum there is nothing wrong with the IP camera, the camera's signal can be read by any application such as VLC and Media Player classic using FFMPEG. Python can be used to view images from the IP Camera using VLC.
BUT I want to use opencv in order to use the bytes coming out of each frame.
Note: user and pword are found at the bottom of the camera.
Code to replicate the problem using opencv in both IDLE and DOS/cmd:
Here is the opencv implementation. It is after instantiation of the VideoCapture that the program does not proceed to the while loop. I used cv2's isOpened to determine that the program stops at instantiation of the VideoCapture.
import numpy as np
import cv2, os
#It does not matter which of the following os.environ assignments worked
os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp"
#os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;0"
#os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;tcp"
#os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "dummy"
# The url3 has been successfully used in VLC player and Media Player Classic Home.
url3 = "rtsp://user:[email protected]:554/onvif1"
#cap = cv2.VideoCapture(url3)
# BUT here the program stops once VideoCapture is instantiated, the program does ...
Change this:
to:
Thank you for response. The fact is I tested whether the VideoCapture was opened by asking
and the result was False.
So the while loop never was invoked. That is the program stopped when VideoCapture was opened. Even if I put the loop of while cap.isOpened() the program would never get the frame data because the status of isOpened() is False thus the while loop is not invoked. Suppose isOpened() was True, the while(True) loop would be invoked and would be stopped by
But isOpened() = False, and if what you suggested to include isOpened() in the loop would not work because it is False.
Hence I could not retrieve a single Frame.
But thank you anyway,
Anthony of Sydney
U should attempt this: ret, frame = cap.read()
Try this:
Thank you again, for your response. It does not work. The cv2.isOpened() is False ! However, your code with a USB camera, works. BUT your code does not work with an IP camera.
The original code below works with a USB camera. the cap.isOpened() prints True
The original code that I did WORKS for USB Camera
BUT same code does not work for a IP web camera
Thank you,
Anthony of Sydney
pc or laptop? I am using linux on raspberry pi 4. I am off for holiday.
Thank you for your reply. Please have a safe trip and come back safely. As per top of the page, I mentioned the specifications, which was a Laptop with Win 7. It is not RPi. It still does not answer the question why other applications on my PC via the router and even my smartphone via the router, other applications work, even VLC on Python IDLE and DOS/cmd. Even the "Media Player Classic" using the FMMPEG works. So why am I having a problem with cv2 and IPCamera, BUT NOT cv2 and usb camera.Please refer to my section in my question on what works. Thank you Anthony of Sydney
This is my friend using pc. Here is code:
HaHa. I see that u r using win7. Actually, OpenCV 3.4.x is obsoleted. The latest is OpenCV4.5.0