资源简介
随机生成五百个点作为初始数据,根据RANSAC算法,对初始数据进行拟合,寻找一条最能表示这五百个点的贝赛尔曲线。
代码片段和文件信息
// BezierFitting.cpp : 定义控制台应用程序的入口点。
//
#include “stdafx.h“
#include
#include
#include
#include
#include
#include
#include
using namespace std;
int divs = 50; // 贝塞尔曲线粗细程度
IplImage *image;
int main(int argc char* argv[])
{
CvSize image_size = cvSize(10241024);
image = cvCreateImage(image_sizeIPL_DEPTH_8U3);
cvZero(image);
cvNamedWindow(“imageShow“0);
//随机生成500个点,x值在[3060]y值在[01024]
vector pointList;
srand((unsigned int) time(NULL));
for (int i = 0;i < 500;i++)
{
int x = rand() %30 + 30;
int y = rand() %1024;
CvPoint pt = cvPoint(xy);
pointList.push_back(pt);
}
uchar *data = (uchar *)image->imageData;
int step = image->widthStep / sizeof(uchar);
vector::iterator iter;
for(iter = pointList.begin();iter != pointList.end();iter++)
{
int x = (*iter).x;
int y = (*iter).y;
data[y * step + x * image->nChannels + 0] = 0;
data[y * step + x * image->nChannels + 1] = 255;
data[y * step + x * image->nChannels + 2] = 0;
}
int BestScore = 0;
int iterTimes = 100;//迭代次数
CvPoint controlPoints[4];//最终控制点
CvPoint samplePoints[4];//迭代过程随机验证的控制点
int countInliners = 0; //内联点数
int k = 1;
srand((unsigned int) time(NULL));
int x = 0;
for (int i = 0;i < iterTimes;i++)
{
//随机选取四个点作为控制点
//srand(time(0));
srand(k);
samplePoints[0] = pointList[rand() %20];
srand(k++);
samplePoints[1] = pointList[rand() %230];
srand(k++);
samplePoints[2] = pointList[rand() %230 + 250];
srand(k++);
samplePoints[3] = pointList[rand() %20 + 480];
//判断点到曲线距离,计算内联点数
countInliners = 0;
//vector::iterator iter;
float dis = 0;//点到曲线距离
// x = samplePoints[0].x;
int x0 = samplePoints[0].x;
int y0 = samplePoints[0].y;
int x1 = samplePoints[1].x;
int y1 = samplePoints[1].y;
int x2 = samplePoints[2].x;
int y2 = samplePoints[2].y;
int x3 = samplePoints[3].x;
int y3 = samplePoints[3].y;
for (iter = pointList.begin();iter != pointList.end();iter++)
{
float d = (float)((*iter).y - (*iter).x);
bool Isinliner = false;
for (float t = 0;t < 1;t += (1/divs))
{
float dTemp = (y0 - x0) * pow(t3) + (y1 - x1) * 3 * pow(t2) * (1 - t) + (y2 - x2) * 3 * t * pow((1 - t)2) + (y3 - x3) * pow((1 - t)3);
if (abs(d - dTemp) < 10)
{
Isinliner = true;
break;
}
}
if (Isinliner)
{
countInliners++;
}
}
if (countInliners > 400) //如果内联点数超出预期值,则直接跳出,否则选择最优的
{
*controlPoints = *samplePoints;
/*for (int k = 0;k < 4;k++)
{
controlPoints[k] = samplePoints[k];
}*/
break;
}
if (countInliners > BestScore)
{
BestScore = countInliners;
*controlPoints = *samplePoints;
/*for (int k = 0;k < 4;k++)
{
controlPoints[k] = samplePoints[k];
}*/
}
}
cvShowImage(“imageShow“image);
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-06-09 16:42 BezierFitting\
目录 0 2014-06-05 15:13 BezierFitting\BezierFitting\
文件 3639 2014-06-09 11:30 BezierFitting\BezierFitting\BezierFitting.cpp
文件 5095 2014-06-09 16:42 BezierFitting\BezierFitting\BezierFitting.vcxproj
文件 1454 2014-06-09 16:42 BezierFitting\BezierFitting\BezierFitting.vcxproj.filters
文件 143 2014-06-05 10:49 BezierFitting\BezierFitting\BezierFitting.vcxproj.user
目录 0 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\
文件 406 2014-06-05 15:13 BezierFitting\BezierFitting\Debug\BezierFitting.exe.em
文件 472 2014-06-05 15:13 BezierFitting\BezierFitting\Debug\BezierFitting.exe.em
文件 381 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\BezierFitting.exe.intermediate.manifest
文件 57 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\BezierFitting.lastbuildstate
文件 3089 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\BezierFitting.log
文件 235642 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\BezierFitting.obj
文件 1179648 2014-06-05 15:13 BezierFitting\BezierFitting\Debug\BezierFitting.pch
文件 713 2014-06-05 15:13 BezierFitting\BezierFitting\Debug\BezierFitting.vcxprojResolveAssemblyReference.cache
文件 0 2014-06-05 15:13 BezierFitting\BezierFitting\Debug\BezierFitting.write.1.tlog
文件 216 2014-06-05 15:13 BezierFitting\BezierFitting\Debug\BezierFitting_manifest.rc
文件 21432 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\CL.read.1.tlog
文件 832 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\CL.write.1.tlog
文件 1506 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\cl.command.1.tlog
文件 2 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\li
文件 2 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\li
文件 2 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\li
文件 2 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\li
文件 2 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\li
文件 2 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\li
文件 2 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\li
文件 2 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\li
文件 2 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\li
文件 2 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\li
文件 2 2014-06-09 11:06 BezierFitting\BezierFitting\Debug\li
............此处省略37个文件信息
相关资源
- OPENCV实现ORB/SURF/SIFT + RANSAC 图像自动拼
- RANSAC算法剔除匹配误配点原理
- 论文研究-SIFT和改进的RANSAC算法在图像
- IEEE Transactions Latex Template
- harris+ncc+ransac
- IEEEtransaction模板(latex)
- harris角点
- Programming with Transactions SSD7Programming
- requires \“org.eclipse.emf.transaction 1.4.0
- Ransac算法
- sift、surf、sift+ransac方法影像匹配代码
- IEEE transaction 模板
- RANSAC&OLS
- TCPIP Illustrated Volume 3 - TCP for Transacti
- OpenCV3.0实现SIFT特征提取+RANSAC剔除误匹
- 基于SURF的RANSAC图像细配准
- RANSAC 提纯算法
评论
共有 条评论