Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

Akaze Error (-215) color.cpp

$
0
0
Hi ! I'm following the tutorial : http://docs.opencv.org/3.0-beta/doc/tutorials/features2d/akaze_matching/akaze_matching.html I'm on Debian. The compilation is good, I had an error on matmul, I modified the file to avoid it. And now when I launch, I have the error : > libdc1394 error: Failed to initialize libdc1394 OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /root/Downloads/opencv-3.0.0/modules/imgproc/src/color.cpp, line 7564 terminate called after throwing an instance of 'cv::Exception' what(): /root/ donwloads/opencv-3.0.0/modules/imgproc/src/color.cpp:7564: error: (-215) scn == 3 || scn == 4 in function cvtColor> Aborted I don't know why I have it so I post my code. #include #include #include #include #include using namespace std; using namespace cv; const float inlier_threshold = 2.5f; // Distance threshold to identify inliers const float nn_match_ratio = 0.8f; // Nearest neighbor matching ratio int main(void) { Mat img1 = imread("lena.png"); Mat img2 = imread("lena2.png"); Mat grayimage1; Mat grayimage2; cvtColor(img1, grayimage1, COLOR_BGR2GRAY); cvtColor(img2, grayimage2, COLOR_BGR2GRAY); img1 = grayimage1; img2 = grayimage2; img1.convertTo(img1, CV_32F); img2.convertTo(img2, CV_32F); Mat homography; FileStorage fs("./match.xml", FileStorage::READ); fs.getFirstTopLevelNode() >> homography; vector kpts1, kpts2; Mat desc1, desc2; Ptr akaze = AKAZE::create(); akaze->detectAndCompute(img1, noArray(), kpts1, desc1); akaze->detectAndCompute(img2, noArray(), kpts2, desc2); BFMatcher matcher(NORM_HAMMING); vector< vector> nn_matches; matcher.knnMatch(desc1, desc2, nn_matches, 2); vector matched1, matched2, inliers1, inliers2; vector good_matches; for(size_t i = 0; i < nn_matches.size(); i++) { DMatch first = nn_matches[i][0]; float dist1 = nn_matches[i][0].distance; float dist2 = nn_matches[i][1].distance; if(dist1 < nn_match_ratio * dist2) { matched1.push_back(kpts1[first.queryIdx]); matched2.push_back(kpts2[first.trainIdx]); } } for(unsigned i = 0; i < matched1.size(); i++) { Mat col = Mat::ones(3, 1, CV_32F); col.at(0) = matched1[i].pt.x; col.at(1) = matched1[i].pt.y; col = homography * col; col /= col.at(2); double dist = sqrt( pow(col.at(0) - matched2[i].pt.x, 2) + pow(col.at(1) - matched2[i].pt.y, 2)); if(dist < inlier_threshold) { int new_i = static_cast(inliers1.size()); inliers1.push_back(matched1[i]); inliers2.push_back(matched2[i]); good_matches.push_back(DMatch(new_i, new_i, 0)); } } Mat res; drawMatches(img1, inliers1, img2, inliers2, good_matches, res); imwrite("res.png", res); double inlier_ratio = inliers1.size() * 1.0 / matched1.size(); cout << "A-KAZE Matching Results" << endl; cout << "*******************************" << endl; cout << "# Keypoints 1: \t" << kpts1.size() << endl; cout << "# Keypoints 2: \t" << kpts2.size() << endl; cout << "# Matches: \t" << matched1.size() << endl; cout << "# Inliers: \t" << inliers1.size() << endl; cout << "# Inliers Ratio: \t" << inlier_ratio << endl; cout << endl; return 0; } Thank you for your help.

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>