Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

What's the most efficient way to transfer from vector to cv::Mat?

Hello,

I have images being streamed and I get them in my code in an array uint8_t *_buffer. It's a 1280x1024 long array and I'm doing this ugly and ultra slow

    cv::Mat MasterFrame(MasterCamera->data(self)->height,MasterCamera->data(self)->width,CV_8UC3);
    for (int x=0;x<MasterCamera->data(self)->width;x++)
    {
        for (int y=0;y<MasterCamera->data(self)->height;y++)
        {
            MasterFrame.at<cv::Vec3b>(y,x)=cv::Vec3b(MasterCamera->data(self)->data._buffer[y*(MasterCamera->data(self)->width*cameratype)+x*cameratype+2],
                                               MasterCamera->data(self)->data._buffer[y*(MasterCamera->data(self)->width*cameratype)+x*cameratype+1],
                                               MasterCamera->data(self)->data._buffer[y*(MasterCamera->data(self)->width*cameratype)+x*cameratype+0]);      
        }
    }

Where I have previously read height and width (1280 and 1024 respectably), and cameratype=3 as it is an RGB camera.

How could I use cv::Mat more efficiently? Can I use memmove for example? I would need the most efficient and fastest way to transfer/copy from the array to the cv::Mat.

Thanks for the help.

What's the most efficient way to transfer from vector array to cv::Mat?

Hello,

I have images being streamed and I get them in my code in an array uint8_t *_buffer. It's a 1280x1024 long array and I'm doing this ugly and ultra slow

    cv::Mat MasterFrame(MasterCamera->data(self)->height,MasterCamera->data(self)->width,CV_8UC3);
    for (int x=0;x<MasterCamera->data(self)->width;x++)
    {
        for (int y=0;y<MasterCamera->data(self)->height;y++)
        {
            MasterFrame.at<cv::Vec3b>(y,x)=cv::Vec3b(MasterCamera->data(self)->data._buffer[y*(MasterCamera->data(self)->width*cameratype)+x*cameratype+2],
                                               MasterCamera->data(self)->data._buffer[y*(MasterCamera->data(self)->width*cameratype)+x*cameratype+1],
                                               MasterCamera->data(self)->data._buffer[y*(MasterCamera->data(self)->width*cameratype)+x*cameratype+0]);      
        }
    }

Where I have previously read height and width (1280 and 1024 respectably), and cameratype=3 as it is an RGB camera.

How could I use cv::Mat more efficiently? Can I use memmove for example? I would need the most efficient and fastest way to transfer/copy from the array to the cv::Mat.

Thanks for the help.