 |
Perfectly Clear SDK Documentation
10.0.1.537
|
Sample source code is provided in this SDK for several applications that are ready to build on linux and OSX systems. These examples each show different usage models and provide a starting point for adapting these into ready-for-production command line applications. These example applications are:
Simple AI Sample - Using Scene Detection
The simplest way to use Perfectly Clear AI. See the "SimpleAiSample" sample for a full implementation of this.
- Setup the license protection
if (bVerbose)
printf("License Code Status is %d\n", code);
- Load image to correct:
bool bConvertToSRGB = true;
- Initialize the AI Engines
std::string exePath = std::string(argv[0]);
std::string binPath = exePath.substr(0, exePath.find_last_of('/')).c_str();
- Perform full correction using the auto function:
int status =
PFC_AutoCorrect(&im, NULL, ignoredParam, -1, NULL,
false, NULL, pAiEngine);
{
printf("Image processed successfully.\n");
}
- Save the corrected image
bool bConvertToOriginalColorSpace = bConvertToSRGB;
bool bPreserveOriginalMetadata = true;
originalImageFile.
SaveImageFile(oname, quality, bConvertToOriginalColorSpace, bPreserveOriginalMetadata);
Detailed AI Sample - Using Scene Detection
To extend the example shown above, you can load custom AI Presets to apply, instead of using the default presets provided by this SDK. See the "DetailedAiSample" sample for a full implementation of this.
if (profilename == NULL)
{
if (bVerbose) {
printf("Using default presets for detected scenes\n");
}
} else {
if (0 != retLoadPresets) {
printf("Cannot load scene presets file '%s' error '%i'\n", profilename, retLoadPresets);
exit(1);
} else {
printf("Loaded scene presets file '%s'\n", profilename);
}
}
And you can determine the scene ID and label:
int version = 0;
printf("AI version '%i' assigned scene '%i' to the image.\n", version, detectedScene);
if (detectedScene >= 0) {
param = sceneParam;
}
}
if(bVerbose) {
int i = 0;
printf("Scene '%i' is named '%s'.\n", detectedScene, description.name);
}
++i;
}
}
AI Image Correction without Scene Detection
You can correct photos without scene detection, but still using the AI Image corrections that are new in this V10 SDK. This is implemented in the "PresetSample" sample code provided with this SDK.
- load the correction parameters to apply from a .preset file
if (profilename != NULL) {
if (bVerbose)
printf("PFC_ReadPresets returns %d\n", ret);
if (ret != 0) {
if (ret == -2) {
printf("Unable to open preset file %s. Using default settings.\n", argv[3]);
} else {
printf("Unable to read preset file.\n");
exit(1);
}
}
} else {
}
- then use these parameters when correcting the image
{
printf("Image processed successfully.\n");
}
{
printf(
"Noise removal status %d\n",
NRRETCODE(status));
printf(
"Perfectly Clear correction status %d\n",
CORERETCODE(status));
printf(
"Face beautification status %d\n",
FBRETCODE(status));
printf(
"Red eye removal status %d\n",
RERETCODE(status));
}
{
printf("Image processing failed with return code: %d\n", status);
}
Standard I/O to read and write images
Instead of operating with files on disk, you can read and write image content from standard I/O, as seen in the "Standard-IO" sample project.
- Setup input buffer to read
fseek(stdin, 0, SEEK_END);
const long inSize = ftell(stdin);
fseek(stdin, 0, SEEK_SET);
if(inSize < 0) {
printf("No image piped.");
exit(1);
}
char* inBuffer = (char *)malloc(inSize);
if (!inBuffer)
{
printf("Unable to create buffer");
exit(1);
}
fread(inBuffer, inSize, 1, stdin);
- Uncompress the incoming image data
bool bConvertToSRGB = true;
const char* pathToSupportFilesFolder = NULL;
printf("Unable to convert input file to sRGB, processing in original color space\n");
} else {
printf("Unable to open input file, ABORTING.\n");
exit(1);
}
}
free(inBuffer);
- Correct the image as usual, then compress and encode the data
bool bConvertToOriginalColorSpace = bConvertToSRGB;
bool bPreserveOriginalMetadata = true;
unsigned char* outBuffer = NULL;
unsigned long outSize = originalImageFile.
CompressImageBuffer(&outBuffer, outType, 90, bConvertToOriginalColorSpace, bPreserveOriginalMetadata);
fwrite(outBuffer, outSize, 1, stdout);
free(outBuffer);
Image Resizing
This sample loads and corrects the image, but also resizes the output images, as seen in "ResizeSample".
imageResized.
width = fileResized.width;
imageResized.
height = fileResized.height;
imageResized.
format = im.format;
imageResized.
stride = fileResized.stride;
imageResized.
data = fileResized.raw_image;
char outResized[1000];
sprintf(outResized,
"%s.%dx%d.jpg", inname, imageResized.
width, imageResized.
height);
fileResized.SaveImageFile(outResized, 90, false, false);
} else {
printf("Image couldn't be resized, failed with return code: %d\n", status);
}
PDF Image Correcting
This sample loads a PDF file and corrects the images it finds, replaces them into the file and saves it back, as seen in "PDFSample".
- First load the PDF file and setup the correction engine
printf("Cannot load path %s\n", inputPath);
return 1;
}
- Then, iterate over the images, correcting each one
printf(" working on image %d\n", i);
printf(" -status %d\n", status);
i++;
}
- Last, write the new PDF containing all the corrected images to disk:
printf("Cannot save to %s\n", outputPath);
return 1;
}
- Copyright
- Copyright (C) 2021 EyeQ Imaging Inc
int profileUUID
utf8-encoded name
int PFC_GetScene(PFCPROFILE precalc, int *version)
Get scene detection label from profile obtained with PFC_Calc For this to work you need to pass AI_SC...
int PFC_SetProtectionPath(const char *utf8FolderPath, const char *liceseCode=NULL)
Set path to location of SDK License files This enables license protection and allows activation using...
@ APPLY_SUCCESS
0 Success.
int PFC_LoadAIEngine(PFCENGINE *pEngineAI, unsigned int aifeatures, const char *binPath)
Load AI models into engine. Takes time and memory. Use single PFCENGINE with loaded modules,...
Represents an image extracted from a PDF file, thru use of a PFCPDFImageIterator.
int CompressImageBuffer(unsigned char **destination, PFC_FILETYPE type, int quality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata)
Compresses the image to the given type and writes compressed data to destination buffer.
#define CORERETCODE(x)
Decode return status of Core correction from master return code.
Struct PFCPARAM the master structure of all processing parameters.
@ AI_CORRECTIONS
Loads AI-basedd corrections model.
int height
Pixel height of image.
@ CALC_ALL
Calculates for all classic features, all of the above.
LoadStatus load(const char *path)
load() loads the file and returns true if succesful.
#define RERETCODE(x)
Decode return status of Red Eye correction from master return code.
PFC_FILE_LOAD_STATUS
Return status values.
int stride
Byte width of each scanline.
PFCAPPLYSTATUS
Enumeration defining return code from the Apply() function.
@ LOAD_FAILED_CONVERT_SRGB
Error: failed to convert to sRGB.
unsigned char * raw_image
#define PFCPROFILE
Define.
int width
Pixel width of image.
unsigned char * data
Pointer pointing to the first byte of image data buffer.
SaveStatus save(const char *path)
save() loads the file and returns true if succesful.
PFC_FILE_LOAD_STATUS ExpandImageBuffer(char *data, long size, PFC_FILETYPE type, bool bConvertToSRGB, const char *iccFolderPath)
Expands the image file data provided in a buffer.
Struct defining an image to be used in PFC library.
Struct defining an PFC engine instance.
int PFC_ReadScenePreset(PFCPARAM ¶m, PFCENGINE *pEngineAI, int scene)
Fill param for the scene from the engine with previously loaded scene presets with PFC_LoadScenePrese...
void PFC_ReleaseProfile(PFCPROFILE pProfile)
Release PFCPROFILE instance.
PFCAPPLYSTATUS PFC_Apply(PFCIMAGE *pImage, PFCENGINE *pEngine, PFCPROFILE pImageProfile, PFCPARAM ¶m, PFC_PROGRESS progfn=NULL, int iOpacity=100, void *pBGProfile=NULL)
Correct image with parameters.
#define NRRETCODE(x)
Decode return status of Noise Removal from master return code.
@ AI_SCENE_DETECTION
Loads scene detection model.
bool PFC_GetSceneDescription(PFCENGINE *pEngine, int index, PFCSCENEDESCRIPTION *sceneDescription)
Get the scene description for the given index number.
PFCENGINE * PFC_CreateEngine()
Create PFCENGINE instance.
PFCPIXELFORMAT format
Defines byte order of input buffer.
@ Ok
Success, file opened successfully.
@ Ok
Success, file saved successfully.
PFCAPPLYSTATUS PFC_Resize(PFCIMAGE *pImageSrc, PFCIMAGE *pImageDst)
Resizes the input image to the dimensions specificed in by the output image. The output image must be...
int PFC_LoadScenePresets(PFCENGINE *pEngine, const char *filePath, int groupUUID=0, int *arrProfileUUID=NULL, int arrProfileUUIDLen=0)
Loads scene optimized presets from presets file. Engine may be AI-enabled with PFC_LoadAIEngine()....
PFCPROFILE PFC_Calc(PFCIMAGE *pImage, PFCIMAGE *pImageds, PFCENGINE *pEngine, unsigned int feature=CALC_ALL, int iISO=-1, char *pCameraModel=NULL, PFCPROFILE pImageProfile=NULL, PFC_PROGRESS progfn=NULL, int iRejectOption=PFC_REJECT_CLIPART, PFCENGINE *pEngineAI=NULL)
Perform initial analysis on images.
PFCPDFImage * nextImage()
Primary use of the iterator. It'll return a pointer to a PFCPDFImage until the document containes no ...
PFCPDFImageIterator allows the user to iterate over the PFC-supported images of a PDF file....
PFCPIXELFORMAT
defines the format of the image data
int PFC_AutoCorrect(PFCIMAGE *pImage, PFCIMAGE *pImageds, PFCPARAM ¶m, int iISO=-1, char *pCameraModel=NULL, BOOL bFastFAE=FALSE, PFC_PROGRESS progfn=NULL, PFCENGINE *pEngineAI=NULL)
Single function to perform Perfectly Clear correction.
void PFC_SetParam(PFCPARAM ¶m, PFCPRESETID id=PRESET_IAUTO_21)
Initialize a PFCPARAM structure.
bool SaveImageFile(const char *filename, int quality, bool bConvertToOriginalColorSpace, bool bEmbedOriginalMetadata)
Write image data to file - specify file type with filename extension.
PFCImageFile Class to encapsulate file handling.
int PFC_ReadPresets(PFCPARAM ¶m, char *filename)
Load image processing settings from a .preset file. Use this function to load image processing settin...
#define FBRETCODE(x)
Decode return status of Face Beautification from master return code.
PFC_FILE_LOAD_STATUS LoadImageFile(const char *filename, bool bConvertToSRGB, const char *iccFolderPath)
Load JPEG, PNG or RAW from file on disk.