gpt4 book ai didi

OpenCV C++/Obj-C : goodFeaturesToTrack inside specific blob

转载 作者:行者123 更新时间:2023-12-02 16:57:30 33 4
gpt4 key购买 nike

是否有一种快速的解决方案可以仅在我感兴趣的 blob 的轮廓内指定 ROI?

到目前为止我的想法:

  • 使用boundingRect,但它包含太多我不想分析的东西。
  • 将 goodFeaturesToTrack 应用于整个图像,然后循环输出坐标以消除我的 blobs 轮廓之外的一次

  • 提前致谢!

    编辑

    我找到了我需要的东西: cv::pointPolygonTest() 似乎是正确的,但我不确定如何实现它......

    这是一些代码:
    // ...
    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() 检查每个点,对吗?

    最佳答案

    您可以在您的兴趣区域上创建一个掩码:

    编辑
    制作面膜的方法:

    做一个面具;

    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 会消耗大量时间,如果您仅将其应用于较小的图像,则整体 yield 是显着的。

    关于OpenCV C++/Obj-C : goodFeaturesToTrack inside specific blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8606029/

    33 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com