0% found this document useful (0 votes)
5 views1 page

дз

This document contains a Python script that implements a simple face recognition application using OpenCV and Tkinter. It allows users to start and stop video capture from their webcam, displaying the video feed in a GUI window. The application uses threading to handle video processing without freezing the interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

дз

This document contains a Python script that implements a simple face recognition application using OpenCV and Tkinter. It allows users to start and stop video capture from their webcam, displaying the video feed in a GUI window. The application uses threading to handle video processing without freezing the interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import cv2

import threading
import tkinter as tk
from tkinter import Label
from PIL import Image, ImageTk

def start_recognition():
global cap, running
running = True
cap = cv2.VideoCapture(0)
process_frame()

def stop_recognition():
global running
running = False
cap.release()

def process_frame():
if running:
ret, frame = cap.read()
if ret:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = Image.fromarray(frame)
imgtk = ImageTk.PhotoImage(image=img)
lbl_video.imgtk = imgtk
lbl_video.configure(image=imgtk)
lbl_video.after(10, process_frame)

root = tk.Tk()
root.title("Face Recognition")

lbl_video = Label(root)
lbl_video.pack()

btn_start = tk.Button(root, text="Старт", command=lambda:


threading.Thread(target=start_recognition).start())
btn_start.pack()

btn_stop = tk.Button(root, text="Стоп", command=stop_recognition)


btn_stop.pack()

root.mainloop()

You might also like