A simple version of camera capture using OpenCv and Tkinter:
import Tkinter as tk
import cv2
from PIL import Image, ImageTk
width, height = 800, 600
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
root = tk.Tk()
root.bind('<Escape>', lambda e: root.quit())
lmain = tk.Label(root)
lmain.pack()
def show_frame():
_, frame = cap.read()
frame = cv2.flip(frame, 1)
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
img = Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image=img)
lmain.imgtk = imgtk
lmain.configure(image=imgtk)
lmain.after(10, show_frame)
show_frame()
root.mainloop()
You will need to download and install PIL...
UPDATE:
... and OpenCV for this to work.
To Install PIL, run the following command in your Terminal/Command Prompt:
pip install Pillow
or python -m pip install Pillow
To Install OpenCV, run the following command in your Terminal/Command Prompt:
pip install opencv-python
or python -m pip install opencv-python
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…