How to resize a captured image and convert it into grayscale picture?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Aduka_27
Posts: 27
Joined: Thu Apr 14, 2022 11:00 am

How to resize a captured image and convert it into grayscale picture?

Post by Aduka_27 » Mon May 09, 2022 2:27 pm

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 :D

tepalia02
Posts: 99
Joined: Mon Mar 21, 2022 5:13 am

Re: How to resize a captured image and convert it into grayscale picture?

Post by tepalia02 » Mon May 09, 2022 3:04 pm

These tasks can be handled by python PIL. But I don't know of any such library in micropython.

Aduka_27
Posts: 27
Joined: Thu Apr 14, 2022 11:00 am

Re: How to resize a captured image and convert it into grayscale picture?

Post by Aduka_27 » Mon May 09, 2022 4:00 pm

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 :?:

User avatar
scruss
Posts: 360
Joined: Sat Aug 12, 2017 2:27 pm
Location: Toronto, Canada
Contact:

Re: How to resize a captured image and convert it into grayscale picture?

Post by scruss » Mon May 09, 2022 6:14 pm

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

Aduka_27
Posts: 27
Joined: Thu Apr 14, 2022 11:00 am

Re: How to resize a captured image and convert it into grayscale picture?

Post by Aduka_27 » Tue May 10, 2022 6:44 am

I know for this driver, but seems that it only works with integrated camera or I am wrong? :D

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How to resize a captured image and convert it into grayscale picture?

Post by pythoncoder » Tue May 10, 2022 10:32 am

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.
Peter Hinch
Index to my micropython libraries.

Post Reply