-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Hi,
I'm using your library to read and set the exposure time of my DCC1545M camera. I'm seeing unexpected behavior.
I've set its exposure time in ThorCam to 71.6ms, in order to get a good exposure (pixel values ~100). When I query the exposure time with get_exposure() it claims the exposure time is set to the minimum value: 0.06675ms. But acquiring an image still gives maximum pixel values of ~100. If I then use set_exposure() to set the exposure time to the value read by get_exposure(), the maximum pixel value drops to 2. It shouldn't have changed, since I simply set it to the value it supposedly already was. Any ideas what could be wrong here?
Thanks,
-Andrew
p.s. I can provide the image files if desired. Let me know how to upload/send them.
Here's my code:
import numpy as np
import imageio
#import the module that controls the Thorlabs DCC1545M camera:
import uc480
# Documentation for this module:
# http://ddietze.github.io/Py-Hardware-Support/uc480.html
# https://github.com/ddietze/Py-Hardware-Support
#He includes example code to interact with the camera,
# which I used as a starting point for the code below.
import pylab as pl
#######################################
#VARIABLES
file_dir = '[censored]'
file_name = '005_auto.png'
file_name2 = '006_auto.png'
#######################################
#PROGRAM START
# create instance and connect to library
cam = uc480.uc480()
# connect to first available camera
cam.connect()
#check the exposure time
exposure = cam.get_exposure()
print('Camera exposure time: {} ms'.format(exposure))
# take a single image
img = cam.acquire()
#reset the exposure time, using the value read from the camera
print('set camera exposure time: {} ms'.format(exposure))
cam.set_exposure(exposure)
#query the exposure time
exposure = cam.get_exposure()
print('Camera exposure time: {} ms'.format(exposure))
img2 = cam.acquire()
#based on the resulting image, the new exposure time is actually much shorter
# than the old one. Even though the software reported that the
# original exposure time was the minimum allowed
# clean up
cam.disconnect()
print('type of image is: ', type(img))
print('img.dtype: ', img.dtype)
#the author of the library cast the image to float, even though the camera
# pixels are 8-bit. He did this in case he wanted to average multiple frames.
# I don't want to do this. So cast it back to uint8.
img = img.astype('uint8')
print('cast to uint8. new datatype is:')
print('img.dtype: ', img.dtype)
print('max of img is: ', np.max(img))
print('max of img2 is: ', np.max(img2))
#output to disk
imageio.imwrite(file_dir+file_name, img, format='PNG-PIL', compress_level=5)
#do the same for img2
img2 = img2.astype('uint8')
imageio.imwrite(file_dir+file_name2, img2, format='PNG-PIL', compress_level=5)
And here's my output:
Load uc480 library..
API version 4.80.5
Found 1 camera(s)
Camera #0: SerNo = b'4102879283', CameraID = 1, DeviceID = 1
Sensor: 1280 x 1024 pixels, RGB = 0, 8 bits/px
Valid exposure times: 0.066750ms to 99.924750ms in steps of 0.066750ms
Camera exposure time: 0.06675 ms
set camera exposure time: 0.06675 ms
Camera exposure time: 0.06675 ms
type of image is: <class 'numpy.ndarray'>
img.dtype: float64
cast to uint8. new datatype is:
img.dtype: uint8
max of img is: 106
max of img2 is: 2.0