0

hi i am just trying to keep video frame using webcam in python GUI using tkinter module

how can i move video to down or to some other place in GUI and how to decrease the video show screen size

i am trying to change lmain = tk.Label(master=window) in main function to lmain = tk.Label(master=window).place(x=500,y=500)

if i do that i am getting the following error

[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674) SourceReaderCB::~SourceReaderCB terminating async callback

#This Python program is developed in order to open an internal camera and display the image within Tkinter window.

#importing modules required
from ttk import *
import tkinter as tk
from tkinter import *
import cv2
from PIL import Image, ImageTk
import os
import numpy as np


global last_frame                                      #creating global variable
last_frame = np.zeros((480, 640, 3), dtype=np.uint8)
global cap
cap = cv2.VideoCapture(0)

def show_vid():                                        #creating a function
    if not cap.isOpened():                             #checks for the opening of camera
        print("cant open the camera")
    flag, frame = cap.read()
    frame = cv2.flip(frame, 1)
    if flag is None:
        print("Major error!")
    elif flag:
        global last_frame
        last_frame = frame.copy()

    pic = cv2.cvtColor(last_frame, cv2.COLOR_BGR2RGB)     #we can change the display color of the frame gray,black&white here
    img = Image.fromarray(pic)
    imgtk = ImageTk.PhotoImage(image=img)
    lmain.imgtk = imgtk
    lmain.configure(image=imgtk)
    lmain.after(10, show_vid)

if __name__ == '__main__':
    window=tk.Tk()                                     #assigning window variable for Tkinter as tk
    lmain = tk.Label(master=window)
    lmain.grid(column=0, rowspan=4, padx=5, pady=5)
    window.title("Sign Language Processor")            #you can give any title
    window.geometry("1366x768")
    show_vid()
    window.mainloop()                                  #keeps the application in an infinite loop so it works continuosly
    cap.release()

  • Can't reproduce this, please make sure, code you posts actually behaves as you claim. Read [AttributeError: NoneType object has no attribute ...](https://stackoverflow.com/a/1101765/7414759) – stovfl Feb 15 '20 at 09:33
  • The code will not work as `l2` is `None`. – acw1668 Feb 15 '20 at 09:38
  • If `flag` is None, then `frame` may not be what you expect. But your code still proceed to process it and it may cause problem. Also if `isOpened()` returns false, you should not read frame from webcam. – acw1668 Feb 15 '20 at 11:48
  • [cv2-warn0-terminating-async-callback-when-attempting-to-take-a-picture](https://stackoverflow.com/questions/53888878/cv2-warn0-terminating-async-callback-when-attempting-to-take-a-picture) may help. – acw1668 Feb 17 '20 at 06:28

0 Answers0