视觉深度图后处理中空洞填充问题

在双目SGBM匹配之后,由于遮挡和误匹配等问题,最后出来的深度图会存在很多噪点和空洞,这些问题无法通过某一种滤波方法解决,对于这个问题我尝试自己写了一个脚本,能比较好的去除空洞。代码如下:
头文件hole_filling.h

#pragma once
#include<iostream>
#include <opencv2/opencv.hpp>
#include<typeinfo>
#include<algorithm>
#include<vector>
#include<numeric>
using namespace std;

void insertDepth32f(cv::Mat& depth);

源文件hole_filling.cpp

#include"hole_filling.h"

void insertDepth32f(cv::Mat& depth)
{
	
	for (int i = 0; i < depth.rows; i++)
	{
		for (int j = 0; j < depth.cols; j++)
		{
			if (depth.channels() == 1)
			{
				//图像数组是逐行逐列顺序排列的,也就是第一行,全列,第二行全列的走
				int a,b,indexs = i * depth.cols + j;
				//cout << typeid(depth.data[indexs]).name() << endl;
				a = (int)depth.data[indexs];
				//cout << a << endl;
				if (a == 0 && j > 50 && j< depth.cols-50 && i>50 && i< depth.rows-50)
				{
					
					//vector<int> testarray = { (int)depth.data[indexs - 50], (int)depth.data[indexs + 50], (int)depth.data[indexs - 50 * depth.cols], (int)depth.data[indexs + 50 * depth.cols] };
					b = max({ (int)depth.data[indexs - 50], (int)depth.data[indexs + 50], (int)depth.data[indexs - 50* depth.cols], (int)depth.data[indexs + 50 * depth.cols] });//accumulate(testarray.begin(),testarray.end(),0)/4;
					//cout << "a的值为:"<<a<<"b的值为:"<<b << endl;
					 depth.data[indexs] = b;
				}
			}
			else if (depth.channels() == 3)
			{
			}
		}
	}

}

我做了两个实验,b = max({ (int)depth.data[indexs - 50], (int)depth.data[indexs + 50], (int)depth.data[indexs - 50* depth.cols], (int)depth.data[indexs + 50 * depth.cols]

  1. 一个是把距离当前空洞像素前后上下50个像素处的最大像素值替代当前空洞像素;
  2. 另一个是把距离当前空洞像素前后上下1个像素处的最大像素值替代当前空洞像素;
    得出来的效果如下:
     原图参数为1参数为50
    可以看到参数设置为50的时候填充缺乏渐变,存在新的噪点,具体选择参数为多少应根据需要处理的图片的分辨率来确定,大分辨率参数可以适当设置的大一些。
  • 4
    点赞
  • 35
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值