1 | initial version |
It looks like you execute kmeans on the whole image. Take a look at: Interactive foreground extraction using grab cut algortihm
Then you can use the result image as mask for src.copyTo(dst, mask);
and then execute kmeans. This should work, because copied pixels are those wich are unequal zero in mask image. But I didn't tested it.
2 | No.2 Revision |
It looks like you execute kmeans on the whole image. Take a look at: Interactive foreground extraction using grab cut algortihm
Then you can use the result image as mask for src.copyTo(dst, mask);
and then execute kmeans. This should work, because copied pixels are those wich are unequal to zero in mask image. But I didn't tested it.
3 | No.3 Revision |
It looks like you execute kmeans on the whole image. Take a look at: Interactive foreground extraction using grab cut algortihm
Then you can use the result image as mask for src.copyTo(dst, mask);
and then execute kmeans. This should work, because copied pixels are those wich are unequal to zero in mask image. But I didn't tested test it.