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.
Find and open …/opencv/cxcore/include/cxtypes.h. Read through and find the many conversion helper functions.
Choose a negative floating-point number. Take its absolute value, round it, and then take its ceiling and floor.
Generate some random numbers.
Create a floating point
CvPoint2D32fand convert it to an integerCvPoint.Convert a
CvPointto aCvPoint2D32f.
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.
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).Display this image using methods described in Chapter 2.
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
cvPtr2Dto point to the middle ("green") channel. Draw a green rectangle between (20, 5) and (40, 20).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).
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access