Improove image edges softness?

asked 2014-07-19 05:12:34 -0500

I am new to OpenCV and writing an application which overlaps two images. I am fetching frames from high quality video. Fetching frames gives me same smoothness on edges as in original videos. But when I merge it with following code, it looses its smoothness on edges.

Code:

int MixImageByBitwise(Mat tmpImage1, Mat tmpImage2, Mat& mOutput, Mat mMask) { Mat mImage1, mImage2;

resize(tmpImage1, mImage1, mMask.size());
resize(tmpImage2, mImage2, mMask.size());

Mat imgGray, imgMask, imgMaskInv, bgImage, fgImage;

cvtColor(mMask, imgGray, CV_BGR2GRAY);
threshold(imgGray, imgMask, 200, 255, THRESH_BINARY);
bitwise_not(imgMask, imgMaskInv);

bitwise_and(mImage1, mImage1, bgImage, imgMaskInv);
bitwise_and(mImage2, mImage2, fgImage, imgMask);

add(fgImage, bgImage, mOutput);

return 0;

}

Following are the notations I used: 1. mImage1 is background image. 2. mImage2 is foreground image with green transparent background. 3. mMask is exactly same as mImage2 with black background. 4. mOutput is output video.

Fetching mask from mImage2 is not giving proper results, hence I am reading the mask separately from another video which has exact same black background instead of green.

Please let me know on following: 1. How to read alpha channel from video frames? 2. How to make green channel transparent? 3. Why the smoothness on edges drops when we convert images in grayscale & then binary?

Also, let me know, any alternative method for above (if any).

Thanking in advance.

edit retag flag offensive close merge delete