using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Kinect空洞填充算法
{
class Program
{
static void Main(string[] args)
{
//假设-8为空洞像素
int[] Data = new int[] { 0, -8, 0, -8, -8, 7,-8, 5, -8, 9 };
//记录空洞像素的个数
int n = 0;
for (int i = 0; i < (Data.Length-1); i++)
{
//最后一个像素的深度值不检测
if ((i + 1 == 9) && Data[i + 1] == -8)
n = 0;
//判断当前的像素是否为空洞
if (Data[i] == -8)
{
//是,数量n+1
n = n + 1;
//是空洞,继续判断下一个像素的深度值
if (Data[i + 1] == 0)
{
//如果下一个像素的深度值为0,将空洞数量置为0
n = 0;
}
//如果下一个像素不为空洞
else if (Data[i + 1] != -8)
{
//进行填充
for (int j = i - n + 1; j <= i; j++)
{
//利用周围深度值补充
Data[j] = Data[i + 1];
}
//空洞数量置为0,继续下一个像素的判断
n = 0;
}
}
}
for (int ii = 0; ii < 10; ii++)
{
Console.Write(Data[ii]);
Console.Write(" ");
}
Console.ReadLine();
}
}
}
Kinect空洞填充算法
最新推荐文章于 2024-01-26 18:26:27 发布