OpenCV create Mat from byte array

前端 未结 3 618
刺人心
刺人心 2021-01-04 06:43

In my C++ dll I am creating Mat from byte array:

BYTE * ptrImageData;  //Image data is in this array passed to this function

Mat newImg = Mat(nImageHeight,          


        
3条回答
  •  甜味超标
    2021-01-04 06:58

    Yes, this is one way to create a Mat from a byte array. You just have to be careful that your array contains what you think it does.

    The image is created with some gray shade not the original one.

    So you are getting an image in newImg? What was the pixel format of the original data?

    Maybe you've switched the red and blue channels. The following line will swap the channels:

    cv::cvtColor(newImg,swappedImg,CV_RGB2BGR);
    

提交回复
热议问题