2. The following exercise is to help master the matrix type. Create a three-channel two-dimensional matrix, byte type, size 100x100, and set all values to 0.
A. Using void cvcircle in matrices (cvarr* img, cvpoint Center, Intradius, cvscalar color, int thickness=1, int line_type=8, int shift= 0) Draw a circle.
B. Use the method learned in chapter 2nd to display this image.
#include <cv.h>#includeintMain () {Cvmat*mat = Cvcreatemat ( -, -, CV_32FC3); Cvzero (MAT); Cvsize rect= Cvsize ( -, -); Iplimage* image = Cvcreateimage (rect, ipl_depth_8u, 3); Cvpoint Center= Cvpoint ( -, -); intRadius = -; Cvscalar Color= Cvscalar ( -, -, -); Cvcircle (image,center, radius, color,1,8,0); Cvnamedwindow ("Main",1); //Cvnamedwindow ("Main1", 1);Cvshowimage ("Mian", image); //cvshowimage ("Main1", mat);Cvwaitkey (0); Cvreleaseimage (&image); Cvreleasemat (&mat); return 0;}
3. Create a two-dimensional byte-type matrix with three channels, size 100x100, and assign all values to 0. The pointer is pointed to the middle channel ("green") through the function cvptr2d. Draw a green rectangle between (20,5) and (40,20) for the vertices.
#include <cv.h>#includeintMain () {cvsize size= Cvsize ( -, -); Iplimage*image = cvcreateimage (size, ipl_depth_8u,3); Cvzero (image); intleft = -; intright = +; inttop =5; intBottom = -; for(Top < bottom; top++) { for(; left < right; left++) { * (cvptr2d (image, top, left) +1) =255; //The cvptr2d parameters are indicated in the current graph, where coordinates are (top,left) and the position of (+ 1) is green; +2 is red; +0 is blue;} Left= -; } Cvnamedwindow ("Main",1); Cvshowimage ("Main", image); Cvwaitkey (); Cvreleaseimage (&image); Cvdestroywindow ("Main"); return 0;}
OpenCV Chapter III