0
votes

There are several topics on this but many of them are very very old and no real solutions have been offered (or none that work for me for sure).

I am trying various libraries to get Python to read the frames of my USB camera (DCC1545M) and they all have various module or DLL import errors. I'm trying Instrumental, Thorcam API, py-harware, micromanager..

Specifically I would ideally love to get it to work with OpenCV, because of all the useful computer vision features that you can later use on the image, which I am not sure you can do with the other libraries.

However, I encounter the same issue as everyone else, in that openCV can not read the USB camera in the first place.

cap = cv2.VideoCapture(1)              ## tried difference indices
  
cap.isOpened()                        ## returns FALSE
img_counter = 0
   
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

while True: 
    ret,frame = cap.read()                     ## returned frame is empty 
    cv2.imshow('preview',frame)
    k = cv2.waitKey(1)
    if k%256==32: # if SPACE is pressed, take image 
        img_name = 'frame_number_{}.png'.format(img_counter)
        cv2.imwrite(img_name,frame)
        print('frame taken ')
        img_counter += 1

cap.release()
cv2.destroyAllWindows()

I have installed the driver from Thorlabs website and I have the uc480_64.dll. The camera is successfully located using the Instrumental() library:

from instrumental import list_instruments, instrument
from ctypes import *

paramsets = list_instruments() ## camera found
print(paramsets)

which returns

[<ParamSet[UC480_Camera] serial=b'4102675270' model=b'C1285R12M' id=1>]

I was wondering if anyone knows if in the last couple of years openCV has managed to find a way to read USB cameras and if so, what is the way? Or of any other reliable method, which allows further image processing on the captured frames.

PS: I posted this on superuser because apparently hardware questions are not allowed on stackoverflow, but suoeruser migrated it back here .. So apologies if it is off-topic here as well.

1

1 Answers

0
votes

Can you communicate with the camera it its native software? https://www.thorlabs.com/software_pages/ViewSoftwarePage.cfm?Code=ThorCam

Our lab is using "pylablib cam-control" to communicate with a variety of cameras (including Thorlabs USB ones): https://pylablib-cam-control.readthedocs.io/en/latest/

Or if you would prefer writing your own code, pylablib includes a class for Thorlabs USB cameras (actually has been tested with your specific camera). https://pylablib.readthedocs.io/en/latest/devices/uc480.html#cameras-uc480