Having error on cv::threshold while using it in a class but on a normal "main entry point" works fine

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);
				return TRUE;

please post exact error msg, thank you.

what is this ?

(post deleted by author)

what now ? please be *** 100% exact*** !
(since neither of it comes from opencv !)
cassert is not used here

also: opencv version / os / compiler ?

but on a normal “main entry point” works fine

how would we know, what you do there ?
explain, why you need classes at all, here
(or typedef’s for cv::Mat, see, this all has some ‘noob going overboard on design’ smell … )

how do we know, the err is from threshold() ?

1 Like

sorry my bad the error was that i am using UTF-16 while the library doesn’t support that!

1 Like