Hello.
I have a problem with my copyTo() function. I have a mask and I'm editing that mask using the cv::circle() function.
It works very well the first time but when I use it the second time the image just doesn't change. The mask is working allright though, that's the weird part!
Here's some code:
//init Point erasor
erasor.x = x;
erasor.y = y;
if (isEraserActive) {
vec.push_back(erasor);
circle(result, erasor, 5, GC_BGD, -1); //edit mask
maskGC = true;
}
//debugging to see if x and y point are actually in the vector
if (isEraserActive == false) {
std::ofstream stream;
stream.open("D:/biem.txt");
for (int i = 0; i < vec.size(); i++) {
stream << vec.at(i) << "\n";
}
stream.close();
}
[...]
if (maskGC != true) {
// GrabCut segmentation
cv::grabCut(imgDebayer, // input image
result, // segmentation result
rect,// rectangle containing foreground
bgModel, fgModel, // models
3, // number of iterations
GC_INIT_WITH_RECT); // use rectangle
// Get the pixels marked as likely foreground
cv::compare(result, cv::GC_PR_FGD, result, cv::CMP_EQ);
imgDebayer.copyTo(foreground, result); // bg pixels not copied
imgResult = foreground;
cv::rectangle(imgResult, rect, cv::Scalar(255, 0, 255), 1);
}
else {
//imshow("result", result);
imgDebayer.copyTo(res, result);
imgResult = res;
}
I don't know why it doesn't work after the first time. It has to work right?