Home > other >  Why do help to have a look at this code run up, thank you Daniel
Why do help to have a look at this code run up, thank you Daniel

Time:09-21

The import cv2
The import tkinter as tk
Controls the from tkinter import filedialog# file
The from PIL import Image, ImageTk# Image control
The import threading# multithreaded
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
create a windowThe window=tk. Tk ()
Window. The title (' camera ')
Sw=window. Winfo_screenwidth (#) to obtain wide screen
Sh window.=winfo_screenheight # () to obtain high screen
Wx=600
Wh=800
Window. Geometry (" % dx + + % d % d % d "% (wx, wh - 200, (sw - wx)/2, (sh - wh)/2 + 100)) # window to the specified location
Canvas=tk canvas (window, bg='white', height=wh/2, width=wx) # drawing canvas
Canvas. Pack ()
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- to open the camera to obtain images
Def video_demo () :
Def cc () :
The capture=cv2. VideoCapture (0)
While (True) :
Ret, frame=the capture. The read () # read the photos from camera
Frame=cv2. Flip (frame, 1) 0: # flip upside down reverse level greater than 0
Cv2image=cv2. CvtColor (frame, cv2 COLOR_BGR2RGBA)
Img=Image. Fromarray (cv2image)
Image_file=ImageTk. PhotoImage (img)
Canvas. Create_image (0, 0, anchor=NW, image=image_file)
T=threading. Thread (target=cc)
T.s tart ()

Bt_start=tk. The Button (window, text='open cameras, height=2, width=15, the command=video_demo)
Bt_start. Place (x=240, y=400)