Title image Spring 2019

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.

Use the C++ interface for OpenCV and a C++ compiler, preferably some version of clang++ or g++, even if you are writing code that looks like mostly straight C. The dwarves have all of the necessary tools installed. You can work on a dwarf from your own computer using ssh. To log into fili, for example, use the following.

ssh <your-colby-id>@fili.cs.colby.edu

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


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, as you will be reusing your code from assignment to assignment. A suggested directory layout is as follows.

       |      |    |   |
      bin include src data

Take a look at the makefile tutorial if you want to understand how the compilation process is set up using make. 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 build 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, in the src diretory type make vid, then run ../bin/vid. You will need to plug in a camera to use it on the dwarves.


For each task you can work on either a single image or 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.

    The first required 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. There are colored objects in the lab you can use to test out your program.

    The second required image 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.

    The third required image 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.

    The fourth required image is an example showing both the original and the filtered version of the image.

  5. The final task is to do some image capture and labeling. These images for be useful for several of the later projects. Take the images with a camaera capable of capturing them in RAW mode. If you have a phone or camera with that capability, you are welcome to use it. You may also check out a camera from the instructor.

    1. 1 picture: take a picture of the MacBeth chart in RAW mode. Try to take the picture with uniform illumination on the chart.
    2. 1 picture: take a picture of the MacBest chart with your cell phone. Try to take the picture with uniform illumination on the chart.
    3. 50 pictures: Pick up the set of 5 specific objects in the object box in the lab. Take ten pictures of each object. Use at least three different locations and take at least three pictures in each location. Vary the camera's viewpoint and change the illumination conditions between the two pictures (e.g. cast shadows).
    4. 50 pictures: For each category in [shoe, teacup/mug, pencil, apple, banana], take ten pictures that include an object in that category. Try not to take more than three pictures of the exact same item and vary the viewpoint, object orientation, and illumination conditions.
    5. 100 pictures: your choice, but without any of the items from the first 100 pictures.

    Upload your pictures to the CS365/Course Materials/imageDB-2019 on the Courses volume. Follow the folder convention in place and put your images in subfolders with your user id.


  1. Take more pictures. In particular, take more pictures of the objects or object 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.


For this project, make a short wiki page with your required 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: cs365s19project01


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