資源簡介
Snake的輪廓線模型繼承了上層知識,而輪廓線與目標輪廓的匹配又結合了底層特征。Snake模型與先檢測邊緣點再將它們連接成邊緣的方法不同,輪廓的連通性及角點均影響能量泛函。因此,Snake模型可以通過優化能量泛函得到一個局部最優的輪廓曲線。

代碼片段和文件信息
#include?“stdafx.h“
#include?“cv.h“
#include?“highgui.h“
#include?
#include?
#include?
#include?
#pragma?comment(lib“highgui.lib“)
#pragma?comment(lib“cv.lib“)?
#pragma?comment(lib“cvaux.lib“)?
#pragma?comment(lib“cxcore.lib“)?
std::vector???InitContour;?
//用于顯示的圖像
IplImage*?temp;??//=?cvCreateImage(cvGetSize(img)?IPL_DEPTH_8U?1);
void?showContent(IplImage?*?img)
{
if(temp==NULL)
temp=?cvCreateImage(cvGetSize(img)?IPL_DEPTH_8U?1);
cvCopyImage(imgtemp);
//在原始圖像上劃線
for?(int?i=0;i {
cvCircle(temp?InitContour[i]?2?cvScalarAll(155));
int?j?=?(i+1)%InitContour.size();
cvLine(?temp??InitContour[i]InitContour[j]??cvScalarAll(100)?1);???????????
}
cvSaveImage(“sef.jpg“temp);
cvShowImage(?“srcImage“?temp?);
}
double?wcvDistance(CvPoint?&pt1CvPoint?&pt2)
{
double?distance?=?sqrt(pow((double)(pt1.x?-?pt2.x)2)+pow((double)(pt1.y?-?pt2.y)2));
return?distance;
}
void?CaculateDiff(std::vector?&srcstd::vector?&diff)
{
int?size?=?src.size();
diff.clear();
diff.reserve(size);
diff.resize(size0.0);
for(int?i=0;i {
int?j?=?(i+1)%size;
diff[i]?=?wcvDistance(src[i]src[j]);
}
}
void?removeNearPoints(std::vector?&srcstd::vector?&dstdouble?max_length)
{
std::vector?result;
result.clear();
std::vector?temp;
temp.clear();
temp?=?src;
std::vector?diff?;
int?removed?=?1;
while(removed!=0)
{
// diff.clear();
result.clear();
removed?=?0;
CaculateDiff(tempdiff);
int?srcsize?=?temp.size();
for(int?i=0;i {
if(diff[i] {
removed++;
continue;
}
result.push_back(temp[i]);
}
temp.clear();
temp?=?result;
}
dst.clear();
dst??=?result;
return?;
}
void?contourInterpolation(std::vector?&srcstd::vector?&dst)
{
std::vector?temp;
std::vector?diff?;
CaculateDiff(srcdiff);
}
void?on_mouse(?int?event?int?x?int?y?int?flags?void*?ptr)
{
if(?event?==?CV_EVENT_LBUTTONDOWN?)
{
InitContour.push_back(cvPoint(xy));
showContent((IplImage?*)ptr);
}
}
//對所有輪廓點進行插值
void?ReGeneralPtArrs(std::vector?&srcstd::vector?&dst)
{
std::vector?temp??=?src;
std::vector?diff?;
for(int?k=0;k<10;k++)
{
int?size?=?temp.size();
CaculateDiff(tempdiff);
std::vector?na;
for?(int?i=0;i {
if(diff[i]<0.5)
continue;
na.push_back(temp[i]);
if(diff[i]>=1.8)
{
int?next?=?(i+1)%size;
CvPoint?ne?=?temp[next];
CvPoint?mid?=?cvPoint((temp[i].x+ne.x)/2(temp[i].y+ne.y)/2);
na.push_back(mid);
}
}
temp.clear();
temp?=?na;
}
dst?=?temp;
}
int?_tmain(int?argc?_TCHAR*?argv[])
{
IplImage?*?srcimage?=?NULL;
if?(?argc?==?2?&&
(srcimage?=
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-10-31?10:02??snake_C++\
?????目錄???????????0??2013-10-31?09:13??snake_C++\Debug\
?????文件?????1442816??2013-10-31?09:13??snake_C++\Debug\Snake_plus.bsc
?????文件??????307287??2013-10-31?09:13??snake_C++\Debug\Snake_plus.exe
?????文件??????436112??2013-10-31?09:13??snake_C++\Debug\Snake_plus.ilk
?????文件??????104481??2013-10-31?09:13??snake_C++\Debug\Snake_plus.obj
?????文件?????5194996??2013-10-31?09:02??snake_C++\Debug\Snake_plus.pch
?????文件??????640000??2013-10-31?09:13??snake_C++\Debug\Snake_plus.pdb
?????文件???????????0??2013-10-31?09:13??snake_C++\Debug\Snake_plus.sbr
?????文件??????148480??2013-10-31?09:21??snake_C++\Debug\vc60.idb
?????文件??????159744??2013-10-31?09:13??snake_C++\Debug\vc60.pdb
?????文件????????4880??2013-10-31?09:13??snake_C++\Snake_plus.cpp
?????文件????????3453??2013-10-31?10:02??snake_C++\Snake_plus.dsp
?????文件?????????545??2013-10-30?17:37??snake_C++\Snake_plus.dsw
?????文件???????41984??2013-10-31?10:02??snake_C++\Snake_plus.ncb
?????文件???????48640??2013-10-31?10:02??snake_C++\Snake_plus.opt
?????文件?????????916??2013-10-31?09:13??snake_C++\Snake_plus.plg
?????文件????????4514??2013-10-30?17:23??snake_C++\Snake_plus.vcproj
?????文件????????1419??2013-10-30?17:23??snake_C++\Snake_plus.vcproj.WENYAOGUANG.Administrator.user
?????文件????????5490??2013-10-30?17:23??snake_C++\Snake_plus.vcxproj
?????文件????????1227??2013-10-30?17:23??snake_C++\Snake_plus.vcxproj.filters
?????文件?????????143??2013-10-30?17:23??snake_C++\Snake_plus.vcxproj.user
?????文件???????20758??2007-01-01?21:29??snake_C++\gvfsnake5_31.BMP
?????文件???????11559??2013-10-31?09:22??snake_C++\sef.jpg
?????文件?????????297??2013-10-30?17:23??snake_C++\stdafx.cpp
?????文件?????????376??2013-10-30?17:23??snake_C++\stdafx.h
- 上一篇:K短路(雙掃描法)C++
- 下一篇:VS2005版MFC備忘錄
評論
共有 條評論