我想知道如何手动执行此操作。我不喜欢折叠,因为它仍然显示方法声明行。但是我注意到,在将方法折叠一段时间之后,最终这些行号被完全隐藏了。我想知道是否有一种方法可以手动执行此操作并隐藏整行代码。这是我在说的。
我正在开发一个程序,试图从拼图中提取彩色方块。我从视频捕获中取出一帧,然后找到所有轮廓。然后,我删除不是正方形形状的轮廓(这可以正常工作,但正在寻找更好的方法)。我面临的主要问题是轮廓重叠。我曾经RETR_TREE获取所有轮廓,但使用时RETR_EXTERNAL轮廓变得更难检测。有没有办法可以改进方块的检测?或者一种可以删除图像中重叠轮廓的方法。
这是有重叠轮廓的图像:在此图像中找到 11 个轮廓,但我只想要 9 个。(我绘制矩形以便更容易地看到重叠)

。如何去除内部轮廓?这是我的代码:
public Mat captureFrame(Mat capturedFrame){
Mat newFrame = new Mat();
capturedFrame.copyTo(newFrame);
//Gray
Mat gray = new Mat();
Imgproc.cvtColor(capturedFrame, gray, Imgproc.COLOR_RGB2GRAY);
//Blur
Mat blur = new Mat();
Imgproc.blur(gray, blur, new Size(3,3));
//Canny image
Mat canny = new Mat();
Imgproc.Canny(blur, canny, 20, 40, 3, true);
//Dilate image to increase size of lines
Mat kernel = Imgproc.getStructuringElement(1, new Size(3,3));
Mat dilated = new Mat();
Imgproc.dilate(canny,dilated, kernel);
List<MatOfPoint> contours = new ArrayList<>();
List<MatOfPoint> squareContours …Run Code Online (Sandbox Code Playgroud) 我有一个轮廓重叠的图像,当我找到它们时,我一直试图使用层次结构过滤掉轮廓。我想要做的是过滤掉父母不等于 -1 的轮廓。但是,当我尝试获取包含层次结构的信息时,父索引几乎每次都等于 null。我不是在查看获取当前轮廓父级状态的正确信息吗?这是我的代码。
List<MatOfPoint> contours = new ArrayList<>();
List<MatOfPoint> squareContours = new ArrayList<>();
Mat hierarchy = new Mat();
//find all contours
Imgproc.findContours(dilated, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
//Remove contours that aren't close to a square shape.
for(int i = 0; i < contours.size(); i++){
if(hierarchy != null){
double area = Imgproc.contourArea(contours.get(i));
MatOfPoint2f contour2f = new MatOfPoint2f(contours.get(i).toArray());
double perimeter = Imgproc.arcLength(contour2f, true);
//Found squareness equation on wiki...
//https://en.wikipedia.org/wiki/Shape_factor_(image_analysis_and_microscopy)
double squareness = 4 * Math.PI * area / Math.pow(perimeter, 2);
if(squareness >= …Run Code Online (Sandbox Code Playgroud)