This C++ code uses the OpenCV library to perform image comparison. Each function description is given as follows-
-
The
match_template
function performs template matching. It takes two images as input: the source image and the template image. The function checks if the images are loaded correctly, then it creates a result matrix to store the result of the template matching. ThematchTemplate
function from OpenCV is used to compare the template image with the source image. The result is then normalized to fall within a certain range. The function then finds the location of the best match using theminMaxLoc
function. Depending on the matching method used, the best match could be the maximum or minimum value in the result matrix. The location of the best match is then used to draw a rectangle on the source image and the result matrix. The images are then displayed usingimshow
. -
The
histogram_comparison
function performs histogram comparison. It takes three images as input: the source image and two test images. The images are converted to the HSV color space using thecvtColor
function. Histograms for the base image, the two test images, and the half-down base image are calculated using thecalcHist
function and normalized. The function then compares the histogram of the base image with the other histograms using thecompareHist
function. The results are printed to the console. -
The
image_subtraction
function performs image subtraction. It takes two images and a result matrix as input. The images are converted to the HSV color space and then subtracted from each other using thesubtract
function. The result is then displayed. -
The
histogram_calculation
function calculates the histogram of two images. The images are split into their BGR channels using thesplit
function. Histograms for each channel are calculated using thecalcHist
function and normalized. The function then draws the histograms for each color channel and displays them.
In the main
function, the user is asked to choose a comparison method. Depending on the user's choice, the corresponding function is called to perform the comparison. The images used for comparison are loaded from the file system.