miniprojet/tests/examples/test-descripteurs.cpp

39 lines
1.1 KiB
C++
Raw Normal View History

#include <math.hpp>
int main(int argc, char** argv) {
std::string imagename = "";
int seuil = 25;
int cmax = 10;
if (argc > 2) {
imagename = argv[1];
seuil = atoi(argv[2]);
}
cv::namedWindow("Image", CV_WINDOW_AUTOSIZE);
cv::namedWindow("Binaire", CV_WINDOW_AUTOSIZE);
cv::namedWindow("Contour", CV_WINDOW_AUTOSIZE);
cv::Mat image = cv::imread(imagename, CV_LOAD_IMAGE_COLOR);
cv::Mat binaire(image.rows, image.cols, CV_8UC1);
cv::Mat contour_image(image.rows, image.cols, CV_8UC1);
std::vector<std::vector<cv::Point>> contours;
std::vector<std::vector<cv::Point>> contrs;
std::vector<cv::Vec4i> hierarchy;
math::filter(image, binaire, seuil);
cv::findContours(binaire, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
int index = math::max_cont(contours);
contrs.push_back(contours[index]);
contrs.push_back(math::simplify_contour(contrs[0], cmax));
cv::drawContours(contour_image, contrs, -1, 255);
imshow("Image", image);
imshow("Binaire", binaire);
imshow("Contour", contour_image);
cv::waitKey(0);
return 0;
}