SaigeVision C/C++  1.4.7
SaigeVision API document for C/C++
ExampleSeg+ClsRuntime.cpp

This is an example of how to inspect sample images by applying Segmentation module and continuously classifying the segmented objects. More details about this example.

#include "SRUtils.h"
int main()
{
std::wstring data_dir = L"../../../examples/data";
// trained model path
std::wstring trainedModelPath_seg = data_dir + L"/models/pcb_sample_model.srSeg";
std::wstring trainedModelPath_cls = data_dir + L"/models/pcb_cls_sample_model.srCls";
// image paths to classify
std::vector<std::wstring> imagePaths(4);
imagePaths[0] = data_dir + L"/images/PCB/Image-1.png";
imagePaths[1] = data_dir + L"/images/PCB/Image-2.png";
imagePaths[2] = data_dir + L"/images/PCB/Image-3.png";
imagePaths[3] = data_dir + L"/images/PCB/Image-4.png";
/***********************************************************
* 최대 이미지 수 설정 (Max # of images to inspect)
* - 검사할 최대 이미지 수를 설정합니다. (Set maximum number of images to inspect)
* - 기본적으로 2의 배수로 설정할 것을 추천드리며 크게 설정할 수록
* GPU 메모리 할당량이 커지니 메모리가 부족하다면 더 작은 수로 설정해주세요.
* (Recommend to set this value as multiple of 2, and if GPU memory is low, set the value as lower number.)
* - 최대 이미지 수 보다 많은 이미지가 들어올 시에 내부적으로 여러번의 검사를 수행하게 됩니다.
* (If more images than nMaxImages are inserted to the inspection function, multiple inspections are conducted automatically.)
***********************************************************/
int nMaxImages = 32; /* 4, 8, 16, 32, 64 */
/***********************************************************
* 0. 이미지 인풋 타입 설정
* inputImageType -
* ImageFilePathMultiByteChar: from file path (multi byte char)
* ImageFilePathWideChar: from file path (wide char)
* UCGrayImage: from memory(8bit unsigned char gray image)
* UCColorImage: from memory(8bit unsigned char color image)
* UIColorImage: from memory(32bit unsigned int color image)
***********************************************************/
//eSRInputImageType inputImageType = eSRInputImageType::ImageFilePathMultiByteChar;
//eSRInputImageType inputImageType = eSRInputImageType::ImageFilePathWideChar;
//eSRInputImageType inputImageType = eSRInputImageType::UCGrayImage;
eSRInputImageType inputImageType = eSRInputImageType::UCColorImage;
//eSRInputImageType inputImageType = eSRInputImageType::UIColorImage;
unsigned char* ucImageData = nullptr; // unsigned char image data
unsigned int* uiImageData = nullptr; // unsigned int image data
/***********************************************************
* 0-1. 정보 띄우기 단계 설정 (Verbosity)
* verbosity -
* 0: only warning
* 1: warning + model info
* 2: warning + model info + result info
* 3: warning + model info + result info + image display
* overlayAlpha - display 이미지 = 원본 이미지 * overlayAlpha + segmentation 라벨 * (1 - overlayAlpha)
* displayTime - 결과 이미지 display 하는 시간 (milliseconds)
* resizeFactor - 결과 이미지 display 하는 스케일 (display 크기 = 원본 크기 * resizeFactor)
***********************************************************/
int verbosity = 3;
double overlayAlpha = 0.7;
int displayTime = 100;
double resizeFactor = 0.5;
/***********************************************************
* 0-2. GPU 번호 설정
* gpuIndex - 사용하고자 하는 gpu의 번호
* Multi GPU 가 가능한 License의 경우에 한하여 gpuIndex를
* 0~3까지 설정해 줄 수 있다. 아닌 경우 gpuIndex는 0을 사용하여야 한다.
***********************************************************/
int gpuIndex = 0;
/***********************************************************
* 0-3. Segmentation 검사 방법 설정
***********************************************************/
// "Saige Vision assertion: For seg + cls inspection, use SR_ONE_CLASS_CV_CONTOUR_OUTPUT or SR_ONE_CLASS_CV_CONTOUR_OUTPUT mode only"
assert(outputMode == SR_ONE_CLASS_CV_CONTOUR_OUTPUT || outputMode == SR_MULTI_CLASS_CV_CONTOUR_OUTPUT);
/***********************************************************
* 1. 모델 파일 및 검사 결과 handle 생성,
* Create handles for model files and inspection results
***********************************************************/
SegTestHandle segHandle = SR_CreateSegTestHandleByWideCharPath(trainedModelPath_seg.c_str());
if (segHandle == nullptr)
{
std::wcout << "Saige Vision failed: Please check the file path of trained model." << std::endl;
}
ClsTestHandle clsHandle = SR_CreateClsTestHandleByWideCharPath(trainedModelPath_cls.c_str());
if (clsHandle == nullptr)
{
std::wcout << "Saige Vision failed: Please check the file path of trained model." << std::endl;
}
std::vector<ClsTestResult> clsTestResults(nMaxImages);
for (size_t i = 0; i < nMaxImages; i++)
{
clsTestResults[i] = SR_MakeClsTestResult();
}
/***********************************************************
* 2. 클래스 정보 확인 (Optional)
* Check class information
***********************************************************/
/* Segmentaion information */
srStatus = SR_PrintSegTestParametersWithoutBG(segHandle);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the handle is not created.
return -1;
}
/* Classification information */
srStatus = SR_PrintClsTestParameters(clsHandle);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the handle is not created.
return -1;
}
// Get classification test parameters one by one
int numberOfClassesOutput = 0;
int maxStrLenOfClassName = 0;
// Get the number of classes
srStatus = SR_GetClsTestNumberOfClasses(clsHandle, &numberOfClassesOutput);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that input pointer is not allocated (nullptr).
return -1;
}
// Get the maximum length of class names
srStatus = SR_GetClsTestMaxStrLenOfClassName(clsHandle, &maxStrLenOfClassName);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that input pointer is not allocated (nullptr).
return -1;
}
std::vector<std::wstring> wClassNames(numberOfClassesOutput);
std::vector<std::string> classNames(numberOfClassesOutput);
std::vector<int> classColorsOutput(numberOfClassesOutput);
wchar_t* wClassNameOutput = new wchar_t[maxStrLenOfClassName];
char* classNameOutput = new char[maxStrLenOfClassName];
for (int i = 0; i < numberOfClassesOutput; i++)
{
// Get a color of single class
srStatus = SR_GetClsTestOneClassColor(clsHandle, i, &(classColorsOutput[i]));
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the input index is out of bound(# of classes) or input pointer is not allocated (nullptr).
return -1;
}
// Get a name of single class by multi byte char (char*)
srStatus = SR_GetClsTestOneClassNameWithMultiByteChar(clsHandle, i, classNameOutput);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the input index is out of bound(# of classes) or input pointer is not allocated (nullptr).
return -1;
}
// Get a name of single class by wide char (wchar_t*)
srStatus = SR_GetClsTestOneClassNameWithWideChar(clsHandle, i, wClassNameOutput);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the input index is out of bound(# of classes) or input pointer is not allocated (nullptr).
return -1;
}
wClassNames[i] = wClassNameOutput;
classNames[i] = classNameOutput;
}
delete[] wClassNameOutput;
delete[] classNameOutput;
/***********************************************************
* 3. 검사 옵션 확인 및 수정 (Optional)
* Check inspection options and set new values
***********************************************************/
bool isToCrop = false;
int cropSize = -1;
float marginOfCrop = 0.05;
srStatus = SR_GetSegTestIsToStoreCroppedImage(segHandle, &isToCrop, &cropSize, &modeOfCrop, &marginOfCrop);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that trained model file's version is low
// please retrain with new version of Saige Vision (higher than 1.3.1)
return -1;
}
srStatus = SR_SetSegTestIsToStoreCroppedImage(segHandle, true, cropSize, modeOfCrop, marginOfCrop, true);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that handle is not created.
return -1;
}
/***********************************************************
* 4. 메모리를 GPU 및 CPU에 할당합니다.
* Allocate GPU and CPU memory
***********************************************************/
srStatus = SR_LoadSegTestNetworkInGPU(segHandle, gpuIndex);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the inserted index is not applicable.
return -1;
}
srStatus = SR_LoadClsTestNetworkInGPU(clsHandle, gpuIndex, nMaxImages);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the inserted index is not applicable.
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);
}
/***********************************************************
* (Segmentation) 5. 이미지 검사하기, Inspect images
***********************************************************/
if (inputImageType == eSRInputImageType::ImageFilePathMultiByteChar)
{
// Check if given image path(UNICODE) can be converted to ASCII CODE without any loss.
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;
}
srStatus = SR_ApplySegTestFromImageFile(segHandle, imagePathMB.data(), segTestResult, outputMode);
}
else if (inputImageType == eSRInputImageType::ImageFilePathWideChar)
{
srStatus = SR_ApplySegTestFromImageFileByWideCharPath(segHandle, imagePaths[i_img].c_str(), segTestResult, outputMode);
}
else if (inputImageType == eSRInputImageType::UCGrayImage)
{
srStatus = SR_ApplySegTestFrom8bitCharGrayArray(segHandle, ucImageData, h, w, segTestResult, outputMode);
}
else if (inputImageType == eSRInputImageType::UCColorImage)
{
srStatus = SR_ApplySegTestFrom8bitCharColorArray(segHandle, ucImageData, h, w, segTestResult, outputMode);
}
else if (inputImageType == eSRInputImageType::UIColorImage)
{
srStatus = SR_ApplySegTestFromUnsignedIntColorArray(segHandle, uiImageData, h, w, segTestResult, outputMode);
}
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the input data is not loaded successfully.
if (verbosity >= 3)
{
DisplayFailedImageOnCVWindow(imagePaths[i_img], "FAIL TO segment", "segmentation Result", displayTime, resizeFactor);
}
continue; // jump to next image
}
/***********************************************************
* (Segmentation) 6. 검사 결과 받아오기, Retrieve inspection results
***********************************************************/
if (inputImageType == eSRInputImageType::ImageFilePathWideChar || inputImageType == eSRInputImageType::ImageFilePathMultiByteChar)
{
// Get dimension of input image to draw results later..
srStatus = SR_GetSegTestResultOriginalImageSize(segTestResult, &w, &h);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the input pointer is not allocated (nullptr).
continue; // jump to next image
}
}
long inspectionTimeOutput = 0, loadImageTimeOutput = 0;
// Get the inspection time
srStatus = SR_GetSegTestInspectionTime(segTestResult, &inspectionTimeOutput);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the input pointer is not allocated (nullptr).
continue; // jump to next image
}
// Get the image-loading time
srStatus = SR_GetSegTestLoadImageTime(segTestResult, &loadImageTimeOutput);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the input pointer is not allocated (nullptr).
continue; // jump to next image
}
// Display and draw
if (verbosity >= 2)
{
std::cout << "====== segmentation Test Result ======" << std::endl;
std::wcout << imagePaths[i_img] << std::endl;
std::cout << " - Image width, height: " << w << ", " << h << std::endl;
std::cout << " - Image Loading time: " << loadImageTimeOutput << std::endl;
std::cout << " - Inspection time: " << inspectionTimeOutput << std::endl << std::endl;
}
// Get Segmented objects
// segmented object after filtering (# of classes x # of objects)
std::vector<SR_SegmentedObject> segmentedObject;
int nSegmentedObjects = 0;
srStatus = SR_GetSegTestNumberOfSegmentedObjects(segTestResult, &nSegmentedObjects);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the segTestResult is not created (nullptr).
continue; // jump to next image
}
segmentedObject.resize(nSegmentedObjects);
srStatus = SR_GetSegTestSegmentedObjects(segTestResult, segmentedObject.data());
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the segTestResult is not created (nullptr).
continue; // jump to next image
}
if (verbosity >= 2)
{
std::cout << " - the number of segmented objects: " << segmentedObject.size() << std::endl;
for (int i = 0; i < segmentedObject.size(); i++)
{
std::cout << " - " << i << "-th segmented objects : " <<
"class[" << segmentedObject[i].classIdx << "], " <<
"area[" << segmentedObject[i].area << "], " <<
"width[" << segmentedObject[i].width << "], " <<
"height[" << segmentedObject[i].height << "], " <<
"x_center[" << segmentedObject[i].xCenter << "], " <<
"y_center[" << segmentedObject[i].yCenter << "]" << std::endl;
}
}
/* Classification 검사 수행 */
if (nSegmentedObjects > 0)
{
if (clsTestResults.size() < nSegmentedObjects)
{
clsTestResults.resize(nSegmentedObjects, nullptr);
for (size_t i = 0; i < clsTestResults.size(); i++)
{
if (clsTestResults[i] == nullptr)
clsTestResults[i] = SR_MakeClsTestResult();
}
}
/***********************************************************
* (Classification) 5. 이미지 검사하기, Inspect images
***********************************************************/
srStatus = SR_ApplyClsTestFromSegmentedObjects(clsHandle, nSegmentedObjects, segmentedObject.data(), clsTestResults.data());
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the input pointer is not allocated (nullptr).
continue; // jump to next image
}
/***********************************************************
* (Classification) 6. 검사 결과 받아오기, Retrieve inspection results
***********************************************************/
// Get the inspection time
srStatus = SR_GetClsTestInspectionTime(clsTestResults[0], &inspectionTimeOutput);
if (srStatus != NO_ERROR_OUT)
{
// if you get this error, it's possible that the input pointer is not allocated (nullptr).
PrintErrorType(srStatus, verbosity);
}
// Get the image-loading time
srStatus = SR_GetClsTestLoadImageTime(clsTestResults[0], &loadImageTimeOutput);
if (srStatus != NO_ERROR_OUT)
{
// if you get this error, it's possible that the input pointer is not allocated (nullptr).
PrintErrorType(srStatus, verbosity);
}
std::cout << "====== classification Test Result (Total) ======" << std::endl;
std::cout << " - Image Loading time: " << loadImageTimeOutput << std::endl;
std::cout << " - Inspection time: " << inspectionTimeOutput << std::endl;
// Display
if (verbosity >= 2)
{
for (size_t i = 0; i < nSegmentedObjects; i++)
{
std::vector<int> scoreOutput(numberOfClassesOutput);
int classOutput = -1;
srStatus = SR_GetClsTestResultScore(clsTestResults[i], numberOfClassesOutput, scoreOutput.data(), true);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the input's [# of classes] does not match the result's or input pointer is not allocated (nullptr).
continue; // jump to next image
}
srStatus = SR_GetClsTestResultClass(clsTestResults[i], &classOutput);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that input pointer is not allocated (nullptr).
continue; // jump to next image
}
std::cout << "====== classification Test Result (Single) ======" << std::endl;
for (int j = 0; j < numberOfClassesOutput; j++)
{
std::cout << " - " << j << "-th class score: " << scoreOutput[j] << std::endl;
}
std::cout << " - Result Class: " << classOutput << std::endl;
}
}
}
if (verbosity >= 3)
{
cv::Mat image = cv::Mat();
if (inputImageType == eSRInputImageType::UCGrayImage)
{
image = cv::Mat(h, w, CV_8UC1, ucImageData);
image = image.clone(); /* to prevent modifying raw data */
}
else if (inputImageType == eSRInputImageType::UCColorImage)
{
image = cv::Mat(h, w, CV_8UC3, ucImageData);
image = image.clone(); /* to prevent modifying raw data */
}
else if (inputImageType == eSRInputImageType::UIColorImage)
{
image = cv::Mat(h, w, CV_8UC4, uiImageData);
image = image.clone(); /* to prevent modifying raw data */
}
else
{
int isSuccess = OpenImageFile(imagePaths[i_img].c_str(), image);
if (isSuccess == 0)
{
std::cout << "Saige Vision FAILED: Fail to open image file to display" << std::endl;
continue;
}
}
if (image.channels() == 4)
{
cv::cvtColor(image, image, cv::COLOR_BGRA2BGR);
}
else if (image.channels() == 1)
{
cv::cvtColor(image, image, cv::COLOR_GRAY2BGR);
}
cv::Mat imageCheck = image.clone();
for (size_t i_o = 0; i_o < nSegmentedObjects; i_o++)
{
int classIdx = 0;
SR_GetClsTestResultClass(clsTestResults[i_o], &classIdx);
unsigned char* tmp = (unsigned char*)(&classColorsOutput[classIdx]);
int b = 0, g = 0, r = 0;
std::memcpy(&b, tmp, 1);
std::memcpy(&g, tmp + 1, 1);
std::memcpy(&r, tmp + 2, 1);
cv::Scalar overlayScalar = cv::Scalar(b, g, r);
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierarchy;
convertSRSegmentedObjectToOpencvFormat(segmentedObject[i_o], contours, hierarchy);
cv::drawContours(imageCheck, contours, -1, overlayScalar, -1, 8, hierarchy);
int dataType = CV_MAKETYPE(CV_8U, segmentedObject[i_o].croppedImageChannels);
cv::Mat croppedImage = cv::Mat(segmentedObject[i_o].croppedImageHeight, segmentedObject[i_o].croppedImageWidth, dataType, segmentedObject[i_o].croppedImage);
cv::putText(croppedImage, classNames[classIdx],
cv::Point(int(croppedImage.size().width * 0.1), int(croppedImage.size().height * 0.9)), // Coordinates
cv::FONT_HERSHEY_COMPLEX_SMALL, // Font
2.0, // Scale. 2.0 = 2x bigger
overlayScalar, // BGR Color
4 // Line Thickness (Optional)
);
}
cv::Mat finalUnifiedImage;
double beta = 1.0 - overlayAlpha;
double gamma = 0.0;
cv::addWeighted(image, overlayAlpha, imageCheck, beta, gamma, finalUnifiedImage);
cv::namedWindow("Segmentation Contour Result", cv::WINDOW_NORMAL);
cv::resizeWindow("Segmentation Contour Result", w * resizeFactor, h * resizeFactor);
cv::imshow("Segmentation Contour Result", finalUnifiedImage);
cv::waitKey(displayTime);
for (size_t i_o = 0; i_o < nSegmentedObjects; i_o++)
{
if (segmentedObject[i_o].croppedImage != nullptr)
{
int dataType = CV_MAKETYPE(CV_8U, segmentedObject[i_o].croppedImageChannels);
cv::Mat croppedImage = cv::Mat(segmentedObject[i_o].croppedImageHeight, segmentedObject[i_o].croppedImageWidth, dataType, segmentedObject[i_o].croppedImage);
cv::namedWindow("Segmentation Cropped Image", cv::WINDOW_NORMAL);
cv::resizeWindow("Segmentation Cropped Image", croppedImage.size().width, croppedImage.size().height);
cv::imshow("Segmentation Cropped Image", croppedImage);
cv::waitKey(displayTime);
}
}
}
if (ucImageData != nullptr)
{
delete[] ucImageData;
}
if (uiImageData != nullptr)
{
delete[] uiImageData;
}
}
/***********************************************************
* 7. Handle 파괴, Destruct handles
***********************************************************/
srStatus = SR_DeleteSegTestResult(segTestResult);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the input pointer is not allocated (nullptr).
return -1;
}
for (size_t i = 0; i < clsTestResults.size(); i++)
{
srStatus = SR_DeleteClsTestResult(clsTestResults[i]);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the input pointer is not allocated (nullptr).
return -1;
}
}
srStatus = SR_DestroySegTestHandle(segHandle);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the input pointer is not allocated (nullptr).
return -1;
}
srStatus = SR_DestroyClsTestHandle(clsHandle);
if (srStatus != NO_ERROR_OUT)
{
PrintErrorType(srStatus, verbosity);
// if you get this error, it's possible that the input pointer is not allocated (nullptr).
return -1;
}
std::cout << "SaigeVision successfully completed, please press enter key to terminate" << std::endl;
std::cin.get();
return 0;
}
SR_DestroyClsTestHandle
eErrorType SR_DestroyClsTestHandle(ClsTestHandle handle)
Destruct a ClsTestHandle.
ClsTestHandle
void * ClsTestHandle
Classification file handler.
Definition: ClassifierTestDLL.h:56
SR_GetClsTestOneClassNameWithWideChar
eErrorType SR_GetClsTestOneClassNameWithWideChar(ClsTestHandle handle, const int classIdx, wchar_t *className)
Get a wide char name of certain class by given index.
SR_GetClsTestOneClassColor
eErrorType SR_GetClsTestOneClassColor(ClsTestHandle handle, const int classIdx, int *classColor)
Get a color of certain class by given index.
SegmentationTestDLL.h
Header file for segmentation module.
SR_MakeSegTestResult
SegTestResult SR_MakeSegTestResult()
Construct a SegTestResult.
SR_CreateClsTestHandleByWideCharPath
ClsTestHandle SR_CreateClsTestHandleByWideCharPath(const wchar_t *filePath)
Create a ClsTestHandle via wide char path.
eModeOfCropLargeObjects
eModeOfCropLargeObjects
Enumerator indicating a mode of cropping large objects in segmentation.
Definition: CommonHeaderDLL.h:99
SR_GetClsTestNumberOfClasses
eErrorType SR_GetClsTestNumberOfClasses(ClsTestHandle handle, int *numberOfClasses)
Get the number of classes.
SR_MULTI_CLASS_CV_CONTOUR_OUTPUT
@ SR_MULTI_CLASS_CV_CONTOUR_OUTPUT
Definition: SegmentationTestDLL.h:64
SR_GetClsTestOneClassNameWithMultiByteChar
eErrorType SR_GetClsTestOneClassNameWithMultiByteChar(ClsTestHandle handle, const int classIdx, char *className)
Get a multi byte char name of certain class by given index.
SR_GetSegTestInspectionTime
eErrorType SR_GetSegTestInspectionTime(SegTestResult segTestResult, long *inspectionTimeInLong)
Get the inspection time.
SR_ApplySegTestFromUnsignedIntColorArray
eErrorType SR_ApplySegTestFromUnsignedIntColorArray(SegTestHandle handle, const unsigned int *imageData, const int height, const int width, SegTestResult segTestResult, int flag)
Apply segmentation algorithm to 4-channels(BGRA) image by 8-bit data.
SR_ApplySegTestFromImageFileByWideCharPath
eErrorType SR_ApplySegTestFromImageFileByWideCharPath(SegTestHandle handle, const wchar_t *imagePath, SegTestResult segTestResult, int flag)
Apply segmentation algorithm to image by file path.
SR_ONE_CLASS_CV_CONTOUR_OUTPUT
@ SR_ONE_CLASS_CV_CONTOUR_OUTPUT
Definition: SegmentationTestDLL.h:63
SR_GetClsTestResultScore
eErrorType SR_GetClsTestResultScore(ClsTestResult clsTestResult, const int numClasses, int *scores, bool includeAddScore=false)
Get scores for each class.
GetImageDataByInputImageType
void * GetImageDataByInputImageType(const std::wstring imagePath, const eSRInputImageType inputType, int &height, int &width, int *channel=nullptr)
Get image data from a file path and image size by an allocated pointer for example projects.
Definition: SRUtils.h:138
SR_GetSegTestNumberOfSegmentedObjects
eErrorType SR_GetSegTestNumberOfSegmentedObjects(SegTestResult segTestResult, int *numberOfSegmentedObjects)
Get the number of SR_SegmentedObject.
SR_LoadClsTestNetworkInGPU
eErrorType SR_LoadClsTestNetworkInGPU(ClsTestHandle handle, int GPUNumber, int batchSize=1)
Allocate required cpu & gpu memory.
SR_GetClsTestMaxStrLenOfClassName
eErrorType SR_GetClsTestMaxStrLenOfClassName(ClsTestHandle handle, int *len)
Get a maximum length of class name.
SR_DeleteClsTestResult
eErrorType SR_DeleteClsTestResult(ClsTestResult clsTestResult)
Destruct a ClsTestResult.
SR_LoadSegTestNetworkInGPU
eErrorType SR_LoadSegTestNetworkInGPU(SegTestHandle handle, int GPUNumber, int batchSize=1)
Allocate required cpu & gpu memory.
SR_SetSegTestIsToStoreCroppedImage
eErrorType SR_SetSegTestIsToStoreCroppedImage(SegTestHandle handle, bool isToStoreCroppedImage, int defaultCropSize, eModeOfCropLargeObjects modeOfCropLargeObjects=SR_CROP_BY_OBJECTSIZE_N_RESIZE_TO_CROPSIZE, float margin=0.05, bool writeOnModelFile=true)
Set the parameters of Segmentation's crop object.
SR_GetSegTestResultOriginalImageSize
eErrorType SR_GetSegTestResultOriginalImageSize(SegTestResult segTestResult, int *width, int *height)
Get the size of inspected image.
eSRInputImageType
eSRInputImageType
Data Type of input Image for example projects.
Definition: SRUtils.h:23
SR_MakeClsTestResult
ClsTestResult SR_MakeClsTestResult()
Construct a ClsTestResult.
SR_CreateSegTestHandleByWideCharPath
SegTestHandle SR_CreateSegTestHandleByWideCharPath(const wchar_t *filePath)
Create a SegTestHandle via wide char path.
SR_DeleteSegTestResult
eErrorType SR_DeleteSegTestResult(SegTestResult segTestResult)
Destruct a SegTestResult.
SR_GetClsTestInspectionTime
eErrorType SR_GetClsTestInspectionTime(ClsTestResult clsTestResult, long *inspectionTimeInLong)
Get the inspection time.
SR_ApplyClsTestFromSegmentedObjects
eErrorType SR_ApplyClsTestFromSegmentedObjects(ClsTestHandle handle, int numberOfObjects, SR_SegmentedObject *segmentedObjects, ClsTestResult *clsTestResults)
Apply classification algorithm to SR_SegmentedObject::croppedImage (Batch inspection mode).
SR_ApplySegTestFrom8bitCharColorArray
eErrorType SR_ApplySegTestFrom8bitCharColorArray(SegTestHandle handle, const unsigned char *imageData, const int height, const int width, SegTestResult segTestResult, int flag)
Apply segmentation algorithm to 3-channels(BGR) image by 8-bit data.
SR_GetSegTestLoadImageTime
eErrorType SR_GetSegTestLoadImageTime(SegTestResult segTestResult, long *imageLoadingTimeInLong)
Get the image loading time.
convertSRSegmentedObjectToOpencvFormat
void convertSRSegmentedObjectToOpencvFormat(const SR_SegmentedObject &object, std::vector< std::vector< cv::Point >> &contours, std::vector< cv::Vec4i > &hierarchies)
convert SR_SegmentedObject to opencv contours and hierarchies for example projects.
Definition: SRUtils.h:334
SR_GetClsTestResultClass
eErrorType SR_GetClsTestResultClass(ClsTestResult clsTestResult, int *classIdx)
Get final class index.
SR_GetClsTestLoadImageTime
eErrorType SR_GetClsTestLoadImageTime(ClsTestResult clsTestResult, long *imageLoadingTimeInLong)
Get the image loading time.
SR_DestroySegTestHandle
eErrorType SR_DestroySegTestHandle(SegTestHandle handle)
Destruct a SegTestHandle.
ClassifierTestDLL.h
Header file for Classification Module.
eErrorType
eErrorType
Enumerator indicating error codes.
Definition: CommonHeaderDLL.h:25
SegTestHandle
void * SegTestHandle
Segmentation file handler.
Definition: SegmentationTestDLL.h:90
DisplayFailedImageOnCVWindow
void DisplayFailedImageOnCVWindow(std::wstring &imagePath, std::string failPhrase, std::string windowName, int displayTime, const float resizeFactor)
Display failed image on opencv window for example projects.
Definition: SRUtils.h:273
SR_ApplySegTestFromImageFile
eErrorType SR_ApplySegTestFromImageFile(SegTestHandle handle, const char *imagePath, SegTestResult segTestResult, int flag)
Apply segmentation algorithm to image by file path.
SRUtils.h
Header file of util functions for example projects.
SegTestResult
void * SegTestResult
Segmentation inspection results handler.
Definition: SegmentationTestDLL.h:105
SR_PrintSegTestParametersWithoutBG
eErrorType SR_PrintSegTestParametersWithoutBG(SegTestHandle handle)
Print a model parameters (Segmentation's class information, inspection options...)
SR_PrintClsTestParameters
eErrorType SR_PrintClsTestParameters(ClsTestHandle handle)
Print a model parameters (Classification's class information, inspection options.....
SR_ApplySegTestFrom8bitCharGrayArray
eErrorType SR_ApplySegTestFrom8bitCharGrayArray(SegTestHandle handle, const unsigned char *imageData, const int height, const int width, SegTestResult segTestResult, int flag)
Apply segmentation algorithm to 1-channel image by 8-bit data.
SR_GetSegTestIsToStoreCroppedImage
eErrorType SR_GetSegTestIsToStoreCroppedImage(SegTestHandle handle, bool *isToStoreCroppedImage, int *defaultCropSize, eModeOfCropLargeObjects *modeOfCropLargeObjects, float *margin)
Get the parameters of Segmentation's crop object.
SR_CROP_BY_OBJECTSIZE_N_RESIZE_TO_CROPSIZE
@ SR_CROP_BY_OBJECTSIZE_N_RESIZE_TO_CROPSIZE
Definition: CommonHeaderDLL.h:100
NO_ERROR_OUT
@ NO_ERROR_OUT
Definition: CommonHeaderDLL.h:26
OpenImageFile
bool OpenImageFile(const std::wstring imagePath, cv::Mat &image, bool asCV8U=false)
Open image file for example projects.
Definition: SRUtils.h:74
SR_GetSegTestSegmentedObjects
eErrorType SR_GetSegTestSegmentedObjects(SegTestResult segTestResult, SR_SegmentedObject *segmentedObjects)
Get SR_SegmentedObject s.