From d94135987e72da9d8894ad08b15a4d12b82de9a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9A?= <1486806484@qq.com> Date: Mon, 26 Jun 2023 15:36:06 +0800 Subject: [PATCH] update --- src/细节功能/Alarm.cpp | 23 ++++++++++++++++++ src/细节功能/Alarm.h | 46 +++++++++++++++++++++++++++++++++++ src/细节功能/Distance.cpp | 19 +++++++++++++++ src/细节功能/Distance.h | 19 +++++++++++++++ src/细节功能/pixel.cpp | 19 +++++++++++++++ src/细节功能/pixel.h | 29 ++++++++++++++++++++++ 6 files changed, 155 insertions(+) create mode 100644 src/细节功能/Alarm.cpp create mode 100644 src/细节功能/Alarm.h create mode 100644 src/细节功能/Distance.cpp create mode 100644 src/细节功能/Distance.h create mode 100644 src/细节功能/pixel.cpp create mode 100644 src/细节功能/pixel.h 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; // µÚ¶þ¸öÎïÌåÔÚͼÏñÖÐËùÕ¼ÏñËØÃæ»ý +};