1 | initial version |
The Mat mask in the main function will be changed after the the function highlight be called.
Add an intermediate variable in the function highlight before mask is changed.
Mat highlight(Mat srcImg, Mat mask) {
if (srcImg.size != mask.size) {
cout << "Your two images tried to highlight have different SIZE.\n";
exit(1);
}
Mat src, temp;
if (mask.channels() != 1)
cvtColor(mask, temp, COLOR_BGR2GRAY);
if (mask.type() != CV_8UC1)
mask.convertTo(temp, CV_8UC1);
threshold(temp, temp, 0, 255, THRESH_BINARY_INV + THRESH_OTSU);
cvtColor(temp, temp, COLOR_GRAY2BGR);
if (srcImg.channels() != 3)
cvtColor(srcImg, src, COLOR_GRAY2BGR);
if (srcImg.type() != CV_8UC3)
srcImg.convertTo(src, CV_8UC3);
dilate(temp- Scalar(0, 0, 255), temp, Mat(), Point(-1, -1), 2);
return src- temp;
}