This is an example of how to inspect sample images by using the minimum number of functions of OCR module. More details about this example.
int main()
{
std::wstring data_dir = L"../../../examples/data";
std::wstring boxModelPath = data_dir + L"/models/ocr.srOcrBox";
std::wstring textModelPath = data_dir + L"/models/ocr.srOcrText";
std::vector<std::wstring> imagePaths(3);
imagePaths[0] = data_dir + L"/images/OCR/text_01.jpg";
imagePaths[1] = data_dir + L"/images/OCR/text_02.jpg";
imagePaths[2] = data_dir + L"/images/OCR/text_03.jpg";
void* imageData = nullptr;
int verbosity = 3;
int gpuIndex = 0;
if (handle == nullptr)
{
std::cout << "Saige Vision failed: Please check the file path of trained model." << std::endl;
}
{
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::ImageFilePathMultiByteChar && inputImageType != eSRInputImageType::ImageFilePathWideChar)
{
}
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, loadImageTimeOutput = 0;
{
PrintErrorType(srStatus, verbosity);
continue;
}
{
PrintErrorType(srStatus, verbosity);
continue;
}
int nTextBoxes = 0;
{
PrintErrorType(srStatus, verbosity);
continue;
}
std::vector<SR_OCRTextBox> textBoxes(nTextBoxes);
if (nTextBoxes > 0)
{
{
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 text boxes: " << nTextBoxes << std::endl;
std::cout << " - Image Loading time: " << loadImageTimeOutput << std::endl << std::endl;
std::cout << " - Inspection time: " << inspectionTimeOutput << std::endl;
std::cout << " - Text boxes information" << std::endl;
}
for (int i = 0; i < nTextBoxes; i++)
{
float x_c = textBoxes[i].box.x;
float y_c = textBoxes[i].box.y;
float width = textBoxes[i].box.width;
float height = textBoxes[i].box.height;
float angle = textBoxes[i].box.angle;
float score = textBoxes[i].box.score;
std::wstring wtext = textBoxes[i].wtext;
std::string text = textBoxes[i].text;
if (verbosity >= 2)
{
printf(" - %d-th box info(x_c, y_c, w, h, angle, score): %0.3f, %0.3f, %0.3f, %0.3f, %0.3f, %0.3f\n",
i, x_c, y_c, width, height, angle, score);
wprintf(L" - %d-th box's characters: %s\n", i, wtext.c_str());
}
}
if (imageData != nullptr)
{
delete[] (unsigned char*)imageData;
}
}
{
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;
}