I have a problem with Opencv and Python. When I try to see frames from camera it does not to recognize a usb camera, I have used standar code from books with two usb cameras, the problem is that only one camera works and I do not know. I run opencv with python on windows, the camera's drivers are installed because Windows recognizes it. Whats it´s wrong with second camera? Thanks
of course! The code is following:
import cv2
import Tkinter as tk
from PIL import Image, ImageTk
#Set up GUI
window = tk.Tk() #Makes main window
window.wm_title("Digital Microscope")
window.config(background="#FFFFFF")
#Graphics window
imageFrame = tk.Frame(window, width=600, height=500)
imageFrame.grid(row=0, column=0, padx=10, pady=2)
#Capture video frames
lmain = tk.Label(imageFrame)
lmain.grid(row=0, column=0)
cap = cv2.VideoCapture(0)
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() #Display 2
window.mainloop() #Starts GUI
I don't exactly remember where I copy this code, I think from here, stackoverflow. Thanks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.