把这段代码从c++转换为c代码Rect<float> Framer::ComputeActiveCropRegion(int frame_number) { const float min_crop_size = 1.0f / options_.max_zoom_ratio; const float new_x_crop_size = std::clamp(region_of_interest_.width * options_.target_crop_to_roi_ratio,

时间: 2024-03-16 18:41:17 浏览: 25
把这段 C++ 代码转换成 C 代码并不是一件简单的事情,因为 C++ 和 C 有许多语法上的不同,C++ 有许多 C 中没有的特性,例如模板、类和命名空间等等。因此,我们需要对代码进行适当的修改和调整。以下是将 C++ 代码转换为 C 代码的一种可能的方式: ```c struct Rect { float x, y, width, height; }; struct FramerOptions { float max_zoom_ratio; float target_crop_to_roi_ratio; }; struct Framer { struct Rect region_of_interest_; struct FramerOptions options_; }; float clamp(float value, float min_value, float max_value) { if (value < min_value) { return min_value; } else if (value > max_value) { return max_value; } else { return value; } } struct Rect ComputeActiveCropRegion(struct Framer *framer, int frame_number) { const float min_crop_size = 1.0f / framer->options_.max_zoom_ratio; const float new_x_crop_size = clamp(framer->region_of_interest_.width * framer->options_.target_crop_to_roi_ratio, min_crop_size, 1.0f); struct Rect active_crop_region; active_crop_region.x = framer->region_of_interest_.x + (framer->region_of_interest_.width - new_x_crop_size) / 2.0f; active_crop_region.y = framer->region_of_interest_.y; active_crop_region.width = new_x_crop_size; active_crop_region.height = framer->region_of_interest_.height; return active_crop_region; } ``` 需要注意的是,C 中没有命名空间的概念,因此我们将结构体 `Rect`、`FramerOptions` 和 `Framer` 放在了全局命名空间中。另外,C 中没有 `std::clamp` 函数,我们需要手动实现一个 `clamp` 函数来实现相同的功能。最后,建议根据实际情况对代码进行适当的调整,以便更好地适应 C 语言的语法和特性。

相关推荐

请详细解释下这段代码Rect<float> Framer::ComputeActiveCropRegion(int frame_number) { const float min_crop_size = 1.0f / options_.max_zoom_ratio; const float new_x_crop_size = std::clamp(region_of_interest_.width * options_.target_crop_to_roi_ratio, min_crop_size, 1.0f); const float new_y_crop_size = std::clamp(region_of_interest_.height * options_.target_crop_to_roi_ratio, min_crop_size, 1.0f); // We expand the raw crop region to match the desired output aspect ratio. const float target_aspect_ratio = static_cast<float>(options_.input_size.height) / static_cast<float>(options_.input_size.width) * static_cast<float>(options_.target_aspect_ratio_x) / static_cast<float>(options_.target_aspect_ratio_y); Rect<float> new_crop; if (new_x_crop_size <= new_y_crop_size * target_aspect_ratio) { new_crop.width = std::min(new_y_crop_size * target_aspect_ratio, 1.0f); new_crop.height = new_crop.width / target_aspect_ratio; } else { new_crop.height = std::min(new_x_crop_size / target_aspect_ratio, 1.0f); new_crop.width = new_crop.height * target_aspect_ratio; } const float roi_x_mid = region_of_interest_.left + (region_of_interest_.width / 2); const float roi_y_mid = region_of_interest_.top + (region_of_interest_.height / 2); new_crop.left = std::clamp(roi_x_mid - (new_crop.width / 2), 0.0f, 1.0f - new_crop.width); new_crop.top = std::clamp(roi_y_mid - (new_crop.height / 2), 0.0f, 1.0f - new_crop.height); const float normalized_crop_strength = std::powf(options_.crop_filter_strength, ElapsedTimeMs(timestamp_) / kUnitTimeSlice); active_crop_region_.left = IirFilter(active_crop_region_.left, new_crop.left, normalized_crop_strength); active_crop_region_.top = IirFilter(active_crop_region_.top, new_crop.top, normalized_crop_strength); active_crop_region_.width = IirFilter( active_crop_region_.width, new_crop.width, normalized_crop_strength); active_crop_region_.height = IirFilter( active_crop_region_.height, new_crop.height, normalized_crop_strength); timestamp_ = base::TimeTicks::Now(); if (VLOG_IS_ON(2)) { DVLOGFID(2, frame_number) << "region_of_interest=" << region_of_interest_; DVLOGFID(2, frame_number) << "new_crop_region=" << new_crop; DVLOGFID(2, frame_number) << "active_crop_region=" << active_crop_region_; } return active_crop_region_; }

请详细解释下这段代码Rect<float> FaceTracker::GetActiveBoundingRectangleOnActiveStream() const { std::vector<Rect<float>> faces = GetActiveFaceRectangles(); if (faces.empty()) { return Rect<float>(); } float min_x0 = 1.0f, min_y0 = 1.0f, max_x1 = 0.0f, max_y1 = 0.0f; for (const auto& f : faces) { min_x0 = std::min(f.left, min_x0); min_y0 = std::min(f.top, min_y0); max_x1 = std::max(f.right(), max_x1); max_y1 = std::max(f.bottom(), max_y1); } Rect<float> bounding_rect(min_x0, min_y0, max_x1 - min_x0, max_y1 - min_y0); VLOGF(2) << "Active bounding rect w.r.t active array: " << bounding_rect; // Transform the normalized rectangle in the active sensor array space to the // active stream space. const float active_array_aspect_ratio = static_cast<float>(options_.active_array_dimension.width) / static_cast<float>(options_.active_array_dimension.height); const float active_stream_aspect_ratio = static_cast<float>(options_.active_stream_dimension.width) / static_cast<float>(options_.active_stream_dimension.height); if (active_array_aspect_ratio < active_stream_aspect_ratio) { // The active stream is cropped into letterbox with smaller height than the // active sensor array. Adjust the y coordinates accordingly. const float height_ratio = active_array_aspect_ratio / active_stream_aspect_ratio; bounding_rect.height = std::min(bounding_rect.height / height_ratio, 1.0f); const float y_offset = (1.0f - height_ratio) / 2; bounding_rect.top = std::max(bounding_rect.top - y_offset, 0.0f) / height_ratio; } else { // The active stream is cropped into pillarbox with smaller width than the // active sensor array. Adjust the x coordinates accordingly. const float width_ratio = active_stream_aspect_ratio / active_array_aspect_ratio; bounding_rect.width = std::min(bounding_rect.width / width_ratio, 1.0f); const float x_offset = (1.0f - width_ratio) / 2; bounding_rect.left = std::max(bounding_rect.left - x_offset, 0.0f) / width_ratio; } VLOGF(2) << "Active bounding rect w.r.t active stream: " << bounding_rect; return bounding_rect; }

在vs2015 c++ .h中加入这段代码会报重定义 namespace cv_dnn { namespace { template <typename T> static inline bool SortScorePairDescend(const std::pair<float, T>& pair1, const std::pair<float, T>& pair2) { return pair1.first > pair2.first; } } // namespace inline void GetMaxScoreIndex(const std::vector<float>& scores, const float threshold, const int top_k, std::vector<std::pair<float, int> >& score_index_vec) { for (size_t i = 0; i < scores.size(); ++i) { if (scores[i] > threshold) { score_index_vec.push_back(std::make_pair(scores[i], i)); } } std::stable_sort(score_index_vec.begin(), score_index_vec.end(), SortScorePairDescend<int>); if (top_k > 0 && top_k < (int)score_index_vec.size()) { score_index_vec.resize(top_k); } } template <typename BoxType> inline void NMSFast_(const std::vector<BoxType>& bboxes, const std::vector<float>& scores, const float score_threshold, const float nms_threshold, const float eta, const int top_k, std::vector<int>& indices, float(*computeOverlap)(const BoxType&, const BoxType&)) { CV_Assert(bboxes.size() == scores.size()); std::vector<std::pair<float, int> > score_index_vec; GetMaxScoreIndex(scores, score_threshold, top_k, score_index_vec); // Do nms. float adaptive_threshold = nms_threshold; indices.clear(); for (size_t i = 0; i < score_index_vec.size(); ++i) { const int idx = score_index_vec[i].second; bool keep = true; for (int k = 0; k < (int)indices.size() && keep; ++k) { const int kept_idx = indices[k]; float overlap = computeOverlap(bboxes[idx], bboxes[kept_idx]); keep = overlap <= adaptive_threshold; } if (keep) indices.push_back(idx); if (keep && eta < 1 && adaptive_threshold > 0.5) { adaptive_threshold *= eta; } } } // copied from opencv 3.4, not exist in 3.0 template<typename Tp> static inline double jaccardDistance_(const Rect_<Tp>& a, const Rect<_Tp>& b) { Tp Aa = a.area(); Tp Ab = b.area(); if ((Aa + Ab) <= std::numeric_limits<Tp>::epsilon()) { // jaccard_index = 1 -> distance = 0 return 0.0; } double Aab = (a & b).area(); // distance = 1 - jaccard_index return 1.0 - Aab / (Aa + Ab - Aab); } template <typename T> static inline float rectOverlap(const T& a, const T& b) { return 1.f - static_cast<float>(jaccardDistance(a, b)); } void NMSBoxes(const std::vector<Rect>& bboxes, const std::vector<float>& scores, const float score_threshold, const float nms_threshold, std::vector<int>& indices, const float eta = 1, const int top_k = 0) { NMSFast(bboxes, scores, score_threshold, nms_threshold, eta, top_k, indices, rectOverlap); } }

请解释下这段代码namespace cros { // This class interfaces with the Google3 auto-framing library: // http://google3/chromeos/camera/lib/auto_framing/auto_framing_cros.h class AutoFramingClient : public AutoFramingCrOS::Client { public: struct Options { Size input_size; double frame_rate = 0.0; uint32_t target_aspect_ratio_x = 0; uint32_t target_aspect_ratio_y = 0; }; // Set up the pipeline. bool SetUp(const Options& options); // Process one frame. |buffer| is only used during this function call. bool ProcessFrame(int64_t timestamp, buffer_handle_t buffer); // Return the stored ROI if a new detection is available, or nullopt if not. // After this call the stored ROI is cleared, waiting for another new // detection to fill it. std::optional<Rect<uint32_t>> TakeNewRegionOfInterest(); // Gets the crop window calculated by the full auto-framing pipeline. Rect<uint32_t> GetCropWindow(); // Tear down the pipeline and clear states. void TearDown(); // Implementations of AutoFramingCrOS::Client. void OnFrameProcessed(int64_t timestamp) override; void OnNewRegionOfInterest( int64_t timestamp, int x_min, int y_min, int x_max, int y_max) override; void OnNewCropWindow( int64_t timestamp, int x_min, int y_min, int x_max, int y_max) override; void OnNewAnnotatedFrame(int64_t timestamp, const uint8_t* data, int stride) override; private: base::Lock lock_; std::unique_ptr<AutoFramingCrOS> auto_framing_ GUARDED_BY(lock_); std::unique_ptr<CameraBufferPool> buffer_pool_ GUARDED_BY(lock_); std::map<int64_t, CameraBufferPool::Buffer> inflight_buffers_ GUARDED_BY(lock_); std::optional<Rect<uint32_t>> region_of_interest_ GUARDED_BY(lock_); Rect<uint32_t> crop_window_ GUARDED_BY(lock_); }; } // namespace

请解释下这段代码namespace cros { // FaceTracker takes a set of face data produced by FaceDetector as input, // filters the input, and produces the bounding rectangle that encloses the // filtered input. class FaceTracker { public: struct Options { // The dimension of the active sensory array in pixels. Used for normalizing // the input face coordinates. Size active_array_dimension; // The dimension of the active stream that will be cropped. Used for // translating the ROI coordinates in the active array space. Size active_stream_dimension; // The threshold in ms for including a newly detected face for tracking. int face_phase_in_threshold_ms = 3000; // The threshold in ms for excluding a face that's no longer detected for // tracking. int face_phase_out_threshold_ms = 2000; // The angle range [|pan_angle_range|, -|pan_angle_range|] in degrees used // to determine if a face is looking at the camera. float pan_angle_range = 30.0f; }; explicit FaceTracker(const Options& options); ~FaceTracker() = default; FaceTracker(FaceTracker& other) = delete; FaceTracker& operator=(FaceTracker& other) = delete; // Callback for when new face data are ready. void OnNewFaceData(const std::vector<human_sensing::CrosFace>& faces); // The all the rectangles of all the detected faces. std::vector<Rect<float>> GetActiveFaceRectangles() const; // Gets the rectangle than encloses all the detected faces. Returns a // normalized rectangle in [0.0, 1.0] x [0.0, 1.0] with respect to the active // stream dimension. Rect<float> GetActiveBoundingRectangleOnActiveStream() const; void OnOptionsUpdated(const base::Value& json_values); private: struct FaceState { Rect<float> normalized_bounding_box = {0.0f, 0.0f, 0.0f, 0.0f}; base::TimeTicks first_detected_ticks; base::TimeTicks last_detected_ticks; bool has_attention = false; }; Options options_; std::vector<FaceState> faces_; }; } // namespace cros

最新推荐

recommend-type

1235012013杨铭.zip

1235012013杨铭.zip
recommend-type

vue项目实战Vue实战项目篇源码.zip

vue项目实战Vue实战项目篇源码.zip Vue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zipVue实战项目篇源码.zi
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

HSV转为RGB的计算公式

HSV (Hue, Saturation, Value) 和 RGB (Red, Green, Blue) 是两种表示颜色的方式。下面是将 HSV 转换为 RGB 的计算公式: 1. 将 HSV 中的 S 和 V 值除以 100,得到范围在 0~1 之间的值。 2. 计算色相 H 在 RGB 中的值。如果 H 的范围在 0~60 或者 300~360 之间,则 R = V,G = (H/60)×V,B = 0。如果 H 的范围在 60~120 之间,则 R = ((120-H)/60)×V,G = V,B = 0。如果 H 的范围在 120~180 之间,则 R = 0,G = V,B =
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

MATLAB柱状图在数据分析中的作用:从可视化到洞察

![MATLAB柱状图在数据分析中的作用:从可视化到洞察](https://img-blog.csdnimg.cn/img_convert/1a36558cefc0339f7836cca7680c0aef.png) # 1. MATLAB柱状图概述** 柱状图是一种广泛用于数据可视化的图表类型,它使用垂直条形来表示数据中不同类别或组别的值。在MATLAB中,柱状图通过`bar`函数创建,该函数接受数据向量或矩阵作为输入,并生成相应的高度条形。 柱状图的优点在于其简单性和易于理解性。它们可以快速有效地传达数据分布和组别之间的比较。此外,MATLAB提供了广泛的定制选项,允许用户调整条形颜色、
recommend-type

已知自动控制原理中通过更高的频率特征来评估切割频率和库存——相位稳定。确定封闭系统的稳定性。求Wcp 和ψ已知W(p)=30•(0.1p+1)•(12.5p+1)/p•(10p+1)•(0.2p+1)•(p+1)

根据相位稳定的定义,我们需要找到一个频率 Wcp,使得相位满足 -ψ = -180°,即 ψ = 180°。此时系统的相位裕度为 0°,系统处于边缘稳定状态。 首先,我们需要将 W(p) 表示成极点和零点的形式。将分母和分子分别因式分解,得到: W(p) = 30 • (0.1p+1) • (12.5p+1) / [p • (10p+1) • (0.2p+1) • (p+1)] = 375p/(p+1) - 3750/(10p+1) + 750p/(0.2p+1) - 3750p/(10p+1) + 150p/(p+1) + 30 因此,系统的极点为 -1、-0.1、-0.2、