Dhanushka Gayashan
Dhanushka Gayashan

Reputation: 724

How compare two images and check whether both images are having same object or not in OpenCV python or JavaCV

I am working on a feature matching project and i am using OpenCV Python as the tool for developed the application.

According to the project requirement, my database have images of some objects like glass, ball,etc ....with their descriptions. User can send images to the back end of the application and back end is responsible for matching the sent image with images which are exist in the database and send the image description to the user.

I had done some research on the above scenario. Unfortunately still i could not find a algorithm for matching two images and identifying both are matching or not.

If any body have that kind of algorithm please send me.(I have to use OpenCV python or JavaCV)

Thank you

Upvotes: 3

Views: 3313

Answers (2)

Unapiedra
Unapiedra

Reputation: 16207

This is a very common problem in Computer Vision nowadays. A simple solution is really simple. But there are many, many variants for more sophisticated solutions.

Simple Solution

  1. Feature Detector and Descriptor based. The idea here being that you get a bunch of keypoints and their descriptors (search for SIFT/SURF/ORB). You can then find matches easily with tools provided in OpenCV. You would match the keypoints in your query image against all keypoints in the training dataset. Because of typical outliers, you would like to add a robust matching technique, like RanSaC. All of this is part of OpenCV.
  2. Bag-of-Word model If you want just the image that is as much the same as your query image, you can use Nearest-Neighbour search. Be aware that OpenCV comes with the much faster Approximated-Nearest-Neighbour (ANN) algorithm. Or you can use the BruteForceMatcher.

Advanced Solution

If you have many images (many==1 Million), you can look at Locality-Sensitive-Hashing (see Dean et al, 100,000 Object Categories).

If you do use Bag-of-Visual-Words, then you should probably build an Inverted Index.

Have a look at Fisher Vectors for improved accuracy as compared to BOW.

Suggestion

Start by using Bag-Of-Visual-Words. There are tutorials on how to train the dictionary for this model.

Training:

  1. Extract Local features (just pick SIFT, you can easily change this as OpenCV is very modular) from a subset of your training images. First detect features and then extract them. There are many tutorials on the web about this.
  2. Train Dictionary. Helpful documentation with a reference to a sample implementation in Python (opencv_source_code/samples/python2/find_obj.py)!
  3. Compute Histogram for each training image. (Also in the BOW documentation from previous step)
  4. Put your image descriptors from the step above into a FLANN-Based-matcher.

Querying:

  1. Compute features on your query image.
  2. Use the dictionary from training to build a BOW histogram for your query image.
  3. Use that feature to find the nearest neighbor(s).

Upvotes: 4

RAUSHAN RAJ
RAUSHAN RAJ

Reputation: 120

I think you are talking about Content Based Image Retrieval

There are many research paper available on Internet.Get any one of them and Implement Best out of them according to your needs.Select Criteria according to your application like Texture based,color based,shape based image retrieval (This is best when you are working with image retrieval on internet for speed).

So you Need python Implementation, I would like to suggest you to go through Chapter 7, 8 of book Computer Vision Book . It Contains Working Example with code of what you are looking for

One question you may found useful : Are there any API's that'll let me search by image?

Upvotes: 1

Related Questions