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

承接实验三

实验配置 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 或3
	double 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);//转换ID
	int convertcr2id(int tempr, int tempc);//转换ID
	void convertid2rc(int id, int&rr, int &cc);//转换ID
	double 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();//输出1
	void out2();//输出2
	void out3();//输出3
	void 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中a
      double &b  返回rgb中b
	  double &c  返回rgb中c
	  double 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值