如何将Mat数据类型转换为无符号短指针

时间:2015-08-22 12:51:44

标签: c++ opencv image-processing

我有一些用c ++编写的图像处理管道模块,其中unsigned short *用作缓存来存储图像数据以供进一步处理。

我在OpenCV中实现了一些功能,它们使用Mat数据类型来存储图像,这些图像在图像上是独立工作的。我想结合两种功能。

如何将无符号short *数据类型转换为cv :: Mat?

如何将cast cv :: Mat数据类型键入unsigned float *?

任何帮助都会非常明显。

    // snippet of code..

    // bayer_Bilinear function requires image datatype unsigned short

    void bayer_Bilinear( unsigned short *bayer, unsigned short *rgb, int sx , int sy);

    int main( ){

        //----------------------read bayr file---------------------------
            unsigned short imageSize;
            unsigned short * src;
            unsigned short * dst;
            // Open the file
            FILE * file = fopen("bayer.raw","r");

            imageSize=Width * Height; // 16bit/pixel

            // Create a buffer
            src = new unsigned short [imageSize];

            // Read the actual data from the file into the buffer
            fread(src,2,imageSize,file);
            fclose (file);

        dst = new unsigned short [imageSize];

    // sending pixel data to bayer function....
            bayer_Bilinear(src, dst, 8, Height);

    // here i want to convert unsigned float * dst to Mat so i can write using opencv 

        imwrite("got.jpg",dst);
    //-- in the same way i have one function to do gamma correct
    // in this function i want to convert Mat back to unsigned sort for calculation 

    gamma (unsigned short * src, unsigned short *dst, int val);

return 0;
}

1 个答案:

答案 0 :(得分:0)

您可以创建指向已分配数据的cv :: Mat:

 Mat::Mat(Size size, int type, void* data, size_t step=AUTO_STEP)

请参阅the OpenCV doc