Below is my class Function that use cv::threshold. the functionality of it is to check if there any diffreneces of two images 1) it loads the images into cv::Mat 2)find diffrenence 3)apply threshold 4)apply dilate 5) find contours 6) get all contours and store them in a map.
But as soon as it reach to the function “cv::threshold” the cassert throws an error says buffer_size % 2 == 0
BOOL AI::detectDifferences(std::string firstFileName, std::string secondFileName)
{
//MatrixImage is just typedef of cv::Mat
MatrixImage img0 = cv::imread("Assets/Image/popcorn0.jpg", cv::IMREAD_GRAYSCALE);
MatrixImage img1 = cv::imread("Assets/Image/popcorn1.jpg", cv::IMREAD_GRAYSCALE);
MatrixImage destination;
cv::absdiff(img0, img1, destination);
cv::Mat threshold;
//cv::threshold(destination, threshold, 0, 255, cv::THRESH_BINARY | cv::THRESH_OTSU);
cv::threshold(destination, threshold, 0, 255, cv::THRESH_BINARY_INV | cv::THRESH_OTSU);
MatrixImage dilate;
MatrixImage kernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(2, 2), cv::Point(-1, -1));
cv::dilate(threshold, dilate, kernel, cv::Point(-1, -1), -1);
std::vector<std::vector<cv::Point>> contours;
std::vector<cv::Vec4i> hierarchy;
cv::findContours(dilate, contours, hierarchy, cv::RETR_EXTERNAL, cv::CHAIN_APPROX_SIMPLE);
this->mapVecRect.insert(std::pair<std::string, OpenCVVectorRect*>(secondFileName, new OpenCVVectorRect()));
for (auto& i : contours)
{
if (cv::contourArea(i) > 100)
{
cv::Rect rect = cv::boundingRect(i);
mapVecRect[secondFileName]->push_back(rect);
}
}
return TRUE;
}