cannot seem to get my camera GUI to work, i run the code it just does nothing. No error no gui.
i tried changing the cv2.VideoCature() to -1 and i just get an error.
is this a legacy camera compatability issue?
from tkinter import *
import cv2
from PIL import Image, ImageTk
cap = cv2.VideoCapture(0)
#width, height = (220,220)# width of camera, height of camera
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 200)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 200)
app = Tk()
app.bind('<Escape>', lambda e: app.quit())
label_widget = Label(app)
label_widget.pack()
def open_camera():
# capture the video frmae by frame
_, frame = cap.read()
# convert image from one color spacee to the other
opencv_image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGBA)
#capture the latest frame and transform to image
captured_image = Image.fromarray(opencv_image)
#convert captured image to photoimage
photo_image = ImageTk.PhotoImage(image=captured_image)
# displaying photoimage in the label
label_widget.photo_image = photo_image
# configuree image in the label
label_widget.configure(image=photo_image)
#repeat the same process after every 10 seconds
label_widget.after(10, open_camera)
button1 = Button(app, text="Open Camera", command=open_camera)
button1.pack()
app.mainloop()