OpenCV视频上的透明画布

时间:2019-06-26 17:08:33

标签: python opencv canvas tkinter

是否可以在tcinter的opencv视频上创建透明画布? OI想在tkinter应用中的视频上画些东西。

我正在尝试使用以下代码:

#Graphics window
mainWindow = tk.Tk()
mainWindow.configure(bg=lightBlue2)
mainWindow.geometry('%dx%d+%d+%d' % (maxWidth,maxHeight,0,0))
mainWindow.resizable(0,0)
# mainWindow.overrideredirect(1)
c = Canvas(mainWindow, width=640, height=480, bd=0, highlightthickness=0)
c.create_line(0,240,640,240, fill='blue')
c.pack()
mainFrame = Frame(mainWindow)
mainFrame.place(x=20, y=20)                

#Capture video frames
lmain = tk.Label(mainFrame)
lmain.grid(row=0, column=0)

cap = cv2.VideoCapture('foot.mp4')

def show_frame():
    ret, frame = cap.read()

    cv2image   = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)

    img   = Image.fromarray(cv2image).resize((760, 400))
    imgtk = ImageTk.PhotoImage(image = img)
    lmain.imgtk = imgtk
    lmain.configure(image=imgtk)
    lmain.after(10, show_frame)

closeButton = Button(mainWindow, text = "CLOSE", font = fontButtons, bg =             white, width = 20, height= 1)
closeButton.configure(command= lambda: mainWindow.destroy())              
closeButton.place(x=270,y=430)  

show_frame()  #Display
mainWindow.mainloop()  #Starts GUI

但是画布始终位于视频的底部或顶部

1 个答案:

答案 0 :(得分:0)

在tkinter中不可能使画布透明,但可以使winodw透明。您还需要做其他事情