Ask Your Question

art_bug's profile - activity

2016-09-04 11:03:20 -0500 received badge  Editor (source)
2016-08-30 12:42:46 -0500 asked a question Problem with drawmatches()

Hi there,

I making logo detection program that uses the SIFT method to detect a logo on image. The latest version of code is

#include <core.hpp>
#include <highgui.hpp>
#include <imgproc.hpp>
#include <cv.hpp>
#include <imgcodecs.hpp>
#include <xfeatures2d.hpp>
#include <vector>
using namespace cv; using namespace cv::xfeatures2d; using std::vector;
vector<Mat> images, templates;
Mat temf = imread("C://DataSet_pic//reference//LEGO_logo.jpg"), teml = imread("C://DataSet_pic//reference//logo-blend-a-med.png");
Mat detectLogo(const Mat &source, const Mat &template_) { Ptr<Feature2D> sift = SIFT::create(); vector<KeyPoint> keypoints_s, keypoints_t; Mat descriptors_s, descriptors_t;
sift->detect(source, keypoints_s); sift->detect(template_, keypoints_t);
sift->compute(source, keypoints_s, descriptors_s); sift->compute(template_, keypoints_t, descriptors_t);
BFMatcher matcher; vector<vector<DMatch>> matches; matcher.knnMatch(descriptors_t, descriptors_s, matches, 2); vector<DMatch> good_matches; for(vector<DMatch> vdm : matches) for(DMatch dm : vdm) if(vdm.data()->distance < dm.distance / 2) good_matches.push_back(*(vdm.data()));
Mat img_matches;
if(good_matches.empty()) return img_matches;
drawMatches(template_, keypoints_t, source, keypoints_s, good_matches, img_matches, Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS); vector<Point2f> templt, scene;
for(unsigned int i = 0; i < good_matches.size(); i++) { templt.push_back( keypoints_t[ good_matches[i].queryIdx ].pt ); scene.push_back( keypoints_s[ good_matches[i].trainIdx ].pt ); }
if(templt.size() < 4 || scene.size() < 4) { img_matches.release(); return img_matches; }
Mat homogr = findHomography(templt, scene, CV_RANSAC); vector<Point2f> templ_corners(4);
templ_corners[0] = cvPoint(0,0); templ_corners[1] = cvPoint(template_.cols, 0); templ_corners[2] = cvPoint(template_.cols, template_.rows); templ_corners[3] = cvPoint(0, template_.rows);
vector<Point2f> scene_corners(4); perspectiveTransform(templ_corners, scene_corners, homogr);
Point p1 = scene_corners[0] + Point2f( template_.cols, 0), p2 = scene_corners[1] + Point2f( template_.cols, 0), p3 = scene_corners[2] + Point2f( template_.cols, 0), p4 = scene_corners[3] + Point2f( template_.cols, 0);
line( img_matches, p1, p2, Scalar(0, 255, 0), 4 ); line( img_matches, p2, p3, Scalar( 0, 255, 0), 4 ); line( img_matches, p3, p4, Scalar( 0, 255, 0), 4 ); line( img_matches, p4, p1, Scalar( 0, 255, 0), 4 );
return img_matches; }
void showFirstLogoMatch() { imshow("Logo detection", detectLogo(images[0], temf)); }
void showLastLogoMatch() { imshow("Logo detection", detectLogo(images[images.size()-1], teml)); }
void showLogoMatch(unsigned short int index) { Mat image = images[index]; Mat img = image.clone();
if(img.size().width == 1280 && img.size().height == 720) { Rect roi(Point(img.size().width / 2 - img.size().width / 4 + 50, img.size().height), Point(img.size().width / 2 + img.size().width / 4 + 50, 0)); Mat image_(img, roi); img = image_; } else if(img.size().width >= 500 && img.size().height >= 370) resize(img, img, Size(), 0.5, 0.5);
for(Mat mat : templates) { if( (mat.size().width >= 1280 || mat.size().width >= 324) && mat.size().height >= 324) resize(mat, mat, Size(), 0.5, 0.5);
Mat logo = detectLogo(img, mat);
if(logo.empty()) continue; else { imshow("Logo detection", logo); waitKey(0); } } }
int main() { vector<String> paths, paths_t; String folder = "C://DataSet_pic//", folder_t = "C://DataSet_pic//reference//";
glob(folder, paths); glob(folder_t, paths_t);
for(String str : paths) images.push_back(imread(str));
for(String str : paths_t) templates.push_back(imread(str));
unsigned int index = 0;
resize(temf, temf, Size(), 0.1667, 0.1667); resize ...




































(more)
2015-09-20 18:11:35 -0500 commented question Problem with build of face detection sample

I rebuilt the library with mingw 4.8.1 but I still give an error undefined reference to __atomic_fetch_add_4. Why?

2015-09-20 14:22:15 -0500 commented question Problem with build of face detection sample

gcc version is 4.7.1

2015-09-19 23:02:00 -0500 asked a question Problem with build of face detection sample

Hello. I did build OpenCV 3.0 using MinGW compiler and latest version of CMake. That library I place to C: disk(and MinGW too). But when I try to compile sample file facedetect.cpp, I give next errors:
=== Build: Debug in opencv_face_detection (compiler: GNU GCC Compiler) ===
obj\Debug\main.o
In function main':<br> D:\Projects\opencv_face_detection\main.cpp|112|undefined reference tocv::imread(cv::String const&, int)'
D:\Projects\opencv_face_detection\main.cpp|121|undefined reference to cv::imread(cv::String const&, int)'<br> D:\Projects\opencv_face_detection\main.cpp|175|undefined reference tocv::imread(cv::String const&, int)'
obj\Debug\main.o
In function ZN2cv3Mat7releaseEv':<br> C:\opencv\build\include\opencv2\core\mat.inl.hpp|666|undefined reference to__atomic_fetch_add_4'
=== Build failed: 4 error(s), 0 warning(s) (0 minute(s), 2 second(s)) ===
I plug in all .dll.a files and I set all settings to compiler and linker settings. What`s wrong?