Angular point detection in OpenCV sub-pixel

Source: Internet
Author: User

Sub-pixel angular point detection target

In this tutorial we will cover the following:

    • Use the OPENCV function Cornersubpix to find a more precise corner position (not a position of the integer type, but a more precise floating-point type position).
Theoretical code

The code for this tutorial is shown below. The source code can also be downloaded from this link

#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"#include <iostream>#include <stdio.h>#include <stdlib.h>UsingNamespaceCv;UsingNamespaceStd;Global variablesMatSrc,Src_gray;IntMaxcorners=10;IntMaxtrackbar=25;RNGRng(12345);Char*Source_window="Image";Function HeadervoidGoodfeaturestotrack_demo(Int,void*);/** @function Main */IntMain(Intargc,Char**Argv){Load source image and convert it to graySrc=Imread(Argv[1],1);Cvtcolor(Src,Src_gray,Cv_bgr2gray);Create WindowNamedwindow(Source_window,Cv_window_autosize);Create Trackbar to set the number of cornersCreatetrackbar("Max Corners:",Source_window,&Maxcorners,Maxtrackbar,Goodfeaturestotrack_demo);Imshow(Source_window,Src);Goodfeaturestotrack_demo(0,0);Waitkey(0);Return(0);}/*** @function Goodfeaturestotrack_demo.cpp* @brief Apply Shi-tomasi Corner Detector*/voidGoodfeaturestotrack_demo(Int,void*){If(Maxcorners<1){Maxcorners=1;}Parameters for Shi-tomasi algorithmVector<point2f>Corners;DoubleQualitylevel=0.01;DoubleMindistance=10;IntBlockSize=3;boolUseharrisdetector=False;DoubleK=0.04;Copy the source imageMatCopy;Copy=Src.Clone();Apply Corner DetectionGoodfeaturestotrack(Src_gray,Corners,Maxcorners,Qualitylevel,Mindistance,Mat(),BlockSize,Useharrisdetector,K);Draw Corners Detectedcout<<"* * Number of corners detected:"<<Corners.Size()<<Endl;IntR=4;For(IntI=0;I<Corners.Size();I++){Circle(Copy,Corners[I],R,Scalar(Rng.Uniform(0,255),Rng.Uniform(0,255),Rng.Uniform(0,255)),-1,8,0);}Show You gotNamedwindow(Source_window,Cv_window_autosize);Imshow(Source_window,Copy);Set the neeed parameters to find the refined cornersSizeWinsize=Size(5,5);SizeZerozone=Size(-1,-1);TermcriteriaCriteria=Termcriteria(Cv_termcrit_eps+Cv_termcrit_iter,40,0.001);Calculate the refined corner locationsCornersubpix(Src_gray,Corners,Winsize,Zerozone,Criteria);Write them downFor(IntI=0;I<corners. Size (); i++ ) {cout< < "--refined Corner [" <<i<< "] (" <<corners[i . x<< "," <<corners< Span class= "p" >[i]. Y<<<<endl }}             
Interpreting the results

Sub-pixel Corner detection results:

Translators

Shuai Zheng, <[email protected], http://www.cbsr.ia.ac.cn/users/szheng/

from:http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/features2d/trackingmotion/corner_subpixeles/ Corner_subpixeles.html#corner-subpixeles

Angular point detection in OpenCV sub-pixel

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.