unity3d - 在 Unity 中的纹理中创建边界框
问题描述
我想在纹理中制作一个边界框。
这个纹理是图像分割的结果
我每次都将分割结果制作成纹理,并尝试为这个过程做一个边界框
我有纹理的像素特定值,但这每次都会随机变化。
所以,我试图用 bfs 算法找到像素值。
public Queue<Node> SegNode = new Queue<Node>();
private bool[,] visit = new bool[256, 256];
private int[] dx = new int[4] { 0, 1, -1, 0 };
private int[] dy = new int[4] { 1, 0, 0, -1 };
public struct Node
{
public int x, y;
public float color;
public Node(int x, int y, float color)
{
this.x = x;
this.y = y;
this.color = color;
}
}
void bfs(int r, int c, float color, float[,,,] pixel)
{
Queue<Node> q = new Queue<Node>();
q.Enqueue(new Node(r, c, color));
while (q.Count > 0)
{
Node curNode = q.Dequeue();
SegNode.Enqueue(curNode);
for (int i = 0; i < 4; i++)
{
int tr = curNode.x + dx[i];
int tc = curNode.y + dy[i];
if (tr >= 0 && tr < segmentationImageSize && tc >= 0 && tc < segmentationImageSize)
{
if (!visit[tr, tc] && pixel[0, tc, tr, 0] == color)
{
visit[tr, tc] = true;
q.Enqueue(new Node(tr, tc, color));
}
}
}
}
我想着如何找到顶部和底部。
但这似乎太慢了。
如何轻松获得边界框?
我正在使用分割的结果值来创建纹理
Texture2D SegResTexture = new Texture2D(widht, height, );
for (int y = 0; y < SegResTexture.height; y++)
{
for (int x = 0; x < SegResTexture.width; x++)
{
SegResTexture.SetPixel(x, y, pixel[0, y, x, 0] < 0.1 ? maskTransparent : maskColor);
}
}
SegResTexture.Apply();
SegmentationRawIamge.GetComponent<RawImage>().texture = SegResTexture;
我想做的类似于下图。
解决方案
推荐阅读
- c - How to convert a character array to a decimal integer array?
- php - Laravel 5.3 从数据库结果创建多维数组
- multithreading - 多线程等待一个线程使用哪种同步模型
- python - 在文件中搜索单词并取整行
- powershell - 在 GWMI 过滤器中输出 PSComputerName
- c# - 如何从一维 int 数组返回数字网格?
- python - 如何使用 statsmodels 和 sklearn 在回归中添加控制变量?
- python - 如何在其定义的函数中使用类变量?
- java - 一会儿如何在 switch 中使用 try catch
- pyspark - 将条件应用于列列表的数据框过滤