我想跟蹤圖像的所有連接像素。我使用Canny算法進行邊緣檢測,現在需要獲取每個獨特的形狀。跟蹤連接像素
這裏是我的以下
x_axis = marker_i; // x & y co-ordinates of the first detected pixels
y_axis = marker_j;
do
{
for (int i=0;i<8;i++){
if(i==0){x_axis = x_axis-1; y_axis = y_axis-1;} // each iteration checks one
if(i==1){x_axis = x_axis; y_axis = y_axis+1;} // of the 8 adjacent pixels
if(i==2){x_axis = x_axis; y_axis = y_axis+1;} // for a match
if(i==3){x_axis = x_axis+1; y_axis = y_axis-2;}
if(i==4){x_axis = x_axis; y_axis = y_axis+2;}
if(i==5){x_axis = x_axis+1; y_axis = y_axis-2;}
if(i==6){x_axis = x_axis; y_axis = y_axis+1;}
if(i==7){x_axis = x_axis; y_axis = y_axis+1;}
if(x_axis >= 1024 || y_axis >= 1280){ x_axis = 0; y_axis = 0;}
if(ch_rd == red [x_axis][y_axis] && ch_gr == green[x_axis][y_axis]
&& ch_bl == blue[x_axis][y_axis] && pixel_comp[x_axis][y_axis]==0){
map++;
pixel_comp[x_axis][y_axis] = 2; // marks that pixel as read
pixal[num][0] = x_axis;
pixal[num][1] = y_axis;
if (map == 1){ curs[0] = x_axis; curs[1] = y_axis;}
if (map > 1){ div[est] = num; est++;} // if there is more than one detection
num++; // adds remaining to an array div
}
}
if(map==0){
x_axis = pixal[div[prev]][0]; y_axis = pixal[div[prev]][1]; prev++;
// if nothing is detected goes to the last item from array div
}
else{
x_axis = curs[0]; y_axis = curs[1];
}
if(map==0 && prev>=est){ dead_end = 1;}
map = 0;
}
while (dead_end==0);
我用這個在以前的版本我的程序代碼,它會unfortuantely檢測所有的形狀,即使他們沒有連接,而不是一個接一個,現在我一直在嘗試opencv,並想知道是否有一個函數或實現這樣做,甚至可以使用非opencv實現或示例?什麼是這個目的的簡單算法?
Google提取連接的組件。 – krzych 2012-07-06 21:22:46