Create an image in opencv and draw points on the image (Pixel Precision)

Source: Internet
Author: User

No more accurate method was found. opencv included an elliptical image, and its center position was pixel-level. How can we achieve sub-pixel accuracy?

The following uses the method of drawing a small circle to draw a point. The coordinate of a point is the center of the circle. Given a smaller radius, the point can be represented by this small circle.

Circle function:

 void cvCircle( CvArr* img, CvPoint center, int radius, CvScalar color, int thickness=1, int line_type=8, int shift=0 );
Example:
Cvsize SZ; // image size
SZ. Height = 600;
SZ. width = 800;
Image = cvcreateimage (SZ, ipl_depth_8u, 0 );
// Store images
Cvnamedwindow ("image1", cv_window_autosize );
Cvsaveimage ("image1.jpg", image );
// Cvshowimage ("image1", image );

// Draw 30 points on the graph. The iamge_ellipse1 is a matrix of 30*2 and contains the image coordinates of 30 points.

For (INT I = 0; I <30; I ++)
{
Cvpoint centerpoint;
Centerpoint. x = int (cvgetreal2d (image_ellipse1, I, 0 ));
Centerpoint. Y = int (cvgetreal2d (image_ellipse1, I, 1 ));
Cvcircle (image, centerpoint, 3, cv_rgb (0,255, 0), 1, 8, 3 );
}

Cvnamedwindow ("image1", cv_window_autosize );
Cvsaveimage ("image1.jpg", image );
Cvshowimage ("image1", image );
Cvwaitkey (0 );
Cvreleaseimage (& image );
Cvdestroywindow ("image1 ");

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.