bool FlosIDSAdaptor::startCapture()
{	
    if(!isOpen()) {
        return false;
    }

    UINT   nMode;
    INT    nRet = IS_SUCCESS;
    double dNominal = 128;
    double dEnable  = 1;
            
    is_SetDisplayMode(m_deviceID, IS_SET_DM_DIB);
    is_SetExternalTrigger(m_deviceID, IS_SET_TRIGGER_SOFTWARE);

    nMode = IO_FLASH_MODE_TRIGGER_HI_ACTIVE;
    is_IO(m_deviceID, IS_IO_CMD_FLASH_SET_MODE, (void *)&nMode, sizeof(nMode));

    is_SetAutoParameter(m_deviceID, IS_SET_ENABLE_AUTO_GAIN, &dEnable, 0);
    is_SetAutoParameter(m_deviceID, IS_SET_AUTO_REFERENCE, &dNominal, 0);

    is_SetColorMode(m_deviceID, IS_CM_BGR8_PACKED);
    is_SetFrameRate(m_deviceID, 20, NULL);

    if((is_CaptureVideo(m_deviceID, IS_DONT_WAIT) != IS_SUCCESS)) {
        imaqkit::adaptorWarn("FlosIDSAdaptor:startCapture", "Could not start capturing.");
        return false;
    }

    setAcquisitionActive(true);
    PostThreadMessage(m_acquireThreadID, WM_USER, 0, 0);

    return true;
}
INT UEyeCamDriver::setExposure(bool& auto_exposure, double& exposure_ms) {
    if (!isConnected())
        return IS_INVALID_CAMERA_HANDLE;

    INT is_err = IS_SUCCESS;
    double minExposure, maxExposure;

    // Set auto exposure
    double pval1 = auto_exposure, pval2 = 0;
    if ((is_err = is_SetAutoParameter(cam_handle_, IS_SET_ENABLE_AUTO_SENSOR_SHUTTER,
                                      &pval1, &pval2))
        != IS_SUCCESS) {
        if ((is_err = is_SetAutoParameter(cam_handle_, IS_SET_ENABLE_AUTO_SHUTTER,
                                          &pval1, &pval2))
            != IS_SUCCESS) {
            std::cerr << "Auto exposure mode is not supported for UEye camera '"
                      << cam_name_ << "' (" << err2str(is_err) << ")" << std::endl;
            auto_exposure = false;
        }
    }

    // Set manual exposure timing
    if (!auto_exposure) {
        // Make sure that user-requested exposure rate is achievable
        if (((is_err = is_Exposure(cam_handle_, IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MIN,
                                   (void*) &minExposure, sizeof(minExposure)))
             != IS_SUCCESS) ||
            ((is_err = is_Exposure(cam_handle_, IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MAX,
                                   (void*) &maxExposure, sizeof(maxExposure)))
             != IS_SUCCESS)) {
            std::cerr << "Failed to query valid exposure range from UEye camera '"
                      << cam_name_ << "'" << std::endl;
            return is_err;
        }
        CAP(exposure_ms, minExposure, maxExposure);

        // Update exposure
        if ((is_err = is_Exposure(cam_handle_, IS_EXPOSURE_CMD_SET_EXPOSURE,
                                  (void*) &(exposure_ms), sizeof(exposure_ms)))
            != IS_SUCCESS) {
            std::cerr << "Failed to set exposure to " << exposure_ms
                      << " ms for UEye camera '" << cam_name_ << "'" << std::endl;
            return is_err;
        }
    }

    std::cout << "Updated exposure: "
              << ((auto_exposure) ? "auto" : to_string(exposure_ms))
              << " ms" << std::endl;

    return is_err;
}
static int ids_core_Camera_setauto_exposure(ids_core_Camera *self, PyObject *value, void *closure) {
    if (value == NULL) {
        PyErr_SetString(PyExc_TypeError, "Cannot delete attribute 'auto_exposure'");
        return -1;
    }

    if (!PyBool_Check(value)) {
        PyErr_SetString(PyExc_TypeError, "Auto exposure must be a bool.");
        return -1;
    }

    double val = (value == Py_True) ? 1 : 0;

    int ret = is_SetAutoParameter(self->handle, IS_SET_ENABLE_AUTO_SHUTTER, &val, NULL);
    switch (ret) {
    case IS_SUCCESS:
        if (val > 0) {
            self->autofeatures++;
        }
        else {
            self->autofeatures--;
        }
        return 0;
    default:
        raise_general_error(self, ret);
        return -1;
    }

    return -1;
}
示例#4
0
int IdsSourceSink::SetAutoShutter(bool fitRange)
{
    if ((fitRange)||(!fitRange)) {
        qDebug()<<"The auto shutter mode parameter has no effect for IDS";
    }
    double dEnable=1.0;
    is_SetAutoParameter(hCam, IS_SET_ENABLE_AUTO_SHUTTER, &dEnable, NULL);
    return 0;
}
INT UEyeCamDriver::setWhiteBalance(bool& auto_white_balance, INT& red_offset,
                                   INT& blue_offset) {
    if (!isConnected())
        return IS_INVALID_CAMERA_HANDLE;

    INT is_err = IS_SUCCESS;

    CAP(red_offset, -50, 50);
    CAP(blue_offset, -50, 50);

    // Set auto white balance mode and parameters
    double pval1 = auto_white_balance, pval2 = 0;
    // TODO: 9 bug: enabling auto white balance does not seem to have an effect; in ueyedemo it seems to change R/G/B gains automatically
    if ((is_err = is_SetAutoParameter(cam_handle_, IS_SET_ENABLE_AUTO_SENSOR_WHITEBALANCE,
                                      &pval1, &pval2))
        != IS_SUCCESS) {
        if ((is_err = is_SetAutoParameter(cam_handle_, IS_SET_AUTO_WB_ONCE,
                                          &pval1, &pval2))
            != IS_SUCCESS) {
            std::cerr << "Auto white balance mode is not supported for UEye camera '"
                      << cam_name_ << "' (" << err2str(is_err) << ")" << std::endl;
            auto_white_balance = false;
        }
    }
    if (auto_white_balance) {
        pval1 = red_offset;
        pval2 = blue_offset;
        if ((is_err = is_SetAutoParameter(cam_handle_, IS_SET_AUTO_WB_OFFSET,
                                          &pval1, &pval2))
            != IS_SUCCESS) {
            std::cerr << "Failed to set white balance red/blue offsets to "
                      << red_offset << " / " << blue_offset
                      << " for UEye camera '" << cam_name_ << "'" << std::endl;
        }
    }

    std::cout << "Updated white balance: "
              << ((auto_white_balance) ? "auto" : "manual")
              << "\n   - red offset: " << red_offset << "\n   - blue offset: "
              << blue_offset << std::endl;

    return is_err;
}
示例#6
0
// -------------------  checkAutoGain_clicked  -----------------------
//
void properties::checkAutoGain_clicked ()
{
    if (m_bInit || !m_hCamera)
        return;

    double dblEnable = (checkAutoGain->isChecked ()) ? 1.0 : 0.0;

    if (is_SetAutoParameter (m_hCamera, IS_SET_ENABLE_AUTO_GAIN, &dblEnable, NULL) != IS_SUCCESS)
        QMessageBox::information (0, "Error !!!", "SetAutoGain failed", 0);

    // we may want to start a timer that updates the current values?
    UpdateMasterGainCtrls ();
}
static PyObject *ids_core_Camera_getauto_speed(ids_core_Camera *self, void *closure) {
    double val;
    int ret;
    
    ret = is_SetAutoParameter(self->handle, IS_GET_AUTO_SPEED, &val, NULL);
    switch (ret) {
    case IS_SUCCESS:
        break;
    default:
        PyErr_SetString(PyExc_IOError, "Failed to get auto speed setting.");
        return NULL;
    }
        
    return PyFloat_FromDouble(val);
}
static PyObject *ids_core_Camera_getauto_exposure_brightness(ids_core_Camera *self, void *closure) {
    double val;
    int ret;

    ret = is_SetAutoParameter(self->handle, IS_GET_AUTO_REFERENCE, &val, NULL);
    switch (ret) {
    case IS_SUCCESS:
        break;
    default:
        raise_general_error(self, ret);
        return NULL;
    }

    /* Value is 0..255, return proportion */
    return PyFloat_FromDouble(val/255);
}
示例#9
0
// -------------------  UpdateMasterGainCtrls  -----------------------
//
void properties::UpdateMasterGainCtrls ()
{
    if (m_bInit || !m_hCamera)
        return;

    QString strTemp;
    double dblEnable = 0.0;

    // get values
    m_maxMasterGain = IS_MAX_GAIN;
    m_minMasterGain = IS_MIN_GAIN;
    m_incMasterGain = 1;
    m_nMasterGain = is_SetHardwareGain (m_hCamera, IS_GET_MASTER_GAIN, IS_IGNORE_PARAMETER,
                                        IS_IGNORE_PARAMETER, IS_IGNORE_PARAMETER);
    is_SetAutoParameter (m_hCamera, IS_GET_ENABLE_AUTO_GAIN, &dblEnable, NULL);
    m_bAutoGain = (dblEnable != 0.0);

    // set text
    strTemp.setNum ((short int)m_minMasterGain, 10);
    textMinMasterGain->setText (strTemp);
    strTemp.setNum ((short int)m_maxMasterGain, 10);
    textMaxMasterGain->setText (strTemp);

    m_bInit = TRUE;
    // update slider control
    sliderMaster->setMinimum (m_minMasterGain);
    sliderMaster->setMaximum (m_maxMasterGain);
    sliderMaster->setSingleStep (m_incMasterGain);
    sliderMaster->setPageStep (4* m_incMasterGain);
    sliderMaster->setValue (m_nMasterGain);
    sliderMaster->setEnabled ((m_SensorInfo.bMasterGain == TRUE) && !m_bAutoGain);
    // update spin control
    spinBoxMaster->setMinimum (m_minMasterGain);
    spinBoxMaster->setMaximum (m_maxMasterGain);
    spinBoxMaster->setSingleStep (m_incMasterGain);
    spinBoxMaster->setValue (m_nMasterGain);
    spinBoxMaster->setEnabled ((m_SensorInfo.bMasterGain == TRUE) && !m_bAutoGain);
    // auto
    checkAutoGain->setChecked (m_bAutoGain);
    checkAutoGain->setEnabled (m_bHasAutoGain && !m_bAutoFramerate);
    m_bInit = FALSE;
}
示例#10
0
bool IdsSourceSink::SetShutter(int shutTime)
{
    double dEnable=0.0;
    is_SetAutoParameter(hCam, IS_SET_ENABLE_AUTO_SHUTTER, &dEnable, NULL); // switch off any autoexposure


    double texp=shutTime/1000.0; // IDS works in msecs

    // get values
    double dblRange[3]; // min, max and increment
    is_Exposure(hCam, IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE, (void*)&dblRange, sizeof(dblRange));

    if (texp<dblRange[0]) texp=dblRange[0];

    is_Exposure(hCam,IS_EXPOSURE_CMD_SET_EXPOSURE,(void*)&texp,sizeof(texp));

    //is_SetExposureTime (hCam, IS_GET_EXPOSURE_TIME, &texp);

    return true;
}
示例#11
0
static PyObject *ids_core_Camera_getauto_exposure(ids_core_Camera *self, void *closure) {
    double val;
    int ret;
    
    ret = is_SetAutoParameter(self->handle, IS_GET_ENABLE_AUTO_SHUTTER, &val, NULL);
    switch (ret) {
    case IS_SUCCESS:
        break;
    default:
        raise_general_error(self, ret);
        return NULL;
    }
        
    if (val) {
        Py_INCREF(Py_True);
        return Py_True;
    }
    else {
        Py_INCREF(Py_False);
        return Py_False;
    }
}
示例#12
0
static int ids_core_Camera_setauto_exposure_brightness(ids_core_Camera *self, PyObject *value, void *closure) {
    int ret;
    double val;
    PyObject *exception;

    if (value == NULL) {
        PyErr_SetString(PyExc_TypeError, "Cannot delete attribute 'auto_exposure_brightness'");
        return -1;
    }

    val = PyFloat_AsDouble(value);
    exception = PyErr_Occurred();
    if (exception) {
        PyErr_SetString(exception, "Exposure brightness must be a number");
        return -1;
    }

    if (val < 0 || val > 1) {
        PyErr_SetString(PyExc_ValueError, "Exposure brightness must be between 0 and 1");
        return -1;
    }

    /* Value is 0..255, extract from proportion */
    val = val * 255;

    ret = is_SetAutoParameter(self->handle, IS_SET_AUTO_REFERENCE, &val, NULL);
    switch (ret) {
    case IS_SUCCESS:
        return 0;
    case IS_INVALID_PARAMETER:
        PyErr_SetString(PyExc_ValueError, "Auto exposure brightness out of range");
        break;
    default:
        raise_general_error(self, ret);
        return -1;
    }

    return -1;
}
示例#13
0
static int ids_core_Camera_setauto_speed(ids_core_Camera *self, PyObject *value, void *closure) {
    int ret;
    double val;
    PyObject *exception;

    if (value == NULL) {
        PyErr_SetString(PyExc_TypeError, "Cannot delete attribute 'auto_speed'");
        return -1;
    }

    val = PyFloat_AsDouble(value);
    exception = PyErr_Occurred();
    if (exception) {
        PyErr_SetString(exception, "Auto speed must be a number");
        return -1;
    }

    /* is_SetAutoParameter() returns IS_NO_SUCCESS for out-of-range values ... */
    if (val < 0 || val > 100) {
        PyErr_SetString(PyExc_ValueError, "Auto speed out of range (0...100)");
        return -1;
    }

    ret = is_SetAutoParameter(self->handle, IS_SET_AUTO_SPEED, &val, NULL);
    switch (ret) {
    case IS_SUCCESS:
        return 0;
    case IS_INVALID_PARAMETER:
        PyErr_SetString(PyExc_ValueError, "Auto speed out of range (0..100)");
        break;
    default:
        raise_general_error(self, ret);
        return -1;
    }

    return -1;
}
示例#14
0
static PyObject *ids_core_Camera_getauto_white_balance(ids_core_Camera *self, void *closure) {
    double val;
    UINT val2;
    int ret;
    
    ret = is_SetAutoParameter(self->handle, IS_GET_ENABLE_AUTO_WHITEBALANCE, &val, NULL);
    switch (ret) {
    case IS_SUCCESS:
        break;
    default:
        raise_general_error(self, ret);
        return NULL;
    }

    ret = is_AutoParameter(self->handle, IS_AWB_CMD_GET_ENABLE, &val2, sizeof(val2));
    switch (ret) {
    case IS_SUCCESS:
        break;
    default:
        raise_general_error(self, ret);
        return NULL;
    }
        
    if (val && val2) {
        Py_INCREF(Py_True);
        return Py_True;
    }
    else if (val || val2) {
        PyErr_SetString(PyExc_RuntimeError, "Only one white balance setting is enabled.  It may or may not work.");
        return NULL;
    }
    else {
        Py_INCREF(Py_False);
        return Py_False;
    }
}
INT UEyeCamDriver::setFrameRate(bool& auto_frame_rate, double& frame_rate_hz) {
    if (!isConnected())
        return IS_INVALID_CAMERA_HANDLE;

    INT is_err = IS_SUCCESS;

    double pval1 = 0, pval2 = 0;
    double minFrameTime, maxFrameTime, intervalFrameTime, newFrameRate;

    // Make sure that auto shutter is enabled before enabling auto frame rate
    bool autoShutterOn = false;
    is_SetAutoParameter(cam_handle_, IS_GET_ENABLE_AUTO_SENSOR_SHUTTER, &pval1, &pval2);
    autoShutterOn |= (pval1 != 0);
    is_SetAutoParameter(cam_handle_, IS_GET_ENABLE_AUTO_SHUTTER, &pval1, &pval2);
    autoShutterOn |= (pval1 != 0);
    if (!autoShutterOn) {
        auto_frame_rate = false;
    }

    // Set frame rate / auto
    pval1 = auto_frame_rate;
    if ((is_err = is_SetAutoParameter(cam_handle_, IS_SET_ENABLE_AUTO_SENSOR_FRAMERATE,
                                      &pval1, &pval2))
        != IS_SUCCESS) {
        if ((is_err = is_SetAutoParameter(cam_handle_, IS_SET_ENABLE_AUTO_FRAMERATE,
                                          &pval1, &pval2))
            != IS_SUCCESS) {
            std::cerr << "Auto frame rate mode is not supported for UEye camera '"
                      << cam_name_ << "' (" << err2str(is_err) << ")"
                      << std::endl;
            auto_frame_rate = false;
        }
    }
    if (!auto_frame_rate) {
        // Make sure that user-requested frame rate is achievable
        if ((is_err = is_GetFrameTimeRange(cam_handle_, &minFrameTime,
                                           &maxFrameTime, &intervalFrameTime))
            != IS_SUCCESS) {
            std::cerr << "Failed to query valid frame rate range from UEye camera '"
                      << cam_name_ << "'" << std::endl;
            return is_err;
        }
        CAP(frame_rate_hz, 1.0 / maxFrameTime, 1.0 / minFrameTime);

        // Update frame rate
        if ((is_err = is_SetFrameRate(cam_handle_, frame_rate_hz, &newFrameRate))
            != IS_SUCCESS) {
            std::cerr << "Failed to set frame rate to " << frame_rate_hz
                      << " MHz for UEye camera '" << cam_name_ << "'" << std::endl;
            return is_err;
        } else if (frame_rate_hz != newFrameRate) {
            frame_rate_hz = newFrameRate;
        }
    }

    std::cout << "Updated frame rate: "
              << ((auto_frame_rate) ? "auto" : to_string(frame_rate_hz))
              << " Hz" << std::endl;

    return is_err;
}
示例#16
0
// -------------------  UpdateRGBGainCtrls  -----------------------
//
void properties::UpdateRGBGainCtrls ()
{
    if (m_bInit || !m_hCamera)
        return;

    QString strTemp;
    double dblEnable = 0.0;

    // get values
    m_maxRGBGain = IS_MAX_GAIN;
    m_minRGBGain = IS_MIN_GAIN;
    m_incRGBGain = 1;
    m_nRedGain = is_SetHardwareGain (m_hCamera, IS_GET_RED_GAIN, IS_IGNORE_PARAMETER,
                                     IS_IGNORE_PARAMETER, IS_IGNORE_PARAMETER);
    m_nGreenGain = is_SetHardwareGain (m_hCamera, IS_GET_GREEN_GAIN, IS_IGNORE_PARAMETER,
                                       IS_IGNORE_PARAMETER, IS_IGNORE_PARAMETER);
    m_nBlueGain = is_SetHardwareGain (m_hCamera, IS_GET_BLUE_GAIN, IS_IGNORE_PARAMETER,
                                      IS_IGNORE_PARAMETER, IS_IGNORE_PARAMETER);
    is_SetAutoParameter (m_hCamera, IS_GET_ENABLE_AUTO_WHITEBALANCE, &dblEnable, NULL);

    // set text
    strTemp.setNum ((short int)m_minRGBGain, 10);
    textMinRGBGain->setText (strTemp);
    strTemp.setNum ((short int)m_maxRGBGain, 10);
    textMaxRGBGain->setText (strTemp);

    m_bInit = TRUE;
    // update slider controls
    // red
    sliderRed->setMinValue (m_minRGBGain);
    sliderRed->setMaxValue (m_maxRGBGain);
    sliderRed->setSteps (m_incRGBGain, 4* m_incRGBGain );
    sliderRed->setValue (m_nRedGain);
    sliderRed->setEnabled ((m_SensorInfo.bRGain == TRUE) && (dblEnable == 0.0));
    // green
    sliderGreen->setMinValue (m_minRGBGain);
    sliderGreen->setMaxValue (m_maxRGBGain);
    sliderGreen->setSteps (m_incRGBGain, 4* m_incRGBGain );
    sliderGreen->setValue (m_nGreenGain);
    sliderGreen->setEnabled ((m_SensorInfo.bGGain == TRUE) && (dblEnable == 0.0));
    // blue
    sliderBlue->setMinValue (m_minRGBGain);
    sliderBlue->setMaxValue (m_maxRGBGain);
    sliderBlue->setSteps (m_incRGBGain, 4* m_incRGBGain );
    sliderBlue->setValue (m_nBlueGain);
    sliderBlue->setEnabled ((m_SensorInfo.bBGain == TRUE) && (dblEnable == 0.0));
    // update spin controls
    // red
    spinBoxRed->setMinValue (m_minRGBGain);
    spinBoxRed->setMaxValue (m_maxRGBGain);
    spinBoxRed->setSingleStep (m_incRGBGain);
    spinBoxRed->setValue (m_nRedGain);
    spinBoxRed->setEnabled ((m_SensorInfo.bRGain == TRUE) && (dblEnable == 0.0));
    // green
    spinBoxGreen->setMinValue (m_minRGBGain);
    spinBoxGreen->setMaxValue (m_maxRGBGain);
    spinBoxGreen->setSingleStep (m_incRGBGain);
    spinBoxGreen->setValue (m_nGreenGain);
    spinBoxGreen->setEnabled ((m_SensorInfo.bGGain == TRUE) && (dblEnable == 0.0));
    // blue
    spinBoxBlue->setMinValue (m_minRGBGain);
    spinBoxBlue->setMaxValue (m_maxRGBGain);
    spinBoxBlue->setSingleStep (m_incRGBGain);
    spinBoxBlue->setValue (m_nBlueGain);
    spinBoxBlue->setEnabled ((m_SensorInfo.bBGain == TRUE) && (dblEnable == 0.0));
    m_bInit = FALSE;
}
示例#17
0
UEyeCaptureInterface::CapErrorCode UEyeCaptureInterface::setCaptureProperty(int id, int value)
{
    int retL = 0;
    int retR = 0;

    switch (id)
    {
        case (CameraParameters::EXPOSURE):
        {
            double ms = 0.0;
            ms = (double)value / EXPOSURE_SCALER;
            ueyeTrace(is_Exposure (leftCamera.mCamera , IS_EXPOSURE_CMD_SET_EXPOSURE, (void*)&ms, sizeof(double)));
            ms = (double)value / EXPOSURE_SCALER;
            ueyeTrace(is_Exposure (rightCamera.mCamera, IS_EXPOSURE_CMD_SET_EXPOSURE, (void*)&ms, sizeof(double)));
            return SUCCESS;
        }
        case (CameraParameters::FPS):
        {
            double fps = (double)value / FPS_SCALER;
            double newFps;
            ueyeTrace(is_SetFrameRate (leftCamera.mCamera , fps, &newFps));
            ueyeTrace(is_SetFrameRate (rightCamera.mCamera, fps, &newFps));
            return SUCCESS;
        }
        case (CameraParameters::MASTER_FLASH_DELAY):
        {
            IO_FLASH_PARAMS flashParams;
            flashParams.s32Delay    = 0;
            flashParams.u32Duration = 0;
            ueyeTrace(is_IO(leftCamera.mCamera, IS_IO_CMD_FLASH_GET_PARAMS, (void*)&flashParams, sizeof(flashParams)));
            flashParams.s32Delay = value;
            ueyeTrace(is_IO(leftCamera.mCamera, IS_IO_CMD_FLASH_SET_PARAMS, (void*)&flashParams, sizeof(flashParams)));
            return SUCCESS;
        }
        case (CameraParameters::MASTER_FLASH_DURATION):
        {
            IO_FLASH_PARAMS flashParams;
            flashParams.s32Delay    = 0;
            flashParams.u32Duration = 0;
            ueyeTrace(is_IO(leftCamera.mCamera, IS_IO_CMD_FLASH_GET_PARAMS, (void*)&flashParams, sizeof(flashParams)));
            flashParams.u32Duration = value;
            ueyeTrace(is_IO(leftCamera.mCamera, IS_IO_CMD_FLASH_SET_PARAMS, (void*)&flashParams, sizeof(flashParams)));
            return SUCCESS;
        }

        case (CameraParameters::SLAVE_TRIGGER_DELAY):
        {
            is_SetTriggerDelay (rightCamera.mCamera, value);
            return SUCCESS;
        }
        case (CameraParameters::EXPOSURE_AUTO) :
        {
            double enable = value;
            ueyeTrace(is_SetAutoParameter(leftCamera.mCamera, IS_SET_ENABLE_AUTO_SHUTTER, &enable, 0));
            return SUCCESS;
        }
        default:
        {
            printf("Set request for unknown parameter (%d)\n", id);
            return ImageCaptureInterface::FAILURE;
        }
    }

    return (ImageCaptureInterface::CapErrorCode) ((bool) retL + (bool) retR);
}
INT UEyeCamDriver::setGain(bool& auto_gain, INT& master_gain_prc,
                           INT& red_gain_prc, INT& green_gain_prc,
                           INT& blue_gain_prc, bool& gain_boost) {
    if (!isConnected())
        return IS_INVALID_CAMERA_HANDLE;

    INT is_err = IS_SUCCESS;

    // Validate arguments
    CAP(master_gain_prc, 0, 100);
    CAP(red_gain_prc, 0, 100);
    CAP(green_gain_prc, 0, 100);
    CAP(blue_gain_prc, 0, 100);

    double pval1 = 0, pval2 = 0;

    if (auto_gain) {
        // Set auto gain
        pval1 = 1;
        if ((is_err = is_SetAutoParameter(cam_handle_, IS_SET_ENABLE_AUTO_SENSOR_GAIN,
                                          &pval1, &pval2))
            != IS_SUCCESS) {
            if ((is_err = is_SetAutoParameter(cam_handle_, IS_SET_ENABLE_AUTO_GAIN,
                                              &pval1, &pval2))
                != IS_SUCCESS) {
                std::cerr << "Auto gain mode is not supported for UEye camera '"
                          << cam_name_ << "' (" << err2str(is_err) << ")" << std::endl;
                auto_gain = false;
            }
        }
    } else {
        // Disable auto gain
        if ((is_err = is_SetAutoParameter(cam_handle_, IS_SET_ENABLE_AUTO_SENSOR_GAIN,
                                          &pval1, &pval2))
            != IS_SUCCESS) {
            if ((is_err = is_SetAutoParameter(cam_handle_, IS_SET_ENABLE_AUTO_GAIN,
                                              &pval1, &pval2))
                != IS_SUCCESS) {
                std::cout << "Auto gain mode is not supported for UEye camera '"
                          << cam_name_ << "' (" << err2str(is_err) << ")" << std::endl;
            }
        }

        // Set gain boost
        if (is_SetGainBoost(cam_handle_, IS_GET_SUPPORTED_GAINBOOST)
            != IS_SET_GAINBOOST_ON) {
            gain_boost = false;
        } else {
            if ((is_err = is_SetGainBoost( cam_handle_, (gain_boost) ?
                    IS_SET_GAINBOOST_ON : IS_SET_GAINBOOST_OFF))
                != IS_SUCCESS) {
                std::cerr << "Failed to "
                          << ((gain_boost) ? "enable" : "disable")
                          << " gain boost for UEye camera '" + cam_name_ + "'" << std::endl;
            }
        }

        // Set manual gain parameters
        if ((is_err = is_SetHardwareGain(cam_handle_, master_gain_prc,
                                         red_gain_prc, green_gain_prc, blue_gain_prc))
            != IS_SUCCESS) {
            std::cerr << "Failed to set manual gains (master: "
                      << master_gain_prc << "; red: " << red_gain_prc
                      << "; green: " << green_gain_prc << "; blue: " << blue_gain_prc
                      << ") for UEye camera '" + cam_name_ + "'" << std::endl;
        }
    }

    if (auto_gain) {
        std::cout << "Updated gain: auto" << std::endl;
    } else {
        std::cout << "Updated gain: manual" << "\n   - master gain: "
                  << master_gain_prc << "\n   - red gain: " << red_gain_prc
                  << "\n   - green gain: " << green_gain_prc
                  << "\n   - blue gain: " << blue_gain_prc
                  << "\n   - gain boost: " << gain_boost << std::endl;
    }

    return is_err;
}
示例#19
0
static int ids_core_Camera_setauto_white_balance(ids_core_Camera *self, PyObject *value, void *closure) {
    int ret;
    double val;
    UINT val2;

    if (value == NULL) {
        PyErr_SetString(PyExc_TypeError, "Cannot delete attribute 'auto_white_balance'");
        return -1;
    }

    if (!PyBool_Check(value)) {
        PyErr_SetString(PyExc_TypeError, "Auto white balance must be a bool.");
        return -1;
    }

    val = (value == Py_True) ? 1 : 0;
    val2 = (UINT) val;

    ret = is_SetAutoParameter(self->handle, IS_SET_ENABLE_AUTO_WHITEBALANCE, &val, NULL);
    switch (ret) {
    case IS_SUCCESS:
        break;
    default:
        goto err;
    }

    ret = is_AutoParameter(self->handle, IS_AWB_CMD_SET_ENABLE, &val2, sizeof(val2));
    switch (ret) {
    case IS_SUCCESS:
        break;
    default:
        goto err_reset_set_auto_param;
    }

    if (val2) {
        UINT nType = IS_AWB_COLOR_TEMPERATURE;
        ret = is_AutoParameter(self->handle, IS_AWB_CMD_SET_TYPE, (void*)&nType, sizeof(nType));
        switch (ret) {
        case IS_SUCCESS:
            break;
        default:
            goto err_reset_auto_param;
        }
    }

    if (val > 0) {
        self->autofeatures++;
    }
    else {
        self->autofeatures--;
    }

    return 0;

err_reset_auto_param:
    val2 = 0;
    is_AutoParameter(self->handle, IS_AWB_CMD_SET_ENABLE, &val2, sizeof(val2));
err_reset_set_auto_param:
    val = 0;
    is_SetAutoParameter(self->handle, IS_SET_ENABLE_AUTO_WHITEBALANCE, &val, NULL);
err:
    raise_general_error(self, ret);
    return -1;
}