附件里的图像是预处理后的焊缝图像,我想找出中间断点的位置坐标。但不知道怎么做程序。请教
解决方案 »
- 编译时改成requireAdministrator后,就会带盾牌了
- 如何在控制台程序中使用CCriticalSection类?
- 图片浏览器设计 listview 虚列表 自绘缩略图函数该何时何地被调用
- 用socket怎样按十六进制接收数据?谢谢
- 求一个自绘控件的思路
- 我在将一个C文件改为C++时碰到下列错误,怎么解决?
- !!!!如何将已有的程序转变为dll文件,
- 请问:用VC做过串口通讯用到什么类,究竟是怎样一个结构?
- 稍后加到 80 分:从一个程序启动另一个程序的问题,见内----尚未解决
- CPropertySheet的问题
- vc如何新建一个Dialog并点击按钮弹出窗口
- ListBox控件的使用问题??
这是我们上一届同学做的程序 对接接头焊缝检测,这只是一部分。
BOOL SearchForVersus(LPSTR lpDIBBits, LONG lWidth, LONG lHeight,int a[],Point p[])
{
// 指向源图像的指针
LPSTR lpSrc;
// 指向缓存图像的指针
LPSTR lpDst;
// 图像每行的字节数
LONG lLineBytes;
//循环变量
long i;
long j;
int k;
//像素值
unsigned char pixel;
//八个方向和起始扫描方向
int Direction[8][2]={{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1}};
int BeginDirect;
//起始边界点与当前边界点
Point StartPoint,CurrentPoint,lPoint,rPoint,EndPoint;
//是否找到起始点
bool bFindStartPoint;
bool bFindEndPoint;
//是否扫描到一个边界点
bool bFindPoint;
//是否扫描到断点
bool bFindBreakPoint;
//是否扫描到最后
bool end;
POINTINFO *PointInfo,*PointInfo1;
PointInfo=new POINTINFO[lWidth+100];
PointInfo1=new POINTINFO[lWidth+100];
//初始化结构数组
for(i=0;i<lWidth+100;i++)
{
PointInfo[i].Mark=FALSE;
}
for(i=0;i<lWidth+100;i++)
{
PointInfo1[i].Mark=FALSE;
}
// 计算图像每行的字节数
lLineBytes = WIDTHBYTES(lWidth * 8);
//先找到最左方的一起点
bFindStartPoint = FALSE;
//每列
for(i =1;i < lWidth-1 && !bFindStartPoint; i++)
{
//每行
for (j = 1;j < lHeight-1 && !bFindStartPoint;j++)
{
// 指向源图像倒数第j行,第i个象素的指针
lpSrc = (char *)lpDIBBits + lLineBytes * j + i;
//取得当前指针处的像素值,注意要转换为unsigned char型
pixel = (unsigned char)*lpSrc;
if(pixel == 0 || pixel == 1)
{
bFindStartPoint = TRUE;
StartPoint.Height = j;
StartPoint.Width = i;
*lpSrc=1;
}
}
}
if(bFindStartPoint==FALSE)
return FALSE;
BeginDirect = 1;
//从初始点开始扫描
CurrentPoint.Height = StartPoint.Height;
CurrentPoint.Width = StartPoint.Width;
PointInfo[0].Mark=TRUE;
PointInfo[0].Height=StartPoint.Height;
PointInfo[0].Width=StartPoint.Width;
end=FALSE;
i=0;
while(!end && i<=lWidth+100)
{
bFindPoint = FALSE;
while(!bFindPoint)
{
//沿扫描方向查看一个像素
lpSrc = (char *)lpDIBBits + lLineBytes * (CurrentPoint.Height + Direction[BeginDirect][1])
+ (CurrentPoint.Width + Direction[BeginDirect][0]);
pixel = (unsigned char)*lpSrc;
if(pixel == 0 || pixel == 1)
{
PointInfo[i+1].Mark=TRUE;
PointInfo[i+1].Height=CurrentPoint.Height+Direction[BeginDirect][1];
PointInfo[i+1].Width=CurrentPoint.Width+Direction[BeginDirect][0];
*lpSrc=1;
CurrentPoint.Height+=Direction[BeginDirect][1];
CurrentPoint.Width+=Direction[BeginDirect][0];
i++;
BeginDirect=1;
bFindPoint=TRUE;
}
else
{
BeginDirect++;
if(BeginDirect==4)//可能是断点,也可能是端点
{//bFindPoint=TRUE;end=TRUE;
if(i<50)
{
bFindBreakPoint=FALSE;
for(j=1;j<20 && !bFindBreakPoint && CurrentPoint.Width+j<lWidth;j++)
{
for(k=0;k<3 && !bFindBreakPoint;k++)//&& CurrentPoint.Height+k<lHeight
{
lpSrc=(char *)lpDIBBits+lLineBytes*(CurrentPoint.Height-k)+CurrentPoint.Width+j;
pixel=(unsigned char) *lpSrc;
if(pixel == 0 || pixel == 1) //则为断点
{
PointInfo[i+1].Mark=TRUE;
PointInfo[i+1].Height=CurrentPoint.Height-k;
PointInfo[i+1].Width=CurrentPoint.Width+j;
*lpSrc=1;
CurrentPoint.Height-=k;
CurrentPoint.Width+=j;
i++;
BeginDirect=1;
bFindPoint=TRUE;
bFindBreakPoint=TRUE;
break;
}
}
}
请教各位:
1.我不明白为什么总用if(pixel == 0 || pixel == 1) ,我觉得应该是if(pixel == 0 )或用if(pixel == 1),而不是在同一个判据下。
2。不知道上面程序检测断点的是怎么做的?
谢谢!