This is a pair assignment. You should create a directory called assignment8 in cs120/assignments for this assignment. All code written for this assignment should be stored in that directory.
$ cd ~/cs120/assignments $ mkdir assignment8$ cd assignment8
There are many uses for an algorithm that can detect faces. For example, some cameras use facial detection to determine where to focus the camera. Facebook uses facial detection to determine whether there is someone to tag in the picture. While fully functioning face detection algorithms can be very complicated, we can perform a simple version of face detection using our PPM images.
Write a function called find_face(template_image_name,
image_name)
, which takes two strings as parameters. The first
string is the name of a template image, while the second string is the
name of a normal image. Both of these images should be in PPM format,
and should be greyscale images. This function should return a tuple,
the location the upper-left corner where the face was found in image_name.
The template image will look like follows:
it is an image that describes what a face looks like.
An example image looks like this:
Which is just a "normal" image.
Your job is to find the location that best matches the template image within the normal image.
You are going to determine this by computing the error between the specified template image and the appropriate pixels in the normal image. You can compute error by computing the mean squared error between the two images. Mean squared error is simply the average of the squared differences between the pixel values. Consider the following example:
Where image 1 is
(0, 1, 2) | (255, 255, 255) |
(255, 255, 255) | (3, 4, 5) |
(6, 7, 8) | (255, 255, 255) | (0, 0, 0) | (255, 255, 255) |
(255, 255, 255) | (9, 10, 11) | (255, 255, 255) | (0, 0, 0) |
(0, 0, 0) | 255, 255, 255) | (0, 0, 0) | (255, 255, 255) |
(255, 255, 255) | (0, 0, 0) | (255, 255, 255) | (0, 0, 0) |
If we were comparing starting at row = 0, col = 0 we are comparing the pixels \((0, 1, 2)\) and \((6, 7, 8)\) the error of the first pixel is: \[p00\_error = \frac{(0 - 6) ^ 2 + (1 - 7) ^ 2 + (2 - 8) ^ 2}{3} = 36\] However comparing the next pixels (\((255, 255, 255)\) and \((255, 255, 255)\)) is: \[p01\_error = \frac{(255 - 255) ^ 2 + (255 - 255) ^ 2 + (255 - 255) ^ 2}{3} = 0\] Which when extended across the total overlap between the images, the mean squared error gives: \[\frac{p00\_error + p01\_error + p10\_error + p11\_error}{4} = 18\]
However, if we were comparing starting at row = 0, col = 1 (\((0, 1, 2)\) and \((255, 255, 255)\)): \[p00\_error = \frac{(0 - 255) ^ 2 + (1 - 255) ^ 2 + (2 - 255) ^ 2}{3} = 64516.666666666664\] and the next comparison (\((255, 255, 255)\) and \((0, 0, 0)\)): \[p01\_error = \frac{(255 - 0) ^ 2 + (255 - 0) ^ 2 + (255 - 0) ^ 2}{3} = 195075\] and the mean squared error between the two: \[\frac{p00\_error + p01\_error + p10\_error + p11\_error}{4} = 95654.75\]
You should assume that there is a face in the image. You will check all possible locations the face can be in. The location that has the face will be the one with the lowest mean squared error.
You may use the PPM module provided in lecture 27 to read in your PPM images. Once you successfully find the face in the first image, you can try your luck with this image:
Lots of classic board games use grids to restrict player movement, think Checkers, Othello, Connect Four, Battleship, or Stratego. The grids in these games are an excellent application of 2D lists in Python. In this assignment you will create a grid-based board game.
Create a Python program that uses the graphics.py and sprite.py modules to recreate a board game. The game can be anything you want, but must do the following:
Splendiferous games will receive extra credit. I will be the arbiter of whether a game is splendiferous .
Your program should include the traditional header, use appropriate variable names, and nicely label all values printed to the terminal. Submission are to be done through inquire.roanoke.edu through the Assignment 8 link. Both partners must submit through inquire!