惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 迷失天堂

映射模式 vc++入门宝典 图象的渐显/渐隐 关于:error LNK2001:unresolved external symbol F11可以切换浏览器状态 const用法 Spy++的用途 Windows 取得程序运行的路径 VC界面开发,我的一些小知识点 inline函数 在VC中启动另外一个程序(.exe、...)方法 在MFC程序中使用VC Components visual c++键盘快捷键大全 在VC中实现扩展广告条 马骏 解决Windows 程序界面闪烁问题的一些经验 OpenGL FAQ CString 操作指南 新的Win32控件(转自:http://www.lzu.edu.cn/netteach/jiaochen/vc++5.0/vc++5.0/chap6/chap6_2.htm) 好用的快捷键推广
二值图像跟踪曲线程序
迷失天堂 · 2005-05-11 · via 博客园 - 迷失天堂

稍后提交一个完整的测试程序

  1
  2BOOL WINAPI TraceDIB(LPSTR lpDIBBits,LONG lWidth,LONG lHeight,CArray<CPoint,CPoint>* pPoint,CArray<int,int>* pSlope)
  3{
  4// 指向源图像的指针
  5BYTE*lpSrc;
  6
  7// 指向缓存图像的指针
  8BYTE*lpDst;
  9
 10// 指向缓存DIB图像的指针
 11BYTE*lpNewDIBBits;
 12HLOCALhNewDIBBits;
 13
 14// 图像每行的字节数
 15LONG lLineBytes=WIDTHBYTES(lWidth * 8);
 16
 17long i,j;
 18DWORD ii=0;
 19
 20BYTE pixel;
 21bool bFindStartPoint;
 22
 23//是否扫描到一个边界点
 24bool bFindPoint;
 25
 26
 27//起始边界点与当前边界点
 28CPoint StartPoint,CurrentPoint;
 29    //顺时针方向
 30int Direction[8][2]={{1,0},{1,-1},{0,-1},{-1,-1},{-1,0},{-1,1},{0,1},{1,1}};
 31int BeginDirect;
 32
 33hNewDIBBits = LocalAlloc(LHND, lLineBytes * lHeight);
 34if (hNewDIBBits == NULL)
 35{
 36// 分配内存失败
 37return FALSE;
 38}

 39lpNewDIBBits = (BYTE* )LocalLock(hNewDIBBits);
 40// 初始化新分配的内存,设定初始值为255
 41lpDst = (BYTE*)lpNewDIBBits;
 42memset(lpDst, (BYTE)255, lLineBytes * lHeight);
 43
 44
 45//先找到最左下方的边界点
 46bFindStartPoint = false;
 47for (j = 0;j < lHeight && !bFindStartPoint;j++)
 48{
 49for(i = 0;i < lWidth && !bFindStartPoint;i++)
 50{
 51// 指向源图像倒数第j行,第i个象素的指针
 52lpSrc = (BYTE *)lpDIBBits + lLineBytes * j + i;
 53
 54pixel = (BYTE)*lpSrc;
 55
 56if(pixel == 0)
 57{
 58bFindStartPoint = true;
 59
 60StartPoint.y = j;
 61StartPoint.x = i;
 62
 63// 指向目标图像倒数第j行,第i个象素的指针
 64lpDst = (BYTE *)lpNewDIBBits + lLineBytes * j + i;
 65*lpDst = (BYTE)0;
 66}

 67}

 68}

 69
 70//由于起始点是在左下方,故起始扫描沿左上方向
 71BeginDirect = 5;
 72//跟踪边界
 73bFindStartPoint = false;
 74//从初始点开始扫描
 75CurrentPoint.y = StartPoint.y;
 76CurrentPoint.x = StartPoint.x;
 77pPoint->Add(CurrentPoint);
 78// 第一个点的斜率为2 
 79pSlope->Add(int(2));
 80ii++;
 81
 82while(!bFindStartPoint)
 83{
 84bFindPoint = false;
 85while(!bFindPoint)
 86{
 87//沿扫描方向查看一个像素
 88long offset = lLineBytes * ( CurrentPoint.y + Direction[BeginDirect][1])
 89+ (CurrentPoint.x + Direction[BeginDirect][0]);
 90lpSrc = (unsigned char *)lpDIBBits + offset;
 91lpDst = (unsigned char *)lpNewDIBBits + offset;
 92pixel = (unsigned char)*lpSrc;
 93
 94if(pixel == 0&&(unsigned char)*lpDst==255)
 95{
 96bFindPoint = true;
 97CurrentPoint.y = CurrentPoint.y + Direction[BeginDirect][1];
 98CurrentPoint.x = CurrentPoint.x + Direction[BeginDirect][0];
 99pPoint->Add(CurrentPoint);
100
101// s = BeginDirect%4;
102//if(s==3)
103//s = -1;
104                //左上方代表方向的5,以后按照
105pSlope->Add(BeginDirect);//s;
106ii++;
107*lpDst = (unsigned char)0;
108//扫描的方向逆时针旋转两格
109BeginDirect--;
110if(BeginDirect == -1)
111BeginDirect = 7;
112BeginDirect--;
113if(BeginDirect == -1)
114BeginDirect = 7;
115}

116else
117{
118if(pixel!=0)
119{
120//扫描方向顺时针旋转一格
121BeginDirect++;
122if(BeginDirect == 8)
123BeginDirect = 0;
124}

125else{
126// 扫描到以扫过的点
127bFindPoint = true;
128bFindStartPoint = true;
129}

130}

131
132}

133}

134
135ASSERT(pPoint->GetSize()==ii);
136
137// 复制腐蚀后的图像
138memcpy(lpDIBBits, lpNewDIBBits, lWidth * lHeight);
139
140// 释放内存
141LocalUnlock(hNewDIBBits);
142LocalFree(hNewDIBBits);
143
144// 返回
145return TRUE;
146}

147
148