PVCAM  3.9.x
Programmable Virtual Camera Access Method library
Post-Processing Programmatically

This sample demonstrates usage of post-processing features and parameters and shows how to correctly control them programmatically. The code is very similar to the PostProcessingParameters sample, but it is not interactive. The only purpose of this example is to find the post-processing parameter for a given ID and toggle its state.

Every camera may support different set of post-processing 'features'. Features are groups that group one or more 'parameters'. These 'parameters' are similar to regular PVCAM parameters, but they need to be discovered by the application at run-time. The 'parameters' are currently limited to uns32 data type.

The application will usually build a tree similar to the following one:

  • Feature: "B.E.R.T" (PARAM_PP_INDEX=0)
  • Parameter: "ENABLED" (PARAM_PP_PARAM_INDEX=0)
  • Parameter: "Threshold" (PARAM_PP_PARAM_INDEX=1)
  • Feature: "DENOISING" (PARAM_PP_INDEX=1)
  • Parameter: "ENABLED" (PARAM_PP_PARAM_INDEX=0)
  • Parameter: "Number of iterations" (PARAM_PP_PARAM_INDEX=1)
  • Parameter: "Sigma" (PARAM_PP_PARAM_INDEX=2)

Because the indexes and their order may be different for every camera, the PVCAM also provides a PARAM_PP_FEAT_ID and PARAM_PP_PARAM_ID parameters. These IDs are uniquely defined in pvcam.h and they are assigned to a particular feature/parameter.

If the application needs to programmatically control a particular PP parameter, then it should use the ID to find to corresponding indexes first, then set the indexes to PVCAM and control the parameter state via PARAM_PP_PARAM parameter.

The code snippet below initializes PVCAM and opens the first available camera. Please refer to the actual code sample in the SDK installation directory for more details about the common helper functions used in this documentation.

std::vector<CameraContext*> contexts;
if (!InitAndOpenOneCamera(contexts, cSingleCamIndex))
return APP_EXIT_ERROR;
CameraContext* ctx = contexts[cSingleCamIndex];

Check if the camera supports post-processing parameters:

if (!IsParamAvailable(ctx->hcam, PARAM_PP_INDEX, "PARAM_PP_INDEX"))
{
CloseAllCamerasAndUninit(contexts);
return APP_EXIT_ERROR;
}

Detect all available post-processing features using the DiscoverCameraPostProcessing helper function and display them in a tree structure:

const std::vector<PvcamPpFeature> ppFeatures = DiscoverCameraPostProcessing(ctx);
printf("Camera Post Processing tree:\n");
for (const PvcamPpFeature& ppFeature : ppFeatures)
{
// Print IDs as signed integers to display invalid values as -1 instead of a large number.
// Valid ID is usually a small number based on current pattern in pvcam.h.
printf("- FEATURE at index %d: id=%d, name='%s'\n",
ppFeature.index, (int32)ppFeature.id, ppFeature.name.c_str());
for (const PvcamPpParameter& ppParam : ppFeature.parameterList)
{
printf(" - PARAMETER at index %d: id=%d, name='%s'\n",
ppParam.index, (int32)ppParam.id, ppParam.name.c_str());
}
}

In this example we will try to find DENOISING feature and its index together with ENABLED parameter index:

int16 denoFeatureIndex;
int16 denoParamIndex;
const bool denoFound = FindPpParamIndexes(ppFeatures,
PP_FEATURE_DENOISING_ENABLED, denoFeatureIndex, denoParamIndex);
if (!denoFound)
{
printf("Camera %d doesn't support DENOISING post-processing feature\n",
ctx->hcam);
CloseAllCamerasAndUninit(contexts);
return APP_EXIT_ERROR;
}

If we found the parameter, toggle its state and exit. Although all post-processing parameters report the value as uns32 type (pl_get_param with ATTR_TYPE returns TYPE_UNS32), the first parameter under each feature usually serves as boolean switch to enable or disable the feature. Value of 0 disables the feature, value of 1 enables it.

uns32 curValue = 0;
if (!GetPpParamValue(ctx, denoFeatureIndex, denoParamIndex, curValue))
{
CloseAllCamerasAndUninit(contexts);
return APP_EXIT_ERROR;
}
uns32 newValue = (curValue != 0) ? 0 : 1;
printf("Current PP_FEATURE_DENOISING_ENABLED value is: %u, setting to %u...\n",
curValue, newValue);
if (!SetPpParamValue(ctx, denoFeatureIndex, denoParamIndex, newValue))
{
CloseAllCamerasAndUninit(contexts);
return APP_EXIT_ERROR;
}
if (!GetPpParamValue(ctx, denoFeatureIndex, denoParamIndex, curValue))
{
CloseAllCamerasAndUninit(contexts);
return APP_EXIT_ERROR;
}
printf("New PP_FEATURE_DENOISING_ENABLED value is: %u\n", curValue);

Cleanup before exiting the application. For more details, please, refer to the Closing Camera and Uninitializing PVCAM section.

CloseCameraAndUninit();
return 0;