image_framework_ymj/image_framework/algorithm/Libapi2D3D.h
2024-12-06 16:25:16 +08:00

114 lines
3.0 KiB
C++
Executable File

#ifndef LIBAPI_2D3D_H
#define LIBAPI_2D3D_H
#include <iostream>
#include <vector>
#include <opencv2/opencv.hpp>
#include <chrono>
#include <random>
#define CAL_2D3D_BASE 2000
#define CAL_OK 0
#define CAL_READFILE_FAILED 1 - CAL_2D3D_BASE
#define CAL_WRITEFILE_FAILED 2 - CAL_2D3D_BASE
#define CAL_NONE_PTR 3 - CAL_2D3D_BASE
#define CAL_PRAMA_EMPUTY 4 - CAL_2D3D_BASE
#define CAL_READIM_FAILED 5 - CAL_2D3D_BASE
#define CAL_NPU_LOAD_DATASET_FAILED 6 - CAL_2D3D_BASE
#define CAL_NPU_MODEL_EXE_FAILED 7 - CAL_2D3D_BASE
#define CAL_NPU_GET_RESULT_FAILED 8 - CAL_2D3D_BASE
#define CAL_NPU_UNLOAD_DATASET_FAILED 9 - CAL_2D3D_BASE
#define CAL_YOLO_DETECT_NO_ROI 10 - CAL_2D3D_BASE
#define CAL_ROIS_PUSH_TREAD_FAILED 11 - CAL_2D3D_BASE
#define CAL_H_FAILED 12 - CAL_2D3D_BASE
#define CAL_3D_COONERS_FAILED 13 - CAL_2D3D_BASE
#define CAL_INNER_COONERS_ISNOT_4 14 - CAL_2D3D_BASE
#define CAL_3D_PROJECT_POINTS_IS_0 15 - CAL_2D3D_BASE
#define CAL_3D_CLOUD_POINTS_IS_0 16 - CAL_2D3D_BASE
#define CAL_HAS_NO_GOOD_CONNER 17 - CAL_2D3D_BASE
#define CAL_2D_ROI_DETECTIION_IS_0 18 - CAL_2D3D_BASE
#define CAL_2D_CAP_IMAGE_FAILED 19 - CAL_2D3D_BASE
class CalUtils
{
public:
static int LibapiGenRandomId(long& id)
{
auto now = std::chrono::system_clock::now();
auto duration = now.time_since_epoch();
auto seconds = std::chrono::duration_cast<std::chrono::seconds>(duration).count();
id = std::hash<long>{}(static_cast<long>(seconds));
return CAL_OK;
};
};
class CSubRoi;
class CMeasureInfo // 设计为单例模式
{
public:
static CMeasureInfo* Get();
static CMeasureInfo* Clear();
static CMeasureInfo* Init(long id, std::string info);
public:
CMeasureInfo();
CMeasureInfo(long id, std::string info);
~CMeasureInfo();
long GetID();
std::string GetInfo();
std::shared_ptr<cv::Mat> GetIm();
void SetIm(std::shared_ptr<cv::Mat>& imptr);
std::shared_ptr<cv::Mat>& GetIm2D3D();
void SetIm2D3D(std::shared_ptr<cv::Mat>& imim2D3Dptr);
std::vector<std::shared_ptr<CSubRoi>>& GetSubRois();
std::vector<std::vector<cv::Point2f>> GetAllRoiConners();
private:
static CMeasureInfo* m_instance;
private:
private:
// 该区域ID
long mId;
// 该区域信息
std::string mInfo;
// 该区域的图像指针
std::shared_ptr<cv::Mat> mImPtr;
// 该区域的图像指针
std::shared_ptr<cv::Mat> mIm2D3DPtr;
// 该区域的子图像指针
std::vector<std::shared_ptr<CSubRoi>> subRois;
};
class CSubRoi
{
public:
CSubRoi();
CSubRoi(long parentId, long id, std::string info);
~CSubRoi();
public:
// 该区域父图像的ID
long mPparentId;
// 该区域ID
long mId;
bool isGood;
// 该区域信息
std::string mInfo;
// 区域与原图的偏移量
cv::Point2f vpOffset;
// 该区域的坐标(ROI的4个坐标点) * 4
std::vector<cv::Point2f> mRoiPoints;
// 该区域的角点的2D信息 * 4
std::vector<cv::Point2f> mInnerConners;
// 该区域的角点的3D信息 * 4
std::vector<cv::Point3f> mInnerConners3D;
// for test cal * 10000+
std::vector<cv::Point2f> mVc2D;
std::vector<cv::Point3f> mVc3D;
cv::Mat H;
};
#endif