我是相当新的编程,并想知道如何开始实施在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