If I have mask like
And I have a image( the size is same to the mask) like
I want to hightlight the mask in the image. If I'm in other Language,I just
As you can see, the result image have a transparent red show the mask. I hope implement this in OpenCV. So I write this code
#include <opencv.hpp>
using namespace cv;
using namespace std;
int main() {
Mat srcImg = imread("C:/Users/zyd199012/Desktop/image.jpg");
Mat mask = imread("C:/Users/zyd199012/Desktop/mask.jpg", IMREAD_GRAYSCALE)>200;
for(int i=0;i<srcImg.rows;i++)
for(int j=0;j<srcImg.cols;j++)
if(mask.at<uchar>(i, j)==255)
circle(srcImg, Point(j,i), 3, Scalar(0, 0, 128,128));
imshow("image",srcImg);
waitKey();
return 0;
}
But as you see, I use a alpha value in Scalar
, but it is not a transparent red
.
Maybe this is due to the srcImg
just have 3 channels. I have two question about this
- How to hightlight the mask with a transparent red(even the image just have 3 channels)?
- I have to draw
circle
pixel by pixel to do this thing?