Commits

iorodeo committed 1fe4f9c

Added abiliy to set gamma, satruation, and whiteBalance (red and blue) from
json configuation file.

  • Participants
  • Parent commits 2b9bcc1

Comments (0)

Files changed (2)

src/demo/fly_sorter/image_grabber.cpp

     }
     catch (RuntimeError &runtimeError)
     {
-        QString errorMsg = QString("Unable to get framerate property: ");
+        QString errorMsg = QString(
+                "Unable to get framerate property: "
+                );
         errorMsg += QString::fromStdString(runtimeError.what());
         emit cameraSetupError(errorMsg);
         return false;
 
     if (param_.frameRate < frameRateInfo.minAbsoluteValue)
     {
-        QString errorMsg = QString("framerate less than minimum allowed %1").arg(frameRateInfo.minAbsoluteValue);
+        QString errorMsg = QString(
+                "framerate less than minimum allowed %1"
+                ).arg(frameRateInfo.minAbsoluteValue);
         emit cameraSetupError(errorMsg);
         return false;
 
     }
     if (param_.frameRate > frameRateInfo.maxAbsoluteValue)
     {
-        QString errorMsg = QString("framerate greater than maximum allowed %1").arg(frameRateInfo.maxAbsoluteValue);
+        QString errorMsg = QString(
+                "framerate greater than maximum allowed %1"
+                ).arg(frameRateInfo.maxAbsoluteValue);
         emit cameraSetupError(errorMsg);
         return false;
     }
 
     if (param_.gain < gainInfo.minAbsoluteValue)
     {
-        QString errorMsg = QString("gain less than minimum allowed %1").arg(gainInfo.minAbsoluteValue);
+        QString errorMsg = QString(
+                "gain less than minimum allowed %1"
+                ).arg(gainInfo.minAbsoluteValue);
         emit cameraSetupError(errorMsg);
         return false;
     }
     if (param_.gain > gainInfo.maxAbsoluteValue)
     {
-        QString errorMsg = QString("gain greater than maximum allowed %1").arg(gainInfo.minAbsoluteValue);
+        QString errorMsg = QString(
+                "gain greater than maximum allowed %1"
+                ).arg(gainInfo.minAbsoluteValue);
         emit cameraSetupError(errorMsg);
         return false;
     }
 
     if (param_.shutter < shutterInfo.minAbsoluteValue)
     {
-        QString errorMsg = QString("shutter less than minimum allowed %1").arg(shutterInfo.minAbsoluteValue);
+        QString errorMsg = QString(
+                "shutter less than minimum allowed %1"
+                ).arg(shutterInfo.minAbsoluteValue);
         emit cameraSetupError(errorMsg);
         return false;
     }
     if (param_.shutter > shutterInfo.maxAbsoluteValue)
     {
-        QString errorMsg = QString("shutter greater than maximum allowed %1").arg(shutterInfo.minAbsoluteValue);
+        QString errorMsg = QString(
+                "shutter greater than maximum allowed %1"
+                ).arg(shutterInfo.minAbsoluteValue);
         emit cameraSetupError(errorMsg);
         return false;
     }
         emit cameraSetupError(errorMsg);
         return false;
     }
-   
-
 
     // Set brightness
     PropertyInfo brightnessInfo;
 
     if (param_.brightness < brightnessInfo.minValue)
     {
-        QString errorMsg = QString("brightness less than minimum allowed %1").arg(brightnessInfo.minValue);
+        QString errorMsg = QString(
+                "brightness less than minimum allowed %1"
+                ).arg(brightnessInfo.minValue);
         emit cameraSetupError(errorMsg);
         return false;
     }
     if (param_.brightness > brightnessInfo.maxValue)
     {
-        QString errorMsg = QString("brightness greater than maximum allowed %1").arg(brightnessInfo.minValue);
+        QString errorMsg = QString(
+                "brightness greater than maximum allowed %1"
+                ).arg(brightnessInfo.minValue);
         emit cameraSetupError(errorMsg);
         return false;
     }
         return false;
     }
 
+    // Set Gamma - if present
+    PropertyInfo gammaInfo;
+    Property gammaProp;
+    try
+    {
+        gammaInfo = cameraPtr_ -> getPropertyInfo(PROPERTY_TYPE_GAMMA);
+        gammaProp = cameraPtr_ -> getProperty(PROPERTY_TYPE_GAMMA);
+    }
+    catch (RuntimeError &runtimeError)
+    {
+        QString errorMsg = QString("Unable to get gamma property: ");
+        errorMsg += QString::fromStdString(runtimeError.what());
+        emit cameraSetupError(errorMsg);
+        return false;
+    }
+    // Color camera specific - for development dont' set if can't 
+    if ((gammaInfo.present) && (gammaInfo.manualCapable) && (gammaInfo.absoluteCapable))
+    {
+        std::cout << "setting gamma" << std::endl; 
+
+        if (param_.gamma < gammaInfo.minAbsoluteValue)
+        {
+            QString errorMsg = QString(
+                    "gamma less than minimum allowed %1"
+                    ).arg(gammaInfo.minAbsoluteValue);
+            emit cameraSetupError(errorMsg);
+            return false;
+        }
+        if (param_.gamma > gammaInfo.maxAbsoluteValue)
+        {
+            QString errorMsg = QString(
+                    "gamma greater than maximum allowed %1"
+                    ).arg(gammaInfo.maxAbsoluteValue);
+            emit cameraSetupError(errorMsg);
+            return false;
+        }
+
+        gammaProp.absoluteControl = true;
+        gammaProp.absoluteValue = param_.gamma;
+        gammaProp.autoActive = false;
+
+        try
+        {
+            cameraPtr_ -> setProperty(gammaProp);
+        }
+        catch (RuntimeError &runtimeError)
+        {
+            QString errorMsg = QString("Unable to set gamma property: ");
+            errorMsg += QString::fromStdString(runtimeError.what());
+            emit cameraSetupError(errorMsg);
+            return false;
+        }
+    }
+    else
+    {
+        std::cout << "not setting gamma" << std::endl; 
+        // -------------------------------------------
+        // TO DO ... emit warning if not present??
+        // -------------------------------------------
+    }
+
+    // Set Saturation - if present
+    PropertyInfo saturationInfo;
+    Property saturationProp;
+    try
+    {
+        saturationInfo = cameraPtr_ -> getPropertyInfo(PROPERTY_TYPE_SATURATION);
+        saturationProp = cameraPtr_ -> getProperty(PROPERTY_TYPE_SATURATION);
+    }
+    catch (RuntimeError &runtimeError)
+    {
+        QString errorMsg = QString("Unable to get saturation property: ");
+        errorMsg += QString::fromStdString(runtimeError.what());
+        emit cameraSetupError(errorMsg);
+        return false;
+    }
+
+    if ((saturationInfo.present) && (saturationInfo.manualCapable) && (saturationInfo.absoluteCapable))
+    {
+        std::cout << "setting saturation" << std::endl; 
+
+        if (param_.saturation < saturationInfo.minAbsoluteValue)
+        {
+            QString errorMsg = QString(
+                    "saturation less than minimum allowed %1"
+                    ).arg(saturationInfo.minAbsoluteValue);
+            emit cameraSetupError(errorMsg);
+            return false;
+        }
+        if (param_.saturation > saturationInfo.maxAbsoluteValue)
+        {
+            QString errorMsg = QString(
+                    "saturation greater than maximum allowed %1"
+                    ).arg(saturationInfo.maxAbsoluteValue);
+            emit cameraSetupError(errorMsg);
+            return false;
+        }
+
+        saturationProp.absoluteControl = true;
+        saturationProp.absoluteValue = param_.saturation;
+        saturationProp.autoActive = false;
+
+        try
+        {
+            cameraPtr_ -> setProperty(saturationProp);
+        }
+        catch (RuntimeError &runtimeError)
+        {
+            QString errorMsg = QString("Unable to set saturation property: ");
+            errorMsg += QString::fromStdString(runtimeError.what());
+            emit cameraSetupError(errorMsg);
+            return false;
+        }
+    }
+    else
+    {
+        std::cout << "not setting saturation" << std::endl;
+        // ------------------------------------------------
+        // TO DO ... emit waring if not present??
+        // ------------------------------------------------
+    }
+
+
+    // Set whiteBalance (Red and Blue) - if present
+    PropertyInfo whiteBalanceInfo;
+    Property whiteBalanceProp;
+    try
+    {
+        whiteBalanceInfo = cameraPtr_ -> getPropertyInfo(PROPERTY_TYPE_SATURATION);
+        whiteBalanceProp = cameraPtr_ -> getProperty(PROPERTY_TYPE_SATURATION);
+    }
+    catch (RuntimeError &runtimeError)
+    {
+        QString errorMsg = QString("Unable to get whiteBalance property: ");
+        errorMsg += QString::fromStdString(runtimeError.what());
+        emit cameraSetupError(errorMsg);
+        return false;
+    }
+
+    if ((whiteBalanceInfo.present) && (whiteBalanceInfo.manualCapable))
+    {
+        std::cout << "setting whiteBalance" << std::endl; 
+
+        if (param_.whiteBalanceRed < whiteBalanceInfo.minAbsoluteValue)
+        {
+            QString errorMsg = QString(
+                    "whiteBalanceRed less than minimum allowed %1"
+                    ).arg(whiteBalanceInfo.minAbsoluteValue);
+            emit cameraSetupError(errorMsg);
+            return false;
+        }
+        if (param_.whiteBalanceRed > whiteBalanceInfo.maxAbsoluteValue)
+        {
+            QString errorMsg = QString(
+                    "whiteBalanceRed greater than maximum allowed %1"
+                    ).arg(whiteBalanceInfo.maxAbsoluteValue);
+            emit cameraSetupError(errorMsg);
+            return false;
+        }
+        if (param_.whiteBalanceBlue < whiteBalanceInfo.minAbsoluteValue)
+        {
+            QString errorMsg = QString(
+                    "whiteBalanceBlue less than minimum allowed %1"
+                    ).arg(whiteBalanceInfo.minAbsoluteValue);
+            emit cameraSetupError(errorMsg);
+            return false;
+        }
+        if (param_.whiteBalanceBlue > whiteBalanceInfo.maxAbsoluteValue)
+        {
+            QString errorMsg = QString(
+                    "whiteBalanceBlue greater than maximum allowed %1"
+                    ).arg(whiteBalanceInfo.maxAbsoluteValue);
+            emit cameraSetupError(errorMsg);
+            return false;
+        }
+        whiteBalanceProp.absoluteControl = false;
+        whiteBalanceProp.valueA = param_.whiteBalanceRed;
+        whiteBalanceProp.valueB = param_.whiteBalanceBlue;
+        whiteBalanceProp.autoActive = false;
+
+        try
+        {
+            cameraPtr_ -> setProperty(whiteBalanceProp);
+        }
+        catch (RuntimeError &runtimeError)
+        {
+            QString errorMsg = QString("Unable to set whiteBalance property: ");
+            errorMsg += QString::fromStdString(runtimeError.what());
+            emit cameraSetupError(errorMsg);
+            return false;
+        }
+    }
+    else
+    {
+        std::cout << "not setting whiteBalance" << std::endl;
+        // ------------------------------------------------
+        // TO DO ... emit waring if not present??
+        // ------------------------------------------------
+    }
     return true;
 }
 

src/demo/fly_sorter/parameters.cpp

     gain = DEFAULT_GAIN;
     shutter = DEFAULT_SHUTTER;
     brightness = DEFAULT_BRIGHTNESS;
+    gamma = DEFAULT_GAMMA;
+    saturation = DEFAULT_SATURATION;
+    whiteBalanceRed = DEFAULT_WHITE_BALANCE_RED;
+    whiteBalanceBlue = DEFAULT_WHITE_BALANCE_BLUE;
     captureMode = ALLOWED_CAPTURE_MODES.front();
     captureInputFile = DEFAULT_CAPTURE_INPUT_FILE;
 }
     paramMap.insert("gain", gain);
     paramMap.insert("shutter", shutter);
     paramMap.insert("brightness", brightness);
+    paramMap.insert("gamma", gamma);
+    paramMap.insert("saturation", saturation);
+    paramMap.insert("whiteBalanceRed", whiteBalanceRed);
+    paramMap.insert("whiteBalanceBlue", whiteBalanceBlue);
     paramMap.insert("captureMode", captureMode);
     paramMap.insert("captureInputFile", captureInputFile);
     return paramMap;
 }
 
 
+
 RtnStatus ImageGrabberParam::fromMap(QVariantMap paramMap)
 {
     RtnStatus rtnStatus;
 
     // Get brightness
     // ---------------
-
     if (!paramMap.contains("brightness"))
     {
         rtnStatus.success = false;
         rtnStatus.message = QString("Image grabber parameter 'brightness' greater than maximum");
         return rtnStatus;
     }
+    brightness = brightnessTemp; 
+
+    // Get gamma 
+    // -----------------
+    if (!paramMap.contains("gamma"))
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("'gamma' not found in image grabber parameters");
+        return rtnStatus;
+    }
+    if (!paramMap["gamma"].canConvert<float>())
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("Unable to convert image grabber parameter 'gamma' to float");
+        return rtnStatus;
+    }
+    float gammaTemp = paramMap["gamma"].toFloat();
+    if (gammaTemp < MINIMUM_GAMMA)
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("Image grabber parameter 'gamma' less than minimum");
+        return rtnStatus;
+    }
+    if (gammaTemp > MAXIMUM_GAMMA)
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("Image grabber parameter 'gamma' greater than maximum");
+        return rtnStatus;
+    }
+
+    // Get saturation 
+    if (!paramMap.contains("saturation"))
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("'saturation' not found in image grabber parameters");
+        return rtnStatus;
+    }
+    if (!paramMap["saturation"].canConvert<float>())
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("Unable to convert image grabber parameter 'saturation' to float");
+        return rtnStatus;
+    }
+    float saturationTemp = paramMap["saturation"].toFloat();
+    if (saturationTemp < MINIMUM_SATURATION)
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("Image grabber parameter 'saturation' less than minimum");
+        return rtnStatus;
+    }
+    if (saturationTemp > MAXIMUM_SATURATION)
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("Image grabber parameter 'saturation' greater than maximum");
+        return rtnStatus;
+    }
+    saturation = saturationTemp;
+
+    
+    // Get whiteBalanceRed 
+    if (!paramMap.contains("whiteBalanceRed"))
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("'whiteBalanceRed' not found in image grabber parameters");
+        return rtnStatus;
+    }
+    if (!paramMap["whiteBalanceRed"].canConvert<unsigned int>())
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("Unable to convert image grabber parameter 'whiteBalanceRed' to float");
+        return rtnStatus;
+    }
+    unsigned int whiteBalanceRedTemp = paramMap["whiteBalanceRed"].toUInt();
+    if (whiteBalanceRedTemp < MINIMUM_WHITE_BALANCE)
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("Image grabber parameter 'whiteBalanceRed' less than minimum");
+        return rtnStatus;
+    }
+    if (whiteBalanceRedTemp > MAXIMUM_WHITE_BALANCE)
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("Image grabber parameter 'whiteBalanceRed' greater than maximum");
+        return rtnStatus;
+    }
+    whiteBalanceRed = whiteBalanceRedTemp;
+    
+    // Get whiteBalanceBlue (unsigned int)
+    if (!paramMap.contains("whiteBalanceBlue"))
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("'whiteBalanceBlue' not found in image grabber parameters");
+        return rtnStatus;
+    }
+    if (!paramMap["whiteBalanceBlue"].canConvert<unsigned int>())
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("Unable to convert image grabber parameter 'whiteBalanceBlue' to float");
+        return rtnStatus;
+    }
+    unsigned int whiteBalanceBlueTemp = paramMap["whiteBalanceBlue"].toUInt();
+    if (whiteBalanceBlueTemp < MINIMUM_WHITE_BALANCE)
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("Image grabber parameter 'whiteBalanceBlue' less than minimum");
+        return rtnStatus;
+    }
+    if (whiteBalanceBlueTemp > MAXIMUM_WHITE_BALANCE)
+    {
+        rtnStatus.success = false;
+        rtnStatus.message = QString("Image grabber parameter 'whiteBalanceBlue' greater than maximum");
+        return rtnStatus;
+    }
+    whiteBalanceBlue = whiteBalanceBlueTemp;
 
     // Get capture mode
     // -----------------