Using histograms for image comparison
Using Python and OpenCV we can compare the histograms of two images to see how similar they are. In this case, an image of an elephant from the database, and the image of the suspected elephant. This is is simplest method for image comparison, but also the least accurate. However, elephants are large and they are a distinct colour, so it might just be viable for the project!
Overview of method using OpenCV and Python
- Import the cv2 package
- Make dictionary to store the image histograms
- Make dictionary to store images
- Use cv2.calcHist to calculate BGR histograms from reference
- elephant images and new pi camera elephant images
- Use cv2.compareHist(H1, H2, method) to compare the histograms of
- new pi camera elephant images and reference elephant images
- Make dictionary to store results of histogram comparisons
The methods available are:
- CV_COMP_CORREL: Correlation between histograms
- CV_COMP_CHISQR: Chi-Squared distance to the histograms
- CV_COMP_INTERSECT: Intersection between two histograms
- CV_COMP_BHATTACHARYYA: Bhattacharyya distance, measuring the “overlap” between the two histograms.