Page 1 of 1

importing a *.bmp file

Posted: Sat Feb 10, 2018 2:51 pm
by pcls1026
Hi,
I am using the attached code to import a 16KB, BMP image file, into the Image frame frame buffer on an M7.
It gives a syntax error.
What am I doing wrong?
Jim

Re: importing a *.bmp file

Posted: Sat Feb 10, 2018 4:21 pm
by iabdalkader
Hi, you have to copy the image to the camera's SD card first, the camera can't access files on your PC and then use this path:

Code: Select all

image.Image("/blkandwht.bmp")

Re: importing a *.bmp file

Posted: Wed Feb 14, 2018 6:46 am
by iabdalkader
Hi, please post your replies to this topic, don't create a new topic for each reply.

Use the Image class (note the capital I)

Code: Select all

image.Image("image.bmp")
You can't load a 900+KBs image see the memory limits in the documentation.

Re: importing a *.bmp file

Posted: Wed Feb 14, 2018 1:46 pm
by pcls1026
Hi,
Sorry about all the posts.
My updated program is attached.
I tried to attach a copy of the image file from the PC, but the following error message ensued "Invalid file extension: blkandwht12.bmp."
I tried to attach a copy of the image file from the K drive, but it did not show there. All of the other k drive files that show up using
windows explorer were there.

I changed to a capital I.
The file is 33KB.
The program runs without errors.
However, the SD card image does not load. Rather, a picture is taken by the camera and loaded.

For your info: Using windows explorer on the PC, I can see that the image file has been copied to drive K. I am assuming that drive K is the cam7 usb port because,
when I pull the cam7 usb connector out of the PC,drive K does not appear in windows explorer.

Thanks,
Jim

Re: importing a *.bmp file

Posted: Wed Feb 14, 2018 2:01 pm
by kwagyeman
Hi, the forum may require you to zip up files you post to the website.

Um, so, you put the file on the camera and tried loading it. What's the exact issue again? Sometimes our software has issues loading BMP files. We have much better support for ppm and pgm files which are easier to parse. You can make these via GIMP.

Re: importing a *.bmp file

Posted: Wed Feb 14, 2018 2:22 pm
by iabdalkader
I think you just need to add copy_to_fb=True.

Code: Select all

image.Image("file.bmp", copy_to_fb=True)

Re: importing a *.bmp file

Posted: Thu Mar 01, 2018 7:42 pm
by pcls1026
Hi,
I apologize for opening this post again but I finally got back to work on it.
I attached my latest script file. I tried to attach the .bmp graphics file but it totally screwed up your attach software.
I Made the changes you suggested but it still doesn't run.
When I save an image from the IDE what format should it be in.
Jim

Re: importing a *.bmp file

Posted: Fri Mar 02, 2018 1:35 pm
by pcls1026
Hi,
I discovered several things I never new before:
1.When I take a cam7 picture with VGA and GRAYSCALE, each pixel in the IMG file is an 8 bit word. However, when I use the "save image to pc" command, on the frame buffer image, it is saved in a 3 byte tuple, ie (255,255,255). Notice that each byte in the tuple is the same.
2. Using "img=image.Image("/blkandwht.bmp",copy_to_fb=TRUE)" DOES work properly. However, the image of "/blkandwht.bmp" does not appear in the frame buffer image. Instead, the cam7 takes a picture and shows it in the frame bufffer image.
3. Knowing that img DOES contain "/blkandwht.bmp", I can access the pixel data using img.get_pixel(x,y) and only use the first value in the tuple for the pixel intensity data.
4.So my procedure now is to save my frame buffer file; convert that file to *.png using GIMP; and import the *.png file into my script and use it test my script.

Questions:
1. Is there a way to save the file from the frame buffer to the pc as one 8 bit word per pixel (*.pgm) instead of a three byte tuple?
2. How can the img file imported, be shown as an image in the frame buffer?

Re: importing a *.bmp file

Posted: Fri Mar 02, 2018 2:03 pm
by kwagyeman
Hi, after pulling an image into the frame buffer you have to execute the sensor.flush() method to get the image to show up on the PC.

The PC pulls images from a hidden JPEG frame buffer which old images get copied to after sensor.snapshot() is called. sensor.flush() copies the image to the JPEG buffer too.

As for saving... Yes, please set the save file name to *.pgm.

Note that our file io code has not been overhauled in some time. It's on my list of things to do to make it a lot better. I'm slowly working my way to fixing issues with it. There's just a lot of code that I have to upgrade still in the way.

Basically, back during the first Kickstarter me and Ibrahim added a lot of code to the camera quickly in order to get it sellable and I'm cleaning up that legacy stuff right now. I started on feature expansion however to make sure we had a good product to sell and I'm only now cleaning up the basic things.