CS 365: Assignment #1

Working with Images and OpenCV

The purpose of this assignment is to familarize you with Unix, C/C++ and the mechanics of creating, manipulating, and writing images and video using the OpenCV package. For this assignment, work by yourself, but feel free to confer with other folks about the mechanics of editing and compiling C/C++ programs.

I would recommend using the C++ interface for OpenCV and a C++ compiler, preferably some version of clang++, even if you are writing code that looks like mostly straight C.

If using a terminal or compiling a C/C++ program is new to you, please check out the Terminal and writing C tutorials.


Setup

Before you start writing code, please take a look at the coding style guide.

You will also want to take a look at the OpenCV tutorials. These include instructions for installing OpenCV on your own computer. You can also use any of the dwarves or macs.

Within your personal directory make a computer vision working directory. It will behoove you to plan ahead when organizing your directory structure. You will be reusing your code from assignment to assignment, building upon it as we go. A suggested directory layout is as follows.

              vision
                 |
       -----------------
       |      |    |   |
      bin include src data

We'll go over how to write a makefile that works with this directory structure. You can also take a look at the makefile tutorial. Download the following tarball and untar it in your vision working directory. It will create the directory structure above and give you two example programs. One example reads in an image and displays it, the other example shows a live video stream on a window.

Sample OpenCV code

The code is set up to work on the dwarves in the Davis 122 lab. To make the program, go into the src directory and type make imod. This should compile the file imgModcpp and create an executable in the bin directory called imod. Typing

../bin/imod ../data/starfuries.png

should start the program running, and it should display the image in a window. Type any key in the window to quit.

If you are running on one of the lab macs, or on your own mac laptop, edit the makefile to uncomment the OSX lines and comment out the Dwarf lines. Then follow the instructions above. If you are running on a Windows machine, you will have to follow the installation and usage instructions on the OpenCV site.

To compile the video capture program, just type make vid, then run ../bin/vid. You will need to plug in a camera to use it on the dwarves.

Tasks

For each task you can work either on a single image or on a video stream.

  1. Figure out how to manipulate the pixel colors of an image or video stream by editing the values of each frame. Start by doing something like increasing the amount of blue in the images.

    Required image one is an example showing an original and a modified image.

  2. Use the OpenCV function threshold to binarize the input image or video. Select some color of interest and try to make that color turn white and the rest of the image turn black. We have colored objects you can use to test out your program.

    Required image two is an example showing both the original image and the thresholded version.

  3. Flip the input image or video horizontally so it acts like a mirror. You can try to do this using an OpenCV function or by manually switching each pixel. Set up your program so the image is flipped or not depending on a keypress by the user. For example, if the user types 'h' then the image should be shown horizontally flipped. If the user types 'h' again, then the image should go back to its original orientation.

    Required image three is an example showing both the original and mirrored versions of the image.

  4. Pick a filter--such as a Gaussian blur or a Laplacian filter--and apply it to your input image or video stream. Make sure the filter is doing what you expect it to do. Your program should allow the user to view either the original or the filtered version of the image.

    Required image four is an example showing both the original and the filtered version of the image.

  5. Capture 100-200 pictures with a camera of your choice. A cell phone is fine. The pictures should follow the guidelines below. Note, if there are any people in your images, you need their permission to use their image for educational and research purposes, preferably in writing.
    1. 1 picture: take a picture of the MacBeth chart with your camera. Try to take the picture with uniform illumination on the chart.
    2. 50 pictures: Pick 5 specific objects. Take ten pictures of each object. Use five different locations and take two pictures in each location from different points of view.
    3. 50 pictures: Pick 5 categories of objects (e.g. car, chair, door, keyboard). For each category, take ten pictures that include an object in that category.
    4. 100 pictures: your choice.

Extensions

  1. Take more pictures. In particular, take more pictures of the objects or object categories, or use more objects or more categories.
  2. Do something more creative with the first set of tasks. Explore other capabilities of OpenCV, such as face detection.
  3. Create a more extensive GUI that lets you apply many different filters or operators to an image or video.

Writeup

For this project, make a short wiki page with your pictures and a description of the process you used to make them (like 1 paragraph at most). If you did any extensions, describe the algorithms and show at least one example for each extension.

Give your wiki page the label: cs365s16project01

Handin

Put a zip file or tar file of your code in your Private Courses handin directory.