You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
2.8 KiB
C

2 months ago
// count.h - 计数模式(count)核心算法与文件保存
#ifndef COUNT_H
#define COUNT_H
#include <string>
#include <vector>
#include <cstdint>
#include "common.h"
// 点集 → X-Z平面白底图像(0=白,255=黑点) + 换算面积。
// 宽: Filter_Polygon 多边形X跨度(1mm=1px); 高: z最大值(1单位=1px);
// 点先按1x1网格标记再膨胀 Point_Dilate×Point_Dilate。
// area_out 返回换算实际面积(mm^2); out_w/out_h 返回实际图像尺寸。
std::vector<uint8_t> points_to_image(const std::vector<CountPoint>& points,
double* area_out = nullptr,
int* out_w = nullptr,
int* out_h = nullptr);
// z轴空隙插值:雷达断流/瞬间丢包导致的 z 空白带,仅在停止采集后调用一次。
// 原理:同一圈(scan包)点 z 相同,正常圈间隔≈normal_gap;
// gap>2×normal_gap 且相邻两圈 Y均值差≤30mm 且 X 在相邻圈范围内时,空隙内补行。
// Z_Interpolate_Mode: none/CopyTranslation/AngleBucketInterpolation(最多补10行)。
// 会原地修改 points(新增点追加到末尾);返回新增点数。
int z_gap_interpolate(std::vector<CountPoint>& points);
// 按层统计物品总数(参照Java):高度=Floor_Height-Y;level=round(高度/层高);
// 每层容差 = Count_Base_Tolerance + level*Count_Additional_Tolerance_Per_Level;
// 从最高层(5)往下找有效层,个数=min(round(面积/(行*宽)), maxPerLayer),
// 结果 = maxPerLayer*(层号-1)+该层个数。
// 返回总个数;不足一个完整箱时返回0。
int calc_item_count(const std::vector<CountPoint>& points, const CountParams& box,
std::string* detail = nullptr, // 每层点数/高度范围/面积详情
std::vector<uint8_t>* top_layer_img = nullptr, // 被计数层(最高有效层)图像
int* top_layer_img_w = nullptr,
int* top_layer_img_h = nullptr,
int* top_layer_level = nullptr,
double* top_layer_area = nullptr);
// 将一次 count 结果保存到任务目录 make_task_dir(task_id)(后台线程异步执行,不阻塞响应):
// count_data.pcd (Y已换成高度 = Floor_Height - y_mm)
// count_points.jpg (全部点 X-Z 平面图)
// count_layer.jpg (被计数层图像, 有有效层时)
// log.txt (Log_Flag 开启时)
void save_count_files_async(const std::vector<CountPoint>& points,
const std::vector<uint8_t>& top_layer_img,
int top_img_w, int top_img_h,
const CountParams& params,
const std::string& layer_detail,
int total, int top_lv, double top_area);
#endif // COUNT_H