Exercises

  1. This chapter completes our introduction to basic I/O programming and data structures in OpenCV. The following exercises build on this knowledge and create useful utilities for later use.

  2. Create a program that reads in and displays an image. When the user's mouse clicks on the image, read in the corresponding pixel (blue, green, red) values and write those values as text to the screen at the mouse location.

  3. Create a program that reads in and displays an image.

  4. Make an application that reads and displays a video and is controlled by sliders. One slider will control the position within the video from start to end in 10 increments; another binary slider should control pause/unpause. Label both sliders appropriately.

  5. Create your own simple paint program.

  6. Write a program that creates an image, sets it to 0, and then displays it. When the user clicks on a location, he or she can type in a label there. Allow Backspace to edit and provide for an abort key. Hitting Enter should fix the label at the spot it was typed.

  7. Perspective transform.

    1. Write a program that reads in an image and uses the numbers 1–9 on the keypad to control a perspective transformation matrix (refer to our discussion of the cvWarpPerspective() in the Dense Perspective Transform section of Chapter 6). Tapping any number should increment the corresponding cell in the perspective transform matrix; tapping with the Shift key depressed should decrement the number associated with that cell (stopping at 0). Each time a number is changed, display the results in two images: the raw image and the transformed image.

    2. Add functionality to zoom in or out?

    3. Add functionality to rotate the image?

  8. Face fun. Go to the /samples/c/ directory and build the facedetect.c code. Draw a skull image (or find one on the Web) and store it to disk. Modify the facedetect program to load in the image of the skull.

    1. When a face rectangle is detected, draw the skull in that rectangle.

      Hint: cvConvertImage() can convert the size of the image, or you could look up the cvResize function. One may then set the ROI to the rectangle and use cvCopy() to copy the properly resized image there.

    2. Add a slider with 10 settings corresponding to 0.0 to 1.0. Use this slider to alpha blend the skull over the face rectangle using the cvAddWeighted function.

  9. Image stabilization. Go to the /samples/c/ directory and build the lkdemo code (the motion tracking or optical flow code). Create and display a video image in a much larger window image. Move the camera slightly but use the optical flow vectors to display the image in the same place within the larger window. This is a rudimentary image stabilization technique.