Ejemplo n.º 1
0
    def __init__(self, camera_name=None, **kwds):
        super(PVCAMCamera, self).__init__(**kwds)

        self.buffer_len = None
        self.data_buffer = None
        self.frame_size = None
        self.frame_x = None
        self.frame_y = None
        self.n_captured = pvc.uns32(
            0)  # No more than 4 billion frames in a single capture..
        self.n_processed = 0

        # Open camera.
        c_name = ctypes.c_char_p(camera_name)
        self.hcam = pvc.int16(0)
        check(pvcam.pl_cam_open(c_name, ctypes.byref(self.hcam), pvc.int16(0)),
              "pl_cam_open")

        # Register our EOF callback. This callback is supposed to increment
        # self.n_captured every time the camera acquires a new frame.
        #
        check(
            pvcam.pl_cam_register_callback_ex3(self.hcam,
                                               pvc.int32(pvc.PL_CALLBACK_EOF),
                                               eof_callback,
                                               ctypes.byref(self.n_captured)),
            "pl_cam_register_callback_ex3")
Ejemplo n.º 2
0
    def __init__(self, camera_name = None, **kwds):
        super(PVCAMCamera, self).__init__(**kwds)

        self.buffer_len = None
        self.data_buffer = None
        self.frame_size = None
        self.frame_x = None
        self.frame_y = None
        self.n_captured = pvc.uns32(0) # No more than 4 billion frames in a single capture..
        self.n_processed = 0

        # Open camera.
        c_name = ctypes.c_char_p(camera_name)
        self.hcam = pvc.int16(0)
        check(pvcam.pl_cam_open(c_name,
                                ctypes.byref(self.hcam),
                                pvc.int16(0)),
              "pl_cam_open")

        # Register our EOF callback. This callback is supposed to increment
        # self.n_captured every time the camera acquires a new frame.
        #
        check(pvcam.pl_cam_register_callback_ex3(self.hcam,
                                                 pvc.int32(pvc.PL_CALLBACK_EOF),
                                                 eof_callback,
                                                 ctypes.byref(self.n_captured)),
              "pl_cam_register_callback_ex3")
Ejemplo n.º 3
0
def getCameraNames():
    """
    Return a list of all the available cameras.
    """
    # Query to get the total number of cameras.
    n_cams = pvc.int16()
    check(pvcam.pl_cam_get_total(ctypes.byref(n_cams)), "pl_cam_get_total")

    # Query the camera names.
    cam_name = ctypes.c_char_p(' ' * pvc.CAM_NAME_LEN)
    camera_names = []
    for i in range(n_cams.value):
        check(pvcam.pl_cam_get_name(pvc.int16(i), cam_name), "pl_cam_get_name")
        camera_names.append(cam_name.value)

    return camera_names
Ejemplo n.º 4
0
    def getParameter(self, pname):
        """
        Returns the current value of a parameter.

        pname - The parameters ID or name.
        """
        pid = self.nameToID(pname)
        ptype = self.getParameterType(pid)

        # Get value for numbers.
        value = self.getTypeInstance(ptype)
        if value is not None:
            return self.getParam(pid, value, pvc.ATTR_CURRENT)

        # Get value for strings.
        if (ptype == pvc.TYPE_CHAR_PTR):
            # Get the string.
            count = self.getParameterCount(pid)
            cstring = ctypes.c_char_p(' ' * count)
            check(
                pvcam.pl_get_param(self.hcam, pid, pvc.int16(pvc.ATTR_CURRENT),
                                   cstring), "pl_get_param")
            return cstring.value

        raise PVCAMException("getParameter: unsupported type " + str(ptype))
Ejemplo n.º 5
0
 def stopAcquisition(self):
     """
     Stop the current acquisition and tell the camera to go to the idle state.
     """
     check(pvcam.pl_exp_stop_cont(self.hcam,
                                  pvc.int16(pvc.CCS_HALT)),
           "pl_exp_stop_cont")
Ejemplo n.º 6
0
def getCameraNames():
    """
    Return a list of all the available cameras.
    """
    # Query to get the total number of cameras.
    n_cams = pvc.int16()
    check(pvcam.pl_cam_get_total(ctypes.byref(n_cams)), "pl_cam_get_total")

    # Query the camera names.
    cam_name = ctypes.c_char_p(' ' * pvc.CAM_NAME_LEN)
    camera_names = []
    for i in range(n_cams.value):
        check(pvcam.pl_cam_get_name(pvc.int16(i), cam_name), "pl_cam_get_name")
        camera_names.append(cam_name.value)

    return camera_names
Ejemplo n.º 7
0
    def getParameter(self, pname):
        """
        Returns the current value of a parameter.

        pname - The parameters ID or name.
        """
        pid = self.nameToID(pname)
        ptype = self.getParameterType(pid)

        # Get value for numbers.
        value = self.getTypeInstance(ptype)
        if value is not None:
            return self.getParam(pid, value, pvc.ATTR_CURRENT)

        # Get value for strings.
        if (ptype == pvc.TYPE_CHAR_PTR):
            # Get the string.
            count = self.getParameterCount(pid)
            cstring = ctypes.c_char_p(' ' * count)
            check(pvcam.pl_get_param(self.hcam,
                                     pid,
                                     pvc.int16(pvc.ATTR_CURRENT),
                                     cstring),
                  "pl_get_param")
            return cstring.value        

        raise PVCAMException("getParameter: unsupported type " + str(ptype))
Ejemplo n.º 8
0
    def captureSetup(self, x_start, x_end, x_bin, y_start, y_end, y_bin,
                     exposure_time):
        """
        Configure for image capture (circular buffer).

        The camera is zero indexed.

        exposure_time is in milliseconds by default?

        How to determine the number of frames per second at a given exposure 
        time? HAL will need to know this in order to time other things properly.
        """
        self.frame_x = (x_end - x_start) / x_bin
        self.frame_y = (y_end - y_start) / y_bin

        # Setup acquisition & determine how large a frame is (in pixels).
        frame_size = pvc.uns32(0)
        region = pvc.rgn_type(x_start, x_end, x_bin, y_start, y_end, y_bin)
        check(
            pvcam.pl_exp_setup_cont(self.hcam, pvc.uns16(1),
                                    ctypes.byref(region),
                                    pvc.int16(pvc.TIMED_MODE),
                                    pvc.uns32(exposure_time),
                                    cytpes.byref(frame_size),
                                    pvc.int16(pvc.CIRC_OVERWRITE)),
            "pl_exp_setup_cont")

        # This assumes that we are dealing with a 16 bit camera.
        # We should verify that it is the same self.frame_x * self.frame_y?
        #
        self.frame_size = frame_size.value / 2

        # Allocate storage for the frames. For now we'll just allocate storage
        # for 100 frames, but it would be better to have this depend on the
        # exposure time (i.e. enough frames to buffer 2 seconds or something).
        #
        # Note: The PVCAM library limits the maximum buffer size to 2**32 bytes.
        #
        self.buffer_len = 100
        size = self.buffer_len * self.frame_size
        self.data_buffer = numpy.ascontiguousarray(
            numpy.empty(size, dtype=numpy.uint16))
Ejemplo n.º 9
0
    def getParam(self, pid, value, attrib):
        """
        Wrapper of pl_get_params, primarily for internal use.
        """

        # Overwrite whatever value is for some attributes.
        #
        if (attrib == pvc.ATTR_ACCESS):
            value = pvc.uns16()
        elif (attrib == pvc.ATTR_AVAIL):
            value = pvc.rs_bool()
        elif (attrib == pvc.ATTR_COUNT):
            value = pvc.uns32()
        elif (attrib == pvc.ATTR_TYPE):
            value = pvc.int16()

        check(
            pvcam.pl_get_param(self.hcam, pid, pvc.int16(attrib),
                               ctypes.byref(value)), "pl_get_param")
        return value.value
Ejemplo n.º 10
0
    def captureSetup(self, x_start, x_end, x_bin, y_start, y_end, y_bin, exposure_time):
        """
        Configure for image capture (circular buffer).

        The camera is zero indexed.

        exposure_time is in milliseconds by default?

        How to determine the number of frames per second at a given exposure 
        time? HAL will need to know this in order to time other things properly.
        """
        self.frame_x = (x_end - x_start)/x_bin
        self.frame_y = (y_end - y_start)/y_bin
        
        # Setup acquisition & determine how large a frame is (in pixels).
        frame_size = pvc.uns32(0)
        region = pvc.rgn_type(x_start, x_end, x_bin, y_start, y_end, y_bin)
        check(pvcam.pl_exp_setup_cont(self.hcam,
                                      pvc.uns16(1),
                                      ctypes.byref(region),
                                      pvc.int16(pvc.TIMED_MODE),
                                      pvc.uns32(exposure_time),
                                      cytpes.byref(frame_size),
                                      pvc.int16(pvc.CIRC_OVERWRITE)),
              "pl_exp_setup_cont")

        # This assumes that we are dealing with a 16 bit camera.
        # We should verify that it is the same self.frame_x * self.frame_y?
        #
        self.frame_size = frame_size.value/2

        # Allocate storage for the frames. For now we'll just allocate storage
        # for 100 frames, but it would be better to have this depend on the
        # exposure time (i.e. enough frames to buffer 2 seconds or something).
        #
        # Note: The PVCAM library limits the maximum buffer size to 2**32 bytes.
        #
        self.buffer_len = 100
        size = self.buffer_len * self.frame_size
        self.data_buffer = numpy.ascontiguousarray(numpy.empty(size, dtype = numpy.uint16))
Ejemplo n.º 11
0
    def getParam(self, pid, value, attrib):
        """
        Wrapper of pl_get_params, primarily for internal use.
        """

        # Overwrite whatever value is for some attributes.
        #
        if (attrib == pvc.ATTR_ACCESS):
            value = pvc.uns16()
        elif (attrib == pvc.ATTR_AVAIL):
            value = pvc.rs_bool()
        elif (attrib == pvc.ATTR_COUNT):
            value = pvc.uns32()
        elif (attrib == pvc.ATTR_TYPE):
            value = pvc.int16()
            
        check(pvcam.pl_get_param(self.hcam,
                                 pid,
                                 pvc.int16(attrib),
                                 ctypes.byref(value)),
              "pl_get_param")
        return value.value
Ejemplo n.º 12
0
 def getTypeInstance(self, ptype):
     """
     Return a ctypes instance of ptype.
     """
     if (ptype == pvc.TYPE_INT16):
         return pvc.int16()
     elif (ptype == pvc.TYPE_INT32):
         return pvc.int32()
     elif (ptype == pvc.TYPE_FLT64):
         return pvc.flt64()
     elif (ptype == pvc.TYPE_UNS8):
         return pvc.uns8()
     elif (ptype == pvc.TYPE_UNS16):
         return pvc.uns16()
     elif (ptype == pvc.TYPE_UNS32):
         return pvc.uns32()
     elif (ptype == pvc.TYPE_UNS64):
         return pvc.uns64()
     elif (ptype == pvc.TYPE_ENUM):
         return pvc.int32()
     elif (ptype == pvc.TYPE_BOOLEAN):
         return pvc.rs_bool()
     elif (ptype == pvc.TYPE_INT8):
         return pvc.int8()
Ejemplo n.º 13
0
 def getTypeInstance(self, ptype):
     """
     Return a ctypes instance of ptype.
     """
     if (ptype == pvc.TYPE_INT16):
         return pvc.int16()
     elif (ptype == pvc.TYPE_INT32):
         return pvc.int32()
     elif (ptype == pvc.TYPE_FLT64):
         return pvc.flt64()
     elif (ptype == pvc.TYPE_UNS8):
         return pvc.uns8()
     elif (ptype == pvc.TYPE_UNS16):
         return pvc.uns16()
     elif (ptype == pvc.TYPE_UNS32):
         return pvc.uns32()
     elif (ptype == pvc.TYPE_UNS64):
         return pvc.uns64()
     elif (ptype == pvc.TYPE_ENUM):
         return pvc.int32()
     elif (ptype == pvc.TYPE_BOOLEAN):
         return pvc.rs_bool()
     elif (ptype == pvc.TYPE_INT8):
         return pvc.int8()
Ejemplo n.º 14
0
 def stopAcquisition(self):
     """
     Stop the current acquisition and tell the camera to go to the idle state.
     """
     check(pvcam.pl_exp_stop_cont(self.hcam, pvc.int16(pvc.CCS_HALT)),
           "pl_exp_stop_cont")