简体   繁体   English

在OpenCV Java中识别矩形

[英]Recognizing rectangles in OpenCV Java

I'm trying to crop rectangles out of an image using OpenCV/Java. 我正在尝试使用OpenCV / Java从图像中裁剪出矩形。 I've been somewhat successful finding the lines that make up the rectangular sections I want to crop, but I'm having a hard time finding the best way to do the following: 我已经很成功地找到了要裁剪的矩形部分的线条,但是我很难找到执行以下操作的最佳方法:

  1. Connect the segmented lines I've found (see screenshot below) into separate rectangles (lines can be shared by multiple adjacent rectangles) 将我找到的分段线(请参见下面的屏幕截图)连接到单独的矩形中(线可以由多个相邻矩形共享)
  2. Determine that a nearly complete rectangle is a rectangle (see broken bottom edge of full rectangle in screenshot, to the left of line #6) 确定一个几乎完整的矩形是一个矩形(请参见屏幕快照中第6行左侧的完整矩形的底边)

Any guidance is appreciated! 任何指导表示赞赏!

矩形图像

I had been using OpenCV's Impgproc.HoughLinesP , which produced the line segments seen in the question's screenshot. 我一直在使用OpenCV的Impgproc.HoughLinesP ,它生成了在问题的屏幕截图中看到的线段。 I ended up scrapping that path, opting for a combination of Imgproc.findContours , Imgproc.contourArea and Imgproc.boundingRect instead. 我最终取消了该路径,而是选择了Imgproc.findContoursImgproc.contourAreaImgproc.boundingRect的组合。 This approach worked for me, and allowed me to avoid writing a bunch of recursive line-combining code. 这种方法对我有用,并且使我避免编写一堆递归的行合并代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM