How to use opencv function mapping to detect copy-move fakes

In my opencv project, I want to detect copy-move fake in image. I know how to use opencv FLANN to map functions in 2 different images, but I'm so confused about how to use FLANN to detect copy-move fakes in an image.

P.S1: I get syntactic key points and image descriptors and get stuck in using the match matching class.

P.S2: the type of object matching is not important to me.

Thanks in advance.

Update:

These drawings are an example of what I need.

Input image

Result

And there is a code that corresponds to the functions of two images and does something similar on two images (not one), the code is in the opencv format in android, as shown below:

vector<KeyPoint> keypoints; Mat descriptors; // Create a SIFT keypoint detector. SiftFeatureDetector detector; detector.detect(image_gray, keypoints); LOGI("Detected %d Keypoints ...", (int) keypoints.size()); // Compute feature description. detector.compute(image, keypoints, descriptors); LOGI("Compute Feature ..."); FlannBasedMatcher matcher; std::vector< DMatch > matches; matcher.match( descriptors, descriptors, matches ); double max_dist = 0; double min_dist = 100; //-- Quick calculation of max and min distances between keypoints for( int i = 0; i < descriptors.rows; i++ ) { double dist = matches[i].distance; if( dist < min_dist ) min_dist = dist; if( dist > max_dist ) max_dist = dist; } printf("-- Max dist : %f \n", max_dist ); printf("-- Min dist : %f \n", min_dist ); //-- Draw only "good" matches (ie whose distance is less than 2*min_dist, //-- or a small arbitary value ( 0.02 ) in the event that min_dist is very //-- small) //-- PS.- radiusMatch can also be used here. std::vector< DMatch > good_matches; for( int i = 0; i < descriptors.rows; i++ ) { if( matches[i].distance <= max(2*min_dist, 0.02) ) { good_matches.push_back( matches[i]); } } //-- Draw only "good" matches Mat img_matches; drawMatches( image, keypoints, image, keypoints, good_matches, img_matches, Scalar::all(-1), Scalar::all(-1), vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS ); //-- Show detected matches // imshow( "Good Matches", img_matches ); imwrite(imgOutFile, img_matches); 
+6
source share
1 answer

I do not know if it is useful to use key points for this problem. I would prefer to check the pattern matching (using the sliding window on your image as a patch). Compared to key points, this method has the disadvantage of being reasonable for rotation and scaling.

If you want to use key points, you can:

  • find a set of key points (SURF, SIFT or whatever),
  • calculate a matching score with any other key points, with the knnMatch function from Brute Force Matcher ( cv::BFMatcher ),
  • matches between the points of difference, that is, points whose distance is greater than zero (or a threshold value), are preserved.

     int nknn = 10; // max number of matches for each keypoint double minDist = 0.5; // distance threshold // Match each keypoint with every other keypoints cv::BFMatcher matcher(cv::NORM_L2, false); std::vector< std::vector< cv::DMatch > > matches; matcher.knnMatch(descriptors, descriptors, matches, nknn); double max_dist = 0; double min_dist = 100; //-- Quick calculation of max and min distances between keypoints for( int i = 0; i < descriptors.rows; i++ ) { double dist = matches[i].distance; if( dist < min_dist ) min_dist = dist; if( dist > max_dist ) max_dist = dist; } // Compute distance and store distant matches std::vector< cv::DMatch > good_matches; for (int i = 0; i < matches.size(); i++) { for (int j = 0; j < matches[i].size(); j++) { // The METRIC distance if( matches[i][j].distance> max(2*min_dist, 0.02) ) continue; // The PIXELIC distance Point2f pt1 = keypoints[queryIdx].pt; Point2f pt2 = keypoints[trainIdx].pt; double dist = cv::norm(pt1 - pt2); if (dist > minDist) good_matches.push_back(matches[i][j]); } } Mat img_matches; drawMatches(image_gray, keypoints, image_gray, keypoints, good_matches, img_matches); 
+2
source

All Articles