Ask Your Question

realkill's profile - activity

2020-10-08 12:44:38 -0600 received badge  Popular Question (source)
2018-05-17 13:37:07 -0600 received badge  Famous Question (source)
2017-05-22 23:09:41 -0600 received badge  Notable Question (source)
2017-02-26 06:46:55 -0600 received badge  Nice Question (source)
2017-01-20 13:33:23 -0600 received badge  Famous Question (source)
2017-01-20 06:41:18 -0600 received badge  Popular Question (source)
2016-11-08 06:11:29 -0600 received badge  Notable Question (source)
2016-06-30 14:07:36 -0600 received badge  Popular Question (source)
2015-10-13 22:17:48 -0600 asked a question How to change transparency of an 4 channels image?

Give a alpha degree and set image transparency. I didn't find the API to do this.

2015-10-13 21:26:20 -0600 asked a question How to get pixel format of a Mat()?

I need to detect the pixel format of a cv::Mat() object, BGR or RGB or BGRA or RGBA or YUV or some else.

I know OpenCV use BGR/BGRA by default, but you can use cvtColor to change it, what I need is going to detect the pixel format for any cv::Mat() object.

Thanks a lot.

2015-10-13 20:03:10 -0600 received badge  Student (source)
2015-10-13 04:56:39 -0600 commented question How to overlay an PNG image with alpha channel to another PNG?

Please check the attachment links at the end of this post.

2015-10-13 03:49:14 -0600 received badge  Editor (source)
2015-10-13 03:45:42 -0600 asked a question How to overlay an PNG image with alpha channel to another PNG?

I have two PNG images (overlay.png and underlay.png) both with alpha channel. I tried the addWeight and copyTo API to mask overlay.png to underlay.png, but the result image is not what I want.

overlay.png image description

underlay.png image description

result png i wish image description

This is my test code:

void blend_two_images() {
cv::Mat underlay = cv::imread("/home/underlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat overlay = cv::imread("/home/overlay.png", CV_LOAD_IMAGE_UNCHANGED);
cv::Mat roi = underlay(cv::Rect(0, 0, overlay.cols, overlay.rows));

cv::addWeighted(roi, 0, overlay, 1, 0, roi);
cv::imwrite("/home/result.png", underlay);  }

And this is the original image files: overlay.png underlay.png

How can I get the result I wish? Thanks a lot!

2015-10-12 20:44:55 -0600 commented question PNG transparent channel lost after perspective transformation.

Thanks, I used cv::imread(path, CV_LOAD_IMAGE_UNCHANGED) to resolve this question, thanks a lot.

2015-09-25 00:36:09 -0600 asked a question PNG transparent channel lost after perspective transformation.

I am perspective transform a RGBA PNG image (depth:8, channel: 4, background: transparent), but the transparent background turns into black after transformation. What's wrong with the following code?

I am a new guy to OpenCV, thank you!

void cv_test(void) {

int i, t, ret;
CvPoint2D32f srcQuad[4];
CvPoint2D32f dstQuad[4];
CvMat *warp_matrix;
IplImage *src, *dst;

src = cvLoadImage("c:\\aqxj.png", CV_LOAD_IMAGE_UNCHANGED);
if(!src) {
    fprintf(stderr, "src:%p", src);
    return;
}

dst = cvCreateImage(cvSize(src->width, src->height), 8, 4);
//dst->origin = src->origin;
ret = cvSaveImage("/home/metalwood/s.png", dst);
cvZero(dst);

fprintf(stderr, "dst width:%d, height:%d.\n", dst->width, dst->height);

srcQuad[0].x = 0; /* Top left. */
srcQuad[0].y = 0;
srcQuad[1].x = src->width - 1; /* Top right. */
srcQuad[1].y = 0;
srcQuad[2].x = 0; /* Bottom left. */
srcQuad[2].y = src->height - 1;
srcQuad[3].x = src->width - 1; /* Bottom right. */
srcQuad[3].y = src->height - 1;

dstQuad[0].x = src->width * 0.05;
dstQuad[0].y = src->height * 0.33;
dstQuad[1].x = src->width * 0.9;
dstQuad[1].y = src->height * 0.25;
dstQuad[2].x = src->width * 0.2;
dstQuad[2].y = src->height * 0.7;
dstQuad[3].x = src->width * 0.8;
dstQuad[3].y = src->height * 0.9;

warp_matrix = cvCreateMat(3, 3, CV_32FC1);
cvGetPerspectiveTransform(srcQuad, dstQuad, warp_matrix);
cvWarpPerspective(src, dst, warp_matrix);

cvNamedWindow("Perspective_Warp", 1);
cvShowImage("Perspective_Warp", dst);
cvWaitKey();

//Save disk
ret = cvSaveImage("c:\\save.png", src);
fprintf(stderr, "ret:%d.\n", ret);

cvReleaseImage(&dst);
cvReleaseMat(&warp_matrix);

}