Qimage to cv::Mat convertion strange behaviour

后端 未结 6 2158
离开以前
离开以前 2020-12-19 16:18

I am trying to create an application where I am trying to integrate opencv and qt.

I managed successfully to convert a cv::Mat to QImage by using the code below:

6条回答
  •  -上瘾入骨i
    2020-12-19 17:16

    opencv images are stepped so that each row begins on a multiple of 32bits, this makes memory access faster. If you are using a 3byte/pixel format then unless you have a width that is 1/3 of a multiple of 4 you will have 'spare' memory at the end of each line

    The safe way is to copy the image data a row at a time. The opencv mat.ptr(row) returns a pointer to the start of each row and the QImage .scanline(row) member does the same

    See How to output this 24 bit image in Qt

    edit: Something like

    for (int i=0;i

提交回复
热议问题