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