我使用OpenCV進行圖像處理。 我正在尋找一個人體,我想要隔離(段)。OpenCV - DrawContour在偏移量
目前,我能夠找到身體的輪廓,並用多邊形近似輪廓。接下來,我想在cvWatershed中使用該輪廓,以真正隔離身體。
有沒有人知道我如何繪製一個輪廓在中心的偏移量? 爲了說明,請參閱下圖。
藍:我想多邊形有,但我無法找到:輪廓
紅的多邊形逼近。 (在上圖中,我使用的Photoshop ...)
以下是我找到&繪製當前輪廓:
CvContourScanner scanner = cvStartFindContours(mask, pStorage, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
CvSeq* c;
CvSeq* polyContour;
int numCont = 0;
int perimScale = 4;
int contour_approx_level = 6;
while((c = cvFindNextContour(scanner)) != NULL)
{
CvSeq* c_new;
// Polygonal approximation
c_new = cvApproxPoly(c, sizeof(CvContour), pStorage, CV_POLY_APPROX_DP, contour_approx_level, 0);
// Create the new contour
cvSubstituteContour(scanner, c_new);
numCont++;
}
polyContour = cvEndFindContours(&scanner);
int i = 0;
for(i=0, c=polyContour; c!=NULL; c = c->h_next, i++)
{
cvDrawContours(pOutput, c, cvScalar(255,125,0), cvScalar(255,255,0), -1, 2, 8);
}
/* Draw the contour at an offset towards the center here */
// Based upon the answers, I found 2 solutions
編輯:我已經找到了兩種解決方案,基於以下答案:
// 1) Erode -
// void cvErode(const CvArr* A, CvArr* C, IplConvKernel* B=0, int iterations=1);
cvErode(pOutput, pOutput, NULL, 3);
// 2) Another option - draw with a black border and thick pencil:
cvDrawContours(pOutput, c, cvScalarAll(0), cvScalarAll(0), 12, 2, 8);
Off course!很簡單!在我的情況下,背景是黑色的,也可以用線條粗細畫出相同的輪廓。 – Entreco