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

111 lines
3.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* @Author: your name
* @Date: 2022-04-20 15:49:50
* @LastEditTime: 2025-09-23 10:45:58
* @LastEditors: xiewenji 527774126@qq.com
* @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/include/CamDeal.h
*/
#ifndef ImageAllResult_H_
#define ImageAllResult_H_
#include <iostream>
#include <stdio.h>
#include <sys/time.h>
#include <opencv2/opencv.hpp>
#include <condition_variable>
#include <mutex>
#include <vector>
#include <thread>
#include <string>
#include <stdlib.h>
#include "Define_Product.hpp"
#include "CheckErrorCodeDefine.hpp"
#include "ImgCheckConfig.h"
#include "ImageDetConfig.h"
#include "DetLog.h"
#include "CheckResultJson.h"
using namespace std;
using namespace cv;
// 包含所有的图片检测结果,如 返回的结果,临时结果, 其他检测结果
class ImageAllResult
{
public:
enum DetStep
{
DetStep_NotDet,
DetStep_Deting,
DetStep_Complet,
};
struct AI_Det_MaskImg
{
cv::Rect roi;
cv::Mat AI_inImg;
cv::Mat AI_mask;
};
private:
/* data */
public:
ImageAllResult(/* args */);
~ImageAllResult();
void AddLog(std::string str);
// 添加图片信息
int AddDetImage(std::shared_ptr<shareImage> p);
DetStep getStep();
void setStep(DetStep step);
bool IsNotDet();
public:
// 裁切大小
cv::Rect CropRoi = cv::Rect(0, 0, 0, 0);
// 检测的原始图片
cv::Mat detImg;
// AI 推理的mask图片
cv::Mat AIMaskImg;
// 结果图片
cv::Mat resultImg;
float fscale_detToresult_x = 0;
float fscale_detToresult_y = 0;
// 产品左上角(rot_cur_roi.boundingRect)在检测图 detImg 中的偏移,缺陷坐标转换到产品坐标系时需减去该间隙
// 注意:这是轴对齐的近似换算,仅在无旋转矩形(vProductQuadInDet 为空)时作为退化路径使用
cv::Point ptRoiOffsetInDet = cv::Point(0, 0);
// 产品旋转外接矩形四角在 detImg 坐标系下的坐标,顺序固定为 0左上 1右上 2左下 3右下
// 非空时用「缺陷点到两条边线段的距离」把点换算成产品坐标,可抗产品倾斜
std::vector<cv::Point2f> vProductQuadInDet;
// 缺陷点(detImg 坐标) -> 产品坐标(像素)
// x = 到左边线段(左下->左上)的垂距,y = 到顶边线段(左上->右上)的垂距,落在矩形内为正
// 这样同一物理位置在产品任意倾斜角下都能得到相同的产品坐标(轴对齐相减做不到)
// vProductQuadInDet 无效时退化为 ptRoiOffsetInDet 轴对齐平移(旧行为)
cv::Point2f DetPointToProductCoord(const cv::Point2f &ptDet) const;
int NG_num = 0;
int YS_num = 0;
int Ok_num = 0;
int NoJudge_num = 0;
public:
DetStep m_step = DetStep_NotDet;
std::string strBaseInfo = "";
std::string strChannel = "";
std::vector<std::string> LogList;
std::shared_ptr<DetLog> detlog;
std::shared_ptr<CheckResult> result; // 返回检测结果
std::shared_ptr<One_Image_CheckResult_> pDetResult; // 检测结果 后续主要对pDetResult 继续分析
std::shared_ptr<ProductBaseResult> productBaseResult; // 产品相关的基本结果信息
std::shared_ptr<CameraBaseResult> cameraBaseResult; // 相机相关的基本结果信息
std::vector<std::shared_ptr<AI_Det_MaskImg>> AI_Qx_MaskList;
std::mutex mtx_Det; // 互斥量
private:
PRINT_LOG_ m_PrintLog;
CheckResultJson m_CheckResultJson;
};
#endif