I want to convert a network camera video to grayscale and save it as an another video file.
I wrote the following code, but it does not work well.
However detect.avi
is output, I can not play this file.
What is the problem?
rtsp_path = f"rtsp://{userid}:{pwd}@{ip_address}:{rtsp_port}/ipcam_h264.sdp"
video = cv2.VideoCapture(rtsp_path )
savepath = "detect.avi"
frame_Rate = video.get(cv2.CAP_PROP_FPS)
height, width, dim = frame.shape
rec = cv2.VideoWriter(savepath, cv2.VideoWriter_fourcc(*'DIVX'), frame_Rate, (int(width), int(height)))
while (video.isOpened()):
开发者_如何学Python ret, frame = video.read()
if frame is None:
break
img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
rec.write(img)
if cv2.waitKey(30) & 0xFF == ord('q'):
video.release()
rec.release()
cv2.destroyAllWindows()
break
cv2.destroyAllWindows()
video.release()
rec.release()
精彩评论