Grabcut algorithim - mask mode in Android
Hi ALL, I am using grabcut mask mode algorithm in Android and for some reason iteration through pixels is not working.. Could you please help me. Please see the code below:
for(int i=0; i<maskImg.cols; i++)
for(int j=0; j<maskImg.rows; j++)
{
//if it's red, make it black
if ((int)maskImg.at<cv::Vec3b>(j,i)[0]==0 && (int)maskImg.at<cv::Vec3b>(j,i)[1] == 0 && (int)maskImg.at<cv::Vec3b>(j,i)[2] == 255) {
//the whole mask is black so this is redundant
mask.at<uchar>(j,i)= GC_BGD; //GC_BGD := 0 := black
}
//if it's green, make it white
if ((int)maskImg.at<cv::Vec3b>(j,i)[0]==0 && (int)maskImg.at<cv::Vec3b>(j,i)[1] == 255 && (int)maskImg.at<cv::Vec3b>(j,i)[2] == 0) {
mask.at<uchar>(j,i) = GC_FGD; //GC_FGD:= 1 := white
}
}
I think what you are doing here is quite weird
int)maskImg.at<cv::Vec3b>(j,i)[0]
This should mean that the type of the image pixel is of Vec3b. That is impossible. I am guessing this should be at least made uchar. I think something like this in your if loop should fix it.
if ((int)maskImg.at<uchar>(j,i)[0]==0 && (int)maskImg.at<uchar>(j,i)[1] == 0 && (int)maskImg.at<uchar>(j,i)[2] == 255)
what if it's neither plain green or plain red ?
(also, please explain: "isn't working" ..)