资源简介
绝对有用的圆检测 用c语言实现,下载绝对值得,不值得找我,但是必须要安装OPENCV
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
//链表结构
struct param_unit
{
CvPoint center;
int radius;
int accum;
param_unit *next;
};
int pht_circle(IplImage *pImg param_unit** head_circle int* p_accum = NULLint prm_ptnum = 30 int prm_tol = 10 int prm_dist = 10 int prm_accum = 50);
int round(double a);
void main()
{
//载入图像
IplImage *pImg_ori *pImg;
pImg_ori = cvLoadImage(“mt1.bmp“CV_LOAD_IMAGE_COLOR);
pImg = cvCreateImage(cvGetSize(pImg_ori) 8 1);
cvCvtColor(pImg_ori pImg CV_BGR2GRAY);
//计时开始
DWORD time1 = GetTickCount ();
//图像预处理
cvSmooth(pImgpImg3);
double prm_cannythd1prm_cannythd2;
prm_cannythd1 = 60;
prm_cannythd2 = 120;
cvCanny(pImgpImgprm_cannythd1prm_cannythd23);
//PHT圆检测算法
param_unit * head_circle = NULL *cur_circle = NULL *end_circle = NULL;
int maxaccum = 0;
int circle_num = pht_circle(pImg &head_circle &maxaccum);
//计时结束
DWORD time2 = GetTickCount();
//输出结果
double time3 = double(time2 - time1)/1000;
cout<<“elapsed time:“< <<“number of circles: “<
cur_circle = head_circle;
int i = 0;
while(cur_circle)
{
if(cur_circle->accum >= maxaccum)
{
i++;
cvCircle(pImg_ori cur_circle->center cur_circle->radius CV_RGB(02550) 2);
cout<<“circle “<center.x<<““<center.y<<“) r=“<radius< }
cur_circle = cur_circle->next;
}
//删除链表
cur_circle = head_circle;
while(cur_circle)
{
end_circle = cur_circle->next;
delete cur_circle;
cur_circle = end_circle;
}
//显示图像
cvNamedWindow(“OriginImage“);
cvNamedWindow(“B/WImage“);
cvShowImage(“OriginImage“pImg_ori);
cvShowImage(“B/WImage“pImg);
//释放资源
cvWaitKey(0);
cvDestroyWindow(“OriginImage“);
cvDestroyWindow(“B/WImage“);
cvReleaseImage(&pImg_ori);
cvReleaseImage(&pImg);
}
int pht_circle(IplImage *pImg param_unit** head_circle int* p_accumint prm_ptnum int prm_tol int prm_dist int prm_accum)
{
// 参数说明:
// prm_ptnum: 连通域阈值,连通域阈值小于此数则不考虑
// prm_tol: 容忍度,两个参数单元的差异小于此数,则认为表示相同的圆
// prm_dist: 点的距离阈值,随机选取的点须保证它们的两两距离不小于此数
// prm_accum: 累加器阈值,累加器阈值小于此数,则不认为它对应的参数表示圆
//轮廓点的总数
long int pt_num = 0;
CvMemStorage *stor;
CvSeq *cont_first *cont;
//寻找连通域
stor = cvCreateMemStorage(0);
cont_first = cvCreateSeq(CV_SEQ_ELTYPE_POINT sizeof(CvSeq) sizeof(CvPoint) stor);
int cont_num = cvFindContours(pImg stor &cont_first sizeof(CvContour) CV_RETR_LIST CV_link_RUNS cvPoint(00));
cont = cont_first;
//迭代次数
int iteration;
//当前连通域点的个数
int total;
//设置随机种子
srand((unsigned)time(NULL));
//点间距离,为方便计算取 dist = |x1-x2| + |y1-y2|
double cxcycr; //一个参数单元
param_unit *head_unit = NULL *cur_uint *end_unit;
param_unit *cur_circle;
CvPoint *pt1
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6415360 2009-05-23 16:23 MidTerm\References\Lect.VIS_016.Hough_transform.ppt
文件 94916 2009-05-23 19:42 MidTerm\References\基于梯度的随机Hough快速圆检测方法(不错).pdf
文件 273666 2007-05-14 20:53 MidTerm\References\用点Hough变换实现圆检测的方法.kdh
文件 2597376 2009-05-30 15:40 MidTerm\Documents\范东凯 08s053048 一种基于随机点hough变换(PHT)的圆检测方法.ppt
文件 1289728 2009-05-30 16:35 MidTerm\Documents\范东凯(08s053048)Report Of CV MidTerm Project.doc
文件 73942 2008-12-06 00:12 MidTerm\Code\PHT_CircularDetc\0004a.bmp
文件 750054 2009-05-26 12:36 MidTerm\Code\PHT_CircularDetc\cirkelhoughtest.bmp
文件 307554 2009-05-19 16:02 MidTerm\Code\PHT_CircularDetc\mt1.bmp
文件 256662 2009-05-19 16:02 MidTerm\Code\PHT_CircularDetc\mt2.bmp
文件 213126 2009-05-19 16:03 MidTerm\Code\PHT_CircularDetc\mt3.bmp
文件 6961 2009-06-10 11:03 MidTerm\Code\PHT_CircularDetc\PHT_CircularDetc.cpp
文件 4236 2009-05-24 18:17 MidTerm\Code\PHT_CircularDetc\PHT_CircularDetc.dsp
文件 557 2009-05-23 17:50 MidTerm\Code\PHT_CircularDetc\PHT_CircularDetc.dsw
文件 50176 2009-06-24 15:10 MidTerm\Code\PHT_CircularDetc\PHT_CircularDetc.ncb
文件 48640 2009-06-24 15:10 MidTerm\Code\PHT_CircularDetc\PHT_CircularDetc.opt
文件 266 2009-06-10 11:06 MidTerm\Code\PHT_CircularDetc\PHT_CircularDetc.plg
目录 0 2009-09-11 09:25 MidTerm\Code\PHT_CircularDetc
目录 0 2009-09-11 09:25 MidTerm\References
目录 0 2009-09-11 09:25 MidTerm\Documents
目录 0 2009-09-11 09:25 MidTerm\Code
目录 0 2009-09-11 09:25 MidTerm
----------- --------- ---------- ----- ----
12383220 21
- 上一篇:MFC 在线考试系统
- 下一篇:C++实现RSA加密解密算法
评论
共有 条评论