Save Binary Image For Frame Differencing

Hi, I’m working on moving object detection with frame differencing + find blobs. I’m thinking about working with binary images and use the erode function to reduce noises.

Is there a way to save a binary image to the disk, or allocate a binary image as the secondary frame buffer?

I’ve tried sensor.BINARY but it doesn’t seem to work with my cam.

RuntimeError: Sensor control failed.
OpenMV v4.5.0; MicroPython v1.20-omv-r8; OPENMV4-STM32H743

Camera sensors don’t output binary images so it’s not a sensor pixformat.

Just do to_bitmap() on the image to make it binrary afterwards.

You can use the sensor.alloc_extra_fb to make a binary frame buffer and then you cand copy images to that and etc.

Also, you can threshold an image via binary() which will produce a black and white image without it being stored in 1-bit per pixel. This allows you to use erode and dilate but then you can also draw on the image with colored lines still.

1 Like

Thanks for the advice. I used binary() on the difference image and I think I got what I want.


I’m now trying to incorporate the background update behavior in, but I don’t think the detection method it uses works for a binary image (I’ve tried different values for TRIGGER_THRESHOLD).

    hist = img.get_histogram()
    diff = hist.get_percentile(0.99).l_value() - hist.get_percentile(0.90).l_value()
    triggered = diff > TRIGGER_THRESHOLD

Do you know what variables should I change for this to work for the new binary image, or Is there another method I could try?

Yeah, for a binary image you should use a different statistics method… I’d recommend looking at what the stats are displayed by the IDE and pick the one which changes the most between a black image and then something in it.