opencv 用cvPryMeanShiftFiltering做图像分割,想将分块后每个区域设置个标签 生成一个label的mat 怎么做

hanshiyingxue 2021-09-19 09:45 393 次浏览 赞 68

最新问答

  • 颂美装饰

    刚好我写了类似的代,但是我用的是 pyrMeanShiftFiltering() 这个函数,可能会稍有些不同。我把我的整个函数放在下面,你自己看下:
    void meanShiftSegmentation(cv::Mat &firstImage, cv::Mat &secondImage, cv::Mat &overlapSegmentsResults)
    {
    int imageHeight = firstImage.rows;
    int imageWidth = firstImage.cols;

    cv::Mat firstResults;
    cv::pyrMeanShiftFiltering(firstImage, firstResults,10,10);
    cv::Mat secondResults;
    cv::pyrMeanShiftFiltering(secondImage, secondResults,10,10);

    cv::Mat mask(imageHeight+2, imageWidth+2, CV_8UC1, cv::Scalar(0));
    uchar* maskData = mask.data;
    RNG rng=theRNG();
    for (int i = 0 ; i < imageHeight ; i++)
    {
    for (int j = 0 ; j < imageWidth ; j++)
    {
    if (maskData[(i+1)*imageWidth + j+1] == 0)
    {
    Scalar newcolor(rng(255),rng(255),rng(255));
    floodFill(firstResults,mask,Point(j,i),newcolor,0,Scalar::all(1),Scalar::all(1));
    }
    }
    }
    mask.setTo(0);
    for (int i = 0 ; i < imageHeight ; i++)
    {
    for (int j = 0 ; j < imageWidth ; j++)
    {
    if (maskData[(i+1)*imageWidth + j+1] == 0)
    {
    Scalar newcolor(rng(255),rng(255),rng(255));
    floodFill(secondResults,mask,Point(j,i),newcolor,0,Scalar::all(1),Scalar::all(1));
    }
    }
    }

    imwrite("E:\\firstMeanShift.png",firstResults);
    imwrite("E:\\secondMeanShift.png",secondResults);
    }

    浏览 348赞 74时间 2023-06-22

opencv 用cvPryMeanShiftFiltering做图像分割,想将分块后每个区域设置个标签 生成一个label的mat 怎么做