文章目录

写在前面

自己的测试环境: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_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.

九、报错 error: ‘CV_RGB2GRAY’ was not declared in this scope

1. 问题描述

编译报错:

error: ‘CV_RGB2GRAY’ was not declared in this scope

2. 解决方法1

将报错文件包含的 CV_RGB2GRAY 进行修改:

CV_RGB2GRAY
修改为:
cv::COLOR_RGB2GRAY

然后再次编译就可以编译通过了。

2. 解决方法2

将报错文件中增加包含头文件:

#include <opencv2/imgproc/types_c.h>
// #include <opencv2/opencv.hpp> // 如果只包含上一个头文件依旧不能解决问题,那么就把两个头文件都包含进去。

然后再次编译就可以编译通过了。

参考链接

[1] 翟羽嚄. OpenCV4、C++:未定义标识符 “CV_RGB2GRAY“ 的解决方案 [EB/OL]. https://blog.csdn.net/mao_hui_fei/article/details/109135733, 2020-10-17/2023-10-29.

十、报错 error: ‘CV_FONT_HERSHEY_SIMPLEX’ was not declared in this scope

1. 问题描述

编译报错:

error: ‘CV_FONT_HERSHEY_SIMPLEX’ was not declared in this scope

2. 解决方法1

将报错文件包含的 CV_FONT_HERSHEY_SIMPLEX 进行修改:

CV_FONT_HERSHEY_SIMPLEX
修改为:
cv::FONT_HERSHEY_SIMPLEX

然后再次编译就可以编译通过了。

参考链接

[1] 宇文树雪. VINS-Mono在opencv4环境下的安装问题和解决方法 [EB/OL]. https://zhuanlan.zhihu.com/p/548140724, 2022-07-31/2023-10-29.

十一、报错 CV_GRAY2BGR was not declared in this scope

1. 问题描述

error: ‘CV_GRAY2BGR’ was not declared in this scope

2. 解决方法

添加头文件

#include <opencv2/imgproc/types_c.h>

然后再次编译就可以编译通过了。

十二、报错 CV_CALIB_CB_ADAPTIVE_THRESH was not declared in this scope

1. 问题描述

error: ‘CV_CALIB_CB_ADAPTIVE_THRESH’ was not declared in this scope

2. 解决方法

添加头文件

#include <opencv2/calib3d/calib3d_c.h>

然后再次编译就可以编译通过了。

参考链接

[1] xlsemmmmmm. opencv常见用法和opencv3->opencv4版本切换 [EB/OL]. https://blog.csdn.net/weixin_43848456/article/details/123380782, 2022-07-10/2024-07-04.

十三、报错 CV_AA was not declared in this scope

1. 问题描述

error: ‘CV_AA’ was not declared in this scope

2. 解决方法

添加头文件

#include <opencv2/imgproc/imgproc_c.h>

然后再次编译就可以编译通过了。

十四、报错 ‘cvCreateMat’ was not declared in this scope ; 或者报错 ‘cvMulTransposed’ was not declared in this scope

1. 问题描述

‘cvCreateMat’ was not declared in this scope;

或者

‘cvMulTransposed’ was not declared in this scope

2. 解决方法

添加头文件

#include <opencv2/imgproc/types_c.h>

然后再次编译就可以编译通过了。

参考链接

[1] 浪荡书生mw. ORB-SLAM2和ORB-SLAM3环境配置及运行 [EB/OL]. https://blog.csdn.net/meng_152634/article/details/127570220, 2024-10-12/2024-10-29.

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐