基于移动式管道滤波算法的仿真

参考论文《基于移动式管道滤波的红外小目标检测方法研究》
在这里插入图片描述
仿真代码如下:


//判断一点的位置在邻域内
bool pointInterNeibor(cv::Point2f pointPos, cv::Point2f curX,int n,int width,int height)
{
	cv::Rect2f neiborRoi;
	int bordenLeft = 0;
	int bordenRight = 0;
	int bordenTop = 0;
	int bordenBottom = 0;
	bordenLeft = curX.x - n < 0 ? 0 : curX.x - n;
	bordenRight= curX.x + n > width ? width : curX.x + n;
	bordenLeft = curX.x - n < 0 ? 0 : curX.x - n;
	bordenTop = curX.y - n < 0 ? 0 : curX.y - n;
	bordenBottom = curX.y + n > height ? height : curX.y + n;
	bool res = false;
	if ((pointPos.x > bordenLeft)&& (pointPos.x<bordenRight)&&
		(pointPos.y>bordenTop) && (pointPos.y < bordenBottom))
	{
		res = true;
	}
	else
	{
		res = false;
	}
	return res;
}



//5帧图像目标的数组,取第一帧作为当前帧,在下一帧观察其小邻域内是否有目标存在,有,则目标计数器加1
//同时比较目标点和可疑目标点的位置,如果有变化,则相应的目标变化计数器加1,记录该帧的目标位置,并将
//其设为候选目标点的当前位置
cv::Point2f guandaoFilter(queue<vector<cv::Point2f>> targetPosQ)
{
	vector<cv::Point2f> singleTargetPos, copySingleTargetPos;
	vector<cv::Point2f>secTargetPos;
	vector<cv::Point2f>thirdTargetPos;
	vector<cv::Point2f>fourTargetPos;
	vector<cv::Point2f>fiveTargetPos;
	cv::Point2f currentPos;
	vector<int>targetFlagVec;
	vector<int>targetPosFlagVec;
	singleTargetPos = targetPosQ.front();
	copySingleTargetPos = targetPosQ.front();
	targetPosQ.pop();
	

	for (int i = 0; i < singleTargetPos.size(); i++)
	{
		queue<vector<cv::Point2f>>tempPosQ;
		int targetFlag = 0;
		int targetPosFlag = 0;
		tempPosQ = targetPosQ;
		secTargetPos = tempPosQ.front();
		for (int j = 0; j < secTargetPos.size(); j++)
		{
			if (pointInterNeibor(secTargetPos[j], singleTargetPos[i], 1, 640, 512))
			{
				targetFlag++;
				if ((secTargetPos[j].x != singleTargetPos[i].x) || (secTargetPos[j].y != singleTargetPos[i].y))
				{
					singleTargetPos[i].x = secTargetPos[j].x;
					singleTargetPos[i].y = secTargetPos[j].y;
					targetPosFlag++;

				}
				else
				{
					;
				}
			}
		}
		tempPosQ.pop();
		thirdTargetPos = tempPosQ.front();
		for (int j = 0; j < thirdTargetPos.size(); j++)
		{
			if (pointInterNeibor(thirdTargetPos[j], singleTargetPos[i], 1, 640, 512))
			{
				targetFlag++;
				if ((thirdTargetPos[j].x != singleTargetPos[i].x) || (thirdTargetPos[j].y != singleTargetPos[i].y))
				{
					singleTargetPos[i].x = thirdTargetPos[j].x;
					singleTargetPos[i].y = thirdTargetPos[j].y;
					targetPosFlag++;

				}
				else
				{
					;
				}
			}
		}
		tempPosQ.pop();

		fourTargetPos = tempPosQ.front();
		for (int j = 0; j < fourTargetPos.size(); j++)
		{
			if (pointInterNeibor(fourTargetPos[j], singleTargetPos[i], 1, 640, 512))
			{
				targetFlag++;
				if ((fourTargetPos[j].x != singleTargetPos[i].x) || (fourTargetPos[j].y != singleTargetPos[i].y))
				{
					singleTargetPos[i].x = fourTargetPos[j].x;
					singleTargetPos[i].y = fourTargetPos[j].y;
					targetPosFlag++;

				}
				else
				{
					;
				}
			}
		}
		tempPosQ.pop();

		fiveTargetPos = tempPosQ.front();
		for (int j = 0; j < fiveTargetPos.size(); j++)
		{
			if (pointInterNeibor(fiveTargetPos[j], singleTargetPos[i], 1, 640, 512))
			{
				targetFlag++;
				if ((fiveTargetPos[j].x != singleTargetPos[i].x) || (fiveTargetPos[j].y != singleTargetPos[i].y))
				{
					singleTargetPos[i].x = fiveTargetPos[j].x;
					singleTargetPos[i].y = fiveTargetPos[j].y;
					targetPosFlag++;

				}
				else
				{
					;
				}
			}
		}
		tempPosQ.pop();
		targetFlagVec.push_back(targetFlag);
		targetPosFlagVec.push_back(targetPosFlag);

	}
	for (int i = 0; i < targetFlagVec.size(); i++)
	{
		if (targetFlagVec[i] > 3 && targetPosFlagVec[i]>2)
		{
			currentPos = copySingleTargetPos[i];      //返回的是比较的第一帧的点的坐标
		}
		
	}
	return currentPos;
}

	

试验发现对于运动目标效果还行,但是无法解决静止目标,需要配合其他算法。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

dx0014

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值