Got error when serialize OccupancyGrid. memoryview assignment: lvalue and rvalue have different structures

I was trying to serialize an OccupancyGrid message. I got the png file and read it with opencv in python. In the header, I set the shape[0] to the width and shape[1] to the height. While calling serialize_cdr, I got this error. memoryview assignment: lvalue and rvalue have different structures I check the code, and the shape of the image array is (500, 620), but in the serialize_cdr function, the variable size is 604. It seems the size is not matching with the data, or maybe I was doing wrong. Is there any test about OccupancyGrid that I can refer to?