Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix opencv python cv2.VideoCapture rtsp onvif "nonmatching transport in server reply" error?

I am on Windows and using Python 3.6.4. I've installed OpenCV (3.4) via pip. Here is the code I am using:

import numpy as np
import cv2

cap = cv2.VideoCapture('rtsp://192.168.15.116:554/onvif1')

while(cap.isOpened()):
    ret, frame = cap.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

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

cap.release()
cv2.destroyAllWindows()

I am getting the following error:

[rtsp @ 03858a40] Nonmatching transport in server reply
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:808)
warning: rtsp://192.168.15.116:554/onvif1 (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:809)

I can go to cmd and type

ffplay rtsp://192.168.15.116/onvif1

and the video will run as well as in VLC using the same rtsp address. Using

cv2.VideoCapture(0)

also works with my webcam.

I've tried copying the file "opencv_ffmpeg340.dll" into all path folders but to no avail. I've also checked build and all video I/O show up with "YES" except for Gstreamer. Any help would be appreciated. Thank you.

like image 733
Projetos Prince Tower Avatar asked Nov 07 '22 11:11

Projetos Prince Tower


1 Answers

I installed OPENCV onto Windows 10 using Microsoft's VCPKG. After which, OPENCV worked fine - except it would not open videos files.

Without success, I tried many suggestions. Finally, what worked for me was very SIMPLE. I included opencv's BIN folder as a PATH in Windows Environment System Variables. That's it. Now, video files are opened and played just fine.

like image 144
Lawes Avatar answered Nov 14 '22 21:11

Lawes