Ask Your Question
0

Here is another rtsp cv2.VideoCapture onvif camera Nonmatching transport and -215:Assertion failed size and width > 0

asked 2020-11-08 20:37:36 -0600

Anthony Of Sydney gravatar image

updated 2020-11-11 01:54:57 -0600

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 ...
(more)
edit retag flag offensive close merge delete

Comments

Change this:

cap.isOpened();  
    while(True):

to:

while cap.isOpened():
supra56 gravatar imagesupra56 ( 2020-11-09 03:34:38 -0600 )edit
1

Thank you for response. The fact is I tested whether the VideoCapture was opened by asking

cap.isOpened()

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

 if cv2.waitKey(1) & 0xFF == ord('q'):
        break

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

Anthony Of Sydney gravatar imageAnthony Of Sydney ( 2020-11-09 15:48:02 -0600 )edit

U should attempt this: ret, frame = cap.read()

 if(ret): 
     cv2.imshow('frame',frame)
     if cv2.waitKey(1) & 0xFF == ord('q'):
          break
    cap.release()
    cv2.destroyAllWindows()
supra56 gravatar imagesupra56 ( 2020-11-09 22:04:59 -0600 )edit

Try this:

import cv2
import numpy as np
import os
os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"] = "rtsp_transport;udp"
cap = cv2.VideoCapture(url3,cv2.CAP_FFMPEG)
while cap.isOpened:
ret, frame = vcap.read()
    if ret == False:
        print("Frame is empty")
        break;
    else:
        cv2.imshow('VIDEO', frame)
        cv2.waitKey(1)
supra56 gravatar imagesupra56 ( 2020-11-09 22:17:41 -0600 )edit

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

import numpy as np
import cv2, os
cap = cv2.VideoCapture(1)
cap.isOpened(); #prints True, and program. Program continues.
while(True):
    ret, frame = cap.read()
    #print(frame)
    cv2.imshow('frame',frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()

BUT same code does not work for a IP web camera

Thank you,

Anthony of Sydney

Anthony Of Sydney gravatar imageAnthony Of Sydney ( 2020-11-10 17:42:02 -0600 )edit

pc or laptop? I am using linux on raspberry pi 4. I am off for holiday.

supra56 gravatar imagesupra56 ( 2020-11-10 21:10:16 -0600 )edit
1

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

Anthony Of Sydney gravatar imageAnthony Of Sydney ( 2020-11-10 21:21:58 -0600 )edit

This is my friend using pc. Here is code:

import numpy as np
import cv2

#cap = cv2.VideoCapture(0)

cap = cv2.VideoCapture('rtsp://username:[email protected]:554/1') # Test

while(cap.isOpened()):
    ret, frame = cap.read()
    cap.set(3, 1280)
    cap.set(4, 720)
    try:
        cv2.imshow('Frame',frame)
    except:
        print('EOF')
        break

    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break

cap.release()
cv2.destroyAllWindows()
supra56 gravatar imagesupra56 ( 2020-11-10 21:27:07 -0600 )edit

HaHa. I see that u r using win7. Actually, OpenCV 3.4.x is obsoleted. The latest is OpenCV4.5.0

supra56 gravatar imagesupra56 ( 2020-11-10 21:31:07 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-11-11 01:28:21 -0600

Anthony Of Sydney gravatar image

updated 2020-11-11 15:32:42 -0600

Thank you for sharing your reply. Unfortunately, it does not work. cap.isOpened() is False Sorry for misstyping, my version of cv2 is

>>> cv2.__version__
'4.4.0'

It works for the USB camera

>>> cap = cv2.VideoCapture(1)
>>> cap.isOpened()
True

It does not work for the IP Camera

>>> cap = cv2.VideoCapture('rtsp://user:[email protected]/onvif1')
>>> cap.isOpened()
False

It works only in "Media Player Classic" program which uses FFMPEG part of K-Lite Codec

Menu: open file/url -> enter the url >>> 'rtsp://user:[email protected]/onvif1'

In sum:

  • Your friend's program works with my USB camera.

  • Your friend's program DOES NOT WORK with my IP Camera.

    cap.isOpened() ;# IS FALSE WHEN INSTANTIATED`.

Thank you anyway,

Anthony of Sydney

edit flag offensive delete link more

Comments

Hi! Im having the exact same problem using an yoosee camera, did you arrive to any solutions or answers? Thank you!

maxmardones gravatar imagemaxmardones ( 2020-11-18 17:31:22 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-11-08 20:37:36 -0600

Seen: 9,688 times

Last updated: Nov 11 '20