我是相當新的編程,並想知道如何開始實施在C++下面的算法,特徵檢測算法的實現
給定一個二進制圖像,其中與強度255像素顯示邊緣和像素,強度0顯示背景,查找圖像中長度大於n
像素的線段。 t
是一個計數器,顯示沒有找到一行的迭代次數,tm
是退出程序之前允許的最大迭代次數。
- 讓
t=0
。 - 從圖像中隨機取兩個邊緣點,並通過它們找到通過 的線的方程。
- 查找
m
,圖像中其他邊緣點的數量在 行的距離d像素內。 如果
m > n
,轉到步驟5否則(
m ≤ n
),遞增1t
並且如果t < tm
轉到步驟2,和如果t ≥ tm
出口程序。- 繪製線條,並從 圖像中刪除落在距離範圍內的邊緣點,其距離範圍爲
d
。然後,轉到步驟1
基本上,我只是想從圖像中隨機挑選兩個點,找到它們之間的距離,如果該距離太小,我會檢測它們之間的一條線。
如果提供了一小段代碼片段讓我開始,我將不勝感激。 這更像是一個RANSAC參數化線條檢測。如果我完成了,我也會保留這篇文章。
/* Display Routine */
#include "define.h"
ByteImage bimg; //A copy of the image to be viewed
int width, height; //Window dimensions
GLfloat zoomx = 1.0, zoomy = 1.0; //Pixel zoom
int win; //Window index
void resetViewer();
void reshape(int w, int h) {
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
if ((w!=width) || (h!=height)) {
zoomx=(GLfloat)w/(GLfloat)bimg.nc;
zoomy=(GLfloat)h/(GLfloat)bimg.nr;
glPixelZoom(zoomx,zoomy);
}
width=w; height=h;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, (GLdouble)w, 0.0, (GLdouble)h);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void mouse(int button, int state, int x, int y) {
glutPostRedisplay();
if((button == GLUT_LEFT_BUTTON) && (state == GLUT_DOWN) &&
(zoomx==1.0) && (zoomy==1.0)){
printf(" row=%d, col=%d, int=%d.\n", y,x, (int)bimg.image[(bimg.nr-1-y)*bimg.nc+x]);
glutPostRedisplay();
}
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(0, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glDrawPixels((GLsizei)bimg.nc,(GLsizei)bimg.nr, GL_LUMINANCE,GL_UNSIGNED_BYTE, bimg.image);
glutSwapBuffers();
}
檢查OpenCV的例子和功能。可以使用[HoughLines函數](http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html)。 OpenCV還提供了檢測邊緣,[features](http://docs.opencv.org/doc/tutorials/features2d/feature_detection/feature_detection.html)等功能。 – wendelbsilva
我知道houghlines,並houghlinesP檢測線,但我想嘗試實現上述算法。 – TheAmateur