miniprojet/tests/src/traitement.cpp

72 lines
1.7 KiB
C++
Raw Normal View History

2019-10-29 09:37:01 +00:00
#include "opencv2/opencv.hpp"
#include <math.h>
#include <algorithm>
#include "math.hpp"
2019-10-29 09:37:01 +00:00
int main(int argc, char** argv) {
2019-12-09 11:10:42 +00:00
int seuil=65;
int cmax = 10;
int N = 5000;
if (argc > 1) {
seuil = atol(argv[1]);
}
2019-10-29 09:41:19 +00:00
char detect;
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;
cv::namedWindow("Image",1);
cv::namedWindow("Detection",1);
cv::namedWindow("Contours",1);
cv::namedWindow("New Contours",1);
while(true) {
int X, Y, DIM, index;
2019-10-29 09:41:19 +00:00
unsigned int numc;
uchar R, G, B;
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierarchy;
cv::Mat frame;
2019-10-29 09:41:19 +00:00
cap >> frame;
X=frame.rows;
Y=frame.cols;
cv::Mat binaire(X,Y,CV_8UC1);
cv::imshow("Image", frame);
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-12-09 11:10:42 +00:00
math::filter(frame, binaire, seuil);
cv::imshow("Detection", binaire);
cv::findContours(binaire, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
cv::Mat Dessin = cv::Mat::zeros(X,Y, CV_8UC1);
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]);
std::cout << "Number of countours: "
<< contours.size()
<< "; Index of biggest contour: "
<< id
<< std::endl;
contrs.push_back(math::simplify_contour(contrs[0], cmax));
cv::drawContours(Dessin, contrs, 0, 255);
cv::drawContours(new_contour_image, contrs, 1, 255);
}
cv::imshow("Contours", Dessin);
cv::imshow("New Contours", new_contour_image);
if(cv::waitKey(30) == 27) {
2019-10-29 09:37:01 +00:00
break;
}
}
return 0;
}