Template matching with matchTemplate
is not good when your object is rotated or scaled in scene.
You should try openCV function from Features2D
Framework. For example SIFT
or SURF
descriptors, and FLANN
matcher. Also, you will need findHomography
method.
Here is a good example of finding rotated object in scene.
Update:
In short, algorithm is this:
-
Finding keypoints of your object image
1.1. Extracting descriptors from those keypoints -
Finding keypoints of your scene image
2.1 Extracting descriptors from keypoints -
Match descriptors by matcher
-
Analyze your matches
There are different classes of FeatureDetectors, DescriptorExtractors, and DescriptorMatches, you may read about them and choose those, that fit good for your tasks.
- openCV FeatureDetector (steps 1 and 2 in algorithm above)
- openCV DescriptorExtractor ( steps 1.1 and 2.1 in algorithm
above ) - openCV DescriptorMatcher ( step 3 in algorithm above )