I am trying to get a camera feed from this microscope device through Python Tkinter.
I have tried using cv2 VideoCapture function, but it did not show the image.
class RunningStatusFrame(ttk.Frame):
def __init__(self, parent):
ttk.Frame.__init__(self, parent)
self.parent = parent
################## Camera Feed ##################
self.camera_frame = LabelFrame(self, text="Camera Feed",
width=800, height=600)
self.camera_frame.grid(row=0, column=0, columnspan=2)
self.camera_feed = Label(self.camera_frame)
self.camera_feed.pack(fill=BOTH)
self.progress = IntVar(self)
self.cam = cv2.VideoCapture(0)
self.showFrame()
################## Progress Bar #################
self.progress_bar = ttk.Progressbar(self,
orient=HORIZONTAL,
length=150,
maximum=100,
mode='determinate',
variable=self.progress)
self.progress_bar.grid(row=1, column=0, columnspan=2)
################## Laser Status ##################
Label(self, text=" Laser:").grid(row=2, column=0, sticky=E)
self.laser_status = Label(self, text="ON", fg="#f00")
self.laser_status.grid(row=2, column=1, sticky=W)
self.updateInfo()
def updateInfo(self):
'''
Function to update information.
'''
if self.parent.parent.select() == ".!notebook.!autorunframe":
pass
self.after(300, self.updateInfo)
def showFrame(self):
'''
Update camera feed.
'''
frame = self.cam.read()
if frame[0] == False:
return None
frame = imutils.resize(frame[1], width=400)
cv2image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
img = Image.fromarray(cv2image)
imgtk = ImageTk.PhotoImage(image=img)
self.camera_feed.imgtk = imgtk
self.camera_feed.configure(image=imgtk)
self.camera_feed.after(20, self.showFrame)
def setProgress(self, value):
'''
Changes progress bar status.
'''
self.progress.set(value)
This works for the webcam from my laptop, but somehow (perhaps because my microscope is an imaging device) it does not show anything. Anyone have done something like this? Any advice would be appreciated!
Thank you
You have a "USB3 Vision" device.
"USB3 Vision" is a specific industry standard, but not part of the USB standard.
USB3 Vision is not a webcam. USB webcams are Unified Video Class (UVC), a device class specified in the standard.
Windows certainly doesn't come with a driver for USB3 Vision. It only comes with UVC.
You're gonna need to talk to the manufacturer and get a driver for your video device. And then that driver still might not present as a video device in Windows media APIs, but you might have to talk to the driver directly.
You could try VideoCapture with the cv.CAP_XIMEA
flag... but I've never tried that. XIMEA makes devices that do USB3 Vision. If you're lucky, the OpenCV videoio
backend for XIMEA might work for your device too.
And definitely check out the comment above by Micka. He strikes me as knowledgeable about these devices.