我有一個二進制圖像數據,它的大小是1280(寬)x1024(長)。這些數據存儲在一個名爲「CamBuff」的1d數組中,大小爲1280 * 1024。如何在數組中找到特定點?
Image is something like this:| 0 1 2... 1278 1279 |
|1280... 2559 |
|. . . . |
|. . . . 1310719 |
CamBuff: [ 0 1 2.... 1279 1280 ... 1310719]
應該只包含0和1,因爲它是一個二值圖像數據的圖像數據(假設背景= 0,對象= 1)。
圖像中有一個對象,我想找到它的中心位置。
我想是這樣的(找對象的寬度,但可能這是錯誤的):
int width = 1280;
int height = 1024;
int a = 0;
int b = 0;
int c, startrow, startcol, endrow, endcol, objectwidth, objectheight;
int h = 1;
int widthstart = 0;
int colstart = 0;
for (int i=0; i<height; i++)
{
for(int k=0; k<width; k++)
{
a = CamBuff[k];
b = CamBuff[h];
c = b - a;
if(c != 0 && widthstart == 0)
{
startrow = h;
widthstart = 1;
}
if(c != 0 && widthstart == 1)
{
endrow = k;
widthstart = 0;
}
h++;
objectwidth = (endrow - startrow)*0.5;
}
}
如果有變化(從背景到對象或反之亦然),C! = 0
如何找到對象的x和y中心位置?
你如何定義中心?該對象所刻的最小矩形的中心,還是幾何(面積)中心?後者將需要更多的計算。 – owacoder
OpenCV可能會對此有所幫助。 – Borgleader