Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Other than the pixel format (as suggested by @berak) you also need to consider the size of the framebuffer. If you write the raw data, it won't jump to new line at the second row of the image.

One solution would be to resize the image to the framebuffer size, and copy it to the framebuffer. It will give a full-screen image.

ret, frame = cap.read()
frame32 = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
fbframe = cv2.resize(frame32, (1920,1080))
with open('/dev/fb1', 'rb+') as buf:
   buf.write(fbframe)

The second solution is to fill the rest of every line with black pixels:

ret, frame = cap.read()
frame32 = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
lineend=np.zeros(stride-4*frame.cols)
with open('/dev/fb1', 'rb+') as buf:
   for row in frame32:
      buf.write(row)
      buf.write(lineend)

Probably you'll have to combine the two solutions; the first won't work well if the ratio of the image side is not the same as your screen; the second will still be problematic if the image is larger than the framebuffer.

You can get the framebuffer resolution from the /sys/class/graphics/fb0/modes file, and the stride from the /sys/class/graphics/fb0/stride file.

The code above is untested, so it might have bugs and need adjustments.