关于代币增发复利DAPP模式制度系统开发逻辑分析(原理概念)

简介: 关于代币增发复利DAPP模式制度系统开发逻辑分析(原理概念)

heco生态链 Huobi HECO Chain(HECO)是一个去中心化高效节能公链,也是huo币开放平台推出的产品,在支撑高性能交易得基础上,实现智能合约的兼容,heco链智能合约dapp,案例演示。

我们把关键帧和PnP的结果都封成了结构体,以便将来别的程序调用。这两个函数的实现如下:

  src/slamBase.cpp

1 // computeKeyPointsAndDesp 同时提取关键点与特征描述子
2 void computeKeyPointsAndDesp( FRAME& frame, string detector, string descriptor )
3 {
4 cv::Ptr<cv::FeatureDetector> _detector;
5 cv::Ptr<cv::DescriptorExtractor> _descriptor;
6
7 cv::initModule_nonfree();
8 _detector = cv::FeatureDetector::create( detector.c_str() );
9 _descriptor = cv::DescriptorExtractor::create( descriptor.c_str() );
10
11 if (!_detector || !_descriptor)
12 {
13 cerr<<"Unknown detector or discriptor type !"<<detector<<","<<descriptor<<endl;
14 return;
15 }
16
17 _detector->detect( frame.rgb, frame.kp );
18 _descriptor->compute( frame.rgb, frame.kp, frame.desp );
19
20 return;
21 }
22
23 // estimateMotion 计算两个帧之间的运动
24 // 输入:帧1和帧2
25 // 输出:rvec 和 tvec
26 RESULT_OF_PNP estimateMotion( FRAME& frame1, FRAME& frame2, CAMERA_INTRINSIC_PARAMETERS& camera )
27 {
28 static ParameterReader pd;
29 vector< cv::DMatch > matches;
30 cv::FlannBasedMatcher matcher;
31 matcher.match( frame1.desp, frame2.desp, matches );
32
33 cout<<"find total "<<matches.size()<<" matches."<<endl;
34 vector< cv::DMatch > goodMatches;
35 double minDis = 9999;
36 double good_match_threshold = atof( pd.getData( "good_match_threshold" ).c_str() );
37 for ( size_t i=0; i<matches.size(); i++ )
38 {
39 if ( matches[i].distance < minDis )
40 minDis = matches[i].distance;
41 }
42
43 for ( size_t i=0; i<matches.size(); i++ )
44 {
45 if (matches[i].distance < good_match_threshold*minDis)
46 goodMatches.push_back( matches[i] );
47 }
48
49 cout<<"good matches: "<<goodMatches.size()<<endl;
50 // 第一个帧的三维点
51 vector<cv::Point3f> pts_obj;
52 // 第二个帧的图像点
53 vector< cv::Point2f > pts_img;
54
55 // 相机内参
56 for (size_t i=0; i<goodMatches.size(); i++)
57 {
58 // query 是第一个, train 是第二个
59 cv::Point2f p = frame1.kp[goodMatches[i].queryIdx].pt;
60 // 获取d是要小心!x是向右的,y是向下的,所以y才是行,x是列!
61 ushort d = frame1.depth.ptr( int(p.y) )[ int(p.x) ];
62 if (d == 0)
63 continue;
64 pts_img.push_back( cv::Point2f( frame2.kp[goodMatches[i].trainIdx].pt ) );
65
66 // 将(u,v,d)转成(x,y,z)
67 cv::Point3f pt ( p.x, p.y, d );
68 cv::Point3f pd = point2dTo3d( pt, camera );
69 pts_obj.push_back( pd );
70 }
71
72 double camera_matrix_data3 = {
73 {camera.fx, 0, camera.cx},
74 {0, camera.fy, camera.cy},
75 {0, 0, 1}
76 };
77
78 cout<<"solving pnp"<<endl;
79 // 构建相机矩阵
80 cv::Mat cameraMatrix( 3, 3, CV_64F, camera_matrix_data );
81 cv::Mat rvec, tvec, inliers;
82 // 求解pnp
83 cv::solvePnPRansac( pts_obj, pts_img, cameraMatrix, cv::Mat(), rvec, tvec, false, 100, 1.0, 100, inliers );
84
85 RESULT_OF_PNP result;
86 result.rvec = rvec;
87 result.tvec = tvec;
88 result.inliers = inliers.rows;
89
90 return result;
91 }
复制
  此外,我们还实现了一个简单的参数读取类。这个类读取一个参数的文本文件,能够以关键字的形式提供文本文件中的变量:

  include/slamBase.h

1 // 参数读取类
2 class ParameterReader
3 {
4 public:
5 ParameterReader( string filename="./parameters.txt" )
6 {
7 ifstream fin( filename.c_str() );
8 if (!fin)
9 {
10 cerr<<"parameter file does not exist."<<endl;
11 return;
12 }
13 while(!fin.eof())
14 {
15 string str;
16 getline( fin, str );
17 if (str[0] == '#')
18 {
19 // 以‘#’开头的是注释
20 continue;
21 }
22
23 int pos = str.find("=");
24 if (pos == -1)
25 continue;
26 string key = str.substr( 0, pos );
27 string value = str.substr( pos+1, str.length() );
28 data[key] = value;
29
30 if ( !fin.good() )
31 break;
32 }
33 }
34 string getData( string key )
35 {
36 map<string, string>::iterator iter = data.find(key);
37 if (iter == data.end())
38 {
39 cerr<<"Parameter name "<<key<<" not found!"<<endl;
40 return string("NOT_FOUND");
41 }
42 return iter->second;
43 }
44 public:
45 map<string, string> data;
46 };

相关文章
|
2月前
|
存储 算法 分布式数据库
持币生息DAPP系统开发|模式方案|源码
区块链将所有信息存储在分类账系统中。此外,任何类型的数据交换都称为“交易”
|
2月前
|
存储 算法 分布式数据库
DAPP质押项目系统开发|需求方案|模式分析
虽然区块大小看起来很小,但它们可以承载多达2000个交易
|
2月前
|
算法 区块链 Python
区块链代币DAPP逻辑系统开发技术方案丨单边上扬模式开发逻辑
区块链代币DAPP逻辑系统开发技术方案丨单边上扬模式开发逻辑
|
2月前
|
存储 安全 区块链
|
2月前
|
安全 区块链
DAPP质押分红项目系统开发|逻辑原理
Web 3.0是一个新的网络技术,它将使用户能够利用区块链技术来访问数字内容
|
9月前
|
存储 区块链 数据安全/隐私保护
DAPP合约代币持币生息系统开发方案模式
我们讲区块链的优势在于把社会生活中某一适应去中心化的应用数据化,数字化,加密化等等
|
11月前
|
区块链 数据安全/隐私保护 Python
DAPP燃烧铸造币合约项目系统开发|模式案例
“Web3.0”是对“Web2.0”的改进,其利用区块链技术去中心化的特点和优势显而易见
|
11月前
|
安全 区块链
区块链币币交易所系统开发成熟技术/方案逻辑/源码部署
Blockchain is a distributed ledger technology that stores data in the form of a gradually growing, linked data block (block), and uses cryptographic methods and consensus algorithms to ensure data security and reliability
|
11月前
|
存储 安全 算法