miniprojet/tests/examples/test-descripteurs.cpp

63 lines
1.7 KiB
C++

#include <math.hpp>
int main(int argc, char** argv) {
std::string imagename = "";
int seuil = 25;
int cmax = 100;
if (argc > 1) {
imagename = argv[1];
} else {
std::cout << "Invalid number of arguments: test-descripteurs <path_to_image> [<threshold>]" << std::endl;
return 0;
}
if (argc > 2) {
seuil = atoi(argv[2]);
}
cv::namedWindow("Image", CV_WINDOW_AUTOSIZE);
cv::namedWindow("Binaire", CV_WINDOW_AUTOSIZE);
cv::namedWindow("Contour", CV_WINDOW_AUTOSIZE);
cv::namedWindow("New Contour", CV_WINDOW_AUTOSIZE);
cv::Mat image = cv::imread(imagename, CV_LOAD_IMAGE_COLOR);
std::cout << image.size() << std::endl;
cv::Mat binaire(image.rows, image.cols, CV_8UC1);
cv::Mat contour_image(image.rows, image.cols, CV_8UC1);
cv::Mat new_contour_image(image.rows, image.cols, CV_8UC1);
std::vector<math::contour> contours;
std::vector<math::contour> contrs;
std::vector<cv::Vec4i> hierarchy;
math::to_binary(image, binaire);
cv::findContours(binaire, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
int index = math::max_cont(contours);
math::contour c = contours[index];
c = math::simplify_contour(c, cmax);
std::array<int, 4> bounds = math::bounds(c);
//math::display(c);
c = math::transform(c, bounds, new_contour_image.rows);
contrs.push_back(contours[index]);
contrs.push_back(c);
cv::drawContours(contour_image, contrs, 0, 255);
cv::drawContours(new_contour_image, contrs, 1, 255);
/*
*/
imshow("Image", image);
imshow("Binaire", binaire);
imshow("Contour", contour_image);
imshow("New Contour", new_contour_image);
while (true) {
if (cv::waitKey(0) == 27) {
return 0;
};
}
return 0;
}