OpenCV C++ 在二維數據中,將點陣包圍的區域填充,並返回區域內所有點位置

//在二維數據中,將點陣包圍的區域填充,並返回區域內所有點位置
void getRegionPoint(int size[2], std::vector<cv::Point> edge, std::vector<cv::Point> &outResult)
{
    cv::Mat mat = cv::Mat::zeros(size[1], size[0], CV_8UC1);

    std::vector<std::vector<cv::Point>> contours;
    contours.push_back(edge);
    cv::drawContours(mat, contours, -1, cv::Scalar(255), CV_FILLED);

    unsigned char *p = mat.data;
    for(int y = 0; y < size[1]; y++)
    {
        for(int x = 0; x < size[0]; x++)
        {
            long long offset = y * size[0] + x;
            if(*(p+offset) > 0)
            {
                outResult.push_back(cv::Point(x, y));
            }
        }
    }
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章