我正在尝试使用Python中的OpenCV访问我的IP摄像头,但是当我运行我的代码时出现以下错误:
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cv::ipp_cvtColor, file ..\..\..\modules\imgproc\src\color.cpp, line 7456
Traceback (most recent call last):
File "C:/Users/taimur.islam/Desktop/ipcamera/b.py", line 11, in <module>
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.error: ..\..\..\modules\imgproc\src\color.cpp:7456: error: (-215) scn == 3 || scn == 4 in function cv::ipp_cvtColor
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:779)
warning: http://Admin:Admin@192.168.10.74:8899/videostream.cgi?.mjpg (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:780)
这是我的代码:
import numpy as np
import cv2
cap = cv2.VideoCapture('http://Admin:Admin@192.168.10.74:8899/videostream.cgi?.mjpg')
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
# Our operations on the frame come here
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()