BFMatcher performances VS OpenCV version
Hello,
First of all, I want to thank you for all the great jobs you 're doing with openCV. I notice a change in computation time of the BFMatcher::match function between 2 opencv versions. The difference is a factor of 2 between 3.4.3 and 3.4.4 (and above). I use a simple test program wich run this function 1000 times and compute average, min and max of the time taken by this function to run. All the versions (except 3.2) are built using the cmake flags shown in this post.
I made a diff of modules/features2d between 3.4.3 and 3.4.4 and did not see any major changes. Do you have some hints of what can cause this? Do I made something wrong with the cmake flags for v3.4.4 and above ?
Thanks for your help,
Best regards
Test code :
int nTest = 1000;
vector<KeyPoint> kpts1;
Mat desc1;
vector<DMatch> matches;
vector<double> bfTime;
Mat img1 = imread("./anImage.jpg", IMREAD_GRAYSCALE);
Ptr<ORB> orb_detector = ORB::create(1500);
Ptr<BFMatcher> matcher = BFMatcher::create(NORM_HAMMING, true);
orb_detector->detect(img1, kpts1);
orb_detector->compute(img1, kpts1, desc1);
for(int i = 0; i < nTest; i++){
auto start = chrono::high_resolution_clock::now();
matcher->match (desc1, desc1, matches);
auto stop = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
bfTime.push_back(double(duration.count())/1e6);
}
double totalTime = accumulate(bfTime.begin(), bfTime.end(), 0.0);
cout << "mean time: "<< totalTime / double(nTest) << " [s] min time: "<< *min_element(bfTime.begin(), bfTime.end()) << " [s] max time: "<< *max_element(bfTime.begin(), bfTime.end()) <<endl;
cmake flags:
cmake .. -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/home/baptiste/App/install/opencv \
-DBUILD_EXAMPLES=OFF \
-DBUILD_JAVA=OFF \
-DBUILD_FAT_JAVA_LIB=OFF \
-DBUILD_opencv_python2=OFF \
-DINSTALL_PYTHON_EXAMPLES=OFF \
-DBUILD_WITH_DEBUG_INFO=OFF \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DENABLE_FAST_MATH=ON \
-DWITH_TBB=OFF \
-DWITH_EIGEN=ON \
-DWITH_IPP=OFF \
-DWITH_ITT=OFF \
-DCV_TRACE=OFF \
-DWITH_LAPACK=OFF \
-DWITH_CUDA=OFF
Maybe you could try to save / load keypoints and descriptors. This way, we are sure that the issue directly comes from the brute force matching method.