我试图找到一种方法对墓 map 像进行近似分割(在文化科学中的 CBIR 背景下 - 但这不是主题)。到目前为止,我正在使用这个策略:
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”和“edge”包含opencv的简单代码,用于模糊图像并进一步处理它。该代码有效。这是一个示例图片:
但现在我不知道分割图像。我想从矩形石的内部到外部,当我找到一条线时,我想记住坐标,然后剪切内容。如果您有想法或提示,谢谢!
最佳答案
您可以尝试使用 Hough-Transformation (cv::HoughLinesP) 参见教程示例 http://docs.opencv.org/modules/imgproc/doc/feature_detection.html
为了找到图片中石头的坐标,您需要计算霍夫变换找到的线的交点。对于类似的用例,我使用了高斯模糊,然后是拉普拉斯变换(而不是精明边缘)。
关于image-processing - OpenCV:约。从轮廓图像分割,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13741825/