图像的轮廓跟踪之c++实现(qt + 不调包)(二,这些物联网嵌入式开发高级必会知识点你能答出来几个

37 阅读1分钟
for(i=0;i<=7;i++)
{
    int inde=(startIndex-i)%8;
    int nx = x+directData[inde][0];
    int ny = y+directData[inde][1];
    if(nx>=0 && nx<image->width() && ny>=0 && ny<image->height())
    {
        color = QColor(image->pixel(nx,ny));

        if(abs(color1[0] - color.red())<50)
        {
            return inde;
        }
    }
}
return 9;

}


**单区域轮廓跟踪**:如果已知图像中某区域的一个边界点,并且知道一个从区域外到达此边界点的链码,通过循环调用NextPoint方法,就可以得到区域的完整轮廓信息。主要步骤有以下:


    1)以当前轮廓点位中心在邻域内搜索下一个轮廓点


    2)若得下一个轮廓点的链码并保存在链码表中


    3)若下一个轮廓点为起始点,则轮廓跟踪完成;否则,将当前点移动到下一个轮廓点,并重复1)和2)步骤



//单区域轮廓跟踪 int* MainWindow:: SingleTrack(QImage* image,int x,int y,int n, unsigned char* color) { int directData[8][2]={ {1,0}, {1,-1}, {0,-1}, {-1,-1}, {-1,0}, {-1,1}, {0,1}, {1,1} }; int* track = new int[9999]; int k=0; int nx=x,ny=y; int inde=n; track[0]=x; track[1]=y; do { inde=NextPoint(image,nx,ny,inde, color); if(inde==9) break; track[k+3]=inde; k++; nx+=directData[inde][0]; ny+=directData[inde][1]; } while(nx!=x||ny!=y); track[2]=k; return track; }


**多区域轮廓跟踪**的步骤有以下几个:


    1)搜索起点并确定起始方向链表


    2)单区域轮廓跟踪


    3)绘制区域轮廓


    4)区域填充



//多区域轮廓跟踪 QImage* MainWindow:: TrackSearch(QImage* image) { QImage* newimage = new QImage(image->width(),image->height(),QImage::Format_ARGB32); QImage* newimage1 = new QImage(image->width(),image->height(),QImage::Format_ARGB32); unsigned char* flag = new unsigned char[image->width()image->height()]; int x1,y1,inde; int track; memset(flag,0,sizeof(unsigned char)image->width()image->height()); unsigned char color=new unsigned char[3]; color[0] = 0; color[1] = 0; color[2] = 0; unsigned char fillColor=new unsigned char[3]; fillColor[0]=255; fillColor[1]=255; fillColor[2]=255; QColor color2; int i =0; while(iwidth()*image->height()) {

		y1=i/image->width();
		x1=i%image->width();
        color2 = QColor(image->pixel(x1,y1));
        int r= color2.red();

        if(abs(color2.blue()- color[0])<50)
        {
            y1=i/image->width();
            x1=i%image->width();
            inde = x1>0?0:6;
			track = SingleTrack(image,x1,y1,inde,color);
			newimage = FillArea(image,track,255,50);
		// newimage1 = DrawTrack(  image,track);
        }
       i+=1;
}
return newimage;

}


#### **下载路径**


**收集整理了一份《2024年最新物联网嵌入式全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升的朋友。**
![img](https://p9-xtjj-sign.byteimg.com/tos-cn-i-73owjymdk6/7ef97d2fa614477fabfbfb3d1d902043~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAg5py65Zmo5a2m5Lmg5LmL5b-DQUk=:q75.awebp?rk3s=f64ab15b&x-expires=1771854897&x-signature=fDKnO23pf2HEN3YQ0ZEMgcFMbL0%3D)
![img](https://p9-xtjj-sign.byteimg.com/tos-cn-i-73owjymdk6/c67e06dcde0648b3a4a03ca602b2a97c~tplv-73owjymdk6-jj-mark-v1:0:0:0:0:5o6Y6YeR5oqA5pyv56S-5Yy6IEAg5py65Zmo5a2m5Lmg5LmL5b-DQUk=:q75.awebp?rk3s=f64ab15b&x-expires=1771854897&x-signature=MWo5qnPqT39Fe%2FkNuXac6PZKCB4%3D)

**[如果你需要这些资料,可以戳这里获取](https://gitee.com/vip204888)**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人**

**都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**