Detecting if an object from one image is in another image with OpenCV

前端 未结 4 1927
别那么骄傲
别那么骄傲 2021-01-01 00:48

I have a sample image which contains an object, such as the earrings in the following image:

http://imgur.com/luj2Z

I then have a large candidate set of imag

4条回答
  •  伪装坚强ぢ
    2021-01-01 01:26

    Fortunately, the kind guys from OpenCV just did that for you. Check in your samples folder "opencv\samples\cpp\matching_to_many_images.cpp". Compile and give it a try wih the default images.

    The algorithm can be easily adapted to make it faster or more precise.

    Mainly, object recognition algorithms are split in two parts: keypoint detection& description adn object matching. For both of them there are many algorithms/variants, with wich you can play directly into OpenCV.

    Detection/description can be done by: SIFT/SURF/ORB/GFTT/STAR/FAST and others.

    For matching you have: brute force, hamming, etc. (Some methods are specific for a given detection algorithm)

    HINTS to start:

    • crop your original image so the interesting object covers as much as possible of the image area. Use it as training.

    • SIFT is the most accurate and the laziest descriptor. FAST is a good combination of precision and accuracy. GFTT is old and quite unreliable. ORB is newly added to OPENCV and is very promising, both in speed and accuracy.

    • The results depend on the pose of the object in the other image. If it is resized, rotated, squeezed, partly covered, etc, try SIFT. if it is a simple task (i.e. it appears at the almost same size/rotation/etc, most of the descriptors will cope well)
    • ORB may not be yet in the OpenCV release. Try to download the latest from openCV trunk and compile it https://code.ros.org/svn/opencv/trunk

    So, you can find the best combination for you by trial and error.

    For the details of every implementation, you should read the original papers/tutorials. google scholar is a good start

提交回复
热议问题