1
votes

I want to transfer RTSP stream from an IP Camera to python, but I can't get it to work with python.

I can view the stream with either VLC or the camera website. I used the following code:

import os
import cv2
import urllib.request
import requests

os.environ["OPENCV_FFMPEG_CAPTURE_OPTIONS"]="rtsp_transport;udp"


#print("Before URL")
#print("After URL")
adr = 'rtsp://192.168.100.86:554'
try:
    stream = cv2.VideoCapture(adr)
except Exception as g:
    print("no stream")

while True:
    img_res = stream.read()
    #print('About to show frame of Video.')
    try:
        cv2.imshow("Capturing",img_res)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    except Exception as e:
        print(e)

Knowing that nmap command shows the camera has these open ports :

Host is up (0.016s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
80/tcp   open  http
554/tcp  open  rtsp
7103/tcp open  unknown
8001/tcp open  vcom-tunnel

When I run the above code with either rtsp:554 or http:80 I get the following error:

 Expected cv::UMat for argument 'mat'
1
any answer from you guys?Mohammed Baashar

1 Answers

1
votes

I checked your code and tried in my ip camera. It is giving the same error. Then I just changed the reading line in loop with:

ret,img_res = stream.read()

And it fixed the problem. I also tried in my webcams and the same error occurs at all if you do not check the frame is okey or not. So checking the frame is critical before other steps. From the documentation ret in here is:

ret is a boolean variable that returns true if the frame is available.