Python Forum
tkinter camera threads
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
tkinter camera threads
#1
Hello everyone.
I have a big code in tkinter with 14 files.In one of my files I control my camera and show the output inside a frame (in tkinter).
So ,I will show you the code below ,it is implemented with threads. I want to use threads, because other parts of my program sticks a little bit.
But the problem is that the frame for output of camera is flashing a little bit.I don't know if my code is correct,
because I create and start a thread every time.
Using threads in video_stream(.) (see below) , other parts of program doesn't stick ,but my frame for the camera output is a little bit flashing.

Code if file a.py:
This is a function of (for example a.py)
import PIL , cv2
from PIL import Image , ImageTk
from tkinter import *
from datetime import datetime
import threading

cap = cv2.VideoCapture(2)

def video_stream(label_frame):
   
    ret , frame = cap.read()
    if(not cap.isOpened() ):
        return -1
        
    elif(ret):
        frame = cv2.flip(frame , 1)
        cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
        img = PIL.Image.fromarray(cv2image)
        imgtk = ImageTk.PhotoImage(image = img)
        label_frame.imgtk = imgtk
        label_frame.configure(image = imgtk)
        thread_call_camera = threading.Thread(target=video_stream,args=(label_frame,))
        thread_call_camera.start()
        #label_frame.after(20 , video_stream , label_frame)
In another file ,for example b.py ,I call: << value = video_stream(a frame I designed here) >>
I can't show you the whole code ,is big and maybe you will get confused.
I just want to tell me if I create threads normally.

Thanks a lot.
Reply


Messages In This Thread
tkinter camera threads - by Nick_tkinter - Apr-15-2021, 05:36 PM
RE: tkinter camera threads - by Yoriz - Apr-15-2021, 05:41 PM
RE: tkinter camera threads - by Nick_tkinter - Apr-15-2021, 06:37 PM
RE: tkinter camera threads - by Yoriz - Apr-15-2021, 07:18 PM
RE: tkinter camera threads - by Nick_tkinter - Apr-15-2021, 07:44 PM
RE: tkinter camera threads - by Yoriz - Apr-15-2021, 08:10 PM
RE: tkinter camera threads - by Nick_tkinter - Apr-16-2021, 12:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter frame camera opencv Nick_tkinter 9 5,412 Mar-21-2021, 06:41 PM
Last Post: Nick_tkinter
  Raspberry Pi camera live feed in tkinter robgar2001 6 12,327 Sep-30-2018, 10:49 PM
Last Post: woooee

Forum Jump:

User Panel Messages

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