绘制 YOLOv5 实例分割预测结果作为掩模。

huangapple go评论64阅读模式
英文:

Plot YOLOv5 instance segmentation predictions as masks

问题

我正在检测网球场,然后从中提取角坐标。YOLOv5实例分割提供一个粗略的多边形,以文本文件的形式作为预测。您如何绘制这个YOLO多边形标签?

来自预测的txt文件示例:

0 0.289062 0.24375 0.2875 0.245312 0.2875 0.248437 0.285937 0.25 0.285937 0.253125 0.284375 0.254687 0.282813 0.254687 0.282813 0.25625 0.28125 0.257812 0.28125 0.265625 0.279687 0.267188 0.279687 0.26875 0.276563 0.271875 0.276563 0.273438 0.275 0.275 0.275 0.282813 0.273438 0.284375 0.273438 0.285937 0.271875 0.2875 0.270312 0.2875 0.26875 0.289062 0.26875 0.301562 0.2625 0.307813 0.2625 0.315625 0.260938 0.317187 0.260938 0.31875 0.257812 0.321875 0.257812 0.323438 0.25625 0.325 0.25625 0.334375 0.253125 0.3375 0.251563 0.3375 0.25 0.339063 0.25 0.348437 0.248437 0.35 0.248437 0.351562 0.245312 0.354688 0.245312 0.35625 0.24375 0.357812 0.24375 0.365625 0.2375 0.371875 0.2375 0.378125 0.234375 0.38125 0.232812 0.38125 0.23125 0.382812 0.23125 0.390625 0.229687 0.392188 0.229687 0.395312 0.226562 0.398438 0.226562 0.4 0.225 0.401563 0.225 0.4125 0.223438 0.414062 0.223438 0.415625 0.21875 0.420312 0.21875 0.429688 0.217187 0.43125 0.217187 0.432813 0.214062 0.435937 0.214062 0.4375 0.2125 0.439063 0.2125 0.446875 0.209375 0.45 0.207813 0.45 0.20625 0.451562 0.20625 0.459375 0.204688 0.460938 0.204688 0.4625 0.201562 0.465625 0.201562 0.467187 0.2 0.46875 0.2 0.476562 0.19375 0.482812 0.19375 0.490625 0.192188 0.492188 0.192188 0.49375 0.189063 0.496875 0.189063 0.498437 0.1875 0.5 0.1875 0.507812 0.18125 0.514063 0.18125 0.521875 0.179688 0.523438 0.179688 0.526563 0.175 0.53125 0.175 0.539062 0.16875 0.545313 0.16875 0.55625 0.167187 0.557813 0.167187 0.559375 0.1625 0.564062 0.1625 0.571875 0.159375 0.575 0.157813 0.575 0.157813 0.576563 0.15625 0.578125 0.15625 0.5875 0.154687 0.589063 0.154687 0.590625 0.15 0.595312 0.15 0.603125 0.14375 0.609375 0.14375 0.61875 0.142188 0.620313 0.142188 0.621875 0.1375 0.626562 0.1375 0.634375 0.13125 0.640625 0.13125 0.651563 0.125 0.657812 0.125 0.665625 0.11875 0.671875 0.11875 0.68125 0.117188 0.682813 0.117188 0.684375 0.1125 0.689062 0.1125 0.696875 0.10625 0.703125 0.10625 0.710938 0.104687 0.7125 0.104687 0.714063 0.101562 0.717188 0.101562 0.71875 0.1 0.720312 0.1 0.728125 0.0953125 0.732813 0.0953125 0.735937 0.09375 0.7375 0.09375 0.74375 0.0921875 0.745313 0.0921875 0.746875 0.0875 0.751562 0.0875 0.759375 0.0828125 0.764063 0.0828125 0.765625 0.08125 0.767187 0.08125 0.771875 0.0796875 0.773438 0.0796875 0.775 0.0765625 0.778125 0.0765625 0.779688 0.075 0.78125 0.075 0.7875 0.0765625 0.789062 0.0765625 0.790625 0.078125 0.790625 0.0796875 0.

英文:

I'm detecting tennis courts to then pull corner coordinates from. YOLOv5 instance segmentation provides a rough polygon in a txt file as prediction. How do you plot this YOLO polygon label?

Example of txt file from predictions:

0 0.289062 0.24375 0.2875 0.245312 0.2875 0.248437 0.285937 0.25 0.285937 0.253125 0.284375 0.254687 0.282813 0.254687 0.282813 0.25625 0.28125 0.257812 0.28125 0.265625 0.279687 0.267188 0.279687 0.26875 0.276563 0.271875 0.276563 0.273438 0.275 0.275 0.275 0.282813 0.273438 0.284375 0.273438 0.285937 0.271875 0.2875 0.270312 0.2875 0.26875 0.289062 0.26875 0.301562 0.2625 0.307813 0.2625 0.315625 0.260938 0.317187 0.260938 0.31875 0.257812 0.321875 0.257812 0.323438 0.25625 0.325 0.25625 0.334375 0.253125 0.3375 0.251563 0.3375 0.25 0.339063 0.25 0.348437 0.248437 0.35 0.248437 0.351562 0.245312 0.354688 0.245312 0.35625 0.24375 0.357812 0.24375 0.365625 0.2375 0.371875 0.2375 0.378125 0.234375 0.38125 0.232812 0.38125 0.23125 0.382812 0.23125 0.390625 0.229687 0.392188 0.229687 0.395312 0.226562 0.398438 0.226562 0.4 0.225 0.401563 0.225 0.4125 0.223438 0.414062 0.223438 0.415625 0.21875 0.420312 0.21875 0.429688 0.217187 0.43125 0.217187 0.432813 0.214062 0.435937 0.214062 0.4375 0.2125 0.439063 0.2125 0.446875 0.209375 0.45 0.207813 0.45 0.20625 0.451562 0.20625 0.459375 0.204688 0.460938 0.204688 0.4625 0.201562 0.465625 0.201562 0.467187 0.2 0.46875 0.2 0.476562 0.19375 0.482812 0.19375 0.490625 0.192188 0.492188 0.192188 0.49375 0.189063 0.496875 0.189063 0.498437 0.1875 0.5 0.1875 0.507812 0.18125 0.514063 0.18125 0.521875 0.179688 0.523438 0.179688 0.526563 0.175 0.53125 0.175 0.539062 0.16875 0.545313 0.16875 0.55625 0.167187 0.557813 0.167187 0.559375 0.1625 0.564062 0.1625 0.571875 0.159375 0.575 0.157813 0.575 0.157813 0.576563 0.15625 0.578125 0.15625 0.5875 0.154687 0.589063 0.154687 0.590625 0.15 0.595312 0.15 0.603125 0.14375 0.609375 0.14375 0.61875 0.142188 0.620313 0.142188 0.621875 0.1375 0.626562 0.1375 0.634375 0.13125 0.640625 0.13125 0.651563 0.125 0.657812 0.125 0.665625 0.11875 0.671875 0.11875 0.68125 0.117188 0.682813 0.117188 0.684375 0.1125 0.689062 0.1125 0.696875 0.10625 0.703125 0.10625 0.710938 0.104687 0.7125 0.104687 0.714063 0.101562 0.717188 0.101562 0.71875 0.1 0.720312 0.1 0.728125 0.0953125 0.732813 0.0953125 0.735937 0.09375 0.7375 0.09375 0.74375 0.0921875 0.745313 0.0921875 0.746875 0.0875 0.751562 0.0875 0.759375 0.0828125 0.764063 0.0828125 0.765625 0.08125 0.767187 0.08125 0.771875 0.0796875 0.773438 0.0796875 0.775 0.0765625 0.778125 0.0765625 0.779688 0.075 0.78125 0.075 0.7875 0.0765625 0.789062 0.0765625 0.790625 0.078125 0.790625 0.0796875 0.792188 0.10625 0.792188 0.107813 0.790625 0.121875 0.790625 0.123438 0.789062 0.139062 0.789062 0.140625 0.7875 0.192188 0.7875 0.19375 0.785937 0.198437 0.785937 0.2 0.7875 0.384375 0.7875 0.385938 0.785937 0.432813 0.785937 0.434375 0.7875 0.440625 0.7875 0.442187 0.785937 0.679688 0.785937 0.68125 0.7875 0.81875 0.7875 0.820312 0.789062 0.832812 0.789062 0.834375 0.790625 0.86875 0.790625 0.870313 0.792188 0.921875 0.792188 0.923437 0.790625 0.923437 0.778125 0.917188 0.771875 0.917188 0.764063 0.915625 0.7625 0.915625 0.760938 0.9125 0.757812 0.9125 0.75625 0.910937 0.754687 0.910937 0.746875 0.909375 0.745313 0.909375 0.74375 0.907812 0.74375 0.904688 0.740625 0.904688 0.729688 0.903125 0.728125 0.903125 0.726562 0.898438 0.721875 0.898438 0.714063 0.896875 0.7125 0.896875 0.710938 0.89375 0.707812 0.89375 0.70625 0.892187 0.704687 0.892187 0.696875 0.890625 0.695312 0.890625 0.69375 0.889063 0.69375 0.885938 0.690625 0.885938 0.682813 0.884375 0.68125 0.884375 0.679688 0.88125 0.676562 0.88125 0.675 0.879687 0.673437 0.879687 0.664062 0.873438 0.657812 0.873438 0.646875 0.867188 0.640625 0.867188 0.632812 0.8625 0.628125 0.8625 0.626562 0.860937 0.625 0.860937 0.614062 0.859375 0.6125 0.857813 0.6125 0.854688 0.609375 0.854688 0.598437 0.853125 0.596875 0.853125 0.595312 0.848437 0.590625 0.848437 0.582812 0.84375 0.578125 0.84375 0.576563 0.842188 0.575 0.842188 0.564062 0.840625 0.5625 0.839063 0.5625 0.835938 0.559375 0.835938 0.55 0.834375 0.548437 0.834375 0.545313 0.832812 0.545313 0.83125 0.54375 0.83125 0.542188 0.829687 0.540625 0.829687 0.532812 0.825 0.528125 0.825 0.526563 0.823438 0.525 0.823438 0.514063 0.821875 0.5125 0.820312 0.5125 0.817187 0.509375 0.817187 0.5 0.815625 0.498437 0.815625 0.495313 0.810938 0.490625 0.810938 0.482812 0.80625 0.478125 0.80625 0.476562 0.804688 0.475 0.804688 0.464063 0.803125 0.4625 0.801562 0.4625 0.798437 0.459375 0.798437 0.446875 0.796875 0.445312 0.796875 0.44375 0.795313 0.44375 0.792188 0.440625 0.792188 0.432813 0.7875 0.428125 0.7875 0.426562 0.785937 0.425 0.785937 0.415625 0.784375 0.414062 0.784375 0.4125 0.782812 0.4125 0.779688 0.409375 0.779688 0.395312 0.775 0.390625 0.775 0.389062 0.773438 0.3875 0.773438 0.38125 0.771875 0.379687 0.771875 0.378125 0.76875 0.375 0.76875 0.373437 0.767187 0.371875 0.767187 0.364062 0.760938 0.357812 0.760938 0.345313 0.759375 0.34375 0.757812 0.34375 0.754687 0.340625 0.754687 0.33125 0.753125 0.329688 0.753125 0.326562 0.751562 0.326562 0.75 0.325 0.75 0.323438 0.748438 0.321875 0.748438 0.314063 0.746875 0.3125 0.746875 0.310937 0.74375 0.307813 0.74375 0.30625 0.742188 0.304688 0.742188 0.295312 0.735937 0.289062 0.735937 0.278125 0.734375 0.276563 0.734375 0.275 0.732813 0.275 0.729688 0.271875 0.729688 0.259375 0.723437 0.253125 0.723437 0.245312 0.721875 0.24375

答案1

得分: 1

Yolo在您的txt文件中给出的格式如下:

[category_idx x1 y1 x2 y2 ... xn yn]

您需要通过将x乘以图像宽度和将y乘以图像高度来使坐标绝对化。

[x1 y1 ... xn yn] 是您的多边形。

然后只需使用“Polygon to Mask”算法。您可以在此问题的评论中找到一个算法:https://github.com/scikit-image/scikit-image/issues/1103

您还可以在论坛上找到类似的问题:
https://stackoverflow.com/questions/42176846/python-turn-polygon-into-mask-array

我建议您使用OpenCV来实现这一点:https://stackoverflow.com/questions/67708224/shapely-polygon-to-binary-mask

您也可以在Google上搜索。

关于标签,您需要将category_idx与实际的类别名称关联起来。

玩得开心 绘制 YOLOv5 实例分割预测结果作为掩模。

英文:

The format given by Yolo in your txt file is such as:

[category_idx x1 y1 x2 y2 ... xn yn]

You have to make the coordinate absolute by multiplying the x by the image width, and the y by the image height.

[x1 y1 ... xn yn] is your polygon.

Then just use a "Polygon to Mask" algorithm. You can find an algorithm in the comments of this issue : https://github.com/scikit-image/scikit-image/issues/1103

You also have similar questions on the forum :
https://stackoverflow.com/questions/42176846/python-turn-polygon-into-mask-array

I recommend this to make it with opencv : https://stackoverflow.com/questions/67708224/shapely-polygon-to-binary-mask

You can also search on Google.

About the label, you have to associate the categoy_idx with the actual category name.

Have fun 绘制 YOLOv5 实例分割预测结果作为掩模。

huangapple
  • 本文由 发表于 2023年7月13日 23:17:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76680995.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定