简体   繁体   中英

Given a image of white lines forming a grid, how to get masks of the interior shapes using opencv?

I am trying to determine if there are pills in different cells of a pillbox. I have a raspberry pi camera that takes pictures of a pillbox at regular intervals. I would like to use computer vision using opencv and python to determine which of the 14 cells have pills in them.

I have gotten as far as isolating the borders of the cells. How do I create opencv masks for the interiors of the cells?

I tried running hough transform on the processed image, but it does not accurately find lines corresponding to each wall

Original image:

在此处输入图片说明

After Processing with cell walls isolated:
在此处输入图片说明

You can try Hough Line detection one the image to detect line segments, and use the information to either close the gaps in your current result or simply detect the cells using only the line segments.

The advantage of using line detections is that once you have the parameters of the line, you can extend it below what actually appears in the image. So, even if a cell has a gap, you should be able to close it.

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