Exercises

In the following exercises, you may need to refer to the CxCore manual that ships with OpenCV or to the OpenCV Wiki on the Web for details of the functions outlined in this chapter.

  1. Find and open …/opencv/cxcore/include/cxtypes.h. Read through and find the many conversion helper functions.

    1. Choose a negative floating-point number. Take its absolute value, round it, and then take its ceiling and floor.

    2. Generate some random numbers.

    3. Create a floating point CvPoint2D32f and convert it to an integer CvPoint.

    4. Convert a CvPoint to a CvPoint2D32f.

  2. This exercise will accustom you to the idea of many functions taking matrix types. Create a two-dimensional matrix with three channels of type byte with data size 100-by-100. Set all the values to 0.

    1. Draw a circle in the matrix using void cvCircle(CvArr* img, CvPoint center, intradius, CvScalar color, int thickness=1, int line_type=8, int shift=0).

    2. Display this image using methods described in Chapter 2.

  3. Create a two-dimensional matrix with three channels of type byte with data size 100-by-100, and set all the values to 0. Use the pointer element access function cvPtr2D to point to the middle ("green") channel. Draw a green rectangle between (20, 5) and (40, 20).

  4. Create a three-channel RGB image of size 100-by-100. Clear it. Use pointer arithmetic to draw a green square between (20, 5) and (40, 20).

  5. Practice using region of interest (ROI). Create a 210-by-210 single-channel byte image and zero it. Within the image, build a pyramid of increasing ...

Get Learning OpenCV now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.