def register_frame_ready_callback(self): """ Register the frame ready callback with the device. """ # keep ref to prevent garbage collection self._rfrc_func = self._get_callback_func() # register callback function with DLL # instead of passing pointer to a variable (3rd param) we will set the flag ourselves IC_GrabberDLL.set_frame_ready_callback(self._handle, self._rfrc_func, None) self._callback_registered = True
def send_trigger(self): """ Send a software trigger to fire the device when in triggered mode. """ err = IC_GrabberDLL.software_trigger(self._handle) if err != 1: raise IC_Exception(err)
def is_open(self): """ Check if the camera device is currently open. :returns: boolean -- True if camera is open. """ return bool(IC_GrabberDLL.is_dev_valid(self._handle))
def prepare_live(self, show_display=False): """ Prepare the device for live video. """ err = IC_GrabberDLL.prepare_live(self._handle, c_int(int(show_display))) if err != 1: raise IC_Exception(err)
def show_property_dialog(self): """ Show property dialog for device. """ err = IC_GrabberDLL.show_property_dialog(self._handle) if err != 1: raise IC_Exception(err)
def start_live(self, show_display=False): """ Start the live video. """ err = IC_GrabberDLL.start_live(self._handle, c_int(int(show_display))) if err != 1: raise IC_Exception(err)
def set_format(self, color_format): """ """ err = IC_GrabberDLL.set_format(self._handle, c_int(color_format)) print 'set format err:', err if err != 1: raise IC_Exception(err)
def suspend_live(self): """ Suspend the live video and put into a prepared state. """ err = IC_GrabberDLL.suspend_live(self._handle) if err != 1: raise IC_Exception(err)
def reset_properties(self): """ Resets all properties to their default values. If a property has automation, the automatic will be enabled. If the device supports external trigger, the external trigger will be disabled. """ return IC_GrabberDLL.reset_properties(self._handle)
def open(self): """ Open the camera device, required for most functions. """ err = IC_GrabberDLL.open_device_by_unique_name(self._handle, self._unique_device_name) if err != 1: raise IC_Exception(err)
def open(self): """ Open the camera device, required for most functions. """ err = IC_GrabberDLL.open_device_by_unique_name( self._handle, self._unique_device_name) if err != 1: raise IC_Exception(err)
def set_video_norm(self, video_norm): """ Sets video norm format, whatver that means. :param video_norm: string -- video norm to use. """ err = IC_GrabberDLL.set_video_norm(self._handle, c_char_p(video_norm)) if err != 1: raise IC_Exception(err)
def snap_image(self, timeout=1000): """ Snap an image. Device must be set to live mode and a format must be set. :param timeout: int -- time out in milliseconds. """ err = IC_GrabberDLL.snap_image(self._handle, c_int(timeout)) if err != 1: raise IC_Exception(err)
def set_video_format(self, video_format): """ Set a video format for the device. Must be supported. :param video_format: string -- video format to use. """ err = IC_GrabberDLL.set_video_format(self._handle, c_char_p(video_format)) if err != 1: raise IC_Exception(err)
def __init__(self, unique_device_name): self._unique_device_name = unique_device_name self._handle = IC_GrabberDLL.create_grabber() if not self._handle: raise IC_Exception(0) self._callback_registered = False self._frame = {'num': -1, 'ready': False}
def enable_trigger(self, enable): """ Enable or disable camera triggering. :param enable: boolean -- True to enable the trigger, False to disable. """ err = IC_GrabberDLL.enable_trigger(self._handle, c_int(int(enable))) if err != 1: #raise IC_Exception(err) pass # todo, always raises false error for some reason...?
def get_video_format_count(self): """ Get the number of the available video formats for the current device. A video capture device must have been opened before this call. :returns: int -- number of available video formats. """ vf_count = IC_GrabberDLL.get_video_format_count(self._handle) if vf_count < 0: raise IC_Exception(vf_count) return vf_count
def __init__(self, unique_device_name): self._unique_device_name = unique_device_name self._handle = IC_GrabberDLL.create_grabber() if not self._handle: raise IC_Exception(todo) self._callback_registered = False self._frame = {'num' : -1, 'ready' : False}
def close_library(self): """ Close the IC Imaging Control library, and close and release all references to camera devices. """ # release handle grabber objects of cameras as they won't be needed again. # try to close & delete each known device, but only if we own the reference to it! for unique_device_name in self.get_unique_device_names(): if unique_device_name in self._devices: # close camera device if open if self._devices[unique_device_name].is_open(): self._devices[unique_device_name].close() # release grabber of camera device IC_GrabberDLL.release_grabber(self._devices[unique_device_name]._handle) # kill refs self._unique_device_names = None self._devices = None # close lib IC_GrabberDLL.close_library()
def save_image(self, filename, filetype=1, jpeq_quality=75): """ Save the contents of the last snapped image into a file. :param filename: string -- filename to name saved file. :param filetype: int -- 0 = BMP, 1 = JPEG. :param jpeq_quality: int -- JPEG file quality, 0-100. """ err = IC_GrabberDLL.save_image(self._handle, c_char_p(filename), c_int(filetype), c_long(jpeq_quality)) if err != 1: raise IC_Exception(err)
def get_unique_device_names(self): """ Gets unique names (i.e. model + label + serial) of devices. :returns: list -- unique devices names. """ if self._unique_device_names is None: # make new list self._unique_device_names = [] # get num devices, must be called before get_unique_name_from_list()! num_devices = IC_GrabberDLL.get_device_count() if num_devices < 0: raise IC_Exception(num_devices) # populate list for i in xrange(num_devices): self._unique_device_names.append(IC_GrabberDLL.get_unique_name_from_list(i)) return self._unique_device_names
def enable_continuous_mode(self, enable): """ Enable or disable continuous mode. :param enable: boolean -- True to enable continuous mode, False to disable. """ actual = not enable #print actual, enable, c_int(int(actual)) err = IC_GrabberDLL.set_continuous_mode(self._handle, c_int(int(actual))) if err != 1: #raise IC_Exception(err) pass # todo, always raises false error for some reason...?
def get_video_format(self, format_index): """ Get a string representation of the video format specified by format_index. format_index must be between 0 and get_video_format_count(). """ # DLL says need to call this first for it to work num_vfs = self.get_video_format_count() if format_index >= num_vfs: raise IC_Exception(-103) vf = IC_GrabberDLL.get_video_format(self._handle, c_int(format_index)) if vf is None: raise IC_Exception(-105) return vf
def close_library(self): """ Close the IC Imaging Control library, and close and release all references to camera devices. """ # release handle grabber objects of cameras as they won't be needed again. # try to close & delete each known device, but only if we own the reference to it! for unique_device_name in self.get_unique_device_names(): if unique_device_name in self._devices: # close camera device if open if self._devices[unique_device_name].is_open(): self._devices[unique_device_name].close() # release grabber of camera device IC_GrabberDLL.release_grabber( self._devices[unique_device_name]._handle) # kill refs self._unique_device_names = None self._devices = None # close lib IC_GrabberDLL.close_library()
def get_unique_device_names(self): """ Gets unique names (i.e. model + label + serial) of devices. :returns: list -- unique devices names. """ if self._unique_device_names is None: # make new list self._unique_device_names = [] # get num devices, must be called before get_unique_name_from_list()! num_devices = IC_GrabberDLL.get_device_count() if num_devices < 0: raise IC_Exception(num_devices) # populate list for i in xrange(num_devices): self._unique_device_names.append( IC_GrabberDLL.get_unique_name_from_list(i)) return self._unique_device_names
def init_library(self): """ Initialise the IC Imaging Control library. """ # remember list of unique device names self._unique_device_names = None # remember device objects by unique name self._devices = {} # no license key needed anymore err = IC_GrabberDLL.init_library(None) if err != 1: raise IC_Exception(err)
def list_video_formats(self): """ :returns: list -- available video formats. """ vf_list = ((c_char * 80) * 40)() num_vfs = IC_GrabberDLL.list_video_formats(self._handle, byref(vf_list), c_int(80)) if num_vfs < 0: raise IC_Exception(num_vfs) return_list = [] for vf in vf_list: if vf.value: return_list.append(vf.value) return return_list
def get_video_norm(self, norm_index): """ Get a string representation of the video norm specified by norm_index. norm_index must be between 0 and get_video_norm_count(). :returns: string -- name of video norm of specified index. """ # DLL says need to call this first for it to work num_vns = self.get_video_norm_count() if norm_index >= num_vns: raise IC_Exception(-102) vn = IC_GrabberDLL.get_video_norm(self._handle, c_int(norm_index)) if vn is None: raise IC_Exception(-104) return vn
def get_image_ptr(self): """ Get image buffer from camera. :returns: ctypes pointer -- pointer to image data. """ img_ptr = IC_GrabberDLL.get_image_ptr(self._handle) if img_ptr is None: raise IC_Exception(0) #img_data = cast(img_ptr, POINTER(c_ubyte * buffer_size)) ####array = (c_ubyte * iheight * iwidth * 3).from_address(addressof(data.contents)) #array = img_data.contents return img_ptr
def get_image_ptr(self): """ Get image buffer from camera. :returns: ctypes pointer -- pointer to image data. """ img_ptr = IC_GrabberDLL.get_image_ptr(self._handle) if img_ptr is None: raise IC_Exception(todo) #img_data = cast(img_ptr, POINTER(c_ubyte * buffer_size)) ####array = (c_ubyte * iheight * iwidth * 3).from_address(addressof(data.contents)) #array = img_data.contents return img_ptr
def get_image_description(self): """ Get image info. :returns: tuple -- (image width, image height, image depth, color format). """ img_width = c_long() img_height = c_long() img_depth = c_int() color_format = c_int() err = IC_GrabberDLL.get_image_description(self._handle, byref(img_width), byref(img_height), byref(img_depth), byref(color_format), ) return (img_width.value, img_height.value, img_depth.value, color_format.value)
def get_image_description(self): """ Get image info. :returns: tuple -- (image width, image height, image depth, color format). """ img_width = c_long() img_height = c_long() img_depth = c_int() color_format = c_int() err = IC_GrabberDLL.get_image_description( self._handle, byref(img_width), byref(img_height), byref(img_depth), byref(color_format), ) return (img_width.value, img_height.value, img_depth.value, color_format.value)
def get_frame_rate(self): """ """ return IC_GrabberDLL.get_frame_rate(self._handle)
def set_frame_rate(self, frame_rate): """ """ err = IC_GrabberDLL.set_frame_rate(self._handle, c_float(frame_rate)) if err != 1: raise IC_Exception(err)
def close(self): """ Close the camera device. """ IC_GrabberDLL.close_device(self._handle)
def stop_live(self): """ Stop the live video. """ IC_GrabberDLL.stop_live(self._handle)
def is_triggerable(self): """ """ return bool(IC_GrabberDLL.is_trigger_available(self._handle))