在头文件中使用opencv类型来实现未定义的标识符
using opencv type in header file achieve to undefined identifier
下面的代码构建和运行都没有问题(只需调整带有或不带有cuda的图像大小(
//#include <opencv2/core.hpp>
//#include <opencv2/imgcodecs.hpp>
//#include <opencv2/highgui.hpp>
#include "opencv2/opencv.hpp"
#include <opencv2/core/utils/logger.hpp>
#include <iostream>
//#include "openCVTest.hpp"
using namespace cv;
using namespace std;
void mainTransform(InputArray src, OutputArray dest, double m) {
resize(src, dest, Size(0, 0), m, m, INTER_CUBIC);
}
int main(int argc, char** argv) {
utils::logging::setLogLevel(utils::logging::LOG_LEVEL_WARNING);
const string keys =
"{help h usage ?| |[image] [-cd=cudaIndex]}"
"{@image | |image to display * 1.5}"
"{cdi |0|cuda device index, -1 for cpu}";
CommandLineParser parser(argc, argv, keys);
if (parser.has("help")) {
parser.printMessage();
return 0;
}
int cudaDeviceIndex = parser.get<int>("cdi");
string imageName = parser.get<string>("@image");
if (!parser.check()) {
parser.printErrors();
return 0;
}
const char* WIN_NAME = "Display window";
cuda::DeviceInfo cudaDeviceInfo;
int cedc = cuda::getCudaEnabledDeviceCount();
if (cedc == 0 || cudaDeviceIndex >= cedc || cudaDeviceIndex < 0) {
cout << "no cuda device " << cudaDeviceIndex << " max is " << cedc - 1 << endl;
cudaDeviceIndex = -1;
}
else {
cuda::setDevice(cudaDeviceIndex);
cudaDeviceInfo = cuda::DeviceInfo(cudaDeviceIndex);
cout << cedc << " cuda device(s), using index 0: " << cudaDeviceInfo.name() << endl;
}
if (imageName == "") {
return 0;
}
namedWindow(WIN_NAME, WINDOW_AUTOSIZE);
Mat image, dest;
image = imread(imageName, IMREAD_COLOR);
if (image.empty()) {
cout << "Could not open or find the image" << std::endl;
return -1;
}
double m = 1.5;
if (cudaDeviceIndex >= 0) {
cout << "from gpu" << std::endl;
cuda::GpuMat gpuImage, gpuDest;
gpuImage.upload(image);
cuda::resize(gpuImage, gpuDest, Size(0, 0), m, m, INTER_CUBIC);
gpuDest.download(dest);
}
else {
cout << "from cpu" << std::endl;
mainTransform(image, dest, m);
resize(image, dest, Size(0, 0), m, m, INTER_CUBIC);
}
imshow(WIN_NAME, dest);
waitKey(0);
return 0;
}
现在,如果我改为:
//#include <opencv2/core.hpp>
//#include <opencv2/imgcodecs.hpp>
//#include <opencv2/highgui.hpp>
#include "opencv2/opencv.hpp"
#include <opencv2/core/utils/logger.hpp>
#include <iostream>
#include "openCVTest.hpp"
带有openCVTest.hpp:
#ifndef _openCVTest_h
#define _openCVTest_h
#include "opencv2/opencv.hpp"
void mainTransform(InputArray src, OutputArray dest, double m);
#endif
我得到了一个C2065错误:在openCVTest.hpp.的第6行中未定义标识符
我禁用了预编译头。
我的目标是将mainTransform
的定义转移到main
之下。
解决方案是,在hpp文件中:
void mainTransform(cv::InputArray src, cv::OutputArray dest, double m);
即使用CCD_ 3前缀,因为CCD_。
相关文章:
- 在头文件中使用opencv类型来实现未定义的标识符
- 为什么T是未定义的?我正在尝试实现一个用于双链表的节点类,它不喜欢我使用友元运算符后的T
- 对具有实现的函数的未定义引用
- 从用户定义的头文件调用函数时出现未定义的引用错误,其实现位于.cpp文件中
- 未定义与未指定与实现定义的行为
- 错误:在 C++ 中实现接口模式时未定义对 typeinfo 的引用
- 如何从uint8_t的缓冲区读取带符号整数,而不调用未定义或实现定义的行为
- 尝试实现堆栈时C++未定义的引用
- 实现虚拟函数时对 vtable 的未定义引用
- 对CUDA实现功能的未定义引用
- 为什么STL实现不使用断言来检测未定义的行为
- 是否定义了此未定义的行为或实现
- 对类的未定义引用,尽管将其公开并实现
- 来自 vtable 的未定义符号是否意味着接口和实现之间存在错误
- C++ 对代码中实现和模板化的函数的未定义引用
- 在文件中使用仅 C 标头实现时未定义的符号C++
- 单例实现和对 ::GetInstance 的未定义引用
- 依赖于实现的行为和未定义的行为之间有什么区别吗
- 在IEEE浮点实现中,当溢出导致INF时,它是否被认为是未定义的bahavior
- 如何实现快速逆平方根没有未定义的行为