码迷,mamicode.com
首页 > 编程语言 > 详细

C++双线性插值-片段

时间:2018-09-09 18:03:45      阅读:373      评论:0      收藏:0      [点我收藏+]

标签:map   last   otto   set   off   直接   offset   for   ott   

代码不能直接使用。

	for (int j = strRY; j<endRY; ++j)
	{
		float * pR = result.ptr<float>(j);

		for (int i = strRX; i < endRX; ++i)
		{
			// To make sure z value;
			float z(FLOAT32_MIN);
			int i_(i - pOffset.x), j_(j - pOffset.y);

			float x = m_mapX.at<float>(j - strRY, i - strRY);
			float y = m_mapY.at<float>(j - strRY, i - strRY);

			// whether out of range.
			if (x < 0 || x >= src2.cols || y < 0 || y >= src2.rows)
				continue;

			int lRow = static_cast<int>(y);
			int nRow = lRow + 1;

			int lCol = static_cast<int>(x);
			int nCol = lCol + 1;

			double u = y - lRow;
			double v = x - lCol;

			// interpolation
			// right bottom.
			if (lRow >= src2.rows - 1 && lCol >= src2.cols - 1)
			{
				float data = m_mapZ.at<float>(lRow, lCol);
				if (data == -1.0e6)
					continue;

				z = (1 - u) * (1 - v) *	data;
			}
			else if (lRow >= src2.rows - 1)//last row
			{
				float data = m_mapZ.at<float>(lRow, lCol);
				float data2 = m_mapZ.at<float>(lRow, nCol);
				if (data == -1.0e6 || data2 == -1.0e6)
					continue;

				z = (1 - u) * (1 - v) *	data +
					(1 - u) * v * data2;
			}
			else if (lCol >= src2.cols - 1)//last col
			{
				float data = m_mapZ.at<float>(lRow, lCol);
				float data3 = m_mapZ.at<float>(nRow, lCol);

				if (data == -1.0e6 || data3 == -1.0e6)
					continue;
				z = (1 - u) * (1 - v) *	data + u * (1 - v) * data3;
			}
			else
			{
				float data = m_mapZ.at<float>(lRow, lCol);
				float data2 = m_mapZ.at<float>(lRow, nCol);
				float data3 = m_mapZ.at<float>(nRow, lCol);
				float data4 = m_mapZ.at<float>(nRow, nCol);
				if (data == -1.0e6 || data2 == -1.0e6 || data3 == -1.0e6 || data4 == -1.0e6)
					continue;

				z = (1 - u) * (1 - v) *	data + (1 - u) * v * data2 +
					u * (1 - v) * data3 + u * v * data4;
			}

			pR[i] = pR[i] == -1.0e6 ? z : 0.5*(pR[i] + z);

		}
	}

  

 

C++双线性插值-片段

标签:map   last   otto   set   off   直接   offset   for   ott   

原文地址:https://www.cnblogs.com/alexYuin/p/9614133.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!