
Working with a mobile phone camera in Python
In a previous article, we looked at installing Python for S60 and working in an interactive console; today we will look at the possibilities of working with Python with a mobile phone camera.
There is a special module for working with the camera in Python
Here are the preview window sizes - they can be of any size.
Now we need to take a picture from the camera, for this we add the ability to take a photo to the central button:
here:
first you need to turn off the preview:
then the most important thing is to get a photo from the camera, the camera.take_photo function serves for this, which can take many parameters, such as zoom, flash use, photo size and others. We set only the size of the photo.
That's actually what we added - get a photo from the camera. As a result, we have an object of the Image class that supports basic operations, such as resizing, saving, adding text, drawing simple shapes, and others.
In order to save the resulting image, the save function is used, which accepts a file name and jpeg quality level from 1 to 99.
Below is a small program with the ability to select photo resolution and detailed comments.

I could not write the source code here, since the hubr eats all the spaces at the beginning of the lines, and for python it is critical, so look at the source with comments here
So, let's get started ...
There is a special module for working with the camera in Python
camera
. To get started, we get the photo resolutions supported by the camera:
And if we just write in the console, we get very strange results - that the camera resolution is not more than 2 megapixels. In order to be able to receive photos to the full “power” of the camera, you must initially transfer the application to landscape mode (horizontal).
To do this, before connecting the camera, we need to add a line .
In order to enable the camera preview, you need to get the canvas of our form, for this:
Also, you must first prepare a small function to initialize the preview:
Well, now we can safely launch the previewer:import camera
sizes = camera.image_sizes()
camera.image_sizes
appuifw.app.orientation = 'landscape'
canvas = appuifw.Canvas()
def cam_finder(im):
canvas.blit(im)
camera.start_finder(cam_finder, size=(320,240))
Here are the preview window sizes - they can be of any size.
Now we need to take a picture from the camera, for this we add the ability to take a photo to the central button:
canvas.bind(key_codes.EKeySelect, take_picture)
here:
EKeySelect
- this is the central button of the joystick, take_picture
- this is the function that will be executed when the button is pressed, we will write it: first you need to turn off the preview:
camera.stop_finder()
then the most important thing is to get a photo from the camera, the camera.take_photo function serves for this, which can take many parameters, such as zoom, flash use, photo size and others. We set only the size of the photo.
pic = camera.take_photo(size = (cur_w,cur_h))
That's actually what we added - get a photo from the camera. As a result, we have an object of the Image class that supports basic operations, such as resizing, saving, adding text, drawing simple shapes, and others.
In order to save the resulting image, the save function is used, which accepts a file name and jpeg quality level from 1 to 99.
pic.save(filename, quality=75)
Below is a small program with the ability to select photo resolution and detailed comments.

I could not write the source code here, since the hubr eats all the spaces at the beginning of the lines, and for python it is critical, so look at the source with comments here