For simple black and white images, you can try compare:
cv::Mat img1 = ...
cv::Mat img2 = ...
cv::Mat result = ...
cv::compare(img1 , img2 , result , cv::CMP_EQ );
int percentage = countNonZero(result);
However, for more advanced comparisons, there are different approaches such as extracting matching areas with matchTemplate