Page 1 of 1

Use opencv mat data to create dispmanx resource

Posted: Sun Sep 09, 2018 7:22 am
by ksharindam
I am a newbie in dispmanx.
I want to load an image with opencv using

Code: Select all

cv::Mat img = cv::imread("test.jpg");
now i want to use write/use to create dispmanx resource.
how i can utilize in this case.

Code: Select all

void *image;
                                &dst_rect );
please explain clearly.

Re: Use opencv mat data to create dispmanx resource

Posted: Tue Sep 11, 2018 3:46 pm
by ksharindam
Finally found it by myself.
Each rows of cv mat data is aligned to 4. But the pitch of image buffer for dispmanx is needed to be multiple of 16. Thats why we can not directly use for the resource buffer.
We have to allocate a data of pitch*height. and copy each row of cv::mat to that allocated memory.

Code: Select all

uchar* cvimg2VCbuffer(int width, int height, int bytesPerLine, uchar* data)
    int pitch = ALIGN_UP(width, 16)*3;
    void* buffer = calloc(1, pitch*height);
    uint8_t *line = (uint8_t*)buffer;
    for (int i = 0;i < height; ++i) {
        memcpy(line, data, bytesPerLine);
        line += pitch;
        data += bytesPerLine;
    return (uchar*)buffer;