So I've decided on using the OpenCV 2.2 Library in C++ for the project.
For today's goal I experimented with using color histograms for comparing the images. Color histograms are a good starting point because it is independent of orientation and size of the insects, making it an easy feature to pull out.
Images were first compressed using pyrDown so the image processing could be done more quickly.
Image sizes went from about 2-4 Megabytes down to a few hundred Kilobytes.
First converted the image to HSV format (for richer color representation, as opposed to RGB histograms), and used a rough binary image as the mask to disregard the background when using calcHist.
HSV image on left, binary image on right.
HSV image on left, binary image on right.
For compareHist, I chose Chi Squared distance (somewhat arbitrarily for now) and then I ran a quick dummy test on 1 train image, and 4 test images:
The true positive image produced a distance of about 30000, while the other images were higher than 80000.
train.jpg |
Test images:
distance: 109642 |
distance: 30000.1 |
distance: 86790.7 |
distance: 181502 |
- Of course, when putting in all the other images, this approach might not be as successful, considering I only included species that seemed significantly distinct in color.
- I spent a lot of time today trying to understand/use the k-nearest neighbor classifier in openCV. The openCV model allows you to easily train a set of images, then predict the class of a test image:
http://opencv.willowgarage.com/documentation/cpp/ml_k_nearest_neighbors.html
K-nearest neighbor is both effective and simple, which is why I have chosen it as a starting point: http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm - I spent the rest of my time figuring out how to load all the image data and class labels into OpenCV Mat structures. I wasn't able to find an easy way navigate directories in C++ without having to download some fancy library, so I wrote a python script to write the absolute paths of the image files, along with their ground truth class label (parent directory) to an output file for easy redirection to C++.
- The image reading takes a long time, so it might be better to compress the images as opposed to compressing them during runtime.
- The Knn classifier expects row vectors for features, but the histograms are N-dimensional matrices, so I will try reshaping the matrices into vectors before feeding them to the classifier.
No comments:
Post a Comment