到目前为止,我已经设法使用蒙版并从第一个获得第二个图像。但我想要的是第二个图像中的黑色区域是透明的(即我试图获得的输出是第三个图像)。下面是目前的代码。请在这方面给我建议。获取蒙面区域是否透明?
编辑:第三个是从Photoshop
//imwrite parameters
compression_params.push_back(CV_IMWRITE_JPEG_QUALITY);
compression_params.push_back(100);
//reading image to be masked
image = imread(main_img, -1);
//CV_LOAD_IMAGE_COLOR
namedWindow("output", WINDOW_NORMAL);
//imshow("output", image);
//Creating mask image with same size as original image
Mat mask(image.rows, image.cols, CV_8UC1, Scalar(0));
// Create Polygon from vertices
ROI_Vertices.push_back(Point2f(float(3112),float(58)));
ROI_Vertices.push_back(Point2f(float(3515),float(58)));
ROI_Vertices.push_back(Point2f(float(3515),float(1332)));
ROI_Vertices.push_back(Point2f(float(3112),float(958)));
approxPolyDP(ROI_Vertices, ROI_Poly, 1, true);
// Fill polygon white
fillConvexPoly(mask, &ROI_Poly[0] , ROI_Poly.size(), 255, 8, 0);
//imshow("output", mask);
// Create new image for result storage
imageDest = cvCreateMat(image.rows, image.cols, CV_8UC4);
// Cut out ROI and store it in imageDest
image.copyTo(imageDest, mask);
imwrite("masked.jpeg", imageDest, compression_params);
imshow("output", imageDest);
cvWaitKey(0);
您可以[混合](http://docs.opencv.org/doc/tutorials/core/adding_images/adding_images.html)在OpenCV中和使用权重两个图像,以使它透明。 – GPPK 2015-02-10 07:53:07
@GPPK感谢您的回复。是。为此,我必须首先有一个透明的图像。在这里,我想要的是从第一个获得像第三个图像。混合可能吗?如果是的话,请你指出正确的方向。 – 2015-02-10 08:00:34