• C++双线性插值-片段


    代码不能直接使用。

    	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);
    
    		}
    	}
    

      

  • 相关阅读:
    vue-cli 安装一直失败
    如果不存在公缀,返回空字符串
    .sh文件格式问题dos转linux或unix
    Kettle串联多个Spark任务
    云效自动化部署+部署包备份
    云效分支管理
    云效IDE综合插件Alibaba Cloud Toolkit
    流水线自动化部署-中转部署-目标机器不联网情况下应用
    云效流水线自动化部署
    云效流水线自动发布到Maven仓
  • 原文地址:https://www.cnblogs.com/alexYuin/p/9614133.html
Copyright © 2020-2023  润新知