OpenCV:约。从Contour-Image分割

时间:2012-12-06 10:39:05

标签: image-processing opencv image-segmentation

我正试图找到一种方法在墓地图像上进行近似分割(在文化科学中的CBIR背景下 - 但这不是主题)。到目前为止,我正在使用这个策略:

  • Blurr图像两次(实验结果)
  • 应用Canny-Edge-Detector
  • 查找轮廓

    int main(int argc, const char* argv[]) {
    
    cout << "Starting " << endl;
    Mat sourceImage;
    sourceImage = imread("singlesegmentation/DSCN5204.JPG",
            CV_LOAD_IMAGE_COLOR);
    
    if (!sourceImage.data) {
        cout << "No Image found." << endl;
        return -1;
    }
    
    cv::Mat blurred = imagePro::blurrNtimes(2, sourceImage);
    cv::Mat target = edged::applyCanny(blurred);
    cout << "Canny applied " << endl;
    
    vector<vector<Point> > contours;
    vector<Vec4i> hierarchy;
    cv::Point offset;
    offset.x = sourceImage.rows / 2;
    offset.y = sourceImage.cols / 2;
    cv::findContours(target, contours, hierarchy, CV_RETR_TREE ,
            CV_CHAIN_APPROX_SIMPLE, offset);
    cout << "Contours applied " << endl;
    
    int idx = 0;
    for (; idx >= 0; idx = hierarchy[idx][0]) {
        Scalar color(rand() & 255, rand() & 255, rand() & 255);
        drawContours(target, contours, idx, color, CV_FILLED, 8, hierarchy);
    }
    cout << "Lines applied " << endl;
    
    cv::namedWindow("Contour", CV_WINDOW_NORMAL);
    cv::imshow("Contour", target);
    cv::waitKey(0);
    
    return 0;
    

    }

命名空间“imagePro”和“edged”包含简单的opencv代码,用于模糊图像并进一步处理。代码有效。这是一个示例图片: Contour-Image of Gravestone 但现在我不知道要分割图像。我想从矩形石的内部走到外面,当我找到一条线时,我想记住坐标,然后剪切内容。谢谢你,如果你有想法或提示!

1 个答案:

答案 0 :(得分:2)

您可以尝试使用Hough-Transformation(cv :: HoughLinesP)查看教程示例http://docs.opencv.org/modules/imgproc/doc/feature_detection.html

为了找到图片中石头的坐标,您需要计算霍夫变换找到的线的交点。对于类似的用例,我使用Gaussian-Blur,然后使用Laplace-Transformation(而不是canny-edge)。

相关问题