0

興味のあるブロブの輪郭内でのみROIを指定する簡単な解決策はありますか?

これまでの私の考え:

  1. boundingRectを使用していますが、分析したくないものが多すぎます。
  2. goodFeaturesToTrackを画像全体に適用してから、出力座標をループして、ブロブの輪郭の外側にあるものを削除します

前もって感謝します!

編集

必要なものが見つかりました:cv :: pointPolygonTest()は正しいようですが、実装方法がわかりません…</ p>

ここにいくつかのコードがあります:

// ...
IplImage forground_ipl = result;
IplImage *labelImg = cvCreateImage(forground.size(), IPL_DEPTH_LABEL, 1);

CvBlobs blobs;
bool found = cvb::cvLabel(&forground_ipl, labelImg, blobs);
IplImage *imgOut = cvCreateImage(cvGetSize(&forground_ipl), IPL_DEPTH_8U, 3);

if (found) {
    vb::CvBlob *greaterBlob = blobs[cvb::cvGreaterBlob(blobs)];
    cvb::cvRenderBlob(labelImg, greaterBlob, &forground_ipl, imgOut);
    CvContourPolygon *polygon = cvConvertChainCodesToPolygon(&greaterBlob->contour);
}

「ポリゴン」には、必要な輪郭が含まれています。

goodFeaturesToTrackは次のように実装されます。

- (std::vector<cv::Point2f>)pointsFromGoodFeaturesToTrack:(cv::Mat &)_image
{
    std::vector<cv::Point2f> corners;
    cv::goodFeaturesToTrack(_image,corners, 100, 0.01, 10);
    return corners;
}

次に、コーナーをループして、cv :: pointPolygonTest()で各ポイントをチェックする必要があります。

4

1 に答える 1

3

関心領域にマスクを作成できます。

編集 マスクの作り方:

マスクを作ります。

Mat mask(origImg.size(), CV_8UC1);
mask.setTo(Scalar::all(0));
// here I assume your contour is extracted with findContours, 
// and is stored in a vector<vector<Point>> 
// and that you know which contour is the blob
// if it's not the case, use fillPoly instead of drawContour();
Scalar color(255,255,255); // white. actually, it's monchannel.
drawContours(mask, contours, contourIdx, color );

// fillPoly(Mat& img, const Point** pts, const int* npts, 
//         int ncontours, const Scalar& color)

これで、使用する準備が整いました。しかし、結果を注意深く見てください-特徴抽出器のマスクパラメーターに関するOpenCVのいくつかのバグについて聞いたことがありますが、これに関するものかどうかはわかりません。

// note the mask parameter:

void goodFeaturesToTrack(InputArray image, OutputArray corners, int maxCorners, 
    double qualityLevel, double minDistance, 
    InputArray mask=noArray(), int blockSize=3, 
    bool useHarrisDetector=false, double k=0.04 )

これにより、アプリケーションの速度も向上します。goodFeaturesToTrackはかなりの時間を消費します。小さい画像にのみ適用すると、全体的なゲインが大幅に向上します。

于 2011-12-22T17:32:44.017 に答える