def Set_Values(cam, exposure, gain, blacklevel, automode):
    """sets the exposure time and gain of the camera"""
    exposure = ueye.double(exposure)
    expo = ueye.double()
    gain = ueye.int(gain)
    # sets the exposure time and gain with the values
    # or sets them automatically
    if automode is False:
        ueye.is_SetHardwareGain(cam, gain, ueye.IS_IGNORE_PARAMETER,
                                ueye.IS_IGNORE_PARAMETER,
                                ueye.IS_IGNORE_PARAMETER)
        ueye.is_Exposure(cam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE, exposure,
                         ueye.ueye.sizeof(exposure))
        expo = exposure
        ueye.is_Blacklevel(cam, ueye.IS_BLACKLEVEL_CMD_SET_OFFSET, blacklevel)
    elif automode is True:
        pval1 = ueye.double(1)
        pval2 = ueye.double(0)
        ueye.is_SetAutoParameter(cam, ueye.IS_SET_ENABLE_AUTO_GAIN, pval1,
                                 pval2)
        pval1 = ueye.double(1)
        pval2 = ueye.double(0)
        ueye.is_SetAutoParameter(cam, ueye.IS_SET_ENABLE_AUTO_SHUTTER, pval1,
                                 pval2)
    return Get_Values(cam.value, expo.value)
 def __set_black_level(self, level):
     bl = ueye.UINT(int(level))
     if not ueye.is_Blacklevel(self.cam,
                               ueye.IS_BLACKLEVEL_CMD_SET_OFFSET, bl,
                               ueye.ctypes.sizeof(bl)) == ueye.IS_SUCCESS:
         raise RuntimeError("IS_BLACKLEVEL_CMD_SET_OFFSET failed")
     return bl.value
def Init_Cam(width=640, heigth=480, gain_boost=1):
    """inits the uEye camera"""
    # inits next available cam
    cam = ueye.HIDS(0)
    ueye.is_InitCamera(cam, None)

    ueye.is_EnableAutoExit(cam, ueye.IS_ENABLE_AUTO_EXIT)

    # sets the Colourmode of the camera
    ueye.is_SetColorMode(cam, ueye.IS_CM_SENSOR_RAW8)

    # sets the trigger
    ret = ueye.is_SetExternalTrigger(cam, ueye.IS_SET_TRIGGER_SOFTWARE)
    mode = ueye.int(0)

    # sets the blacklevel
    ueye.is_Blacklevel(cam, ueye.IS_BLACKLEVEL_CMD_SET_MODE, mode,
                       ueye.sizeof(mode))

    # sets the size of the image
    rectAOI = ueye.IS_RECT()
    rectAOI.s32X = 44
    rectAOI.s32Y = 0
    rectAOI.s32Width = 480
    rectAOI.s32Height = 480
    ueye.is_AOI(cam, ueye.IS_AOI_IMAGE_SET_AOI, rectAOI, ueye.sizeof(rectAOI))

    # allocates memory with given size
    width = ueye.int(width)
    heigth = ueye.int(heigth)
    bitspixel = ueye.int(8)
    pcImgMem = ueye.c_mem_p()
    pid = ueye.int()
    ueye.is_AllocImageMem(cam, 480, heigth, bitspixel, pcImgMem, pid)

    # sets the image memory as active
    ueye.is_SetImageMem(cam, pcImgMem, pid)

    # activates video mode
    ueye.is_CaptureVideo(cam, ueye.IS_DONT_WAIT)

    # sets gain boost mode
    if gain_boost == 1:
        ueye.is_SetGainBoost(cam, ueye.IS_SET_GAINBOOST_ON)
    else:
        ueye.is_SetGainBoost(cam, ueye.IS_SET_GAINBOOST_OFF)
    return cam, ret, pcImgMem, pid
Пример #4
0
    def configure(self, parameters):
        # Exposure varies by camera: 0.020ms to 69.847 for UI-3250 model (check uEye cockpit for specifics)
        # Gain (master) can be set between 0-100
        # Black level can be set between 0-255
        # Gamma can be set between 0.01 and 10

        #Set dict keys to all lower case
        parameters = dict((k.lower(), v) for k, v in parameters.items())

        if 'exposure' in parameters:
            #Doesn't do anything
            err = ueye.is_Exposure(
                self._cam, ueye.IS_EXPOSURE_CMD_SET_EXPOSURE,
                ueye.DOUBLE(parameters['exposure']),
                ueye.sizeof(ueye.DOUBLE(parameters['exposure'])))
            if err != ueye.IS_SUCCESS:
                raise CameraException(self._cam, 'ueye>configure>exposure>',
                                      err)

        if 'gain' in parameters:
            err = ueye.is_SetHardwareGain(self._cam,
                                          ueye.INT(parameters['gain']),
                                          ueye.IS_IGNORE_PARAMETER,
                                          ueye.IS_IGNORE_PARAMETER,
                                          ueye.IS_IGNORE_PARAMETER)
            if err != ueye.IS_SUCCESS:
                raise CameraException(self._cam, 'ueye>configure>gain>', err)

        if 'black_level' in parameters:
            err = ueye.is_Blacklevel(
                self._cam, ueye.IS_BLACKLEVEL_CMD_SET_OFFSET,
                ueye.INT(parameters['black_level']),
                ueye.sizeof(ueye.INT(parameters['black_level'])))
            if err != ueye.IS_SUCCESS:
                raise CameraException(self._cam, 'ueye>configure>black_level>',
                                      err)

        if 'gamma' in parameters:
            # Digital gamma correction
            err = ueye.is_Gamma(
                self._cam, ueye.IS_GAMMA_CMD_SET,
                ueye.INT(int(parameters['gamma'] * 100)),
                ueye.sizeof(ueye.INT(int(parameters['gamma'] * 100))))
            if err != ueye.IS_SUCCESS:
                raise CameraException(self._cam, 'ueye>configure>gamma>', err)