![]() |
python opencv grayscale conversion error - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: python opencv grayscale conversion error (/thread-17249.html) |
python opencv grayscale conversion error - Spandora - Apr-03-2019 Hi, I am running below script. I tried with different video files format, avi/mp4 but the error is at line where each video frame is converted into grayscale. I tried this code by providing images from folder it works but when used video. There is error for grayscale conversion. Please advice.
import numpy as np import cv2 path = 'file_example_AVI_480_750kB.avi' # below code works with OpenCV cap = cv2.VideoCapture(path) while(cap.isOpened()): ret, frame = cap.read() frameNum = frameNum+1; # to implement gray conversion of frame nframe_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #Below code, shows each frame in a moving video #if ret == True: # Display the resulting frame # cv2.imshow('Frame', frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows() RE: python opencv grayscale conversion error - heiner55 - May-26-2019 Your code runs well with the below change: if ret == True: nframe_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) |