Ask Your Question

Rival's profile - activity

2016-02-11 03:20:35 -0600 received badge  Student (source)
2015-11-18 10:14:51 -0600 received badge  Scholar (source)
2015-11-18 10:14:48 -0600 received badge  Supporter (source)
2015-11-18 10:09:16 -0600 commented answer How to obtain Alpha from cv::mat (For wxWidgets::wxImage)

Thanks! I figured this out yesterday before seeing this post, but the internet needed this type of documentation out there anyways, so thank you kind stranger! You've made solving this issue a little easier for anyone else in the future.

2015-11-18 10:07:41 -0600 commented question How to obtain Alpha from cv::mat (For wxWidgets::wxImage)

Well, It appears the output from this function goes into a different object named wxMemoryDC which does not play well with alpha at all, causing me to indirectly assume my code that builds an alpha channel into a new image was broken, when in actuality, that was not the case. Sorry! haha.

2015-11-17 16:36:27 -0600 commented question How to obtain Alpha from cv::mat (For wxWidgets::wxImage)

You're still not getting through to me. You just did exactly as I have already done. But I did get new information out of that such as calling .isContinuous on matrixChannels[3]. The result is true. Is this a problem if it is true?

2015-11-17 15:45:54 -0600 commented question How to obtain Alpha from cv::mat (For wxWidgets::wxImage)

I'm sorry but I don't really follow (Or understand the language.) I tried to re-read that function as much as possible to attempt and understand it, and I can see the case CV_32F: containing an if/else condition with the else case containing code being done on four pointers instead of three like all the others. So I assume that one specifically is dealing with Alpha? Even so, I have no clue really what's going on in this function.

2015-11-17 14:54:45 -0600 received badge  Editor (source)
2015-11-17 12:41:09 -0600 asked a question How to obtain Alpha from cv::mat (For wxWidgets::wxImage)

The following code is not the entire block of code , instead it is the important pieces needed to get my question across. In short: I am asking how to receive the Alpha data from CV::Mat so that I may pass it into a parameter requesting an unsigned char* as Alpha.

in a scaling function, I have a cv::mat(Destination) that is built as so:

cvImage = convertWxToMatWithAlpha(image); //(cvImage is a CV::Mat)
wxData = (byte*) malloc(width * height * 4);
dst = cv::Mat(height, width, CV_8UC4, wxData);

I then re-size the image and save the results in dst which is a CV::Mat

cv::resize(cvImage,dst, cv::Size(width,height), 0, 0, CV_INTER_LINEAR);

I now need to create a wxImage with alpha using the dst(Be sure this is created using convertWxToMatWithAlpha, this is a function that is defined below in one of the answers.) mat. (Thanks pklab !)

    CV_Assert(dst.type() == CV_8UC4); //Throw an error if this is false.
   //Create a matrix which we will store the data in RBG format.
    cv::mat RGBMatrix; 
    //Convert the dst(BGRA) to RBG and store it in RBGMatrix.
    cv::cvtColor( dst,RGBMatrix, CV_BGRA2RGB ); 
    //Create an alpha matrix which we will mix into the RBGMatrix.
    cv::Mat alpha = cv::Mat::zeros(dst.size(),CV_8UC1); 
    int from_to[] = {3,0};
    cv::mixChannels(&dst,1,&alpha,1,from_to,1);
    if(dst.channels() == 4) //if we have four channels then build the wximage.
    {
        image->Create(dst.cols,dst.rows,RGBMatrix.data,alpha.data,false);
        return true;
    }

The constructor for wxImage I am using is specified as:

 wxImage(int width, int height, unsigned char *data, unsigned char *alpha, bool static_data=false)

EDIT: The above is the correct way of doing this. This is no longer a question, but now just a "how to". I hope this helps people in the future on the internet find a solution to this problem. Also take note of the answers given below this question.