?? queisser.txt
字號:
Computing the Hough Transform
by Andrew Queisser
Listing 1
for (double theta=0.0, thetaIndex=0;
theta<PI;
thetaIndex++, theta+=PI/numAngleCells)
{
rho = rhoMax + x*cos(theta) + y*sin(theta);
accum[thetaIndex][(int)rho]++;
}
Listing 2
bool LineHoughAccum::DoAddPoint(int x, int y)
{
int a;
int distCenter = m_rowLength/2;
// calculate rho for angle 0
int lastDist = distCenter + ((m_cosTable[0]*x + m_sinTable[0]*y) >> 10);
// loop through angles 1 through 180
for (a=1; a<m_cosTable.size(); a++)
{
int dist = distCenter + ((m_cosTable[a]*x + m_sinTable[a]*y) >> 10);
if (dist >= 0 && dist<m_rowLength)
{
// accumulate cells filling in multiple values for one angle
int stepDir = dist>lastDist ? 1 : -1;
for (int cell=lastDist; cell!=dist; cell+=stepDir)
m_accum[a*m_rowLength + cell] += 1;
}
lastDist = dist;
}
m_numAccumulated += 1;
return true;
}
Listing 3
x -= dx/2; y -= dy/2;
for (thetaIndex=0; thetaIndex<cosTable.size(); thetaIndex++)
{
rho = rhoMax + x*cosTable[thetaIndex] + y*sinTable[thetaIndex];
rho >>= 1; // represents a rhoDivisor of 2
accum[thetaIndex][(int)rho]++;
}
Listing 4
class HoughAccum
{
protected:
int m_dx, m_dy;
vector<int> m_accum;
int m_rowLength;
int m_numAccumulated;
virtual bool DoAddPoint(int x, int y)=0;
public:
HoughAccum();
virtual ~HoughAccum();
virtual void Init(int dx, int dy)=0;
virtual void Clear();
bool AddPoint(int x, int y);
int GetCell(int row, int col) { return m_accum[row*m_rowLength + col]; }
void SetCell(int row, int col, int value) {
m_accum[row*m_rowLength + col] = value; }
void GetAccumSize(int *numRows, int *numCols)
{
*numRows = m_accum.size()/m_rowLength;
*numCols = m_rowLength;
}
int NumAccumulated() { return m_numAccumulated; }
};
class LineHoughAccum
: public HoughAccum
{
protected:
vector<int> m_cosTable;
vector<int> m_sinTable;
virtual bool DoAddPoint(int x, int y);
public:
LineHoughAccum(int numAngleCells);
virtual ~LineHoughAccum();
virtual void Init(int dx, int dy);
};
2
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -