This is an example of how to inspect sample images by using the minimum number of functions of det module. More details about this example.
int main()
{
std::wstring data_dir = L"../../../examples/data";
std::wstring trainedModelPath = data_dir + L"/models/lego_sample_model.srDet";
std::vector<std::wstring> imagePaths(5);
imagePaths[0] = data_dir + L"/images/Lego/sample1.png";
imagePaths[1] = data_dir + L"/images/Lego/sample2.png";
imagePaths[2] = data_dir + L"/images/Lego/sample3.png";
imagePaths[3] = data_dir + L"/images/Lego/sample4.png";
imagePaths[4] = data_dir + L"/images/Lego/sample5.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;
}
int numberOfBoxesOutput = 0;
long inspectionTimeOutput = 0;
{
PrintErrorType(srStatus, verbosity);
continue;
}
{
PrintErrorType(srStatus, verbosity);
continue;
}
std::vector<SR_DetectedBox> detectedBoxes(numberOfBoxesOutput);
{
PrintErrorType(srStatus, verbosity);
continue;
}
if (verbosity >= 2)
{
std::cout << "====== Detection Test Result ======" << std::endl;
std::wcout << imagePaths[i_img] << std::endl;
std::cout << " - Number of final detected boxes: " << numberOfBoxesOutput << std::endl;
std::cout << " - Inspection time: " << inspectionTimeOutput << std::endl;
std::cout << " - Detected boxes information" << std::endl;
}
for (int i = 0; i < numberOfBoxesOutput; i++)
{
int xmin = static_cast<int>(detectedBoxes[i].box.x_tl);
int ymin = static_cast<int>(detectedBoxes[i].box.y_tl);
int xmax = static_cast<int>(detectedBoxes[i].box.x_br);
int ymax = static_cast<int>(detectedBoxes[i].box.y_br);
if (verbosity >= 2)
{
printf(" - %d-th box info(label, score, x_topLeft, y_topLeft, x_bottomRight, y_bottomRight): %d, %0.2f, %d, %d, %d, %d\n",
i, detectedBoxes[i].box.classIdx, detectedBoxes[i].box.score, xmin, ymin, xmax, ymax);
}
}
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 Detection Module.
eErrorType SR_PrintDetTestParameters(DetTestHandle handle)
Print a model parameters (Detection'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_GetDetTestNumberOfClasses(DetTestHandle handle, int *numberOfClasses)
Get the number of classes.
eErrorType SR_MakeDetTestResult_ErrorType(DetTestResult *detTestResult)
Construct a DetTestResult.
eErrorType SR_CreateDetTestHandleByWideCharPath_ErrorType(DetTestHandle *detTestHandle, const wchar_t *filePath)
Create a DetTestHandle via wide char path.
void * DetTestResult
Detection inspection results handler.
Definition: DetectorTestDLL.h:67
void * DetTestHandle
Detection file handler.
Definition: DetectorTestDLL.h:52
eErrorType SR_DestroyDetTestHandle(DetTestHandle handle)
Destruct a DetTestHandle.
eErrorType SR_DeleteDetTestResult(DetTestResult detTestResult)
Destruct a DetTestResult.
eErrorType SR_ApplyDetTestFrom8bitCharGrayArray(DetTestHandle handle, const unsigned char *imageData, const int height, const int width, DetTestResult detTestResult)
Apply detection algorithm to 1-channel image by 8-bit data.
eErrorType SR_ApplyDetTestFrom8bitCharColorArray(DetTestHandle handle, const unsigned char *imageData, const int height, const int width, DetTestResult detTestResult)
Apply detection algorithm to 3-channels(BGR) image by 8-bit data.
eErrorType SR_ApplyDetTestFromImageFile(DetTestHandle handle, const char *imagePath, DetTestResult detTestResult)
Apply detection algorithm to image by file path.
eErrorType SR_ApplyDetTestFromImageFileByWideCharPath(DetTestHandle handle, const wchar_t *imagePath, DetTestResult detTestResult)
Apply detection algorithm to image by file path.
eErrorType SR_ApplyDetTestFromUnsignedIntColorArray(DetTestHandle handle, const unsigned int *imageData, const int height, const int width, DetTestResult detTestResult)
Apply detection algorithm to 4-channels(BGRA) image by 8-bit data.
eErrorType SR_GetDetTestInspectionTime(DetTestResult detTestResult, long *inspectionTimeInLong)
Get the inspection time.
eErrorType SR_GetDetTestResultDetectedBoxes(DetTestResult detTestResult, const int numDetectedBoxes, SR_DetectedBox *detectedBoxes)
Get SR_DetectedBox.
eErrorType SR_GetDetTestResultNumberOfBoxes(DetTestResult detTestResult, int *numDetectedBoxes)
Get the number of detected boxes.
eErrorType SR_LoadDetTestNetworkInGPU(DetTestHandle handle, int GPUNumber)
Allocate required cpu & gpu memory.