我正在尝试将分水岭段作为图像保存到 android 中的 sdcard。
代码在 C++ 中尝试过并且工作正常
for (int m = 0; m < images.size(); m++) {
//wshed = wshed*0.5 + imgGray*0.5;
cv::Mat input_bgra;
cv::cvtColor(images[m], input_bgra, CV_BGR2BGRA);
// find all white pixel and set alpha value to zero:
for (int y = 0; y < input_bgra.rows; ++y)
for (int x = 0; x < input_bgra.cols; ++x)
{
cv::Vec4b & pixel = input_bgra.at<cv::Vec4b>(y, x);
// if pixel is black
if (pixel[0] == 0 && pixel[1] == 0 && pixel[2] == 0)
{
// set alpha to zero:
pixel[3] = 0;
}
}
std::ostringstream name;
name << "D:/Sathiya/res/intlayer" << m << ".png";
imwrite(name.str(), input_bgra);
}
不知道如何在android中实现这一点。