终于鼓起勇气看hough变换源码了, 之前自己还瞎写了一个检测椭圆中心的 =_=! 不过还好大致一样
static void
HoughLinesStandard( const Mat& img, float rho, float theta,
int threshold, std::vector<Vec2f>& lines, int linesMax,
double min_theta, double max_theta )
{
int i, j;
float irho = 1 / rho;
CV_Assert( img.type() == CV_8UC1 ); //检测输入的是否为 单通道 8-bit图像
const uchar* image = img.ptr(); //读取img
int step = (int)img.step;
int width = img.cols;
int height = img.rows;
if (max_theta < min_theta ) { //check if max_theta > min_theta
CV_Error( CV_StsBadArg, "max_theta must be greater than min_theta" );
}
int numangle = cvRound((max_theta - min_theta) / theta); //对于angle提供多少个'格子'
int numrho = cvRound(((width + height) * 2 + 1) / rho); //对于 rho 提供多少个'格子'
//至于(width + height) * 2 + 1)我不太理解,数学上最少格子数吧
//theta --Angle resolution of the accumulator in radians.
//rho --Distance resolution of the accumulator in pixels
AutoBuffer<int> _accum((numangle+2) * (numrho+2)); //关于AutoBuffer请看最下面
//