2019-10-29 09:37:01 +00:00
|
|
|
#include "opencv2/opencv.hpp"
|
2019-11-26 09:56:37 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include "math.hpp"
|
2019-10-29 09:37:01 +00:00
|
|
|
|
2019-10-29 15:58:26 +00:00
|
|
|
int main(int argc, char** argv) {
|
2019-12-09 11:10:42 +00:00
|
|
|
int seuil=65;
|
2019-11-28 15:08:21 +00:00
|
|
|
int cmax = 10;
|
2019-10-29 15:58:26 +00:00
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
seuil = atol(argv[1]);
|
|
|
|
}
|
|
|
|
|
2019-10-29 09:41:19 +00:00
|
|
|
char detect;
|
2019-10-29 15:58:26 +00:00
|
|
|
cv::VideoCapture cap(0);
|
2019-10-29 09:41:19 +00:00
|
|
|
if(!cap.isOpened())
|
2019-10-29 09:37:01 +00:00
|
|
|
return -1;
|
2019-10-29 15:58:26 +00:00
|
|
|
cv::namedWindow("Image",1);
|
|
|
|
cv::namedWindow("Detection",1);
|
|
|
|
cv::namedWindow("Contours",1);
|
2019-11-28 15:08:21 +00:00
|
|
|
cv::namedWindow("New Contours",1);
|
2019-10-29 15:58:26 +00:00
|
|
|
while(true) {
|
2019-11-26 09:56:37 +00:00
|
|
|
int X, Y, DIM, index;
|
2019-10-29 09:41:19 +00:00
|
|
|
unsigned int numc;
|
2019-11-26 09:56:37 +00:00
|
|
|
uchar R, G, B;
|
|
|
|
std::vector<std::vector<cv::Point>> contours;
|
2019-10-29 15:58:26 +00:00
|
|
|
std::vector<cv::Vec4i> hierarchy;
|
|
|
|
cv::Mat frame;
|
2019-10-29 09:41:19 +00:00
|
|
|
cap >> frame;
|
|
|
|
X=frame.rows;
|
|
|
|
Y=frame.cols;
|
2019-10-29 15:58:26 +00:00
|
|
|
cv::Mat binaire(X,Y,CV_8UC1);
|
|
|
|
cv::GaussianBlur(frame, frame, cv::Size(7,7), 1.5, 1.5);
|
2019-10-29 09:41:19 +00:00
|
|
|
X=frame.rows;
|
|
|
|
Y=frame.cols;
|
|
|
|
DIM=frame.channels();
|
2019-10-29 15:58:26 +00:00
|
|
|
|
2019-12-09 11:10:42 +00:00
|
|
|
math::filter(frame, binaire, seuil);
|
2019-10-29 15:58:26 +00:00
|
|
|
|
|
|
|
cv::findContours(binaire, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
|
|
|
|
cv::Mat Dessin = cv::Mat::zeros(X,Y, CV_8UC1);
|
2019-11-28 15:08:21 +00:00
|
|
|
cv::Mat new_contour_image = cv::Mat::zeros(X,Y, CV_8UC1);
|
|
|
|
|
|
|
|
if (contours.size() > 0) {
|
|
|
|
std::vector<std::vector<cv::Point>> contrs;
|
|
|
|
|
|
|
|
int id = math::max_cont(contours);
|
|
|
|
contrs.push_back(contours[id]);
|
|
|
|
contrs.push_back(math::simplify_contour(contrs[0], cmax));
|
2019-11-26 09:56:37 +00:00
|
|
|
|
2019-12-16 16:30:29 +00:00
|
|
|
math::csignal desc = math::descriptors(contrs[0], cmax);
|
|
|
|
|
2019-11-28 15:08:21 +00:00
|
|
|
cv::drawContours(Dessin, contrs, 0, 255);
|
|
|
|
cv::drawContours(new_contour_image, contrs, 1, 255);
|
|
|
|
}
|
2019-12-16 16:30:29 +00:00
|
|
|
|
|
|
|
cv::imshow("Image", frame);
|
|
|
|
cv::imshow("Detection", binaire);
|
2019-10-29 15:58:26 +00:00
|
|
|
cv::imshow("Contours", Dessin);
|
2019-11-28 15:08:21 +00:00
|
|
|
cv::imshow("New Contours", new_contour_image);
|
2019-12-16 16:30:29 +00:00
|
|
|
|
2019-10-29 15:58:26 +00:00
|
|
|
if(cv::waitKey(30) == 27) {
|
2019-10-29 09:37:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|