CS448a Assignment 1

Due: Tuesday April 22, 2:45pm

The goal of this assignment is to get you comfortable programming for the N95. You'll be implementing a simple image filter that runs on live viewfinder frames. To do this you'll write a Python script that uses a C++ module. If you don't have an N95 yet and you're enrolled in the class, you should see Andrew or Eddy in Gates 376.

  1. First, you'd like to be able to talk to your phone from your PC or Mac. Go to http://www.nokiausa.com/A4735050 and download and install Nokia PC Suite. After installation, follow the instructions in the Get Connected wizard to get your phone talking to your computer. If you use a USB connection, make sure the phone is in PC Suite mode (a dialog should come up when you plug the USB cable into your phone). Don't update your phone to the latest firmware - it introduces a threading problem with the viewfinder.

  2. We have prepared a virtual machine for N95 development. To run our virtual machine you'll need to download and install VMware Player from http://www.vmware.com/products/player/ for windows or linux, or a trial version of vmware fusion from http://www.vmware.com/products/fusion for mac. Feel free to enter completely false personal information in their registration box. They won't verify the email address you give them. After installation you will probably need to reboot.

  3. Next you need our virtual machine. First make sure you have at least 13 gigabytes free on your hard drive. Download the virtual machine from http://graphics-static.stanford.edu/cs448a/cs448a_n95_vm.zip, and uncompress it somewhere. If downloading it is going to be a problem for you, see Andrew or Eddy for a copy on a DVD. Standard decompression software may not work due to the extreme file size. 7-zip will definitely work (http://www.7-zip.org). You can delete the zip file after decompression to save space.

  4. While the VM image is downloading and/or decompressing, install Python for S60 on your phone. Go to http://sourceforge.net/project/showfiles.php?group_id=154155 and download PythonForS60_1_4_2_3rdEd.SIS and PythonScriptShell_1_4_2_3rdEd.SIS. Once downloaded, double click on them to install them on your phone in the same order (ScriptShell last). Next install the POSIX library for Symbian from http://developer.symbian.com/wiki/download/attachments/1411/pips_s60_1_2_SS.sis?version=1. You'll need this for things like fopen, fprintf, and all your favorite POSIX functions.

  5. Find where you decompressed the VM, and double click on the vmx file to boot the virtual machine inside VMware player or VMware fusion. If a dialog pops up asking if you moved or copied the VM, say that you copied it. If a dialog appears asking if you'd like to take ownership of the VM, say yes. It may take a while to boot. Be patient. Once inside, if the VM desktop is too large, you may wish to go to System->Preferences->Screen Resolution inside the VM and pick a smaller resolution.

    Read Getting_Started.txt on the desktop inside the virtual machine. This document assumes you have bluetooth available. If you don't have bluetooth support on the computer you are using, we have a number of bluetooth dongles we're prepared to lend people for the duration of the course. Getting_Started.txt encourages you to try out the N95 examples provided. CameraApp doesn't currently work, so avoid that one.

    Your working VM should look something like this:

  6. If you don't already know python, read through the tutorial at http://docs.python.org/tut/tut.html. You can run python in the VM by typing 'python' in a shell to type along with the tutorial.

  7. In the ~/Examples/pycamera directory in your VM, read the test_viewfinder_simple.py script. Install ~/pycamera.sisx to your phone (by clicking on it from outside the VM, as described in Getting_Started.txt, or by typing 'gnome-obex-send' pycamera.sisx in the VM home directory). On your phone, open the camera shutter, quit the native camera program, navigate to the applications menu, open python, and run the script. Now run the more complicated test_viewfinder.py, and study the source code to see how it works. test_viewfinder.py uses every camera parameter than can be modified using pycamera.

    Refer to test_pycamera.py for lower level camera usage, and pycamera.py to see how the Viewfinder class used in the test_viewfinder examples is implemented.

  8. There is an example of a python module implemented in C++ in the ~/Examples/python_image directory in your VM. Python modules written in C++ are a good way to write code for the phone that runs quickly, without the hassle of using the full C++ application framework. Run "make clean", "make", and then "make push" to send the example python_image module to your phone. It will arrive as a bluetooth message in your phone inbox. Open the message to install the module. If you get an "update error", go to tools->application manager, and remove any application named "python_image", "imageops", or "Python Example Module". If prompted, install python_image to your phone memory (not the memory card).

    Open python, and run test_python_image.py. Read through python/python_image.py, python/test_python_image.py, and src/python_image.cpp to get a sense of how C++ image processing from python works.

  9. Add a function to python_image.cpp that computes a horizontal gradient filter (or some other equivalently complex image processing operation of your choice). Follow the examples set by the other functions already there. Make extensive use of log calls for debugging, but be aware that these will slow down your module dramatically, and you should turn them off for the final version (check the top of Log.h to do so). To add a function to the module, you need to add a function in three places.

    • Write a pure C++ function in Util.cpp that applies your image processing operation to the input image. Use the other functions there as an example.

    • Write a C++ function in python_image.cpp that calls your pure C++ function, and handles python argument parsing. Again use the other functions there as an example. Also refer to the Python/C api at http://docs.python.org/api/api.html

    • Write a python function in python_image.py that calls your C++ function, converting the image input and/or output into python image objects. Again use the other functions in that file as examples.

  10. Using test_viewfinder_simple.py, and test_python_image.py as a starting point, write a python script that applies your function to every incoming viewfinder frame before it is displayed.

    Every time you change code from python_image, you will need to "make clean", "make", and "make push", to push your python module to the phone.

  11. The source code for this assignment is due at 2:45pm on Tuesday April 22 (just before class starts). Zip up only the source files that you created or modified and email them to Andrew (abadams AT stanford.edu) with the subject line "cs448a assignment 1 submission". The next day, on Wednesday April 23 you will need to demo your script to Andrew, who will hold extra long office hours from 1-4pm. If you can't make his office hours you may also demo to him after class on Tuesday April 22, or Thursday April 24.

F.A.Q.

Send any questions about the assignment to Andrew (abadams AT stanford.edu). Andrew will be overseas while you're working on this, so you may not get immediate replies. You can also ask Eddy for help in Gates 376, as he knows how to program these phones, and mostly set up the VM. Keep in mind he's not an official TA for this course, and is only helping you out of the goodness of his heart, so try not to take up too much of his time.


© 2008 Marc Levoy, Andrew Adams, and Kari Pulli
Last update: April 14, 2008, 10:49:57 PM