示例**為7邊形,直接改巨集定義即可
#include
#include
#include
#include
#include
#define shape 7 //要檢測的多邊形邊數shape 檢測形狀 3為三角形,4矩形,5為五邊形……
//////
//////
//////
//////
//////
//////
//////
//////
//////
//////
//////
//函式功能:用向量來做cosα=兩向量之積/兩向量模的乘積求兩條線段夾角
//輸入: 線段3個點座標pt1,pt2,pt0,最後乙個引數為公共點
//輸出: 線段夾角,單位為角度
//////
//////
//////
//////
//////
//////
//////
//////
//////
//////
//////
double angle( cvpoint* pt1, cvpoint* pt2, cvpoint* pt0 )
//////
//////
//////
//////
//////
//////
//////
//////
//////
//////
//////
//函式功能:採用多邊形逼近檢測,通過約束條件尋找多邊形
//輸入: img 原影象
// storage 儲存
// minarea,maxarea 檢測多邊形的最小/最大面積
// minangle,maxangle 檢測多邊形邊夾角範圍,單位為角度
//輸出: 多邊形序列
//////
//////
//////
//////
//////
//////
//////
//////
//////
//////
//////
cvseq* findsquares4( iplimage* img, cvmemstorage* storage ,int minarea, int maxarea, int minangle, int maxangle)
}
//這裡的s為直角判定條件 單位為角度
if( s > minangle && s < maxangle )
for( int i = 0; i < shape; i++ )
cvseqpush( squares,(cvpoint*)cvgetseqelem( result, i ));
}
contours = contours->h_next;
} } }
cvreleaseimage( &gray );
cvreleaseimage( &pyr );
cvreleaseimage( &tgray );
cvreleaseimage( &timg );
return squares;
} ///
//////
//////
//////
//////
//////
//////
//////
//////
//////
//////
/////函式功能:畫出所有矩形
//輸入: img 原影象
// squares 多邊形序列
// wndname 視窗名稱
//輸出: 影象中標記多邊形
//////
//////
//////
//////
//////
//////
//////
//////
//////
//////
//////
void drawsquares( iplimage* img, cvseq* squares ,const
char* wndname)
cvpolyline( cpy, &rect, &count, 1, 1, cv_rgb(rand()&255,rand()&255,rand()&255), 1, cv_aa, 0 );//彩色繪製
Opencv繪製多邊形
利用opencv繪製多邊形,主要是因為給的資料是4個點,而繪製矩形的函式cv2.rectangle只傳遞兩個點,即左上和右下。繪製矩形框可以參考這裡 就是利用cv2.fillpoly函式 cv2.fillpoly img,area1,area2,area3 2,255,255 image表示處理的 ...
判斷多邊形重疊 多邊形碰撞檢測
在討論多邊形碰撞檢測之前,我們可以先思考一下遊戲物件怎麼判斷2d圖形有碰撞,靠的是判斷2d圖形在遊戲世界中有接觸,或者有重疊區域,大到包含,小到重疊接觸乙個點。那麼我們就需要精確計算2d圖形在某一幀有重疊部分,或者預判到下一幀有重疊部分,那麼就是碰撞到了。先從簡單的模型來討論碰撞。判斷乙個點是否在多...
opencv 提取多邊形mask區域
最近在專案中需要提取多邊形區域,並傳入到運算元中計算,故記錄一下對多邊形mask區域的提取方法。include using namespace cv int main 關鍵函式為 fillpoly,該函式提供兩種呼叫介面,分別如下 void fillpoly mat img,const point ...