《学习OpenCV》课后习题解答(第四章)(仅供参考)(不断更新)

代码在VS2008下通过,要在附加依赖项中添加:opencv_core220d.lib opencv_highgui220d.lib opencv_imgproc220d.lib。也可以在代码里面添加以下内容:

还要配置好OpenCV环境,设置环境变量啊什么的。具体可见这篇文章:配置

Chapter 4:

1、Th is chapter completes our introduction to basic I/1. O programming and data structures in OpenCV. Th e following exercises build on this knowledge and create useful
utilities for later use.
a. Create a program that (1) reads frames from a video, (2) turns the result to grayscale,and (3) performs Canny edge detection on the image. Display all three stages of processing in three diff erent windows, with each window appropriately named for its function.
b. Display all three stages of processing in one image.
Hint: Create another image of the same height but three times the width as the video frame. Copy the images into this, either by using pointers or (more cleverly) by creating three new image headers that point to the beginning of and to one-third and two-thirds of the way into the imageData. Th en use cvCopy().

c. Write appropriate text labels describing the processing in each of the three slots.

a、Solution:

Test:

注意:在定义IplImage* frame_gray时,一定要记得用cvCreateImage初始化。否则会出现如下错误信息:


b+c、Solution

Test:

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.

Solution:

Test:

a. For the program of exercise 1b, display the mouse coordinates of the individual image when clicking anywhere within the three-image display.

Solution:

Test:

3. Create a program that reads in and displays an image.
a. Allow the user to select a rectangular region in the image by drawing a rectangle with the mouse button held down, and highlight the region when the mouse button is released. Be careful to save an image copy in memory so that your drawing into the image does not destroy the original values there. Th e next mouse click should start the process all over again from the original image.

solution:

Test:

b. In a separate window, use the drawing functions to draw a graph in blue, green,and red for how many pixels of each value were found in the selected box. This is the color histogram of that color region. Th e x-axis should be eight bins that represent pixel values falling within the ranges 0–31, 32–63, . . ., 223–255. The y-axis should be counts of the number of pixels that were found in that bin range. Do this for each color channel, BGR.

solution:

Test:



posted on 2011-08-24 21:48  江南烟雨hust  阅读(886)  评论(0)    收藏  举报

导航