文章目录
- 写在前面
- 一、报错 `CV_INTER_LINEAR was not declared in this scope`
- 二、报错 `CV_RANSAC was not declared in this scope`
- 三、报错 `CV_WINDOW_AUTOSIZE was not declared in this scope`
- 四、报错 `CV_GRAY2RGB was not declared in this scope`
- 五、报错 `fatal error: opencv/cv.h: No such file or directory`
- 六、报错 `fatal error: opencv/highgui.h: No such file or directory`
- 七、报错 `error: ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope`
- 八、报错 `error: ‘CV_LOAD_IMAGE_COLOR’ was not declared in this scope`
写在前面
自己的测试环境:Ubuntu 20.04.5,OpenCV4.2.0
一、报错 CV_INTER_LINEAR was not declared in this scope
1. 问题描述
自己把OpenCV3的程序转到OpenCV4下进行编译,遇到如下报错
error: ‘CV_INTER_LINEAR’ was not declared in this scope
2. 解决方法
出现这个问题的主要原因是 OpenCV3 和 OpenCV4 中的某些变量是不一样的。OpenCV4部分取消了CV_前缀
解决方法很简单,就是找到报错的文件,报错的变量修改适配 OpenCV4 中的变量。
CV_INTER_LINEAR 修改为 cv::INTER_LINEAR
或者,添加头文件
#include<opencv2/imgproc/imgproc_c.h>
然后再次编译就可以编译通过了。
二、报错 CV_RANSAC was not declared in this scope
1. 问题描述
error: ‘CV_RANSAC’ was not declared in this scope
2. 解决方法
程序中的 CV_RANSAC 修改为 cv::RANSAC
然后再次编译就可以编译通过了。
三、报错 CV_WINDOW_AUTOSIZE was not declared in this scope
1. 问题描述
error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope
2. 解决方法
CV_WINDOW_AUTOSIZE 修改为 cv::WINDOW_AUTOSIZE
或者,添加头文件
#include <opencv2/highgui/highgui_c.h>
然后再次编译就可以编译通过了。
参考链接
[1] xlsemmmmmm. opencv常见用法和opencv3->opencv4版本切换 [EB/OL]. https://blog.csdn.net/weixin_43848456/article/details/123380782, 2022-07-10/2022-11-28.
四、报错 CV_GRAY2RGB was not declared in this scope
1. 问题描述
error: ‘CV_GRAY2RGB’ was not declared in this scope
2. 解决方法
添加头文件
#include <opencv2/imgproc/types_c.h>
然后再次编译就可以编译通过了。
参考链接
[1] 老文化沙漠. opencv4中未定义标识符CV_BGR2GRAY和CV_CAP_PROP_FRAME_COUNT问题 [EB/OL]. https://blog.csdn.net/qq_48176859/article/details/109735701, 2020-11-17/20222-12-03.
五、报错 fatal error: opencv/cv.h: No such file or directory
1. 问题描述
编译报错:
找不到opencv/cv.h文件
fatal error: opencv/cv.h: No such file or directory
2. 解决方法
将报错文件包含的头文件进行修改:
#include <opencv/cv.h>
修改为:
#include <opencv2/imgproc/types_c.h>
然后再次编译就可以编译通过了。
六、报错 fatal error: opencv/highgui.h: No such file or directory
1. 问题描述
编译报错:
fatal error: opencv/highgui.h: No such file or directory
2. 解决方法
将报错文件包含的头文件进行修改:
#include <opencv/highgui.h>
修改为:
#include <opencv2/highgui/highgui_c.h>
然后再次编译就可以编译通过了。
参考链接
[1] xlsemmmmmm. opencv常见用法和opencv3->opencv4版本切换 [EB/OL]. https://blog.csdn.net/weixin_43848456/article/details/123380782, 2022-07-10/2022-11-28.
七、报错 error: ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope
1. 问题描述
编译报错:
error: ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope
2. 解决方法
将报错文件包含的头文件进行修改:
CV_LOAD_IMAGE_GRAYSCALE
修改为:
cv::IMREAD_GRAYSCALE
然后再次编译就可以编译通过了。
参考链接
[1] 我是快乐的小趴菜. ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope [EB/OL]. https://blog.csdn.net/guanjing_dream/article/details/124960771, 2022-05-25/2022-12-05.
八、报错 error: ‘CV_LOAD_IMAGE_COLOR’ was not declared in this scope
1. 问题描述
编译报错:
error: ‘CV_LOAD_IMAGE_COLOR’ was not declared in this scope
2. 解决方法
将报错文件包含的头文件进行修改:
CV_LOAD_IMAGE_COLOR
修改为:
cv::IMREAD_COLOR
然后再次编译就可以编译通过了。
参考链接
[1] 我是快乐的小趴菜. ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope [EB/OL]. https://blog.csdn.net/guanjing_dream/article/details/124960771, 2022-05-25/2022-12-05.