Download the corresponding version of opencv-contrib
CMake compilation
If there are errors check the log
Open the log file and use the address inside to download the file from the browser.
After the file is downloaded, place it in the corresponding location of the file and modify the file name.
Enter Vs compilation
About OpenCV4.0.1 + contrib configuration when running the program "cannot locate the program entry point" solution
Solution
Copy all the dll suffix files in ... \ opencv \ opencv_contrib \ x64 \ vc15 \ bin to C: \ Windows \ System32, the problem is solved.
Test code
1 #include <opencv2/opencv.hpp> 2 #include <opencv2/xfeatures2d.hpp> 3 //#include <opencv2/> 4 5 using namespace std; 6 using namespace cv; 7 8 int main() 9 { 10 cv::Mat imageL = cv::imread("origin_1.jpg"); 11 cv::Mat imageR = cv::imread("origin_2.jpg"); 12 /*imshow("1", imageL); 13 imshow("2", imageR); 14 waitKey (); 15 return 0; * / 16 17 18 19 // Extract feature point method 20 // SIFT 21 cv :: Ptr <cv :: xfeatures2d :: SIFT> sift = cv :: xfeatures2d :: SIFT :: create (); 22 // ORB 23 // cv :: Ptr <cv :: ORB> orb = cv :: ORB :: create (); 24 // SURF 25 // cv :: Ptr <cv :: xfeatures2d :: SURF> surf = cv :: xfeatures2d :: SURF :: create (); 26 27 // Feature point 28 std :: vector <cv :: KeyPoint> keyPointL, keyPointR; 29 // Extract feature point 30 separately sift->detect(imageL, keyPointL); 31 sift->detect(imageR, keyPointR); 32 33 //画特征点 34 cv::Mat keyPointImageL; 35 cv::Mat keyPointImageR; 36 drawKeypoints(imageL, keyPointL, keyPointImageL, cv::Scalar::all(-1), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS); 37 drawKeypoints(imageR, keyPointR, keyPointImageR, cv::Scalar::all(-1), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS); 38 39 //显示窗口 40 cv::namedWindow("KeyPoints of imageL", cv :: WINDOW_AUTOSIZE); 41 cv :: namedWindow ( " KeyPoints of imageR " , cv :: WINDOW_AUTOSIZE); 42 43 // Display feature points 44 cv :: imshow ( " KeyPoints of imageL " , keyPointImageL); 45 cv: : imshow ( " KeyPoints of imageR " , keyPointImageR); 46 47 // Feature point matching 48 cv :: Mat despL, despR; 49 // Extract feature points and calculate feature descriptor 50 sift-> detectAndCompute (imageL, cv :: Mat (), keyPointL, despL); 51 sift->detectAndCompute (imageR, cv :: Mat (), keyPointR, despR); 52 53 // Struct for DMatch: query descriptor index, train descriptor index, train image index and distance between descriptors. 54 // int queryIdx-> is the test image The subscript of the feature point descriptor (descriptor) is also the subscript of the corresponding feature point (keypoint) of the descriptor. 55 // int trainIdx –> is the index of the feature point descriptor of the sample image, and also the index of the corresponding feature point. 56 // int imgIdx-> useful when the sample is multiple images. 57 // float distance –> represents the Euclidean distance of this pair of matched feature point descriptors (essentially vectors). The smaller the value, the more similar the two feature points. 58 std :: vector <cv :: DMatch> matches; 59 60 // If the flannBased method is used, the type of the desp through orb needs to be converted first. 61 if(despL.type ()! = CV_32F || despR.type ()! = CV_32F) 62 { 63 despL.convertTo (despL, CV_32F); 64 despR.convertTo (despR, CV_32F); 65 } 66 67 hp :: Ptr <cv :: DescriptorMatcher> matcher = cv :: DescriptorMatcher :: create ( " FlannBased " ); 68 matcher-> match (despL, despR, matches); 69 70 // 计算 特征 点 距离 的 最大值 71 double maxDist = 0 ; 72 for ( int i = 0 ; i <despL.rows; i ++ ) 73 { 74 double dist = matches[i].distance; 75 if (dist > maxDist) 76 maxDist = dist; 77 } 78 79 //挑选好的匹配点 80 std::vector< cv::DMatch > good_matches; 81 for (int i = 0; i < despL.rows; i++) 82 { 83 if (matches[i].distance < 0.5 * maxDist) 84 { 85 good_matches.push_back(matches[i]); 86 } 87 } 88 89 90 91 cv::Mat imageOutput; 92 cv::drawMatches(imageL, keyPointL, imageR, keyPointR, good_matches, imageOutput); 93 94 cv::namedWindow("picture of matching", cv::WINDOW_AUTOSIZE); 95 cv::imshow("picture of matching", imageOutput); 96 cv::waitKey(0); 97 return 0; 98 }