影像標籤化的問題 |
尚未結案
|
chtsai1025
一般會員 發表:6 回覆:3 積分:1 註冊:2010-02-24 發送簡訊給我 |
各位前輩 最近再利用影像處理去擷取紅色的目標物 是用YUV來擷取 不過遇到一個問題 就是我將紅色區塊標示標籤 不過像附檔的圖一樣 明明是同一區塊的紅色 卻出現了三個標籤值 請問前輩 這會是哪裡出了問題嗎?? 附上標籤化的程式如下 [code cpp] int Label=1; // 標籤Frame初始化 for(int Row=0;Row } } // 標籤法演算法(3*3) // 尋找方向如下: // →→→ // ↑ ↓ // ←← ↓ for(int Row=1;Row // 周圍如果也是紅色,且有非零的標籤值,就將標籤值給中間的 if((ColorBufOrgn[Row-1][Col-1][2] == 255)&&(ColorBufOrgn_Labeling[Row-1][Col-1] != 0)) {ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row-1][Col-1];} else if((ColorBufOrgn[Row-1][Col][2] == 255)&&(ColorBufOrgn_Labeling[Row-1][Col] != 0)) {ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row-1][Col];} else if((ColorBufOrgn[Row-1][Col 1][2] == 255)&&(ColorBufOrgn_Labeling[Row-1][Col 1] != 0)) {ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row-1][Col 1];} else if((ColorBufOrgn[Row][Col 1][2] == 255)&&(ColorBufOrgn_Labeling[Row][Col 1] != 0)) {ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row][Col 1];} else if((ColorBufOrgn[Row 1][Col 1][2] == 255)&&(ColorBufOrgn_Labeling[Row 1][Col 1] != 0)) {ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row 1][Col 1];} else if((ColorBufOrgn[Row 1][Col][2] == 255)&&(ColorBufOrgn_Labeling[Row 1][Col] != 0)) {ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row 1][Col];} else if((ColorBufOrgn[Row 1][Col-1][2] == 255)&&(ColorBufOrgn_Labeling[Row 1][Col-1] != 0)) {ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row 1][Col-1];} else if((ColorBufOrgn[Row][Col-1][2] == 255)&&(ColorBufOrgn_Labeling[Row][Col-1] != 0)) {ColorBufOrgn_Labeling[Row][Col] = ColorBufOrgn_Labeling[Row][Col-1];} // 唯一能更改標籤的地方 else{ColorBufOrgn_Labeling[Row][Col] = Label; Label ;} } } } //這裡進行再過濾,防止誤判 //透過這個,可以確保一整個區塊的標籤都是同樣的 for(int Row=1;Row for(int Col=1;Col if( (ColorBufOrgn_Labeling[Row-1][Col-1] != 0)&&(ColorBufOrgn_Labeling[Row][Col-1] != 0)&&(ColorBufOrgn_Labeling[Row 1][Col-1] != 0)&& (ColorBufOrgn_Labeling[Row-1][Col ] != 0)&&(ColorBufOrgn_Labeling[Row][Col ] != 0)&&(ColorBufOrgn_Labeling[Row 1][Col ] != 0)&& (ColorBufOrgn_Labeling[Row-1][Col 1] != 0)&&(ColorBufOrgn_Labeling[Row][Col 1] != 0)&&(ColorBufOrgn_Labeling[Row 1][Col 1] != 0)){ // 檢查是不是每個Label都相同,只要有一個不同就會處理 if( (ColorBufOrgn_Labeling[Row-1][Col-1] != ColorBufOrgn_Labeling[Row ][Col-1])|| (ColorBufOrgn_Labeling[Row ][Col-1] != ColorBufOrgn_Labeling[Row 1][Col-1])|| (ColorBufOrgn_Labeling[Row 1][Col-1] != ColorBufOrgn_Labeling[Row-1][Col ])|| (ColorBufOrgn_Labeling[Row-1][Col ] != ColorBufOrgn_Labeling[Row ][Col ])|| (ColorBufOrgn_Labeling[Row ][Col ] != ColorBufOrgn_Labeling[Row 1][Col ])|| (ColorBufOrgn_Labeling[Row 1][Col ] != ColorBufOrgn_Labeling[Row-1][Col 1])|| (ColorBufOrgn_Labeling[Row-1][Col 1] != ColorBufOrgn_Labeling[Row ][Col 1])|| (ColorBufOrgn_Labeling[Row ][Col 1] != ColorBufOrgn_Labeling[Row 1][Col 1]) ){ // 檢查裡面有沒有1 if( (ColorBufOrgn_Labeling[Row-1][Col-1] == 1)||(ColorBufOrgn_Labeling[Row][Col-1] == 1)||(ColorBufOrgn_Labeling[Row 1][Col-1] == 1)|| (ColorBufOrgn_Labeling[Row-1][Col ] == 1)||(ColorBufOrgn_Labeling[Row][Col ] == 1)||(ColorBufOrgn_Labeling[Row 1][Col ] == 1)|| (ColorBufOrgn_Labeling[Row-1][Col 1] == 1)||(ColorBufOrgn_Labeling[Row][Col 1] == 1)||(ColorBufOrgn_Labeling[Row 1][Col 1] == 1)){ ColorBufOrgn_Labeling[Row-1][Col-1] = 1; ColorBufOrgn_Labeling[Row ][Col-1] = 1; ColorBufOrgn_Labeling[Row 1][Col-1] = 1; ColorBufOrgn_Labeling[Row-1][Col ] = 1; ColorBufOrgn_Labeling[Row ][Col ] = 1; ColorBufOrgn_Labeling[Row 1][Col ] = 1; ColorBufOrgn_Labeling[Row-1][Col 1] = 1; ColorBufOrgn_Labeling[Row ][Col 1] = 1; ColorBufOrgn_Labeling[Row 1][Col 1] = 1; } // 檢查有沒有2 else if((ColorBufOrgn_Labeling[Row-1][Col-1] == 2)||(ColorBufOrgn_Labeling[Row][Col-1] == 2)||(ColorBufOrgn_Labeling[Row 1][Col-1] == 2)|| (ColorBufOrgn_Labeling[Row-1][Col ] == 2)||(ColorBufOrgn_Labeling[Row][Col ] == 2)||(ColorBufOrgn_Labeling[Row 1][Col ] == 2)|| (ColorBufOrgn_Labeling[Row-1][Col 1] == 2)||(ColorBufOrgn_Labeling[Row][Col 1] == 2)||(ColorBufOrgn_Labeling[Row 1][Col 1] == 2)){ ColorBufOrgn_Labeling[Row-1][Col-1] = 2; ColorBufOrgn_Labeling[Row ][Col-1] = 2; ColorBufOrgn_Labeling[Row 1][Col-1] = 2; ColorBufOrgn_Labeling[Row-1][Col ] = 2; ColorBufOrgn_Labeling[Row ][Col ] = 2; ColorBufOrgn_Labeling[Row 1][Col ] = 2; ColorBufOrgn_Labeling[Row-1][Col 1] = 2; ColorBufOrgn_Labeling[Row ][Col 1] = 2; ColorBufOrgn_Labeling[Row 1][Col 1] = 2; } // 只要一個區域內有非0非1非2的標籤, 直接判定為3 else /*if((ColorBufOrgn_Labeling[Row-1][Col-1] == 3)||(ColorBufOrgn_Labeling[Row][Col-1] == 3)||(ColorBufOrgn_Labeling[Row 1][Col-1] == 3)|| (ColorBufOrgn_Labeling[Row-1][Col ] == 3)||(ColorBufOrgn_Labeling[Row][Col ] == 3)||(ColorBufOrgn_Labeling[Row 1][Col ] == 3)|| (ColorBufOrgn_Labeling[Row-1][Col 1] == 3)||(ColorBufOrgn_Labeling[Row][Col 1] == 3)||(ColorBufOrgn_Labeling[Row 1][Col 1] == 3))*/{ ColorBufOrgn_Labeling[Row-1][Col-1] = 3; ColorBufOrgn_Labeling[Row ][Col-1] = 3; ColorBufOrgn_Labeling[Row 1][Col-1] = 3; ColorBufOrgn_Labeling[Row-1][Col ] = 3; ColorBufOrgn_Labeling[Row ][Col ] = 3; ColorBufOrgn_Labeling[Row 1][Col ] = 3; ColorBufOrgn_Labeling[Row-1][Col 1] = 3; ColorBufOrgn_Labeling[Row ][Col 1] = 3; ColorBufOrgn_Labeling[Row 1][Col 1] = 3; } } } } } [/code] 謝謝 編輯記錄
chtsai1025 重新編輯於 2011-02-15 23:57:06, 註解 無‧
chtsai1025 重新編輯於 2011-02-16 00:00:51, 註解 無‧ chtsai1025 重新編輯於 2011-02-16 04:34:10, 註解 無‧ |
taishyang
站務副站長 發表:377 回覆:5490 積分:4563 註冊:2002-10-08 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |