0

I found out that there is Chamfer Matching available in OpenCV. I can see there is a function chamferMatching() for C++ and there seems to be a way to use it in Python, too. However, I was unable to find how to use this feature in Java. I am using OpenCV 3.1 Where can I find it in the Java interface? Is it even available there?

If not, what can I use instead? I am trying to recognize fruits. For now apples in particular. I want to match precomputed apple contour to found contours in the image (chamfer matching). After finding a possible apple I am planning to use a classifier to make sure the color and texture are correct.

Template matching seems to be a bad choice because it doesn't work with recognizing rotated objects. I am wondering if I can use Feature Descriptors. Note that I am not trying to recognize a particular apple and I don't know if Feature Descriptors are good for this.

Any thoughts?

EDIT: Ok, I decided to use the findContours() function to get all of the contours in the image, then filter them by area and compare each of the filtered contours with others, designated as templates from training, using matchShapes(). I implemented this and it is not working right (because findContours() is not detecting the apple contours) but I'll post another question with this specific problem. Here I want to ask if this way sounds ok and if there is a better way to detect and compare contours.

Nedko
  • 496
  • 5
  • 16
  • 1
    I can't seem to find that function in the C++ API of OpenCV 3.1, but if it were available we could access it with the JavaCPP Presets: https://github.com/bytedeco/javacpp-presets/tree/master/opencv – Samuel Audet Jan 16 '16 at 14:04
  • Thank you for the link! A little while ago I found out that it is a method of JavaCV and it is probably not in OpenCV at all. So I'll probably have to use something else... – Nedko Jan 16 '16 at 17:03

1 Answers1

0

Ok, I figured it out. There seems to be no Chamfer Matching in OpenCV. It is implemented in JavaCV and there is no sign of it in the native code. Since I'm using OpenCV for Java it is not a good solution for me.

This answer helped me a lot. It is in C++ but it can easily be written in Java.

Initially, I am training the program using a database of 100 images of green apples. The training is actually just storing the largest contour of every photo in a file.

The key to my problem was dividing the image into the 3 different channels resulting in 3 different grayscale images. I transform them using Canny and dilate. Now I check every one of them for contours and it is very likely I will detect the contours of the apple in at least one of them. Once I have all the contours from the 3 images, I filter them by size and then comparing them with every single contour from the training data. If the contour is close enough to one of them I assume it is a contour of an apple.

There seems to be quite a lot of false positives but they will be filtered out when my coleague implements the module doing checks for color and texture of the selected contours (their content).

Here's our project's repository if it would be of help to anyone.

Community
  • 1
  • 1
Nedko
  • 496
  • 5
  • 16