简体   繁体   English

在OpenCV Python中获取蒙版的轮廓

[英]Getting contours of a mask in opencv python

I am trying to segment an area of interest out of an image for some process I am automating. 我正在尝试从图像中分割出我感兴趣的某个区域,以进行一些自动化的过程。 My idea was to tape off the area with black tape and use lighting to influence the segmentation. 我的想法是用黑色胶带将区域粘住,并使用照明来影响分割。 This is all going to according to plan, except when some object is in front of the taped off area. 这一切都是按计划进行的,除非有一些物体在录音区域的前面。

数字

The above image is the one I am trying to edit. 上面的图片是我要编辑的图片。 Normally if there was no tube I can do it, and use the colored squares to measure the area in cm/mm/m. 通常,如果没有管子,我可以做,并使用彩色正方形测量以cm / mm / m为单位的面积。 Right now I can't, because my code only detects the blue square. 目前无法,因为我的代码仅检测到蓝色方块。

A super easy solution would be to tape off the part of the tube with black tape and just run the normal code. 超级简单的解决方案是用黑色胶带将管子的一部分粘掉,然后运行常规代码。 But I'd like to do this programmatically. 但我想以编程方式执行此操作。

I have tried using this source: Find and draw the largest contour in opencv on a specific color (Python) 我尝试使用此源: 在opencv中找到并绘制特定颜色的最大轮廓(Python)

And some others. 还有一些。 But I just can't figure it out. 但我只是想不通。

What is the best approach? 最好的方法是什么?

I solved it. 我解决了 Just calculate the edges of the black taped off area before inserting the tube. 只需在插入管子之前计算黑色胶带区域的边缘即可。 Save those values to somewhere, for example a XML file and then use those values in the next portion of the process. 将这些值保存到某个地方,例如XML文件,然后在过程的下一部分中使用这些值。 Assuming the camera and the position of the plate doesn't change. 假设相机和板的位置没有变化。

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

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