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; }