‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope

在编译时提示找不到opencv相关标志:
‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope
CV_LOAD_IMAGE_UNCHANGED’ was not declared in this scope
‘CV_MINMAX’ was not declared in this scope

原因是作者代码使用的opencv版本是3.x,而自己默认的opencv版本是4.4.0,在新版本中相关的定义已经发生了变化,解决办法有两个:
方法一:
碰巧自己电脑也装了opencv3.2,该一下代码默认使用的opencv版本就好了,一步到位
CMakeLists.txt文件中,将find_package(OpenCV REQUIRED)改为find_package(OpenCV 3.2 REQUIRED)3.2即自己的电脑上opencv3.x的具体版本。

方法二:
将对应3.x版本的旧标志替换为4.x版本的新标志即可,参考如下:

   CV_LOAD_IMAGE_UNCHANGED  = -1 ( = cv::IMREAD_UNCHANGED),
   CV_LOAD_IMAGE_GRAYSCALE  = 0  ( = cv::IMREAD_GRAYSCALE),
   CV_LOAD_IMAGE_COLOR      = 1  ( = cv::IMREAD_COLOR),
   CV_LOAD_IMAGE_ANYDEPTH   = 2  ( = cv::IMREAD_ANYDEPTH),
   CV_LOAD_IMAGE_ANYCOLOR   = 4
   CV_MINMAX = NORM_MINMAX

你可能感兴趣的:(C++学习笔记,opencv,计算机视觉)