OpenCV中# define CV_EXPORTS __declspec(dllexport)的含义

__declspec(dllexport/import)关键字用于控制函数的导出与导入。__declspec(dllexport)声明将函数导出为DLL供他人使用;__declspec(dllimport)声明从DLL导入函数。使用__declspec(dllimport)有助于编译器生成更优代码。

# define CV_EXPORTS __declspec(dllexport)

问题出自:

class CV_EXPORTS Mat

{

...................

};

__declspec关键字的含义如下:

__declspec(dllexport) 
声明一个导出函数,是说这个函数要导出成DLL(动态链接库),我要给别人用。
__declspec(dllimport) 
声明一个导入函数,是说这个函数是从别的DLL(动态链接库),导入。不使用__declspec(dllimport)也能正确编译代码,但使用__declspec(dllimport)使编译器可以生成更好的代码。编译器之所以能够生成更好的代码,是因为它可以确定函数是否存在于DLL中。

gym#pragma once #include <opencv2/opencv.hpp> #include <iostream> #include <vector> struct PresenceDetectionParam { int class_id = -1; std::string className = "1"; float confidence= 0.0; }; // 下相机对位计算 struct CameraAlignmentParam { bool sign = false; // 偏移计算成功 float angle = 0.0; // 旋转角度 cv::Point offset = cv::Point(-1. -1); // xy偏移量 }; #ifdef PresenceDetection_EXPORTS #define PresenceDetection_API __declspec(dllexport) #else #define PresenceDetection_API __declspec(dllimport) #endif class PresenceDetection_API PresenceDetection { public: PresenceDetection(); ~PresenceDetection(); public: /** @brief 不同生产阶段的物料有无检测 @param in_image 输入图像 @param in_stage 输入的生产阶段,参照enum Stage @param in_detectexist 输入检测需求:存在true 不存在false @param in_threshold 输入检测阈值 (0.0,1.0),阈值越大检测越精准 @param out_status 与输入检测需求是否对应:对应true 不对应false @return 0是正常 -1图像为空 -2检测有误 -3目标分数过低 */ int AI_PresenceDetection(cv::Mat in_image, int in_stage, bool in_detectexist, float in_threshold, bool& out_status); /** @brief 下相机对位计算 @param in_image 输入图像 @param out_modulepose 输出模组的 旋转角度和x、y偏移量 @return 0是正常 -1图像为空 -2检测有误 */ int Module_DownCameraAlignment(cv::Mat in_image); private: /** @brief 不同生产阶段的物料有无检测 @param in_detectexist 输入检测需求:存在true 不存在false @param in_aiexist 输入AI训练时定义的 目标存在的索引 @param in_ainonexist 输入AI训练时定义的 目标不存在的索引 @param in_airesult 输入模型检测结果 @param out_status 与输入检测需求是否对应:对应true 不对应false */ void ResultCompare(bool in_detectexist, std::vector<int> in_aiexist, std::vector<int> in_ainonexist, int in_airesult, bool& out_status); public: CameraAlignmentParam CameraAlignment_Param = {}; PresenceDetectionParam PresenceDetection_Param ; private: // 生产阶段 enum Stage { PCB,// PCB板检测 SHELL,// 外壳检测 LENS,// 镜头检测 PCB_AND_SHELL,// PCB与外壳组装在一起的检测 LENS_AND_SHELL// 镜头与外壳组装在一起的检测 }; // 模型预测结果排序 enum AI_Predict { nonpcb,// 未检测到PCB nonshell,// 未检测到外壳 pcb,// PCB shell // 外壳 }; }; int PresenceDetection::AI_PresenceDetection(cv::Mat in_image, int in_stage, bool in_detectexist, float in_threshold, bool &out_status) /** @brief 不同生产阶段的物料有无检测 @param in_image 输入图像 @param in_stage 输入的生产阶段,参照enum Stage @param in_detectexist 输入检测需求:存在true 不存在false @param in_threshold 输入检测阈值 (0.0,1.0),阈值越大检测越精准 @param out_status 与输入检测需求是否对应:对应true 不对应false @return 0是正常 -1图像为空 -2检测有误 -3目标分数过低 */ { // 数据预处理接口定义、推理接口定义 std::shared_ptr<BaseImageprocess> baseImageprocess; bool runOnGPU = false; std::shared_ptr<Inference> inference = std::make_shared<Inference>( "best.onnx", cv::Size(320, 320), runOnGPU ); // 图像数据为空 if (in_image.empty()) { return -1; } // 灰度图像转为三通道图像 if (in_image.channels() == 1) { cv::cvtColor(in_image, in_image, cv::COLOR_GRAY2BGR); } // 推理 std::vector<Detection> output = inference->runInference(in_image); Detection detection; if (output.size() == 1) { detection = output[0]; std::string classString = detection.className + &#39; &#39; + std::to_string(detection.confidence).substr(0, 4); std::cout << "Class: " << classString << std::endl; cv::Size textSize = cv::getTextSize(classString, cv::FONT_HERSHEY_DUPLEX, 1, 2, 0); } else { return -2; } if (detection.confidence < 0.8) { return -3; } // 不同生产阶段的物料检测 switch (in_stage) { case PCB: { ResultCompare(in_detectexist, { 2 }, {0,1}, detection.class_id, out_status); break; } case SHELL: { ResultCompare(in_detectexist, { 3 }, { 0,1 }, detection.class_id, out_status); break; } case LENS: { std::cout << ""; break; } case PCB_AND_SHELL: { std::cout << ""; break; } case LENS_AND_SHELL: { std::cout << ""; break; } default:break; } std::string c = PresenceDetection_Param.className; PresenceDetection_Param.class_id = detection.class_id; PresenceDetection_Param.confidence = detection.confidence; return 0; } 其中std::string c = PresenceDetection_Param.className; e;报错:引发了异常: 读取访问权限冲突。 **std::_String_alloc<std::_String_base_types<char,std::allocator<char> > >::_Mysize**(...) 返回 0x28。
07-26
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昊虹AI笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值