描述
github上找到了一个Opencv3版本的代码,clone下来后编译提示错误
终端提示
use of undeclared identifier 'CV_EVENT_LBUTTONDOWN'; did you mean 'EVENT_LBUTTONDOWN'?
类似的提示还有
use of undeclared identifier 'CV_EVENT_LBUTTONUP'; did you mean 'EVENT_LBUTTONUP'?
use of undeclared identifier 'CV_BGR2HSV'; did you mean 'COLOR_BGR2HSV'?
use of undeclared identifier 'CV_HSV2BGR'; did you mean 'COLOR_HSV2BGR'?
use of undeclared identifier 'CV_MINMAX'
use of undeclared identifier 'CV_TERMCRIT_EPS'
use of undeclared identifier 'CV_TERMCRIT_ITER'
use of undeclared identifier 'CV_AA'
解决方案
- 原因:显而易见的是,Opencv版本不同时变量名称发生了改变,我的电脑是Opencv4
解决办法一
这种解决办法适合,Opencv4版本中仍然存在的变量
按照终端的提示,将错误的use of undeclared identifier
变量名替换为did you mean
后的变量名
CV_EVENT_LBUTTONDOWN
变为EVENT_LBUTTONDOWN
CV_EVENT_LBUTTONUP
变为EVENT_LBUTTONUP
CV_BGR2HSV
变为COLOR_BGR2HSV
CV_HSV2BGR
变为COLOR_HSV2BGR
解决办法
部分变量Opencv4已经删除了,这种时候就需要对未定义的变量进行声明
在代码中添加宏定义
#define CV_TERMCRIT_EPS 2
#define CV_TERMCRIT_ITER 1
#define CV_AA 16
还有一个比较特殊的更改就是
将CV_MINMAX
变量改成NORM_MINMAX
,就可以解决