This is an example of how to inspect sample images by using the minimum number of functions of cls module. More details about this example.
int main()
{
std::wstring data_dir = L"../../../examples/data";
std::wstring trainedModelPath = data_dir + L"/models/textile_sample_model.srCls";
std::vector<std::wstring> imagePaths(6);
imagePaths[0] = data_dir + L"/images/Textile/class1_ok/000001.png";
imagePaths[1] = data_dir + L"/images/Textile/class1_ng/000002.png";
imagePaths[2] = data_dir + L"/images/Textile/class2_ok/000001.png";
imagePaths[3] = data_dir + L"/images/Textile/class2_ng/000002.png";
imagePaths[4] = data_dir + L"/images/Textile/class3_ok/000001.png";
imagePaths[5] = data_dir + L"/images/Textile/class3_ng/000002.png";
unsigned char* ucImageData = nullptr;
unsigned int* uiImageData = nullptr;
int verbosity = 2;
int gpuIndex = 0;
{
std::wcout << "Saige Vision failed: Please check the file path of trained model." << std::endl;
}
{
PrintErrorType(srStatus, verbosity);
return -1;
}
{
PrintErrorType(srStatus, verbosity);
return -1;
}
int numberOfClassesOutput = 0;
{
PrintErrorType(srStatus, verbosity);
return -1;
}
{
PrintErrorType(srStatus, verbosity);
return -1;
}
for (size_t i_img = 0; i_img < imagePaths.size(); i_img++)
{
int h = 0, w = 0;
if (inputImageType == eSRInputImageType::UIColorImage)
{
uiImageData = (unsigned int*)GetImageDataByInputImageType(imagePaths[i_img], inputImageType, h, w);
}
else
{
ucImageData = (unsigned char*)GetImageDataByInputImageType(imagePaths[i_img], inputImageType, h, w);
}
if (inputImageType == eSRInputImageType::ImageFilePathMultiByteChar)
{
size_t sizeOfChar = 0;
size_t sizeOfWChar = wcslen(imagePaths[i_img].c_str());
size_t bufferSize = sizeOfWChar * 2;
std::vector<char> imagePathMB(bufferSize);
sizeOfChar = wcstombs(
imagePathMB.data(),
imagePaths[i_img].c_str(),
bufferSize
);
if (sizeOfChar != sizeOfWChar)
{
std::wcout << "Saige Vision FAILED: Wrong Image path" << imagePaths[i_img] << std::endl;
continue;
}
}
else if (inputImageType == eSRInputImageType::ImageFilePathWideChar)
{
}
else if (inputImageType == eSRInputImageType::UCGrayImage)
{
}
else if (inputImageType == eSRInputImageType::UCColorImage)
{
}
else if (inputImageType == eSRInputImageType::UIColorImage)
{
}
{
PrintErrorType(srStatus, verbosity);
continue;
}
long inspectionTimeOutput = 0;
{
PrintErrorType(srStatus, verbosity);
continue;
}
{
PrintErrorType(srStatus, verbosity);
continue;
}
if (verbosity >= 2)
{
std::cout << "====== classification Test Result ======" << std::endl;
std::wcout << imagePaths[i_img] << std::endl;
for (int j = 0; j < numberOfClassesOutput; j++)
{
std::cout <<
" - " << j <<
"-th class score (original, with additional): " << clsResult.
scoresOriginal[j] <<
'\t' << clsResult.
scoresIncludingAdd[j] << std::endl;
}
std::cout <<
" - Result Class: " << clsResult.
classIdx << std::endl;
std::cout << " - Inspection time: " << inspectionTimeOutput << std::endl << std::endl;
}
if (ucImageData != nullptr)
{
delete[] ucImageData;
}
if (uiImageData != nullptr)
{
delete[] uiImageData;
}
}
{
PrintErrorType(srStatus, verbosity);
return -1;
}
{
PrintErrorType(srStatus, verbosity);
return -1;
}
std::cout << "SaigeVision successfully completed, please press enter key to terminate" << std::endl;
std::cin.get();
return 0;
}
Header file for Classification Module.
eErrorType SR_PrintClsTestParameters(ClsTestHandle handle)
Print a model parameters (Classification's class information, inspection options.....
Header file of util functions for example projects.
eSRInputImageType
Data Type of input Image for example projects.
Definition: SRUtils.h:23
eErrorType SR_GetClsTestNumberOfClasses(ClsTestHandle handle, int *numberOfClasses)
Get the number of classes.
void * ClsTestHandle
Classification file handler.
Definition: ClassifierTestDLL.h:56
eErrorType SR_MakeClsTestResult_ErrorType(ClsTestResult *clsTestResult)
Construct a ClsTestResult.
eErrorType SR_CreateClsTestHandleByWideCharPath_ErrorType(ClsTestHandle *clsTestHandle, const wchar_t *filePath)
Create a ClsTestHandle via wide char path.
void * ClsTestResult
Classification inspection results handler.
Definition: ClassifierTestDLL.h:71
eErrorType SR_DeleteClsTestResult(ClsTestResult clsTestResult)
Destruct a ClsTestResult.
eErrorType SR_DestroyClsTestHandle(ClsTestHandle handle)
Destruct a ClsTestHandle.
eErrorType SR_ApplyClsTestFrom8bitCharColorArray(ClsTestHandle handle, const unsigned char *imageData, const int height, const int width, ClsTestResult clsTestResult)
Apply classification algorithm to 3-channels(BGR) image by 8-bit data.
eErrorType SR_ApplyClsTestFromImageFileByWideCharPath(ClsTestHandle handle, const wchar_t *imagePath, ClsTestResult clsTestResult)
Apply classification algorithm to image by file path.
eErrorType SR_ApplyClsTestFromUnsignedIntColorArray(ClsTestHandle handle, const unsigned int *imageData, const int height, const int width, ClsTestResult clsTestResult)
Apply classification algorithm to 4-channels(BGRA) image by 8-bit data.
eErrorType SR_ApplyClsTestFromImageFile(ClsTestHandle handle, const char *imagePath, ClsTestResult clsTestResult)
Apply classification algorithm to image by file path.
eErrorType SR_ApplyClsTestFrom8bitCharGrayArray(ClsTestHandle handle, const unsigned char *imageData, const int height, const int width, ClsTestResult clsTestResult)
Apply classification algorithm to 1-channel image by 8-bit data.
eErrorType SR_GetClsTestInspectionTime(ClsTestResult clsTestResult, long *inspectionTimeInLong)
Get the inspection time.
eErrorType SR_GetClsTestClassifiedResult(ClsTestResult clsTestResult, SR_ClassifiedResult *classifiedResult)
Get SR_ClassifiedResult.
eErrorType SR_LoadClsTestNetworkInGPU(ClsTestHandle handle, int GPUNumber, int batchSize=1)
Allocate required cpu & gpu memory.
Struct describing result of classification.
Definition: CommonHeaderDLL.h:289
int * scoresIncludingAdd
scores including additional scores for each class
Definition: CommonHeaderDLL.h:295
int classIdx
index of the classified result
Definition: CommonHeaderDLL.h:291
int * scoresOriginal
original scores for each class
Definition: CommonHeaderDLL.h:293