Overlaying text on Image

Hello,

I have an OC2640 Arducam that I would like to use for an autonomous camera project. Do any of you know about a simple library that would help me modify the incoming image (in BMP format most likely)? I know we are dealing with very limited ressources so maybe that best way would simply be to add a black bar containing information like camera number and date/time in the lowest part of the image.

Platform is Particle Boron, but I would like to test it first on a simple arduino Uno.

Thank you for your help!

Oh and before someone accuses me of high treason by the fourth commandment, I've been at it (google) for several hours without luck. But at least I learned a bit on how dot matrix and BMP works.

The Uno does not have enough memory to store an image or do image processing.

As @jremington says the Uno does not have enough memory to store an image, however you may still be able to overlay text on the image by using the image file as input and outputting a modified file i.e. processing the image file without holding it or the output file in RAM.

How easy this will be will depend a lot on the actual BMP format. Monochrome images will be easier than colour and if the files use compression then that could complicate things a lot.

Your idea of inserting a black bar containing the text is probably a good one. If you try to write the text onto the actual image without a text background then you will hit the problem that the text colour may match the image pixel colour and so not be visible e.g. writing white text onto a photo that has a large area of white. There are ways that you could avoid having a background bar but with some images you might end up with text that has a rather speckled appearance.

ardly:
As @jremington says the Uno does not have enough memory to store an image

Luckily speed of execution is not a big issue here, I plan to take a picture every 4 hours, but since it is a battery powered/solar application, every seconds of processing still have an impact.

Yes I believe indeed the black bar is the better idea, do you have any idea on how I could elegantly generate something like a 1600x200 black bar (not a problem so far) with text passed in from variables?

I am thinking of hacking into adafruit GFX library but there must be a simpler way...

Thanks

The Uno has 2048 bytes of RAM memory. There is no simple way to use an Uno to do what you want.

The simple approach is to use a processor with sufficient RAM to store an image.

jremington:
The Uno has 2048 bytes of RAM memory. There is no simple way to use an Uno to do what you want.

The simple approach is to use a processor with sufficient RAM to store an image.

I agree the Uno cannot store an image in RAM and things would be much simpler on a machine with more memory. I don't believe that it is impossible to do do it though.

The BMP format seems to store the image in a pixel array that represents the image pixel by pixel. If the image is stored on an SD card I do not see why the Uno cannot read through the image outputting a new file row by row. The relevant section of the pixel array would be replaced by rectangle of mainly black pixels with text pixels in another colour.

The first thing to do would be to take a BMP image of a simple shape e.g. bands of black and white, or some other pattern and attempt to read and decode the file. If you can do that I don;t see why replacement should not be possible even on a Uno - or am I missing something?

From that camera website they list a example
4.3 ArduCAM REVC Examples
This example captures a 320×240 resolution BMP file and stores into SD card memory, then playback captured image on LCD screen if press the shutter button more than 3 seconds.

So indeed you might be able to copy the saved SD file into a new file with modifications.

am I missing something?

Yes. The OP asked for a simple way to modify an image, using an Uno.

It is certainly possible to use an Uno to read in an image, byte by byte, modify appropriate bytes, and write them back out, byte by byte.

If you can think of a simple way of doing all that, which would necessarily include flexible means of specifying, identifying and modifying only the appropriate image bytes, please post some example code for the OP to enjoy.

jremington:
Yes. The OP asked for a simple way to modify an image, using an Uno.

It is certainly possible to use an Uno to read in an image, byte by byte, modify appropriate bytes, and write them back out, byte by byte.

If you can think of a simple way of doing all that, which would necessarily include flexible means of specifying, identifying and modifying only the appropriate image bytes, please post some example code for the OP to enjoy.

He asked for a simple library, but he also said he knew resources were very limited.
I don't think having oodles of memory would actually make things easier. Even with lots of memory you still need to home in and replace the appropriate section of the image. I also suspect that the program does not need to be that flexible, the images could possibly be all in exactly the same format with the same width and height. If the images are compressed that would add a whole new level of complexity.

I found this post which seems to give the bare bones of a solution;

I don't think having oodles of memory would actually make things easier.

It makes the OP's desired operation completely trivial, as you well know from using Paint, Gimp, Photoshop, etc. Images are bit addressable if they are in memory.

And a SD card is flash memory, so writing bit by bit causes wear.

OP, do you need 1600x1200 images? You can set the camera to generate considerably smaller JPGs (e.g. 160x120) which might be more manageable for a lesser Arduino to manipulate.

Sadly 1600x1200 is mandatory...but UNO is not! I stated that the final design would be a particle Boron which has a nordic semiconductor: 256kb of RAM....still not enough you would say. This platform however have an onboard 4mb SPI flash. I would need the datasheet on the chip, but I believe there would be a longevity problem, same as an SD card. All this to say, i'm stuck with 1600x1200 but not the Uno.

Can you tackle the problem another way by say naming the image after the camera and the date and time.
The image itself might then be modifed later on a different device, if that is still required?

ardly:
Can you tackle the problem another way by say naming the image after the camera and the date and time.
The image itself might then be modifed later on a different device, if that is still required?

I tought about this one, or including log files with image because it must contain fields like; camera name, date/time, battery voltage, device temp and Cell signal power (RSSI). I could definitely do that and it would be a far easier option but quite inelegant. So that would be my last option.

Blackfin:
OP, do you need 1600x1200 images? You can set the camera to generate considerably smaller JPGs (e.g. 160x120) which might be more manageable for a lesser Arduino to manipulate.

BlackFin, even if I could do that, what would be the best way to write some text on the image?

Let me first ask if you're sure you can get the images as BMPs?

These are way easier to work with than JPGs.

Yes OV2640 arducam module can output multiple format: Redirecting... . It got an 8mb frame buffer also to help with large file manipulation. Also, see "ArduCAM_Camera_Playback" which stores BMP file on SD Card as precedently refered by Slumpert

You should look at how many write cycles your SD Card or SPI flash supports, it may suit your application.

Your images are 1600 x 1200, will they all be at that resolution and are they using compression or can you avoid it being used?

If it was me I would take a BMP image of a simple black and white pattern. I would then, probably on a PC, try to read and decode the the BMP file. If I was able to "see" the pattern through my code I would then adapt my program to output a new BMP with the camera/date/time in the image against a black background.

Assuming I could then view the image and it looked the way I wanted it I would then repeat the exercise on an Arduino.

You have not said what your programming abilities are. The task would not be simple, but it should not be that difficult.