OPENCV Chapter III

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.