Beispiel #1
0
 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
Beispiel #2
0
 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
Beispiel #3
0
 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)
Beispiel #4
0
 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)
Beispiel #5
0
    def wait_til_frame_ready(self, timeout=0):
        """
        Wait until the devices announces a frame as being ready.
        Requires register_frame_ready_callback() being called.
        
        :param timeout: int -- timeout in milliseconds. Set to 0 for no timeout.
        
        :returns: int -- frame number that was announced as ready.
        """
        if timeout:
            start = time.clock()
            elapsed = (time.clock() - start) * 1000
            while not self._frame['ready'] and elapsed < timeout:
                time.sleep(0.001)
                elapsed = (time.clock() - start) * 1000
        else:
            while not self._frame['ready']:
                time.sleep(0.001)

        if self._frame['ready']:
            return self._frame['num']
        else:
            print 'Timed-out'
            #             return self._frame['num']
            raise IC_Exception(-100)
Beispiel #6
0
 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)
Beispiel #7
0
 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)
Beispiel #8
0
 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)
Beispiel #9
0
 def __init__(self, handle, name):
  
     self._handle = handle
     self._prop_name = name
     
     self._avail_funcs = {       'video'    :   IC_GrabberDLL.is_video_property_available,       
                                 'camera'   :   IC_GrabberDLL.is_camera_property_available}      
     self._auto_avail_funcs = {  'video'    :   IC_GrabberDLL.is_video_property_auto_available,  
                                 'camera'   :   IC_GrabberDLL.is_camera_property_auto_available} 
     self._range_funcs = {       'video'    :   IC_GrabberDLL.video_property_get_range,          
                                 'camera'   :   IC_GrabberDLL.camera_property_get_range}         
     self._get_value_funcs = {   'video'    :   IC_GrabberDLL.get_video_property,                
                                 'camera'   :   IC_GrabberDLL.get_camera_property}               
     self._set_value_funcs = {   'video'    :   IC_GrabberDLL.set_video_property,                
                                 'camera'   :   IC_GrabberDLL.set_camera_property}               
     self._get_auto_funcs = {    'video'    :   IC_GrabberDLL.get_auto_video_property,           
                                 'camera'   :   IC_GrabberDLL.get_auto_camera_property}          
     self._set_auto_funcs = {    'video'    :   IC_GrabberDLL.enable_auto_video_property,              
                                 'camera'   :   IC_GrabberDLL.enable_auto_camera_property}          
     
     vid_props = IC_Property.get_video_property_names()
     cam_props = IC_Property.get_camera_property_names()
     
     if name in vid_props:
         self._prop_type = 'video'
         self._prop_index = vid_props.index(name)
     elif name in cam_props:
         self._prop_type = 'camera'
         self._prop_index = cam_props.index(name)
     else:
         raise IC_Exception(0)
Beispiel #10
0
 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)
Beispiel #11
0
 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)
Beispiel #12
0
 def auto(self, aut):
     """
     """
     err = self._set_auto_funcs[self._prop_type](self._handle,
                                                 c_int(self._prop_index),
                                                 c_long(int(aut)))
     if err != 1:
         raise IC_Exception(err)
Beispiel #13
0
 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)
Beispiel #14
0
 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)
Beispiel #15
0
    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}
Beispiel #16
0
 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)
Beispiel #17
0
 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
Beispiel #18
0
 def auto(self):
     """
     """
     aut = c_int()
     
     err = self._get_auto_funcs[self._prop_type](self._handle,
                                                 c_int(self._prop_index),
                                                 byref(aut))
     if err != 1:
         raise IC_Exception(err)
     else:
         return bool(aut.value)
Beispiel #19
0
 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)
Beispiel #20
0
 def value(self):
     """
     """
     val = c_long()
     
     err = self._get_value_funcs[self._prop_type](self._handle,
                                                  c_int(self._prop_index),
                                                  byref(val))
     if err != 1:
         raise IC_Exception(err)
     else:
         return val.value
Beispiel #21
0
    def value(self, val):
        """
        """

        # turn off auto first
        self.auto = False

        # set value
        err = self._set_value_funcs[self._prop_type](self._handle,
                                                     c_int(self._prop_index),
                                                     c_long(val))
        if err != 1:
            raise IC_Exception(err)
Beispiel #22
0
    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)
Beispiel #23
0
 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
Beispiel #24
0
    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
Beispiel #25
0
 def range(self):
     """
     Get valid range of values for the property.
     
     :returns: tuple -- (range min, range max).
     """
     rmin = c_long()
     rmax = c_long()
     err = self._range_funcs[self._prop_type](self._handle,
                                              c_int(self._prop_index),
                                              byref(rmin), byref(rmax))
     if err != 1:
         raise IC_Exception(err)
     else:
         return (rmin.value, rmax.value)
    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 get_device(self, unique_device_name):
        """
        Gets camera device object based on unique name string.
        Will create one only if it doesn't already exist.

        :param device_name: string -- the unique name of the device.

        :returns: IC_Camera object -- the camera device object requested.	
        """
        # check name is valid
        if unique_device_name in self.get_unique_device_names():

            # check if already have a ref to device
            if unique_device_name not in self._devices:

                # if not, create one
                self._devices[unique_device_name] = IC_Camera(
                    unique_device_name)

            return self._devices[unique_device_name]

        raise IC_Exception(-106)
Beispiel #28
0
 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)