c++ - 删除 opencv 和 c++ 中的边界线

标签 c++ opencv edge-detection

enter image description here

我有很 multimap 像,有和没有类似于上图的文字。我想去除边缘的线条,如果图​​像中存在噪音,我也想去除噪音。

这些线条仅出现在边缘,因为我从表格中裁剪了这些图像。

最佳答案

您可以尝试以下方法。但我不能保证您的图像文件中的所有行都可以删除。

首先通过应用霍夫变换检测图像中存在的所有线条

vector<Vec2f> lines;
HoughLines(img, lines, 1, CV_PI/180, 100, 0, 0 ); 

然后遍历检测到的每一行,

获取图片大小

#you may have laoded image to some file
#such as 
#  Mat img=imread("some_file.jpg");
int rows=img.rows;
int colms=img.cols;
Point pt3;

现在你知道矩阵的大小,接下来得到线的中心点,你可以这样做,

for( size_t i = 0; i < lines.size(); i++ )

{
  float rho = lines[i][0], theta = lines[i][1];
  Point pt1, pt2;
  double a = cos(theta), b = sin(theta);
  double x0 = a*rho, y0 = b*rho;
  pt1.x = cvRound(x0 + 1000*(-b));
  pt1.y = cvRound(y0 + 1000*(a));
  pt2.x = cvRound(x0 - 1000*(-b));
  pt2.y = cvRound(y0 - 1000*(a));
  pt3.x=(pt1.x+pt2.x)/2;
  pt3.y=(pt1.y+pt2.y)/2;

  *** 
  //decide whether you want to remove the line,i.e change line color to 
  // white or not

    line( img, pt1, pt2, Scalar(255,255,255), 3, CV_AA); // if you want to change
}

***一旦你有了图像的中心点和大小,你就可以比较中心点在左、右、上、下的位置。您可以通过如下比较来做到这一点。不要使用 (==) 允许一些差异。
1. (0, cols/2) -- 图像顶部, 2. (rows/2,0) -- 图像左侧, 3. (rows, cols/2) -- 图像底部 4. (rows/2, cols) -- 图片右侧

(因为你的图像已经模糊了,平滑、腐 eclipse 和膨胀可能效果不好)

关于c++ - 删除 opencv 和 c++ 中的边界线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28230551/

相关文章:

c++ - 这两个局部变量有什么区别?

c++ - CString 无法从资源加载日语字符串

c++ - 使用 OpenMP 的并行 IplImage 转换

matlab - "Simple"边缘-线-检测

Android Studio Opencv Canny检测

c++ - 如何使用 GLFW 在 openGL 中旋转相机?

c++ - MakeStream::iterate() 的 Range V3 是什么?

opencv - OPENCV 2.4.9调整大小会更改像素值吗?

android - 使用 openCV 读取复选框

c++ - 检测 parking 场线和ROI openCV