A description of the Houghlines function angle problem

Source: Internet
Author: User

These are the instructions inside the OPECV reference.

Image must be a 8-bit single-channel graph (can make grayscale, binary, edge, etc.)

Rho: Distance resolution, typically 1

Theta: Angular resolution, typically cv_pi/180

Threshold: Threshold, returns only pixels and lines greater than Threshold

Srn: (guessing) distance scaling

Stn: (guessing) angle scaling

Key notes

Lines:

-P: Distance from line to Origin (upper left corner)

-: Angle

Here the angle of the document is written vertical line~0°,horizontal line~90° But it doesn't say the direction is clockwise Ah!

Which leads me to wonder how the following angle is calculated.

An example using the Hough line detector can is found at opencv_source_code/samples/cpp/houghlines.cpp

You can draw two straight lines in the drawing.

#include"opencv2/highgui/highgui.hpp"#include"opencv2/imgproc/imgproc.hpp"#include<iostream>using namespaceCV;using namespacestd;Static voidHelp () {cout<<"\nthis program demonstrates line finding with the Hough transform.\n"        "usage:\n"        "./houghlines <image_name>, Default is pic1.png\n"<<Endl;}intMainintargcChar**argv) {    Const Char* filename = argc >=2? argv[1] :"D:/vs/cardpic/w.png"; Mat src= Imread (filename,0); if(Src.empty ()) {Help (); cout<<"can not open"<< filename <<Endl; return-1;    } Mat DST, CDST; Canny (SRC, DST, -, $,3);    Cvtcolor (DST, CDST, COLOR_GRAY2BGR); Vector<Vec2f>lines; Houghlines (DST, lines,1, cv_pi/ the, the,0,0 );  for(size_t i =0; I < lines.size (); i++ )    {        floatRho = lines[i][0], theta = lines[i][1]; cout<<i<<":"<<theta* the/cv_pi<<Endl;        Point Pt1, Pt2; DoubleA = cos (theta), B =sin (theta); Doublex0 = A*rho, y0 = b*Rho; pt1.x= Cvround (x0 + +*(-b)); Pt1.y= Cvround (y0 + +*(a)); pt2.x= Cvround (X0- +*(-b)); Pt2.y= Cvround (Y0- +*(a)); Line (CDST, pt1, Pt2, Scalar (0,0,255),1, CV_AA); } imshow ("Source", SRC); Imshow ("detected lines", CDST);    Waitkey (); return 0;}

A description of the Houghlines function angle problem

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.