I 'm working on a python script. In this scrypt I try to open my ip camera and try to perform a motion detection.
I have tested my script first with my webcam (cv2.VideoCapture(0)), everything works fine.
But when I’am using my ipcamera I get the following error:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function ‘cv::cvtColor’
What I have found is the following:
It can happen because the cap.read fuction returns a false, thus the frame is empty.
Possible solutions are to cover it by an if statement
if ret false:
cap.release()
cap = cv2.VideoCapture(‘IP camera’)
ret, frame = cap.read()
This solution doesn’t work because ret is always false.
this keeps me in an endless loop
print(cv2.getBuildInformation()), find the “video I/O” section, post it here. it needs to include ffmpeg or gstreamer. I don’t know if both support rtsp but at least one of them does.