Error I don't understand - 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: Error I don't understand (/thread-38406.html) |
Error I don't understand - finndude - Oct-09-2022 Hi, Heres is the code below: from tkinter import * from PIL import ImageTk, Image import cv2 import time data = cv2.VideoCapture("video.mp4") while not data.isOpened(): pass fps = data.get(cv2.CAP_PROP_FPS) length = int(data.get(cv2.CAP_PROP_FRAME_COUNT)) width = int(data.get(cv2.CAP_PROP_FRAME_WIDTH)) height = int(data.get(cv2.CAP_PROP_FRAME_HEIGHT)) print(fps, length, width, height) data.read() data.release() counter = 0 root = Tk() root.title("VIDEOS CANVAS TOOL") root.geometry(str(width) + "x" + str(height)) canvas = Canvas(root, width=width, height=height) canvas.grid(row=0) def showFrame(frame=0): t0 = time.time() data.set(cv2.CAP_PROP_POS_FRAMES, frame) success, image = data.read() #if not success: #print("error") #return image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) t1 = time.time() print("1", t1 - t0) image = ImageTk.PhotoImage(image=Image.fromarray(image)) t2 = time.time() print("2", t2 - t1) canvas.delete("all") canvas.create_image(0, 0, image=image, anchor=NW) t3 = time.time() print("3", t3 - t2) canvas.image = image t4 = time.time() print("4", t4 - t3) print("all", t4 - t0) root.after(int(1000//fps), lambda: showFrame(frame+1)) showFrame() # play the video root.mainloop()I get this error, but I don't understand what is going wrong here? Any thoughts?
RE: Error I don't understand - deanhystad - Oct-10-2022 Your src image is empty. Same question was asked here: https://stackoverflow.com/questions/60686426/opencv-in-python-gives-error-src-empty-in-function-cv2cvtcolor The error message could certainly be better. I often use assert when developing and testing code, then I go through the working code and replace likely assertion fails with a test that raises an exception. I am surprised something as likely as passing None as the source image is caught/reported using an assertion. Your image is empty because you released (data.release()) your video. If you take out lines 17-19 your program might work. RE: Error I don't understand - finndude - Oct-12-2022 Sorted, thanks! |