Page 1 of 1
How to resize a captured image and convert it into grayscale picture?
Posted: Mon May 09, 2022 2:27 pm
by Aduka_27
Hi guys,
Is there any library available for MicroPython that can enable image resize and conversion from colored to grayscale image? I am using ov2640 camera (not the one integrated into esp32-cam board) to capture a photo but all libraries available for Python are not compatible with MicroPython. Any kind of help is welcome

Re: How to resize a captured image and convert it into grayscale picture?
Posted: Mon May 09, 2022 3:04 pm
by tepalia02
These tasks can be handled by python PIL. But I don't know of any such library in micropython.
Re: How to resize a captured image and convert it into grayscale picture?
Posted: Mon May 09, 2022 4:00 pm
by Aduka_27
Yes, I use that library when I work with classic Python, but not feasible with MicroPython. I have to convert and resize the capture image from my camera. Seems that this type of library is still not available for MicroPython

Re: How to resize a captured image and convert it into grayscale picture?
Posted: Mon May 09, 2022 6:14 pm
by scruss
I think you'll have to do the conversion outside MicroPython: very few MicroPython devices have the RAM or processing power to do image conversion.
If you're using
lemariva /
micropython-camera-driver, it can capture at a range of sizes:
Code: Select all
camera.framesize(camera.FRAME_240x240)
# The options are the following:
# FRAME_96X96 FRAME_QQVGA FRAME_QCIF FRAME_HQVGA FRAME_240X240
# FRAME_QVGA FRAME_CIF FRAME_HVGA FRAME_VGA FRAME_SVGA
# FRAME_XGA FRAME_HD FRAME_SXGA FRAME_UXGA FRAME_FHD
# FRAME_P_HD FRAME_P_3MP FRAME_QXGA FRAME_QHD FRAME_WQXGA
# FRAME_P_FHD FRAME_QSXGA
# Check this link for more information: https://bit.ly/2YOzizz
and provide greyscale images too:
Code: Select all
camera.speffect(camera.EFFECT_NONE)
# The options are the following:
# EFFECT_NONE (default) EFFECT_NEG EFFECT_BW EFFECT_RED EFFECT_GREEN EFFECT_BLUE EFFECT_RETRO
But it seems it will always supply a JPEG
Re: How to resize a captured image and convert it into grayscale picture?
Posted: Tue May 10, 2022 6:44 am
by Aduka_27
I know for this driver, but seems that it only works with integrated camera or I am wrong?

Re: How to resize a captured image and convert it into grayscale picture?
Posted: Tue May 10, 2022 10:32 am
by pythoncoder
Image conversions are computationally intensive and are a bit of a tall order on a microcontroller. To put this into context I wrote a routine to scale an 8x8 image to 32x32 using bicubic interpolation. For performance it uses the STM inline Arm Thumb assembler. On a Pyboard D SF2W it achieves a frame rate of 2.5Hz.
This gives a clue as to likely performance of more normally sized images.