Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error I don't understand
#1
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?


Error:
Traceback (most recent call last): File "C:\Users\Finley\Downloads\Biz Project Test.py", line 52, in <module> showFrame() # play the video File "C:\Users\Finley\Downloads\Biz Project Test.py", line 35, in showFrame image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) 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'
Any thoughts?
"Only Boring People Get Bored"
Reply
#2
Your src image is empty. Same question was asked here:

https://stackoverflow.com/questions/6068...v2cvtcolor

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.
Reply
#3
Sorted, thanks!
"Only Boring People Get Bored"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Don't understand error message Milfredo 2 2,066 Aug-24-2020, 05:00 PM
Last Post: Milfredo
Exclamation Get syntax error. Dont understand why beLIEve 21 14,723 Aug-25-2019, 02:28 PM
Last Post: ThomasL
  Syntax error for a reason I don't understand DanielCook 2 2,456 Aug-07-2019, 11:49 AM
Last Post: buran
  Error in script don't understand, please help! DanielR 0 2,053 Mar-15-2019, 12:39 PM
Last Post: DanielR
  I don't understand where is the error ghiso983 3 2,478 Jan-29-2019, 02:46 PM
Last Post: perfringo
  I don't understand the error MasterGame 1 2,566 Jul-18-2018, 07:55 PM
Last Post: gontajones
  Index Error, can't understand why. Diamond 5 4,325 Jan-03-2018, 11:45 AM
Last Post: Diamond

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020