思路: 将彩色图转为BGRA格式,改变A通道(透明度)
int main(int argc, char* argv[])
{
Mat src = imread("logo.png");
//imshow("src", src);
Mat result;
cvtColor(src, result, COLOR_BGR2BGRA);
for (int i = 0; i < src.rows; i++)
{
for (int j = 0; j < src.cols; j++)
{
uchar* pSrc = src.ptr<uchar>(i, j); //获取每一行首地址
uchar* pResult = result.ptr<uchar>(i, j);
if (pSrc[0] > 200 && pSrc[1] > 200 && pSrc[2] > 200)
pResult[3] = 0;
}
}
imwrite("result.png", result);
//imshow("result", result);
waitKey(0);
return 0;
}