数字高程模型内插 opencv C++ CSU

  • 承接实验三
  • 实验配置 C++ vs2017 opencv
  • 实验4 数字高程模型内插
    • 一、实验目的
    • 二、实验内容与要求
      • 1.DEM类设计
      • 2.设计最小二乘配置的点云格网DEM内插程序。
    • 三、设计与实现
      • 3.1类的设计
      • 3.2控件按钮及其属性
      • 3.3主要代码
        • 3.3.1文件:< CDem.h >
        • 3.3.2文件:< CMatchingImg.cpp >
        • 3.3.3文件: < C_points.h >
        • 3.3.4文件: < C_points.cpp >
        • 3.3.5文件: < CBasic.cpp >(仅展示部分)
        • 3.3.6文件: < ZRX0107170110Dlg.cpp >(仅展示部分)
      • 3.4运行结果
        • 3.4.1采用uav1m.txt
        • 3.4.2采用uav3m.txt
  • 代码虽多不要贪杯~

承接实验三

实验配置 C++ vs2017 opencv

实验4 数字高程模型内插

一、实验目的

  • 掌握最小二乘配置算法

二、实验内容与要求

1.DEM类设计

要求: 设计一个DEM类,包括记录DEM的原点坐标、DEM格网间距、DEM格网大小、DEM高程等基本属性(DEM的格式如下表所示)。
DSAA
nx ny
nx is the integer number of grid lines along the X axis (columns)
ny is the integer number of grid lines along the Y axis (rows)
xlo xhi
xlo is the minimum X value of the grid
xhi is the maximum X value of the grid
ylo yhi
ylo is the minimum Y value of the grid
yhi is the maximum Y value of the grid
zlo zhi
zlo is the minimum Z value of the grid
zhi is the maximum Z value of the grid
grid row 1
grid row 2
grid row 3
these are the rows of Z values of the grid, organized in row order. Each row has a constant Y coordinate. Grid row 1 corresponds to ylo and the last grid row corresponds to yhi. Within each row, the Z values are arranged from xlo to xhi.

DSAA
10 10
0.0 9.0
0.0 7.0
25.00 97.19
91.03 77.21 60.55 46.67 52.73 64.05 41.19 54.99 44.30 25.00
96.04 81.10 62.38 48.74 57.50 63.27 48.67 60.81 51.78 33.63
92.10 85.05 65.09 53.01 64.44 65.64 52.53 66.54 59.29 41.33
94.04 85.63 65.56 55.32 73.18 70.88 55.35 76.27 67.20 45.78
97.19 82.00 64.21 61.97 82.99 80.34 58.55 86.28 75.02 48.75
91.36 78.73 64.05 65.60 82.58 81.37 61.16 89.09 81.36 54.87
86.31 77.58 67.71 68.50 73.37 74.84 65.35 95.55 85.92 55.76
80.88 75.56 74.35 72.47 66.93 75.49 86.39 92.10 84.41 55.00
74.77 66.02 70.29 75.16 60.56 65.56 85.07 89.81 74.53 51.69
70.00 54.19 62.27 74.51 55.95 55.42 71.21 74.63 63.14 44.99

2.设计最小二乘配置的点云格网DEM内插程序。

基于设计的DEM类,要求读入给定格式的点云数据,把剔除粗差后的点云写入到给定的文件中,再利用剔除粗差后的点内插一个均匀格网的DEM。

三、设计与实现

3.1类的设计

3.2控件按钮及其属性


3.3主要代码

这里仅展示涉及到相关系数法相关功能的代码。

3.3.1文件:< CDem.h >

#pragma once
#include "C_points.h"
/***************************************************************************
类:CDem
作用:封装最小二乘DEM制作操作函数,仅储存按钮操作功能,调用txt
Welcome to my Github and my CSDN blog , more information will be available about the project!
Github:https://github.com/Yiqingde
CSDN Blog:https://me.csdn.net/weixin_42348202
历史:**日期**         **理由**            **签名**2019年10月26日        创建             ***
/**************************************************************************/
class CDem
{C_points *p;//数据对象,一维数组int allpoints;//所有点//定义行列数int nx;//行号int ny;//列号double width;//分辨率1 或3double dists;//距离//定义六个变量用来储存最大最小值double xlo;double xhi;double ylo;double yhi;double zlo;double zhi;
public:CDem();~CDem();int Div(const CString strLine, char split, CStringArray &strArray);//字符串分割函数void findpoints(int x, int y, int size, C_points *d);//寻点void convertxy2id(double x, double y, int &tempr, int &tempc, int &id);//转换IDint convertcr2id(int tempr, int tempc);//转换IDvoid convertid2rc(int id, int&rr, int &cc);//转换IDdouble dist(double x, double y, double x2, double y2);//计算距离double truedist2(double x, double y, double x2, double y2);//计算距离double workout(int rr, int cc, Mat X_six);//最小二乘矩阵bool readDem();//读取dem数据void search();//搜索函数void out();//输出1void out2();//输出2void out3();//输出3void getcolor1(Mat &f);//渐变颜色函数,矩阵void returncolor(double &a, double &b, double &c, double zz, double min, double max, Mat color);//得到颜色void BeatifulDem();//进行最后的Dem美化,去除噪声void main();//主函数
};

3.3.2文件:< CMatchingImg.cpp >

#include "stdafx.h"
#include "CDem.h"
typedef struct tagDIRECTION
{int x_offset;int y_offset;
}DIRECTION;DIRECTION direction_8[] = { {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1} };
//DIRECTION direction_4[] = { {0, -1},{0, 1} ,{-1, 0}, {1, 0}};
CDem::CDem()
{this->xlo = 9999999;this->ylo = 9999999;this->zlo = 9999999;this->xhi = 0;this->yhi = 0;this->zhi = 0;width = 3;dists = 10;
}CDem::~CDem()
{if (p != NULL){delete[] p;}
}/***************************************************************************
函数:getcolor1(Mat &f)
作用:颜色代码
参数:Mat &f 颜色矩阵 浮点数0-1
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void CDem::getcolor1(Mat &f)
{f.create(64, 3, CV_64FC1);double temp_1 = 0.5625;for (int i = 0; i < 8 ;i++){f.at<double>(i, 0) = 0;f.at<double>(i, 1) = 0;f.at<double>(i, 2) = temp_1;temp_1 += 0.0625;}temp_1 = 0.0625;for (int i = 8; i < 24; i++){f.at<double>(i, 0) = 0;f.at<double>(i, 1) = temp_1;f.at<double>(i, 2) = 1;temp_1 += 0.0625;}temp_1 = 0.0625;for (int i = 24;  i < 40;i++){f.at<double>(i, 0) = temp_1;f.at<double>(i, 1) = 1;f.at<double>(i, 2) = 1-temp_1;temp_1 += 0.0625;}temp_1 = 0.9375;for (int i = 40; i < 55; i++){f.at<double>(i, 0) = 1;f.at<double>(i, 1) = temp_1;f.at<double>(i, 2) = 0;temp_1 -= 0.0625;}temp_1 = 1;for (int i = 55; i < 64;i++){f.at<double>(i, 0) = temp_1;f.at<double>(i, 1) = 0;f.at<double>(i, 2) = 0;temp_1 -= 0.0625;}
}/***************************************************************************
函数:returncolor(double &a, double &b, double &c, double zz, double min, double max,Mat color)
作用:由颜色矩阵获得rgb颜色,根据最大值最小值
参数:double &a  返回rgb中adouble &b  返回rgb中bdouble &c  返回rgb中cdouble zz  依据该值上色double min 最小值double max 最大值Mat color 颜色矩阵
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void CDem::returncolor(double &a, double &b, double &c, double zz, double min, double max,Mat color)
{int t = (zz - min) * 64 / (max - min);t = t < 0 ? 0 : t;t = t > 64 ? 64 : t;a = color.at<double>(t, 0);b = color.at<double>(t, 1);c = color.at<double>(t, 2);
}//***********************************
//字符分割函数
//***********************************
int CDem::Div(const CString strLine, char split, CStringArray &strArray)
{strArray.RemoveAll();//自带清空属性CString temp = strLine;int tag = 0;while (1){tag = temp.Find(split);if (tag >= 0){strArray.Add(temp.Left(tag));temp = temp.Right(temp.GetLength() - tag - 1);}else { break; }}strArray.Add(temp);return strArray.GetSize();
}/***************************************************************************
函数:convertcr2id(int tempr, int tempc)
作用:输入行号列号返回 id
参数:int temprint tempc
返回值:int 一维数组得id号
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
int CDem::convertcr2id(int tempr, int tempc)
{int id = (tempr - 1)*ny + tempc - 1;return id;
}/***************************************************************************
函数:convertid2rc(int id, int&rr, int &cc)
作用:输入id 解求行列号
参数:int id  id号int &rr  行列号int &cc  行列号
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void CDem::convertid2rc(int id, int &rr, int &cc)
{double temp = double(id + 1) - 0.05;rr = (int(temp) / ny) + 1;cc = id + 1 - (rr - 1) *ny;
}/***************************************************************************
函数:convertxy2id(double x, double y, int &tempr, int &tempc, int &id)
作用:输入xy   返回 解求行列号及id 塞入数组时使用
参数:double x x值double y y值int &tempr  行号int &tempc  列号int &id  id
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void CDem::convertxy2id(double x, double y, int &tempr, int &tempc, int &id)
{tempr = int((x - xlo-0.001) / width) + 1;tempc = int((y - ylo-0.001) / width) + 1;id=convertcr2id(tempr, tempc);
}/***************************************************************************
函数:dist(double x, double y, double x2, double y2)
作用:求取距离
参数:double x 真xyz值double y 真xyz值double x2 格网点的行列号double y2 格网点的行列号
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
double CDem::dist(double x, double y, double x2, double y2)
{x2= (x2 - 1)*width + xlo;y2= (y2 - 1)*width + ylo;double distance = sqrt((x - x2)*(x - x2) + (y - y2)*(y - y2));return distance;
}/***************************************************************************
函数:dist(double x, double y, double x2, double y2)
作用:求取距离的平方
参数:double x 真xyz值double y 真xyz值double x2 真xyz值double y2 真xyz值
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
double CDem::truedist2(double x, double y, double x2, double y2)
{double distance = (x - x2)*(x - x2) + (y - y2)*(y - y2);return distance;
}/***************************************************************************
函数:readDem()
作用:读取Dem数据 存入p中
参数:无
返回值:bool 读1 非0
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
bool CDem::readDem()//读取dem数据
{CFileDialog dlgFile(TRUE, _T("txt"), NULL,OFN_ALLOWMULTISELECT | OFN_EXPLORER,//_T("(文本文件)|*.txt"));_T(""));if (dlgFile.DoModal() == IDCANCEL) return 0;CString strName = dlgFile.GetPathName();//获取打开文件文件名(路径)setlocale(LC_ALL, "");CStdioFile sf;if (!sf.Open(strName, CFile::modeRead)) return 0;//打开strName文件路径中的内容CString strLine;CString strContent;//接受内容字符串CStringArray array;//供下文分割使用strContent.Empty();//strContent中内容清空//开始读数据 BOOL bEOF = sf.ReadString(strLine);//第一行if (bEOF == 0) { AfxMessageBox(_T("空数据")); return 0; }allpoints = _ttoi(strLine);vector<Point3d> int_points_xyz;vector<Point3i> int_points_rgb;for (int i = 0; i < allpoints; i++){bEOF = sf.ReadString(strLine);if (bEOF == 0) { AfxMessageBox(_T("数据不规范")); return 0; }int n = Div(strLine, ' ', array);if (n < 3) { AfxMessageBox(_T("数据缺失")); return 0; }C_points temp;temp.addxyz(int_points_xyz, _tstof(array[0]), _tstof(array[1]), _tstof(array[2]));temp.addrgb(int_points_rgb, _ttoi(array[3]), _ttoi(array[4]), _ttoi(array[5]));xlo = (xlo < _tstof(array[0])) ? xlo : _tstof(array[0]);xhi = (xhi > _tstof(array[0])) ? xhi : _tstof(array[0]);ylo = (ylo < _tstof(array[1])) ? ylo : _tstof(array[1]);yhi = (yhi > _tstof(array[1])) ? yhi : _tstof(array[1]);zlo = (zlo < _tstof(array[2])) ? zlo : _tstof(array[2]);zhi = (zhi > _tstof(array[2])) ? zhi : _tstof(array[2]);}//进行行和列的初始化if (allpoints > 100000) { width = 1; }const int r = (xhi - xlo ) / width+1;//行数 是x决定const int c = (yhi - ylo ) / width+1;//列数nx = r;ny = c;p = new C_points[r*c];//定义的一维数组 for (int i = 0; i < allpoints; i++){int tempr, tempc,  idd = 0;convertxy2id(int_points_xyz.at(i).x, int_points_xyz.at(i).y, tempr, tempc, idd);p[idd].add_int(tempr, tempc, int_points_xyz.at(i).x, int_points_xyz.at(i).y, int_points_xyz.at(i).z, int_points_rgb.at(i).x, int_points_rgb.at(i).y, int_points_rgb.at(i).z);}for (int i = 0; i < r*c; i++){int temp_r, temp_c;convertid2rc(i, temp_r, temp_c);p[i].row = temp_r;p[i].col = temp_c;}return 1;
}/***************************************************************************
函数:findpoints(int x, int y, int size, C_points *d)
作用:寻找点位,存入d对象成员的mat矩阵
参数:int x 输入行号int y 输入列号int size 窗口大小C_points *d 即对象
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void  CDem::findpoints(int x, int y, int size, C_points *d)
{int halfsize = size / 2;for (int i = -halfsize; i < size; i++){for (int j =-halfsize; j < size; j++){//窗口出界则跳过if (convertcr2id(x + i, y + j) > 0 && convertcr2id(x + i, y + j) < nx*ny&&(x+i)>0&& (x + i) <=nx&& (y + i) > 0 && (y + i) <= ny){//判断该点是否有元素if (d[convertcr2id(x + i, y + j)].sizee != 0){for (int ii = 0; ii < d[convertcr2id(x + i, y + j)].sizee; ii++){//自适应增大窗口double temp = dist(d[convertcr2id(x + i, y + j)].xyz.at(ii).x, d[convertcr2id(x + i, y + j)].xyz.at(ii).y,x,y);if (temp < size*5){d[convertcr2id(x, y)].X_six.at<double>(d[convertcr2id(x, y)].sizeee, 0) = d[convertcr2id(x + i, y + j)].xyz.at(ii).x;d[convertcr2id(x, y)].X_six.at<double>(d[convertcr2id(x, y)].sizeee, 1) = d[convertcr2id(x + i, y + j)].xyz.at(ii).y;d[convertcr2id(x, y)].X_six.at<double>(d[convertcr2id(x, y)].sizeee, 2) = d[convertcr2id(x + i, y + j)].xyz.at(ii).z;d[convertcr2id(x, y)].X_six.at<double>(d[convertcr2id(x, y)].sizeee, 3) = 1;d[convertcr2id(x, y)].rgb_r = d[convertcr2id(x + i, y + j)].rgb.at(ii).x;d[convertcr2id(x, y)].rgb_g = d[convertcr2id(x + i, y + j)].rgb.at(ii).y;d[convertcr2id(x, y)].rgb_b = d[convertcr2id(x + i, y + j)].rgb.at(ii).z;d[convertcr2id(x, y)].sizeee++;}if (d[convertcr2id(x, y)].sizeee == 6) { return; }}}}}}
}/***************************************************************************
函数:workout(int rr, int cc, Mat X_six)
作用:最小二乘算法
参数:int rr 行号int cc 列号Mat X_six 矩阵
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
double CDem::workout(int rr, int cc, Mat X_six)
{Mat X_six_clone;//将矩阵复制X_six_clone = X_six.clone();   if (p[convertcr2id(rr, cc)].sizeee ==6){//局部中心化double x_center = 0;double y_center = 0;for (int i = 0; i < X_six_clone.rows; i++){x_center += X_six_clone.at<double>(i, 0);y_center += X_six_clone.at<double>(i, 1);}x_center = x_center / X_six_clone.rows;y_center = y_center / X_six_clone.rows;for (int i = 0; i < X_six_clone.rows; i++){X_six_clone.at<double>(i, 0) = X_six_clone.at<double>(i, 0) - x_center;X_six_clone.at<double>(i, 1) = X_six_clone.at<double>(i, 1) - y_center;}Mat M=Mat::zeros(X_six_clone.rows,6, X_six_clone.type());Mat Z=Mat::zeros(X_six_clone.rows,1, X_six_clone.type());Mat P=Mat::zeros(X_six_clone.rows,6, X_six_clone.type());for (int i = 0; i < M.rows; i++){M.at<double>(i, 0) = X_six_clone.at<double>(i, 0)*X_six_clone.at<double>(i, 0);M.at<double>(i, 1) = X_six_clone.at<double>(i, 0)*X_six_clone.at<double>(i, 1);M.at<double>(i, 2) = X_six_clone.at<double>(i, 1)*X_six_clone.at<double>(i, 1);M.at<double>(i, 3) = X_six_clone.at<double>(i, 0);M.at<double>(i, 4) = X_six_clone.at<double>(i, 1);M.at<double>(i, 5) = 1;Z.at<double>(i, 0) = X_six_clone.at<double>(i, 2);P.at<double>(i, i) = 1/truedist2(X_six_clone.at<double>(i, 0), X_six_clone.at<double>(i, 1), x_center, y_center);}Mat X = (M.t()*M).inv()*M.t()*Z;//最小二乘解求double f = X.at<double>(5, 0);//对于明显错误的进行加权算法if (f < zlo || f > zhi){double sum = 0;double f = 0;for (int j = 0; j < p[convertcr2id(rr, cc)].sizeee; j++){sum += X_six.at<double>(j, 3);}for (int j = 0; j < p[convertcr2id(rr, cc)].sizeee; j++){f += X_six.at<double>(j, 3)*X_six.at<double>(j, 2);}return f / sum;}//滤波return f;}
}/***************************************************************************
函数:search()
作用:搜索解求
参数:
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void CDem::search()
{for (int i = 0; i < nx*ny; i++){int rr = 0;int cc = 0;convertid2rc(i, rr, cc);//由id得行和列int ddsize = 4;//其实窗口4*4while (1){findpoints(rr, cc,ddsize, p);ddsize += 4;//找不到6个点,窗口依次增加4if (p[i].sizeee == 6) { break; }//找到即撤}p[i].zz = workout(rr, cc, p[i].X_six);//解求}
}/***************************************************************************
函数:out()
作用:输出Dem.grd.txt
参数:
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void CDem::out()
{//输出至txt中CStdioFile SF;CString strLine;CString strOut;setlocale(LC_ALL, "");if (!SF.Open(_T("Dem.grd"), CFile::modeCreate | CFile::modeWrite)) return;strLine.Format(_T("%s\n%d %d\n%f %f\n%f %f\n%f %f\n"),"DSAA",nx, ny,xlo, xhi,ylo, yhi,zlo, zhi);strOut += strLine;for (int j = 1; j <= ny; j++){for (int i = 1; i <= nx; i++){strLine.Format(_T("%.4f "), p[convertcr2id(i, j)].zz);strOut += strLine;}}SF.WriteString(strOut);SF.Close();AfxMessageBox(_T("成功!已输入至“Dem.grd 、DemDataforCloudCompare_2color.txt、DemPecessForDebug.txt”中(在MFC工作路径)"));
}/***************************************************************************
函数:out2()
作用:输出DemDataforCloudCompare_2color.txt,可用DemDataforCloudCompare_2color
打开两种颜色,一种渐变,一种真实
参数:
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void CDem::out2()
{CStdioFile SF;CString strLine;CString strOut;setlocale(LC_ALL, "");if (!SF.Open(_T("DemDataforCloudCompare_2color.txt"), CFile::modeCreate | CFile::modeWrite)) return;Mat colormap;getcolor1(colormap);for (int i = 0; i < (nx*ny); i++){int cc = 0; int rr = 0;convertid2rc(i, rr, cc);int i2 = convertcr2id(rr, cc);double x_center = (rr - 1)*width + xlo;double y_center = (cc - 1)*width + ylo;double a;double b;double c;returncolor(a, b, c, p[i].zz,zlo,zhi,colormap);strOut += strLine;strLine.Format(_T("%.8f %.8f %.8f %f %f %f %d %d %d\n"),x_center, y_center, p[i].zz,a,b,c, p[i].rgb_r, p[i].rgb_g, p[i].rgb_b);strOut += strLine;}SF.WriteString(strOut);SF.Close();
}/***************************************************************************
函数:out3()
作用:输出DemPecessForDebug.txt
参数:
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void CDem::out3()
{CStdioFile SF;CString strLine;CString strOut;setlocale(LC_ALL, "");if (!SF.Open(_T("DemPecessForDebug.txt"), CFile::modeCreate | CFile::modeWrite)) return;for (int i = 0; i < (nx*ny); i++){int cc = 0; int rr = 0;convertid2rc(i, rr, cc);int i2 = convertcr2id(rr, cc);double x_center = (rr - 1)*width + xlo;double y_center = (cc - 1)*width + ylo;strOut += strLine;strLine.Format(_T("%.8f %.8f %.8f \n"),x_center, y_center, p[i].zz);strOut += strLine;for (int j = 0; j < p[i].sizeee; j++){int rr = 0;int cc = 0;int iddd = 0;convertxy2id(p[i].X_six.at<double>(j, 0), p[i].X_six.at<double>(j, 1), rr, cc, iddd);double sd = p[i].X_six.at<double>(j, 2);strLine.Format(_T("%.8f %.8f %.8f %d %d %d \n"),p[i].X_six.at<double>(j, 0), p[i].X_six.at<double>(j, 1), p[i].X_six.at<double>(j, 2), rr, cc, iddd);strOut += strLine;}strLine.Format(_T("\n"));}strOut += strLine;SF.WriteString(strOut);SF.Close();
}/***************************************************************************
函数:BeatifulDem()
作用:除噪
参数:
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void CDem::BeatifulDem()
{for (int i = 1; i <= nx; i++){for (int j = 1; j <= ny; j++){int tag = 5;if (convertcr2id(i + tag, j) > 0 && convertcr2id(i - tag, j) > 0 && convertcr2id(i, j + tag) > 0 && convertcr2id(i, j - tag) > 0){if (convertcr2id(i + tag, j) < nx*ny && convertcr2id(i - tag, j) < nx*ny  && convertcr2id(i, j + tag) < nx*ny  && convertcr2id(i, j - tag) < nx*ny){double temp1 = fabs(p[convertcr2id(i, j)].zz - p[convertcr2id(i + tag, j)].zz);double temp2 = fabs(p[convertcr2id(i, j)].zz - p[convertcr2id(i - tag, j)].zz);double temp3 = fabs(p[convertcr2id(i, j)].zz - p[convertcr2id(i, j + tag)].zz);double temp4 = fabs(p[convertcr2id(i, j)].zz - p[convertcr2id(i, j - tag)].zz);double Dist = 5;double ff =  p[convertcr2id(i + tag, j)].zz+ p[convertcr2id(i - tag, j)].zz+ p[convertcr2id(i, j + tag)].zz+ p[convertcr2id(i, j - tag)].zz;if (temp1 > Dist&&temp2 > Dist&&temp3 > Dist&&temp4 > Dist){p[convertcr2id(i, j)].zz = ff/4;}}}}}for (int i = 1; i <= nx; i++){for (int j = 1; j <= ny; j++){int tag = 5;if (i <= tag || i > nx - tag || j <= tag || j > ny - tag){int t = (i - tag) > 0 ? (i - tag) : (i + tag);int t2 = (j - tag) > 0 ? (j - tag) : (j + tag);p[convertcr2id(i, j)].zz = p[convertcr2id(t, t2)].zz;}}}
}
/***************************************************************************
函数:main()
作用:主函数
参数:
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void CDem::main()
{bool tagger=readDem();//读取数据if (tagger == 0) { return; }search();//搜索BeatifulDem();//除噪out2();//输出out3();//输出out();//输出
}

3.3.3文件: < C_points.h >

#pragma once
/***************************************************************************
类:C_points
作用:存储格网点的元素
Welcome to my Github and my CSDN blog , more information will be available about the project!
Github:https://github.com/Yiqingde
CSDN Blog:https://me.csdn.net/weixin_42348202
历史:**日期**         **理由**            **签名**2019年10月26日        创建             ***
/**************************************************************************/
#include <opencv2/opencv.hpp>
#include <vector>
#include <opencv2/flann/miniflann.hpp>
using namespace cv;
using namespace std;
class C_points
{public:C_points();~C_points();int row;//row指的是行号  xint col;//col指的是列号  ydouble zz;//高程int rgb_r;//颜色int rgb_g;int rgb_b;vector<Point3d> xyz;//高程vector<Point3i> rgb;//颜色int sizeee;//用来给X_six计数int sizee;//vector的大小Mat X_six;//存储最小二乘需要的数据void addxyz(vector<Point3d> &xyz, double x, double y, double z);//加xyzvoid addrgb(vector<Point3i> &rgb, int r, int g, int b);//加颜色void add_int(double r, double c, double x, double y, double z, int r2, int g, int b);//加初始值
};

3.3.4文件: < C_points.cpp >

#include "stdafx.h"
#include "C_points.h"C_points::C_points()
{tag = 0;sizee=0;sizeee = 0;X_six.create(6, 4, CV_64FC1);rgb_r = 0;rgb_g = 0;rgb_b = 0;
}C_points::~C_points()
{}
/***************************************************************************
函数:addxyz(vector<Point3d> &xyz, double x, double y, double z)
作用:xyz写入vector
参数:vector<Point3d> &xyz 存入vector数组double x x值double y y值double z z值
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void C_points::addxyz(vector<Point3d> &xyz, double x, double y, double z)
{Point3d temp;temp.x = x;temp.y = y;temp.z = z;sizee++;xyz.push_back(temp);
}
/***************************************************************************
函数:addrgb(vector<Point3i> &rgb, int r, int g, int b)
作用:rgb写入vector
参数:vector<Point3i> &rgb 存入vector数组int rint gint b
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void C_points::addrgb(vector<Point3i> &rgb, int r, int g, int b)
{Point3i temp;temp.x = r;temp.y = g;temp.z = b;rgb.push_back(temp);
}
/***************************************************************************
函数:add_int(double r, double c, double x, double y, double z, int r2, int g, int b)
作用:写入综合函数
参数:double r 行号double c 列号double x x值double y y值int r2 rgb的r2int g  rgb的bint b  rgb的b
返回值:无
历史:**日期**         **理由**            **签名**2019年10月27日        创建             ***
/**************************************************************************/
void C_points::add_int(double r, double c, double x, double y, double z, int r2, int g, int b)
{row = r;col = c;addxyz(xyz, x, y, z);addrgb(rgb, r2, g, b);
}

3.3.5文件: < CBasic.cpp >(仅展示部分)

/***************************************************************************
函数:Button_DEM()
作用:DEM按钮
参数:无
返回值:无
历史:**日期**         **理由**            **签名**2019年10月6日        创建             ***
/**************************************************************************/
void CBasic::Button_DEM()
{CDem t;t.main();
}

3.3.6文件: < ZRX0107170110Dlg.cpp >(仅展示部分)

void CZRX0107170110Dlg::OnBnClickedread7()
{// TODO: 在此添加控件通知处理程序代码CBasic tt;tt.Button_DEM();
}

3.4运行结果

3.4.1采用uav1m.txt





3.4.2采用uav3m.txt




代码虽多不要贪杯~

数字高程模型内插 opencv C++ CSU相关推荐

  1. 实现移动曲面拟合法的数字高程模型内插,数据格式X、Y、Z,数据量大,使用C++语言实现...

    移动曲面拟合法是一种数字高程模型的内插方法,用于在有限的测量点数据基础上建立数字高程模型. 在使用 C 语言实现移动曲面拟合法的数字高程模型内插时,需要先将数据存储到数组中,其中数组 X 存储着横坐标 ...

  2. 测绘-编写数字高程模型(DEM)内插程序

    一. 实习目的 掌握移动曲面法数字高程模型内插原理及其内插子程序的设计方法,了解其它逐点高程内插方法的基本原理. 二. 实习内容 根据提供的10个数据点的坐标(Xn,Yn,Zn)和待求点的平面坐标(X ...

  3. 【合辑】数字高程模型科普

    [合辑]数字高程模型科普 文章目录 一.数字高程模型的提出.演变.重要性及定义 二.DEM的重要性 三.DEM的主要采集方式 3.1 摄影测量方法 3.2 合成孔径雷达干涉测量方法 3.3 机载激光扫 ...

  4. 山科大数字高程模型(朱红春版)复习 2021

    数字高程模型(朱红春版)复习 2021 19-3 DSH,CBW 2021年遥感系数字高程模型考试,这个去年(2020年)疫情期间的题目,附参考答案,仅代表编写者个人观点,不及格概不负责. 附CBW整 ...

  5. 数据解惑 · 带你认识数字高程模型(DEM)

    01 什么是DEM? 数字高程模型(Digital Elevation Model),简称DEM,是用一组有序数值阵列形式表示地面高程起伏形态的一种实体地面模型.DEM数据在测绘.气象.地质.军事.土 ...

  6. 基于c#的相关性分析_基于数字高程模型的城市地貌与地名相关性分析——以兰州市为例...

    江西地名研究 基于数字高程模型的城市地貌与地名 相关性分析--以兰州市为例 文/张鹏丽,李育 提要:以兰州市为例,使用 ASTER 30米分辨率的数字高程模型DEM并提取了兰州市周边所有地名信息:通过 ...

  7. 倾斜摄影三维模型、激光点云、正射影像、数字高程模型如何实现在线浏览?

    四维轻云是成都远石技术团队基于浏览器打造的一款地理空间数据管理云平台,可实现TB级大规模倾斜摄影三维模型发布管理,并支持私有化部署和高阶功能定制化开发. 1.注册登录 首先在四维轻云官网点击「立即试用 ...

  8. 数字高程模型(DEM)—知识汇总

    数字高程的定义 数字高程模型(Digital Elevation Model,简称DEM)是DTM中最基本的部分,它是对地球表面地形地貌的一种离散的数学表达.DEM表示区域D上的三维向量有限序列,用函 ...

  9. 全球数字高程模型(数据)

    数据是GIS的"血液",矢量和影像数据在网上很多,但高程数据却很有限.很多三维GIS的从业人员经常为找不到合适的高程数据而苦恼,小编整理了一些高程数据下载渠道分享给大家. SRTM ...

  10. 常见的数字高程模型结构有哪些?

    常见的数字高程模型DEM结构有哪些? 数字高程模型结构包括:规则格网DEM数据结构.不规则三角网DEM数据结构.格网与不规则三角网结构混合结构. 规则格网DEM数据结构 (1)简单矩阵结构:数据在水平 ...

最新文章

  1. js判断手机浏览器屏幕方向
  2. zookeeper代码浅析
  3. DSDT亮度修复失败
  4. 安卓逆向工具apkide安装
  5. Logstash同步mysql一对多数据到ES(踩坑日记系列)
  6. linux 函数手册 在线,Linux系统API函数手册
  7. web developer tips (55):多项目解决方案中设置启动项
  8. 滑动窗口法LeetCode
  9. PyTorch绘制训练过程的accuracy和loss曲线
  10. Excel转PDF方法
  11. 链家广州二手房的数据与分析——数据分析1
  12. Linux之USB无线网卡开发(二)
  13. 冒泡排序的交换次数 (树状数组)
  14. linux挂载4T及以上硬盘
  15. docker-部署lnmp
  16. 统计cassandra单表数据量
  17. 一周IT歪评丨清北BAT落户雄安新区/刘强东穿9块钱大裤衩/青少年沉迷王者日本称不惧怕中国
  18. 软著申请具体需要哪些步骤呢?
  19. linux加硬盘方法,linux系统添加硬盘方法
  20. 【计算机系统1 】1 LC-3仿真器安装和使用

热门文章

  1. mangodb和php比较,php-mongodb从不同的数据库中选择
  2. ssm项目的maven-pom.xml
  3. zynq跑linux所需内存大小,Zynq-Linux移植学习笔记之33-CMA连续物理内存配置
  4. oracle esb 灾备,两地三中心双活系统灾备切换场景和数据补录问题?
  5. 域名解析到指定端口_南京课工场IT培训:搭建nginx虚拟主机——基于域名、端口和IP...
  6. raid5用户mbr还是gpt_系统硬盘gpt转换的操作方法
  7. vue-awesome-swiper:依赖于6.X版本Swiper时轮播分页器下方小圆点不显示
  8. SQL:postgresql中st_union合并多条geom数据
  9. 彻底搞懂使用MyBatis时为什么Dao层不需要@Repository
  10. bootstrap select2 动态从后台Ajax动态获取数据