From c132000776adbd26102c78cec35f3eb3af388455 Mon Sep 17 00:00:00 2001 From: Guillaume Courrier Date: Mon, 16 Dec 2019 17:30:29 +0100 Subject: [PATCH] =?UTF-8?q?fin=20de=20l'impl=C3=A9mentation=20des=20descri?= =?UTF-8?q?pteurs=20de=20Fourrier,=20enfin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/examples/main.cpp | 2 +- tests/src/math.hpp | 41 +++++++++++++++++++++++++++++++++++++++- tests/src/traitement.cpp | 16 ++++++---------- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/tests/examples/main.cpp b/tests/examples/main.cpp index f4bfd23..fddff0c 100644 --- a/tests/examples/main.cpp +++ b/tests/examples/main.cpp @@ -11,7 +11,7 @@ int main (int ac,char ** av) { csignal coord = {0,1,0,0,0,0,0}; coord = {0,1,0,0,0}; csignal res; - res = fft_rec(coord); + res = dft(coord); for(int n=0; npush_back(t); + } + return *res; + } + csignal fft_rec(const csignal& input) { int size = input.size(); std::cout << "Size: " << size << std::endl; @@ -277,10 +292,34 @@ namespace math { return res; } + csignal descriptors(const contour& cont, int cmax) { + csignal z = cont2sig(cont); + complex zm = mean(z); + csignal tfd = dft(diff(z, zm)); + tfd /= z.size(); + int cmin = -cmax; + csignal desc = extract(tfd, cmin, cmax); + + if (std::abs(desc[desc.size()/2-1]) > std::abs(desc[desc.size()/2+1])) { + std::reverse(desc.begin(), desc.end()); + } + + double phy = std::arg(desc[desc.size()/2-1]*desc[desc.size()/2+1])/2; + desc *= std::exp(complex(0, -phy)); + double theta = std::arg(desc[desc.size()/2+1]); + + for (int k=0; k 1) { seuil = atol(argv[1]); @@ -31,7 +30,6 @@ int main(int argc, char** argv) { 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); X=frame.rows; Y=frame.cols; @@ -39,7 +37,6 @@ int main(int argc, char** argv) { 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); @@ -49,20 +46,19 @@ int main(int argc, char** argv) { 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)); + math::csignal desc = math::descriptors(contrs[0], cmax); + cv::drawContours(Dessin, contrs, 0, 255); cv::drawContours(new_contour_image, contrs, 1, 255); } + + cv::imshow("Image", frame); + cv::imshow("Detection", binaire); cv::imshow("Contours", Dessin); cv::imshow("New Contours", new_contour_image); + if(cv::waitKey(30) == 27) { break; }