The first learning season (4.24-5.7)

The goals for this season are:

1. Improve the Qt software (can be directly experimented)

2. Basic understanding of the process of active and passive remote sensing classification and deep learning, and understand the benchmark model

3. Finish reading 10 papers (at least five in English)

On the first day, 4.24 Monday, the hierarchical clustering algorithm and the settings in ArcGIS will display the results

1. Hierarchical clustering algorithm

For clustering trunks (similar to single tree segmentation)

step:

1) Find a point p10 in the space, use kdTree to find n points closest to it, and judge the distance from these n points to p. Put the points p12, p13, p14... whose distance is less than the threshold r into the class Q

2) Find a little p12 in the interval where Q removes p10, repeat 1

3) Remove p10, p12 in Q to find a point, repeat 1, find p22, p23, p24...all put into Q

4) When Q can no longer have new points added, the search is completed

#include <pcl/ModelCoefficients.h>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/features/normal_3d.h>
#include <pcl/kdtree/kdtree.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/segmentation/extract_clusters.h>
#include<pcl/visualization/pcl_visualizer.h>
#include <stdlib.h>
#include <time.h>

using namespace std;

//定义一个表示颜色的三维矢量结构体
struct vecrgb
{
	double r;
	double g;
	double b;
};

int main(int argc, char** argv)
{
	// 读取点云数据
	pcl::PCDReader reader;
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	reader.read("重叠点云2_cut1.pcd", *cloud);

	// KdTree的搜索方式
	pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
	tree->setInputCloud(cloud);

	//聚类点集的索引
	//存储单个独立的聚类
	std::vector<pcl::PointIndices> cluster_indices;

	// 欧几里德聚类提取及参数设计
	pcl::EuclideanClusterExtraction<pcl::PointXYZ> ec;
	ec.setClusterTolerance(0.4); // 设置空间聚类的距离0.5米  距离在0.4米以内的点将被聚类在一起。当两个点之间的距离大于0.4米时,它们将被视为不同的聚类。
	ec.setMinClusterSize(35);  // 设置有效聚类包含的最小的个数
	ec.setMaxClusterSize(200);  // 设置有效聚类包含的最大的个数
	ec.setSearchMethod(tree);  // 设置搜索方法
	ec.setInputCloud(cloud);	//设置输入点云
	ec.extract(cluster_indices);  // 获取切割之后的聚类索引保存到cluster_indices

	// 获取每个聚类的索引个数
	int j = 0;
	int r, g, b = 0;
	for (int it = 0; it < cluster_indices.size(); it++)
	{
		//逐个点集赋色
	/*	srand(time(NULL));*/ //这句话也不能加,加了颜色就都一样了
		r = rand() % 255;
		g = rand() % 255;
		b = rand() % 255;

		//使用ptr定义一个智能指针,方便内存管理
		//智能指针确保为点云对象分配的内存得到适当的管理,当最后一个引用被删除时,该对象会被自动删除。
		//"new "操作符被用来为点云对象分配内存,并且该对象的构造函数被调用,没有参数,创建一个没有点的空点云。
		pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_cluster(new pcl::PointCloud<pcl::PointXYZRGB>);
		for (int pit = 0; pit < cluster_indices[it].indices.size(); pit++)
		{
			pcl::PointXYZRGB point;
			//存储每个聚类之后的点的坐标和颜色
			point.x = cloud->points[cluster_indices[it].indices[pit]].x;
			point.y = cloud->points[cluster_indices[it].indices[pit]].y;
			point.z = cloud->points[cluster_indices[it].indices[pit]].z;
			point.r = r;
			point.g = g;
			point.b = b;
			cloud_cluster->points.push_back(point);
		}
		//这三句话是必须写的,否则点云输出时pcl::io::savePCDFileASCII(ss.str(), *cloud_cluster);会报错
		cloud_cluster->width = cloud_cluster->points.size(); 
		//cloud_cluster->width被设置为当前簇中的点的数量,这是用pcl::PointCloud对象的point成员的size()方法得到的。
		cloud_cluster->height = 1;
		//cloud_cluster->height被设置为1,表示该点云代表单行的点。
		cloud_cluster->is_dense = true;
		//cloud_cluster->is_dense被设置为true,这意味着该点云不包含无效或NaN(非数字)值。
		// 当点云被写入磁盘或用于下游处理步骤时,这些属性很重要。通过设置宽度和高度属性,点云可以被其他软件工具正确解释。
		// 而通过设置is_dense为true,可以清楚地看到点云中没有丢失或无效的值。
		cout << "PointCloud representing the Cluster: " << cloud_cluster->points.size() << " data points." << endl;

		//点云多次输出
		std::stringstream ss;
		//std::stringstream ss创建一个名为ss的新字符串流对象。
		ss << "聚类结果_" << j << ".pcd";          //改写成自己的点云写出路径
		pcl::io::savePCDFileASCII(ss.str(), *cloud_cluster);
		j++;
	}
	std::system("pause");//防止控制台窗口一闪而过
	return (0);
}

2. Some understanding of clustering

1) Clustering based on distance only, and there is no requirement for the starting point of clustering, usually called clustering
2) Clustering based on distance, and there are certain requirements for the starting point of clustering, usually called region growth
3) According to various conditions constraints Clustering, and there are certain requirements for the starting point of the clustering, usually called multi-feature constrained growth tips: In the paper, multi-feature constrained growth is used more often, by changing the selection method of the starting point and the constraints of growth as innovation, in Image processing neighborhood This clustering method is also called connectivity analysis, but the image opencvQ uses the two-dimensional horizontal distance between pixels, and the point cloud pcl library uses the three-dimensional space distance between points.

  The settings in ArcGIS will display the results

The next day, 4.25 Tuesday, the error resolution of the QAxObject library << and >>

1. If #include<QAxObject> reports an error, replace it with #include<ActiveQt/QAxObject>

2. Error codes containing the QAxObject library may report errors

1) Unable to open source file QAxObject

Solution: add module

2) Unresolved external symbol:

Solution: 1. In Project -> Properties -> Linker -> Input -> Additional Dependencies

release:Qt5AxContainer.lib;Qt5AxBase.lib

debug:Qt5AxContainerd.lib;Qt5AxBased.lib

2. In Linker -> General -> Additional Libraries

$(QTDIR)\LIB

If not: 3. Add qtmain.lib in Project -> Properties -> Linker -> Input -> Additional Dependencies

3. >> is input << is output

The third day, 4.26 Wednesday, put the external class into its own program

How to put external classes into your own program:

Example: for the excelengine class, sourced from: GitHub - TheThreeDog/ExcelEngine: A Qt-based Excel operation engine that encapsulates some interfaces for operating Excel files, which is more convenient than using QAxObject directly, and the code readability is also better.

 1. Pay attention to the code in the .h file to obtain the object of the singleton mode

2. Add this object to the header file of your main window code

 3. The cpp file should also be added

4. After that, it can be used normally

Fourth day 4.27 Thursday navigation bar (treeWidget) design

1. Set icons and child nodes in the navigation bar

    imageItem1->setIcon(0, QIcon(":/img/1.png"));
    QTreeWidgetItem* imageItem1_1 = new QTreeWidgetItem(imageItem1, QStringList(QString("Band1"))); //子节点1
    imageItem1_1->setIcon(0, QIcon(":/img/1.png"));
    imageItem1->addChild(imageItem1_1); //添加子节点

2. Define the navigation bar of the parent and child nodes

    ui->treeWidget->expandAll(); //结点全部展开
    QStringList l;
    l << QStringLiteral("点位1");
    //第一个参数指向自己,第二个参数必须重载QStringList
    QTreeWidgetItem* pf = new QTreeWidgetItem(ui->treeWidget, l);
    l.clear();
    l << QStringLiteral("东方向位移");
    QTreeWidgetItem* p1 = new QTreeWidgetItem(pf, l);
    //此处必须为pf否则将不会显示父子关系
    l.clear();
    l << QStringLiteral("北方向位移");
    QTreeWidgetItem* p2 = new QTreeWidgetItem(pf, l);
    l.clear();
    l << QStringLiteral("纵向位移");
    QTreeWidgetItem* p3 = new QTreeWidgetItem(pf, l);

    ui->treeWidget->addTopLevelItem(pf);
    pf->addChild(p1);
    pf->addChild(p2);
    pf->addChild(p3);

3. The order of writing C++ code: first write the function definition and member variables in the header file; then write the function definition

4. Classical function analysis: The modification function of the database is often added function rewriting, the core cares about setting a setType function

//设置类型,判断是增加还是修改
void Dlg_AddStu::setType(bool isAdd,stuInfo info)       //如果调用时参数是true,则不用传入info,如果是false,则需要
{
    m_isAdd = isAdd;        //是添加
    m_info = info;          //将形参info转为成员变量m_info,以便该类的其他函数使用

    //把六个属性拿到,写入输入栏中
    ui->le_name->setText(info.name);       
    ui->sp_age->setValue(info.age);
    ui->le_class->setText(QString::number(info.uiclass));
    ui->le_grade->setText(QString::number(info.grade));
    ui->le_phone->setText(info.phone);
    ui->le_wechat->setText(info.Wechat);
}

5. QSqlQuery sql(m_db) statement explanation

The QSqlQuery class in Qt is used, which represents a SQL query operation, and uses a QSqlDatabase object as a parameter of its constructor. The QSqlDatabase object (named "m_db" in this example) is an open database connection that is used to execute SQL query operations.

In this code, the QSqlQuery object is initialized to a variable named "sql", which will use "m_db" as the target database for its SQL query operations. This QSqlQuery object can execute various types of SQL query statements, such as SELECT, INSERT, UPDATE, and DELETE statements, as well as execute stored procedures and functions.

Once the QSqlQuery object is created, it can be used to execute SQL query statements, for example:

sql.exec("SELECT * FROM customers WHERE name LIKE 'John%'");

This example demonstrates how to use the QSqlQuery object to perform a simple SELECT query operation to find customer records whose names begin with "John". In this example, the exec() function of the QSqlQuery object is used to execute the SQL query statement and returns a QSqlQuery object that can be used to access the query results.

The fifth day, 4.28 Friday, optimization of the data table, structure design, and acquisition of the current time

1. SQLite does not support truncate to clear data, you can use delete from table name

2. The creation of the structure is very important in database processing, because the structure can be used as a data type

struct dataInfo
{
    QString GPST;
    QString eb;
    QString nb;
    QString ub;
    QString Q;
    QString ns;
    QString sde;
    QString sdn;
    QString sdu;
    QString sden;
    QString sdnu;
    QString sdue;
    QString age;
    QString ratio;
};

dataInfo info
QList<dataInfo> 
QList<dataInfo> getPagedata(quint32 page, quint32 uiCnt);

3. If your database id column is not self-incrementing and is still null, then set it as the primary key

 4. Solve the problem of error reporting 

Possibility 1: The data in the data table does not match, just modify the database

Possibility 2: The drawing function is executed before the data function, and there is no way to draw a picture based on the data without a data table

5. Get the current time and add it to the timeValues ​​list

        QVector<QDateTime> timeValues;
        timeValues.append(now.addSecs(i * 60));

Sixth day 4.29 Saturday visio/office install ceil function

1.ceil function: used to round up

2. Visio installation:

1) Install visio first and then office 

2) The versions of visio and office must be the same, for example, both are 2016, and one cannot be c2r (click-to-run) and the other is MSI (Windows installer)

3) The digits of visio and office should be the same, for example, both are 64-bit

3.Office can use the school's genuine software management and service platform

Seventh day 4.30 Sunday IDM use

1. Use of IDM proxy server

1) Download - Options - Proxy Server - Click the "Use the settings in the system" button

2) Check the proxy server address and port of the machine

 cmd-type ipconfig or use software

The eighth day 5.1 Monday false color processing

1. Pseudo-color processing: Define each pixel value of the image as an index value or code value, and then look it up in the color lookup table according to it, and get the real color according to the address. This process is called pseudo-color processing, and the resulting image is called a pseudo-color image.

Its significance in hyperspectral object classification:

1) Enhancement of color information: Pseudocolor images usually use color to enhance the visual effect of images, making them more attractive and appealing. The enhancement of color information can be achieved by adding specific colors, adjusting color distribution, and using specific algorithms, so that the image has higher brightness and wider color gamut range.

2) The difference in color information: Pseudo-color images usually only cover a part of the object, while true-color images usually only consider a part of the object, and pseudo-color processing can take the color differences between different objects into account, so as to better Reflect the details and characteristics of objects.

3) Calculation of color information: Pseudo-color processing needs to calculate the color distance between two or more pixels, which can help identify different objects. True-color images usually only consider the color distance between pixels, while pseudo-color processing needs to consider more details and features.

Ninth Day 5.2 Tuesday Three readings on HSI+lidar papers

Today I mainly read three papers on HSI combined with lidar for classification, namely:

1. Comparison of tree species classification combining multiple features + CNN/RF/SVM three methods

2. Use RF's classification of ground features, the basic content is very detailed

3. Land use classification using RF, its content is relatively simple

Tenth day 5.3 Wednesday AM3Net MSI and SAR Analysis of several deep learning methods HSI area CNN types

Today, I mainly read and learned about the construction model and analysis of AM3Net. The core content can be found in the special issue. Other extended knowledge is as follows:

1. Some advantages of MSI and SAR

MSI: Can capture energy scattering and radiation effects of targets at different wavelengths

SAR: Capturing the magnitude and phase characteristics of a specific microblog band target

2. Analysis of several deep learning methods

1) ELM: Forehead Neural Network Algorithm, others are Backpropagation Neural Networks; there are obvious disadvantages

2) EndNet: There are few model parameters, but the learning efficiency is low, and more training times are needed to learn the best model

3) DeepCNN: The network structure of the feature encoding part is simple

4) FusAtNet: Based on a variety of attention mechanism designs, although some data enhancements have been removed, but

5) HRWN: Based on the post-optimization design idea, after obtaining the classification structure of the fusion model, it is necessary to further optimize the classification results through an active learning algorithm based on random walk

3. Advantages of deep learning methods over traditional machine learning methods

Features can be automatically extracted from the input data

4. The difference and usage of three kinds of CNN

1D-CNN single spectral signal

2D-CNN Photo Image

3D-CNN hyperspectral cube/volume data

5. Hyperspectral area:

Visible and near-infrared (VNIR): 400nm to 1000nm [this area is more common]

Short-wave infrared (SWIR): 900nm~2500nm

引自:J. Wang, J. Li, Y. Shi, J. Lai and X. Tan, "AM3Net: Adaptive Mutual-learning-based Multimodal Data Fusion Network," in IEEE Transactions on Circuits and Systems for Video Technology, vol. 32, no. 8, pp. 5411-5426, Aug. 2022, doi: 10.1109/TCSVT.2022.3148257.

The eleventh day, 5.4 Thursday ※The environment configuration of pytorch, the use of visdom, the setup installation method

Today, the environment configuration of pytorch and the use of visdom and the basic method of creating a virtual environment by anaconda are completed:

1. The overall installation steps of the pytorch environment, taking the environment of AM3Net as an example

1. Build a virtual environment, install pytorch (CPU+GPU), and check with code

Among them: the CPU uses the instructions given by the official website, and the GPU uses the wheel to download

Note 1: When verifying python, if there are multiple versions of python in the computer, there may be conflicts and errors. For example, your anaconda is python3, and your computer originally has python2. Then you can directly use the python command in cmd. To python2 in the computer, an error will be reported: Warning: This Python interpreter is in a conda environment, but the environment has not been activated. Libraries may fail to load. To activate this environment please see Managing environments — conda 0.0.0.dev0 + placeholder documentation

Solution: Change the python in the virtual environment directory to python37, run python37, and then change back to python

But it is recommended to use pycharm or Spyder to run and set the environment directly to avoid conflicts

Note 2: You can view and modify the library of the configuration environment in the .condarc file (open with Notepad) under C:\Users\username, such as

 2. To install visdom, first use the command to install, if an error occurs:

PackagesNotFoundError: The following packages are not available from current channels:

  - wisdom

Current channels:- Index of /anaconda/cloud/pytorch/win-64/ | Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror

  - Index of /anaconda/cloud/pytorch/noarch/ | Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror

  - Index of /anaconda/pkgs/free/win-64/ | Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror

  - Index of /anaconda/pkgs/free/noarch/ | Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror

  - Index of /anaconda/pkgs/main/win-64/ | Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror

  - Index of /anaconda/pkgs/main/noarch/ | Tsinghua University Open Source Software Mirror Station | Tsinghua Open Source Mirror

  - main/win-64

  - main/north

  - r/win-64

  - r/noorch

  - msys2/win-64

  - msys2/noarch

To search for alternate channels that may provide the conda package you're

looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.

Solution: Search for the library in    https://anaconda.org    , and then display it according to the method inside; but you need to see the version clearly

Note: the visdom library will bring down a bunch of libraries, don't worry

3. Install MMCV. This library can be installed with setup.py or with instructions, but the latter is recommended. Use: pip install mmcv== 1 . 3 . 1 rc4 -f ( ) https://download.openmmlab. com/mmcv/dist/cu110/torch1.7/index.html

Note: The MMCV library will bring down a bunch of libraries, don't worry

 4. The installation of cupy-cuda110 will also have the same problem as the installation of visdom , and the solution is the same when encountering it

 5. Install numpy, scipy, sklearn (scikit-learn), just use the command directly

Two, visdom-related

1. Solutions to problems that may occur during visdom installation:
1) Modify the server.py file

Find the Anaconda3\Lib\site-packages\visdom\server.py file and comment out the download line

 2) Replace the static folder

download link:

GitHub - fossasia/visdom: A flexible tool for creating, organizing, and sharing visualizations of live, rich data. Supports Torch and Numpy.

Just replace the corresponding folder

2. The startup command of visdom: python -m visdom.server (used in the command line terminal)

3. Verification code:

import visdom
import torch
vis = visdom.Visdom()
x = torch.arange(1,100,0.01)
y=torch.sin(x)
vis.line(X=x, Y=y,win='sinx',opts={'title':'text1'})

Three, setup installation method

For example, when using setup.py to install, an error is reported

ImportError: cannot import name ‘_nt_quote_args‘ from ‘distutils.spawn‘

Solution:

Install setuptools first:

pip install setuptools==59.6.0

Then fully install:

python setup.py install

The twelfth day 5.5 Friday conda basic instructions problem summary mutual conversion between mat format and tif format

1. Several common commands of conda:

1. Create environment: conda create -n name python=3.6 (your conda version)

2. View the existing environment: conda info --envs or conda env list

3. Activate the environment: conda activate name

4. Exit the environment: conda deactivate

5. Delete the environment: conda remove -n name --all

6. View the list of libraries in the environment: conda list

7. Install/uninstall library: conda install/uninstall library name + (URL)/wheel

Note: If in pycharm, 6 and 7 use pip instead of conda

2. Problem summary

1. If the libraries in the virtual environment and the real environment conflict, just remove the one in the real environment

2. If an error is reported

UserWarning: Cannot import torch.fx, `merge_dict` is a simple function to merge multiple dicts

  warnings.warn('Cannot import torch.fx, `merge_dict` is a simple function '

It is because the version of mmcv does not match the version of pytorch. There is no fx in pytorch, but pytorch must be 1.8 or higher to install fx. In fact, there is no big problem. If you want to solve it, you must either reinstall pytorch to an adapted version, or reinstall mmcv to the adapted version, the latter is recommended

3. If an error is reported

UserWarning: Implicit dimension choice for softmax has been deprecated. Change the call to include dim=X as an argument.

  weight_alpha = F.softmax(self.Weight_Alpha)

Solution: This warning message is because in PyTorch, torch.nn.functional.softmaxthe function performs a softmax operation on the last dimension of the input tensor by default. But in some cases, the shape of the input tensor may not be as expected, so PyTorch reminds the user to explicitly specify on which dimension to softmax.

In order to eliminate this warning message, the original code can be changed to:

weight_alpha = F.softmax(self.Weight_Alpha)

Change to:

weight_alpha = F.softmax(self.Weight_Alpha, dim=-1)

Among them, dim=-1it means to perform softmax operation on the last dimension of the tensor. You can also specify other dimensions to operate according to the specific situation.

Guess you like

Origin blog.csdn.net/z377989129/article/details/130367195