简体   繁体   中英

Detecting shapes enclosed by patterns in OpenCV

So, lets say I have a multitude of images that contain a multitude of shapes. In these images there may be shapes inside shapes, and there are two types of shapes. There are shapes with a pattern (like hash marks or diagonal lines), and there are shapes that don't have a pattern inside them.

Such an image could like like this: 矩形形状 Let's say I want to only detect shapes that have a pattern in side of them, like this:

具有突出显示紫色形状的同一图像

And once I have detected the shape, I want to output a file that looks like this: 只有上面突出显示的形状

My original solution was to convolve the image with the a 3 3 identity matrix, blur the image, and then try to detect blobs from the blurred image. This doesn't work very consistently, and will not work at all in my images that have a more difficult pattern (like a crosshatch)

Does anybody know of any good strategies I could use to generate that output file?

This is a follow up on a question I asked a while ago, here The answer I received last time was fantastic for the examples I posted, but I'd like to move to opencv, and the answer from last time fails for things like the example above, due to the nested shapes.

As an aside, is there a more proper way for me to ask this question? It's very similar to my previous question, but slightly different. I'm posting this on the bases that it's different enough from my last question.

Since you have not provided code for your question, I'll also provide the answer without code:

  1. Detect the lines of the diagonal pattern by using a hough transformation
  2. Determine the end points of the diagonal pattern
  3. For each contour, check whether the end points of the diagonal pattern lie on the contour (using Shapely)
  4. For each contour which intersects with end points of the diagonal pattern, fill it
  5. For each contour which intersects with end points of the diagonal pattern, determine all inner contours (children) using contour hierarchy and deselect the areas belonging to these inner contours.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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