Sub-pixel point positioning

Source: Internet
Author: User

code example:

#include"opencv2/highgui/highgui.hpp"#include"opencv2/imgproc/imgproc.hpp"#include<iostream>#include<stdio.h>#include<stdlib.h>using namespaceCV;using namespacestd;#defineWindow_name "Shi-tomasi Corner point Detection"Mat src, gray;intMaxcornernum =Ten;intMaxtrackbarnum = -;//scroll bar callback functionvoidCornersrefinement (int,void*) {Mat copy=Src.clone (); if(Maxcornernum <=1) {Maxcornernum=1; }    //Corner Point detection parameter PreparationVector<point2f>Corners; DoubleQualitylevel=0.01;//minimum acceptable feature value for corner detection    DoubleMindistance =Ten;//the minimum distance between corner points    intBlockSize =3;//The specified field range when calculating the derivative autocorrelation matrix    DoubleK =0.04;//weight Factor//perform Shi-tomasi corner detection.Goodfeaturestotrack (gray, corners, Maxcornernum, Qualitylevel, Mindistance, Mat (), BlockSize,false, K); //pixel-level corners are plotted with blue circles.     for(inti =0; I < corners.size (); i++) {Circle (copy, Corners[i],4, Scalar (255,0,0),2,8,0); }    ///precise parameter of corner position.Size winsize = Size (5,5); Size Zerozone= Size (-1, -1); Termcriteria Criteria=Termcriteria (Cv_termcrit_eps+Cv_termcrit_iter, +,//maxcount=40        0.001);//epsilon=0.001    ///calculate the position of the corner point after the precisionCornersubpix (gray, corners, winsize, zerozone, criteria); //sub-pixel corner makes the supply red circle draw     for(inti =0; I < corners.size (); i++) {Circle (copy, Corners[i],4, Scalar (255,0,255),2,8,0); //output angular Point coordinatescout <<" ["<< I <<"]  ("<< corners[i].x <<","<< corners[i].y <<")"<<Endl; } cout<<Endl; Imshow (window_name, copy);}intMain () {src= Imread ("church.jpg",1);    Cvtcolor (src, Gray, Color_bgr2gray);    Namedwindow (Window_name, window_autosize); Createtrackbar ("Maximum Corner points", Window_name, &Maxcornernum, Maxtrackbarnum, cornersrefinement);    Imshow (Window_name, SRC); Cornersrefinement (0,0); Waitkey (0); return 0;}

Effect:

Sub-pixel point positioning

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.