diff --git a/doc/fireFind(终).png b/doc/fireFind(终).png new file mode 100644 index 0000000..4162d0c Binary files /dev/null and b/doc/fireFind(终).png differ diff --git a/doc/森警软件体系结构设计文档 (1).doc b/doc/森警软件体系结构设计文档 (1).doc new file mode 100644 index 0000000..f38dedf Binary files /dev/null and b/doc/森警软件体系结构设计文档 (1).doc differ diff --git a/doc/火势预测顺序图2.png b/doc/火势预测顺序图2.png new file mode 100644 index 0000000..91ee046 Binary files /dev/null and b/doc/火势预测顺序图2.png differ diff --git a/doc/部署图终.png b/doc/部署图终.png new file mode 100644 index 0000000..a900820 Binary files /dev/null and b/doc/部署图终.png differ diff --git a/doc/顺序图.svg b/doc/顺序图.svg new file mode 100644 index 0000000..494d92e --- /dev/null +++ b/doc/顺序图.svg @@ -0,0 +1 @@ +location(lon,lat,size,slope,alt,cover)sendMessage(lon,lat)sendWeather(dir,level,T,humi,size)ffp(dir,level,slope,alt,cover,size,T,humi)getMessage(dir,level,T,humi)<<boundary>><<controller>><<controller>><<entity>>sendResult(area)PredictionUIWeatherGetFireForecastBaiduAPI \ No newline at end of file diff --git a/src/林火预测/FP.cpp b/src/林火预测/FP.cpp new file mode 100644 index 0000000..e1ca9a1 --- /dev/null +++ b/src/林火预测/FP.cpp @@ -0,0 +1,152 @@ +#include +#include +#include "levelToSpeed.h" + +using namespace std; +#define M_PI acos(-1) + + +class ForestFirePrediction { +public: + // 构造函数 + ForestFirePrediction(int wind_direction, double wind_level, double slope, double altitude, int cover_type, double fire_size, double temperature, double waterlevel) { + this->wind_direction = wind_direction; + this->wind_level = wind_level; + this->slope = slope; + this->altitude = altitude; + this->cover_type = cover_type; + this->fire_size = fire_size; + this->temperature = temperature; + this->waterlevel = waterlevel; + } + + // 计算受阻距离(单位:km) + double get_distance() { + double rad_slope = slope * M_PI / 180.0; // 将坡度转化为弧度 + double distance = sin(rad_slope) * altitude / 1000.0; // 计算受阻距离 + return distance; + } + + // 预测火灾蔓延范围 + void predict_range() { + double impact_factor; // 植被类型影响系数 + double correction_coef; // 风速补正系数 + double distance; // 受阻距离 + double composite_index; // 综合指数 + + // 根据植被类型获取影响系数 + switch (cover_type) { + case 1: // 针叶林 + impact_factor = 0.7; + break; + case 2: // 落叶林 + impact_factor = 0.5; + break; + case 3: // 灌木林 + impact_factor = 0.4; + break; + default: + cout << "植被类型输入错误!" << endl; + return; + } + + // 计算风速补正系数 + int angle = abs(wind_direction - 180); // 计算风向与火灾扩散方向之间的夹角 + if (angle <= 45 || angle >= 315) { // 如果夹角较小,则不需要进行风速补正 + correction_coef = 1; + } + else { + correction_coef = 0.65 + 0.35 * cos((angle - 45) * M_PI / 270.0); // 使用公式计算风速补正系数 + } + + // 计算受阻距离 + distance = get_distance(); + + // 计算综合指数 + composite_index = correction_coef * (1 + distance) * impact_factor; + + // 计算火灾蔓延半径 + double radius = sqrt(fire_size * 1000000 * composite_index) / M_PI; + double range = radius * pow(10, 1.5 * levelToSpeed(wind_level) / 30.0); + + // 输出预测结果 + cout << "火灾蔓延范围预测结果:" << endl; + cout << "火源最可能在" << radius << "米范围内发生。" << endl; + cout << "在风速为 " << wind_level << "级风的情况下,火源最可能的蔓延范围为 " << range << " 米。" << endl; + } + + // 预测火灾蔓延速度 + void predict_speed(int level) { + double slope_factor; // 坡度影响因子 + double speed_factor; // 风速影响因子 + double size_factor; // 火源面积影响因子 + + // 计算坡度影响因子 + if (slope > 0) { + slope_factor = pow(3.33, sqrt(slope)); + } + else { + slope_factor = 1; + } + + // 计算风速影响因子 + double wind_speed = levelToSpeed(wind_level); + speed_factor = 5.15 * pow(wind_speed, 0.39) + 0.299 * temperature + 0.009 * (100 - waterlevel) - 0.304; + + // 计算火源面积影响因子 + size_factor = pow(fire_size, 0.77); + + // 计算火灾蔓延速度 + double speed = 0.348 * sqrt(size_factor * slope_factor * speed_factor); + + + // 输出预测结果 + cout << "火灾蔓延速度预测结果:" << endl; + cout << "火灾蔓延速度可能为" << speed << "km/h。" << endl; + } + +private: + int wind_direction; // 风向(单位:度) + double wind_level; // 风力等级 + double slope; // 坡度(单位:度) + double altitude; // 海拔高度(单位:m) + int cover_type; // 植被类型(1:针叶林;2:落叶林;3:灌木林) + double fire_size; // 火源面积(单位:平方米) + double temperature; // 温度(单位:摄氏度) + double waterlevel; // 湿度(单位:%) +}; + +int main() { + // 读取参数 + int wind_direction; + int wind_level; + double slope; + double altitude; + int cover_type; + double fire_size; + double temperature; + double waterlevel; + cout << "请输入风向(0-360度):" << endl; + cin >> wind_direction; + cout << "请输入风力等级(级):" << endl; + cin >> wind_level; + cout << "请输入坡度(度):" << endl; + cin >> slope; + cout << "请输入海拔高度(m):" << endl; + cin >> altitude; + cout << "请输入植被类型(1:针叶林;2:落叶林;3:灌木林):" << endl; + cin >> cover_type; + cout << "请输入火源面积(m^2):" << endl; + cin >> fire_size; + cout << "请输入当天气温(°C):" << endl; + cin >> temperature; + cout << "请输入当天湿度(%):" << endl; + cin >> waterlevel; + + // 预测火灾蔓延范围和速度 + ForestFirePrediction ffp(wind_direction, wind_level, slope, altitude, cover_type, fire_size, temperature, waterlevel); + ffp.predict_range(); + ffp.predict_speed(wind_level); + + return 0; +} \ No newline at end of file diff --git a/src/林火预测/Ks_correction.h b/src/林火预测/Ks_correction.h new file mode 100644 index 0000000..d97eede --- /dev/null +++ b/src/林火预测/Ks_correction.h @@ -0,0 +1,30 @@ +#include +using namespace std; + +double Ks_cor(int cover_type) +{ + double impact_factor = 0; + // ֲͻȡӰϵ + switch (cover_type) { + case 1: // Ҷ + impact_factor = 0.7; + break; + case 2: // Ҷ + impact_factor = 0.5; + break; + case 3: // ľ + impact_factor = 0.4; + break; + case 4: //֦Ҷ + impact_factor = 1.2; + break; + case 5: //ԭ + impact_factor = 2; + break; + + default: + cout << "ֲ" << endl; + return -1; + } + return impact_factor; +} \ No newline at end of file diff --git a/src/林火预测/levelToSlope.h b/src/林火预测/levelToSlope.h new file mode 100644 index 0000000..28c3a6a --- /dev/null +++ b/src/林火预测/levelToSlope.h @@ -0,0 +1,49 @@ +#include +#include +using namespace std; + +//0㡫5Ϊƽ£ +//6㡫15Ϊ£ +//16㡫25Ϊб£ +//26㡫35Ϊ£ +//36㡫40Ϊ£ +//41㡫45Ϊ£ +//46Ϊ¡ +double levelToSlope(int level) { + double slope = 0; + double theta = 0; + if (level >= 0 && level <= 7) { + + switch (level) { + case 1: + theta = 0; + break; + case 2: + theta = 11; + break; + case 3: + theta = 21; + break; + case 4: + theta = 30; + break; + case 5: + theta = 38; + break; + case 6: + theta = 45; + break; + case 7: + theta = 60; + break; + + } + + } + + else { + cout << "Ч¶ȵȼ" << endl; + } + slope = tan(theta); + return slope; +} diff --git a/src/林火预测/levelToSpeed.h b/src/林火预测/levelToSpeed.h new file mode 100644 index 0000000..7098b2f --- /dev/null +++ b/src/林火预测/levelToSpeed.h @@ -0,0 +1,62 @@ +#include +using namespace std; + +double levelToSpeed(int level) { + double speed = 0; + if (level >= 0 && level <= 12) { + double speed = 0; + switch (level) { + case 1: + speed = 0.3; + break; + case 2: + speed = 1.6; + break; + case 3: + speed = 3.4; + break; + case 4: + speed = 5.5; + break; + case 5: + speed = 8.0; + break; + case 6: + speed = 10.8; + break; + case 7: + speed = 13.9; + break; + case 8: + speed = 17.2; + break; + case 9: + speed = 20.8; + break; + case 10: + speed = 24.5; + break; + case 11: + speed = 28.5; + break; + case 12: + speed = 32.7; + break; + + } + + } + else if (level == 13) { + speed = 35.8; + } + else if (level == 14) { + speed = 41.5; + } + else if (level == 15) { + speed = 48.2; + } + else { + cout << "无效的风力等级!" << endl; + } + return speed; +} \ No newline at end of file diff --git a/src/林火预测/pixel.cpp b/src/林火预测/pixel.cpp new file mode 100644 index 0000000..20440aa --- /dev/null +++ b/src/林火预测/pixel.cpp @@ -0,0 +1,19 @@ +#include "pixel.h" +#include + +using namespace std; + +int main() { + // ʵͼռ + PixelRatioConverter p(5, 10, 100, 200); + + // ȡرϵ + double ratio = p.getPixelRatio(); + cout << "رϵ" << ratio << endl; + + // һͼռ + int next_pixel_area = p.getNextPixelArea(15); + cout << "һͼռ" << next_pixel_area << endl; + + return 0; +} \ No newline at end of file diff --git a/src/林火预测/pixel.h b/src/林火预测/pixel.h new file mode 100644 index 0000000..5a590a6 --- /dev/null +++ b/src/林火预测/pixel.h @@ -0,0 +1,29 @@ +class PixelRatioConverter { +public: + // 캯ʵеͼռ + PixelRatioConverter(double real_area1, double real_area2, int pixel_area1, int pixel_area2) { + this->real_area1 = real_area1; + this->real_area2 = real_area2; + this->pixel_area1 = pixel_area1; + this->pixel_area2 = pixel_area2; + } + + // ȡرϵ + double getPixelRatio() { + double ratio = (real_area1 / real_area2) * (pixel_area2 / pixel_area1); + return ratio; // رϵ + } + + // رϵһͼռ + int getNextPixelArea(int next_real_area) { + double ratio = this->getPixelRatio(); + int next_pixel_area = static_cast(next_real_area / ratio); + return next_pixel_area; // һͼռ + } + +private: + double real_area1; // һʵе + double real_area2; // ڶʵе + int pixel_area1; // һͼռ + int pixel_area2; // ڶͼռ +}; diff --git a/src/林火预测/wind_direction.h b/src/林火预测/wind_direction.h new file mode 100644 index 0000000..a9b39fc --- /dev/null +++ b/src/林火预测/wind_direction.h @@ -0,0 +1,38 @@ +#include +using namespace std; + +int windToDirection(int type) +{ + int direction = 0; + + // ͻȡ + switch (type) { + case 1: // + direction = 0; + break; + case 2: // + direction = 45; + break; + case 3: // + direction = 90; + break; + case 4: // Ϸ + direction = 135; + break; + case 5: // Ϸ + direction = 180; + break; + case 6: //Ϸ + direction = 225; + break; + case 7: // + direction = 270; + break; + case 8: // + direction = 315; + default: + cout << "ֲ" << endl; + return -1; + } + return direction; +} \ No newline at end of file diff --git a/src/林火预测/风速补正综合指标法/ForestPolice.cpp b/src/林火预测/风速补正综合指标法/ForestPolice.cpp new file mode 100644 index 0000000..ee1f49a --- /dev/null +++ b/src/林火预测/风速补正综合指标法/ForestPolice.cpp @@ -0,0 +1,141 @@ +#include +#include +#include "levelToSpeed.h" + +using namespace std; +#define M_PI acos(-1) + + +class ForestFirePrediction { +public: + // 构造函数 + ForestFirePrediction(int wind_direction, double wind_level, double slope, double altitude, int cover_type, double fire_size) { + this->wind_direction = wind_direction; + this->wind_level = wind_level; + this->slope = slope; + this->altitude = altitude; + this->cover_type = cover_type; + this->fire_size = fire_size; + } + + // 计算受阻距离(单位:km) + double get_distance() { + double rad_slope = slope * M_PI / 180.0; // 将坡度转化为弧度 + double distance = sin(rad_slope) * altitude / 1000.0; // 计算受阻距离 + return distance; + } + + // 预测火灾蔓延范围 + void predict_range() { + double impact_factor; // 植被类型影响系数 + double correction_coef; // 风速补正系数 + double distance; // 受阻距离 + double composite_index; // 综合指数 + + // 根据植被类型获取影响系数 + switch (cover_type) { + case 1: // 针叶林 + impact_factor = 0.7; + break; + case 2: // 落叶林 + impact_factor = 0.5; + break; + case 3: // 灌木林 + impact_factor = 0.4; + break; + default: + cout << "植被类型输入错误!" << endl; + return; + } + + // 计算风速补正系数 + int angle = abs(wind_direction - 180); // 计算风向与火灾扩散方向之间的夹角 + if (angle <= 45 || angle >= 315) { // 如果夹角较小,则不需要进行风速补正 + correction_coef = 1; + } + else { + correction_coef = 0.65 + 0.35 * cos((angle - 45) * M_PI / 270.0); // 使用公式计算风速补正系数 + } + + // 计算受阻距离 + distance = get_distance(); + + // 计算综合指数 + composite_index = correction_coef * (1 + distance) * impact_factor; + + // 计算火灾蔓延半径 + double radius = sqrt(fire_size * 1000000 * composite_index) / M_PI; + double range = radius * pow(10, 1.5 * levelToSpeed(wind_level) / 30.0); + + // 输出预测结果 + cout << "火灾蔓延范围预测结果:" << endl; + cout << "火源最可能在" << radius << "米范围内发生。" << endl; + cout << "在风速为 " << wind_level << "级风的情况下,火源最可能的蔓延范围为 " << range << " 米。" << endl; + } + + // 预测火灾蔓延速度 + void predict_speed(int level) { + double slope_factor; // 坡度影响因子 + double speed_factor; // 风速影响因子 + double size_factor; // 火源面积影响因子 + + // 计算坡度影响因子 + if (slope > 0) { + slope_factor = pow(3.33, sqrt(slope)); + } + else { + slope_factor = 1; + } + + // 计算风速影响因子 + double wind_speed = levelToSpeed(wind_level); + speed_factor = 5.15 * pow(wind_speed, 0.39); + + // 计算火源面积影响因子 + size_factor = pow(fire_size, 0.77); + + // 计算火灾蔓延速度 + double speed = 0.348 * sqrt(size_factor * slope_factor * speed_factor); + + // 输出预测结果 + cout << "火灾蔓延速度预测结果:" << endl; + cout << "火灾蔓延速度可能为" << speed << "km/h。" << endl; + } + +private: + int wind_direction; // 风向(单位:度) + double wind_level; // 风力等级 + double slope; // 坡度(单位:度) + double altitude; // 海拔高度(单位:m) + int cover_type; // 植被类型(1:针叶林;2:落叶林;3:灌木林) + double fire_size; // 火源面积(单位:平方米) +}; + +int main() { + // 读取参数 + int wind_direction; + int wind_level; + double slope; + double altitude; + int cover_type; + double fire_size; + cout << "请输入风向(0-360度):" << endl; + cin >> wind_direction; + cout << "请输入风力等级(级):" << endl; + cin >> wind_level; + cout << "请输入坡度(度):" << endl; + cin >> slope; + cout << "请输入海拔高度(m):" << endl; + cin >> altitude; + cout << "请输入植被类型(1:针叶林;2:落叶林;3:灌木林):" << endl; + cin >> cover_type; + cout << "请输入火源面积(m^2):" << endl; + cin >> fire_size; + + // 预测火灾蔓延范围和速度 + ForestFirePrediction ffp(wind_direction, wind_level, slope, altitude, cover_type, fire_size); + ffp.predict_range(); + ffp.predict_speed(wind_level); + + return 0; +} \ No newline at end of file diff --git a/src/林火预测/风速补正综合指标法/levelToSpeed.h b/src/林火预测/风速补正综合指标法/levelToSpeed.h new file mode 100644 index 0000000..4a3a051 --- /dev/null +++ b/src/林火预测/风速补正综合指标法/levelToSpeed.h @@ -0,0 +1,62 @@ +#include +using namespace std; + +double levelToSpeed(int level) { + double speed = 0; + if (level >= 0 && level <= 12) { + double speed = 0; + switch (level) { + case 1: + speed = 0.3; + break; + case 2: + speed = 1.6; + break; + case 3: + speed = 3.4; + break; + case 4: + speed = 5.5; + break; + case 5: + speed = 8.0; + break; + case 6: + speed = 10.8; + break; + case 7: + speed = 13.9; + break; + case 8: + speed = 17.2; + break; + case 9: + speed = 20.8; + break; + case 10: + speed = 24.5; + break; + case 11: + speed = 28.5; + break; + case 12: + speed = 32.7; + break; + + } + + } + else if (level == 13) { + speed = 35.8; + } + else if (level == 14) { + speed = 41.5; + } + else if (level == 15) { + speed = 48.2; + } + else { + cout << "Чķȼ" << endl; + } + return speed; +} \ No newline at end of file diff --git a/src/林火预测/风速补正综合指标法/model.cpp b/src/林火预测/风速补正综合指标法/model.cpp new file mode 100644 index 0000000..1d8191f --- /dev/null +++ b/src/林火预测/风速补正综合指标法/model.cpp @@ -0,0 +1,149 @@ +#include +#include + +using namespace std; + +class ForestFireModel { +private: + int rows; // ɭֵͼ + int cols; // ɭֵͼ + double ignitionProbability; // ȼ + double burningProbability; // Ӹ + double** forestMap; // ɭֵͼ + +public: + ForestFireModel(int rows, int cols, double ignitionProbability, double burningProbability) { + this->rows = rows; + this->cols = cols; + this->ignitionProbability = ignitionProbability; + this->burningProbability = burningProbability; + + // ʼɭֵͼ + forestMap = new double* [rows]; + for (int i = 0; i < rows; i++) { + forestMap[i] = new double[cols]; + for (int j = 0; j < cols; j++) { + forestMap[i][j] = (double)rand() / (RAND_MAX); + } + } + } + + // ģɢ + void simulate(int steps) { + for (int t = 0; t < steps; t++) { + double** nextMap = new double* [rows]; + for (int i = 0; i < rows; i++) { + nextMap[i] = new double[cols]; + for (int j = 0; j < cols; j++) { + bool isBurning = false; + bool isIgnited = (double)rand() / (RAND_MAX) < ignitionProbability; + if (isIgnited || forestMap[i][j] > 0) { + // ȼǰλѾŻжΧǷлɢ + for (int k = -1; k <= 1; k++) { + for (int l = -1; l <= 1; l++) { + if (k == 0 && l == 0) { + continue; + } + int ii = i + k; + int jj = j + l; + if (ii < 0 || ii >= rows || jj < 0 || jj >= cols) { + continue; + } + if (forestMap[ii][jj] > 0) { + // Χл𣬵ǰλҲŻ + isBurning = true; + } + else if ((double)rand() / (RAND_MAX) < burningProbability) { + // ͨʾǰλǷŻ + isBurning = true; + } + } + } + } + nextMap[i][j] = isBurning ? 1 : (isIgnited ? 0.5 : forestMap[i][j]); + } + } + // ɭֵͼ + for (int i = 0; i < rows; i++) { + for (int j = 0; j < cols; j++) { + forestMap[i][j] = nextMap[i][j]; + } + delete[] nextMap[i]; + } + delete[] nextMap; + } + } + + // ָλõĻٶ + double spreadSpeed(int x, int y) { + double speed = 0; + if (forestMap[x][y] == 0) { + return speed; + } + for (int i = 0; i < rows; i++) { + for (int j = 0; j < cols; j++) { + double distance = sqrt(pow(x - i, 2) + pow(y - j, 2)); + if (forestMap[i][j] > 0 && distance > 0) { + speed += forestMap[i][j] / distance; + } + } + } + return speed; + } + + // 㵱ǰΧİ뾶 + double fireRadius() { + double radius = 0; + for (int i = 0; i < rows; i++) { + for (int j = 0; j < cols; j++) { + if (forestMap[i][j] >= 1) { + double distance = sqrt(pow(i - rows / 2, 2) + pow(j - cols / 2, 2)); + radius = max(radius, distance); + } + } + } + return radius; + } + + // ɭֵͼ + void printMap() { + for (int i = 0; i < rows; i++) { + for (int j = 0; j < cols; j++) { + if (forestMap[i][j] >= 1) { + cout << "* "; + } + else if (forestMap[i][j] > 0) { + cout << "o "; + } + else { + cout << ". "; + } + } + cout << endl; + } + } + + ~ForestFireModel() { + for (int i = 0; i < rows; i++) { + delete[] forestMap[i]; + } + delete[] forestMap; + } +}; + +int main() { + srand(time(0)); + + // ģһ5x5ɭ֣ȼΪ0.2ӸΪ0.8ģ100 + ForestFireModel model(5, 5, 0.2, 0.8); + model.simulate(100); + model.printMap(); + + // ָλõĻٶ + cout << "Spread speed at position (2, 3): " << model.spreadSpeed(2, 3) << endl; + + // 㵱ǰΧİ뾶 + cout << "Fire radius: " << model.fireRadius() << endl; + + return 0; +} diff --git a/src/登录页面—vue/Login.vue b/src/登录页面—vue/Login.vue new file mode 100644 index 0000000..e6489a7 --- /dev/null +++ b/src/登录页面—vue/Login.vue @@ -0,0 +1,111 @@ + + + + + + \ No newline at end of file diff --git a/src/细节功能/Alarm.cpp b/src/细节功能/Alarm.cpp new file mode 100644 index 0000000..7895190 --- /dev/null +++ b/src/细节功能/Alarm.cpp @@ -0,0 +1,23 @@ +#include "Alarm.h" +#include +#include + +using namespace std; + +int main() { + AlarmSystem alarm; // ϵͳ + + alarm.arm(); // ϵͳ + + // ģյϢ + string message = "¶쳣"; + alarm.receiveMessage(message); + + alarm.disarm(); // رվϵͳ + + // ٴģյϢھϵͳѹرգᴥ + string message2 = "־"; + alarm.receiveMessage(message2); + + return 0; +} diff --git a/src/细节功能/Alarm.h b/src/细节功能/Alarm.h new file mode 100644 index 0000000..982452e --- /dev/null +++ b/src/细节功能/Alarm.h @@ -0,0 +1,46 @@ +#include +#include + +using namespace std; + +class AlarmSystem { +public: + // 캯ʼϵͳ + AlarmSystem() { + isArmed = false; + alarmMessage = "쳣"; + } + + // ϵͳ + void arm() { + isArmed = true; + cout << "ϵͳ" << endl; + } + + // رվϵͳ + void disarm() { + isArmed = false; + cout << "ϵͳѹر" << endl; + } + + // Ϣ + void receiveMessage(const string& message) { + if (isArmed) { + cout << "յϢ" << message << endl; + triggerAlarm(); + } + else { + cout << "δϵͳϢ" << message << endl; + } + } + +private: + bool isArmed; // ϵͳǷ + string alarmMessage; // Ϣ + + // + void triggerAlarm() { + cout << "" << alarmMessage << endl; + // ʵ־ľ紥֪ͨ + } +}; diff --git a/src/细节功能/Distance.cpp b/src/细节功能/Distance.cpp new file mode 100644 index 0000000..bc74a67 --- /dev/null +++ b/src/细节功能/Distance.cpp @@ -0,0 +1,19 @@ +#include "Distance.h" +#include + +using namespace std; + +int main() { + // Ļ߳Ⱥľӽµλ + TreeDistanceEstimator treeEstimator(0.1, 30); + + // Ľ + treeEstimator.setFocalLength(100); + + // ľľ + double distance = treeEstimator.estimateDistance(); + + cout << "ľ룺" << distance << " " << endl; + + return 0; +} diff --git a/src/细节功能/Distance.h b/src/细节功能/Distance.h new file mode 100644 index 0000000..0f483b9 --- /dev/null +++ b/src/细节功能/Distance.h @@ -0,0 +1,19 @@ +class TreeDistanceEstimator { +public: + // 캯Ļ߳Ⱥľӽµλ + TreeDistanceEstimator(double baseline, double pixel_displacement) { + this->baseline = baseline; + this->pixel_displacement = pixel_displacement; + } + + // ľľ + double estimateDistance() { + double distance = (baseline * focal_length) / pixel_displacement; + return distance; // عľ + } + +private: + double baseline; // Ļ߳ + double pixel_displacement; // ľӽµλ + double focal_length; // +}; diff --git a/src/细节功能/pixel.cpp b/src/细节功能/pixel.cpp new file mode 100644 index 0000000..20440aa --- /dev/null +++ b/src/细节功能/pixel.cpp @@ -0,0 +1,19 @@ +#include "pixel.h" +#include + +using namespace std; + +int main() { + // ʵͼռ + PixelRatioConverter p(5, 10, 100, 200); + + // ȡرϵ + double ratio = p.getPixelRatio(); + cout << "رϵ" << ratio << endl; + + // һͼռ + int next_pixel_area = p.getNextPixelArea(15); + cout << "һͼռ" << next_pixel_area << endl; + + return 0; +} \ No newline at end of file diff --git a/src/细节功能/pixel.h b/src/细节功能/pixel.h new file mode 100644 index 0000000..5a590a6 --- /dev/null +++ b/src/细节功能/pixel.h @@ -0,0 +1,29 @@ +class PixelRatioConverter { +public: + // 캯ʵеͼռ + PixelRatioConverter(double real_area1, double real_area2, int pixel_area1, int pixel_area2) { + this->real_area1 = real_area1; + this->real_area2 = real_area2; + this->pixel_area1 = pixel_area1; + this->pixel_area2 = pixel_area2; + } + + // ȡرϵ + double getPixelRatio() { + double ratio = (real_area1 / real_area2) * (pixel_area2 / pixel_area1); + return ratio; // رϵ + } + + // رϵһͼռ + int getNextPixelArea(int next_real_area) { + double ratio = this->getPixelRatio(); + int next_pixel_area = static_cast(next_real_area / ratio); + return next_pixel_area; // һͼռ + } + +private: + double real_area1; // һʵе + double real_area2; // ڶʵе + int pixel_area1; // һͼռ + int pixel_area2; // ڶͼռ +};