int main()
{
int nMaxImages = 8;
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";
int verbosity = 3;
int displayTime = 100;
double resizeFactor = 1.0;
int gpuIndex = 0;
if (handle == nullptr)
{
std::wcout << "Saige Vision failed: Please check the file path of trained model." << std::endl;
}
int nTotalImages = imagePaths.size();
std::vector<ClsTestResult> clsTestResults(nTotalImages);
for (size_t i_img = 0; i_img < nTotalImages; i_img++)
{
}
{
PrintErrorType(srStatus, verbosity);
return -1;
}
int numberOfClassesOutput = 0;
int maxStrLenOfClassName = 0;
{
PrintErrorType(srStatus, verbosity);
return -1;
}
{
PrintErrorType(srStatus, verbosity);
return -1;
}
std::vector<std::string> classNames(numberOfClassesOutput);
std::vector<std::wstring> wClassNames(numberOfClassesOutput);
std::vector<int> classColorsOutput(numberOfClassesOutput);
std::vector<int> additionalScoreOutput(numberOfClassesOutput);
char* classNameOutput = new char[maxStrLenOfClassName];
wchar_t* wClassNameOutput = new wchar_t[maxStrLenOfClassName];
for (int i = 0; i < numberOfClassesOutput; i++)
{
{
PrintErrorType(srStatus, verbosity);
return -1;
}
{
PrintErrorType(srStatus, verbosity);
return -1;
}
{
PrintErrorType(srStatus, verbosity);
return -1;
}
classNames[i] = classNameOutput;
wClassNames[i] = wClassNameOutput;
}
delete[] classNameOutput;
delete[] wClassNameOutput;
{
PrintErrorType(srStatus, verbosity);
return -1;
}
#ifdef SR_USE_NEW_ADDITIONAL_SCORE
std::vector<int> additionalScore(numberOfClassesOutput);
for (int i = 0; i < numberOfClassesOutput; i++)
{
additionalScore[i] = 10;
}
{
PrintErrorType(srStatus, verbosity);
return -1;
}
#endif
#ifdef SR_USE_FORWARD_TIME_LIMIT
float timeLimit = 1000;
{
PrintErrorType(srStatus, verbosity);
return -1;
}
#endif
#ifndef SR_USE_FORWARD_TIME_LIMIT
{
PrintErrorType(srStatus, verbosity);
return -1;
}
#endif
{
PrintErrorType(srStatus, verbosity);
return -1;
}
std::vector<int> heights(nTotalImages, 0);
std::vector<int> widths(nTotalImages, 0);
unsigned char** ucImageData = new unsigned char*[nTotalImages];
unsigned int** uiImageData = new unsigned int*[nTotalImages];
for (size_t i_img = 0; i_img < nTotalImages; i_img++)
{
uiImageData[i_img] = nullptr;
ucImageData[i_img] = nullptr;
if (inputImageType == eSRInputImageType::UIColorImage)
{
}
else
{
}
}
if (inputImageType == eSRInputImageType::UCGrayImage)
{
}
else if (inputImageType == eSRInputImageType::UCColorImage)
{
}
else if (inputImageType == eSRInputImageType::UIColorImage)
{
}
{
PrintErrorType(srStatus, verbosity);
std::cout << "Fail to classify" << std::endl;
}
else
{
if (verbosity >= 2)
{
long inspectionTimeOutput = 0, loadImageTimeOutput = 0;
{
PrintErrorType(srStatus, verbosity);
}
{
PrintErrorType(srStatus, verbosity);
}
std::cout << "====== classification Test Result (Total) ======" << std::endl;
std::cout << " - Total Image Loading time: " << loadImageTimeOutput << std::endl;
std::cout << " - Total Inspection time: " << inspectionTimeOutput << std::endl;
}
for (size_t i_img = 0; i_img < nTotalImages; i_img++)
{
std::vector<int> scoreOutput(numberOfClassesOutput);
int classOutput = -1;
{
PrintErrorType(srStatus, verbosity);
continue;
}
{
PrintErrorType(srStatus, verbosity);
continue;
}
if (verbosity >= 2)
{
std::cout << "====== classification Test Result (Single) ======" << std::endl;
std::wcout << imagePaths[i_img] << 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(heights[i_img], widths[i_img], CV_8UC1, ucImageData[i_img]);
image = image.clone();
}
else if (inputImageType == eSRInputImageType::UCColorImage)
{
image = cv::Mat(heights[i_img], widths[i_img], CV_8UC3, ucImageData[i_img]);
image = image.clone();
}
else if (inputImageType == eSRInputImageType::UIColorImage)
{
image = cv::Mat(heights[i_img], widths[i_img], CV_8UC4, uiImageData[i_img]);
image = image.clone();
}
else
{
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);
}
if (image.channels() == 1)
{
cv::cvtColor(image, image, cv::COLOR_GRAY2BGR);
}
int colorTmp = classColorsOutput[classOutput];
unsigned char r = (colorTmp >> 16) & 0xFF;
unsigned char g = (colorTmp >> 8) & 0xFF;
unsigned char b = (colorTmp) & 0xFF;
cv::Scalar classColor = cv::Scalar(b, g, r);
cv::putText(image, classNames[classOutput],
cv::Point(int(image.size().width * 0.1), int(image.size().height * 0.9)),
cv::FONT_HERSHEY_COMPLEX_SMALL,
2.0,
classColor,
4
);
cv::namedWindow("classification Result", cv::WINDOW_NORMAL);
cv::resizeWindow("classification Result", image.size().width * resizeFactor, image.size().height * resizeFactor);
cv::imshow("classification Result", image);
cv::waitKey(displayTime);
}
}
}
{
PrintErrorType(srStatus, verbosity);
return -1;
}
for (size_t i_img = 0; i_img < nTotalImages; i_img++)
{
{
PrintErrorType(srStatus, verbosity);
return -1;
}
if (ucImageData[i_img] != nullptr)
{
delete[] ucImageData[i_img];
ucImageData[i_img] = nullptr;
}
if (uiImageData[i_img] != nullptr)
{
delete[] uiImageData[i_img];
uiImageData[i_img] = nullptr;
}
}
delete[] uiImageData;
delete[] ucImageData;
std::cout << "SaigeVision successfully completed, please press enter key to terminate" << std::endl;
std::cin.get();
return 0;
}