-
Notifications
You must be signed in to change notification settings - Fork 2
How to use
ikopylov edited this page Nov 16, 2015
·
2 revisions
Library has a two separate API for C and for C++. You can find full example here: https://github.com/qoollo/pattcut-odr-library/blob/master/src/RecognitionLibTest/src/main.cpp
Supported classifier types:
- PattCut classifier format. Sample classifier can be found here: https://github.com/qoollo/pattcut-odr-library/tree/master/classifiers
- OpenCV Haar cascade classifier. You can found samples here: https://github.com/Itseez/opencv/tree/master/data/haarcascades
Supported Image formats:
- JPEG
- PNG
- BMP
To use C API you should include 'pattcut/PattCutC.h' header.
Example:
char* error_message;
PattCut_RecognitionController ctrl = pattcut_init_controller();
pattcut_load_classifier_from_file(ctrl, "classifier.xml", &error_message);
pattcut_free_error_message(&error_message);
PattCut_RecognitionResult* res = pattcut_perform_recognition_on_image_file(ctrl, "image.jpg", nullptr, 0, -1, -1, -1, -1, &error_message);
if (res != nullptr)
{
if (res->best_classifier_id > 0)
printf("Recognized\n");
for (int i = 0; i < res->result_per_classifier[0].areas_count; i++)
{
PattCut_CapturedArea cur_area = res->result_per_classifier[0].areas[i];
printf("veracity: %f", cur_area.veracity);
printf(", wnd_count: %d", cur_area.merged_window_count);
printf(", area: [%d, %d; %d, %d]\n", cur_area.rect_x, cur_area.rect_y, cur_area.rect_width, cur_area.rect_height);
}
}
pattcut_free_error_message(&error_message);
pattcut_free_recognition_results(&res);
pattcut_destroy_controller(&ctrl);
To use C++ API you should include 'pattcut/PattCutCPP.h' header.
Example:
PattCutLib::RecognitionController controller;
auto classifier_id = controller.load_classifier_from_file("classifier.xml");
auto res = controller.perform_recognition("image.jpg");
if (res.best_classifier_id() > 0)
std::cout << "recognized!" << std::endl;
for (int i = 0; i < res.result_per_classifier(0).areas().size(); i++)
{
auto cur_area = res.result_per_classifier(0).areas(i);
std::cout << "veracity: " << cur_area.veracity() <<
", wnd_count: " << cur_area.merged_window_count() <<
", area: [" << cur_area.rect_x() << ", " << cur_area.rect_y() << "; " << cur_area.rect_width() << ", " << cur_area.rect_height() << "]" << std::endl;
}