this has little to do with Arduino, it's more a question for a Python forum...
when you do
h, w, *pixels = re.findall(r'[0-9]+', contents)
you use regular expression pattern matching.
h takes the first value from contents
w takes the second value from contents
pixels is the rest
so in your case you use the first two values 117 and 111 and height and width...
then you use h and w to reshape the array
na = np.array(pixels, dtype=np.uint8).reshape((int(h),int(w),3))
==> the size has to make sense, here it does not...
try this to see it:
import re
import numpy
contents = "6,3,117,111,124,124,120,140,142,157,167,172,184,190,194,188,182,185,188,1"
h, w, *pixels = re.findall(r'[0-9]+', contents)
print(h)
print(w)
print(pixels)
na = numpy.array(pixels, dtype=numpy.uint8).reshape((int(h),int(w),1))
print(na)
h will be 6 and w will be 3
pixels will be ['117', '111', '124', '124', '120', '140', '142', '157', '167', '172', '184', '190', '194', '188', '182', '185', '188', '1']
and na will be
[[[117]
[111]
[124]]
[[124]
[120]
[140]]
[[142]
[157]
[167]]
[[172]
[184]
[190]]
[[194]
[188]
[182]]
[[185]
[188]
[ 1]]]
the size is available, just print height and width before spitting out the pixels, this is the struct representing the framebuffer
typedef struct {
uint8_t * buf; /*!< Pointer to the pixel data */
size_t len; /*!< Length of the buffer in bytes */
size_t width; /*!< Width of the buffer in pixels */
size_t height; /*!< Height of the buffer in pixels */
pixformat_t format; /*!< Format of the pixel data */
struct timeval timestamp; /*!< Timestamp since boot of the first DMA buffer of the frame */
} camera_fb_t;