OpenCV: error: ‘CV_GRAY2BGR’ was not declared in this scope
## error: ‘CV_GRAY2BGR’ was not declared in this scope
```sh
/home/yubao/data/project/slambook2/VO_Direct/direct_method.cpp: In function ‘void DirectPoseEstimationSingleLayer(const cv::Mat&, const cv::Mat&, const VecVector2d&, std::vector >, Sophus::SE3d&)’:
/home/yubao/data/project/slambook2/VO_Direct/direct_method.cpp:206:35: error: ‘CV_GRAY2BGR’ was not declared in this scope
cv::cvtColor(img2, img2_show, CV_GRAY2BGR);
^~~~~~~~~~~
CMakeFiles/direct_method.dir/build.make:62: recipe for target 'CMakeFiles/direct_method.dir/direct_method.cpp.o' failed
make[2]: *** [CMakeFiles/direct_method.dir/direct_method.cpp.o] Error 1
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/direct_method.dir/all' failed
make[1]: *** [CMakeFiles/direct_method.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
```
## Solution
```cpp
cv::Mat img2_show;
#if (CV_VERSION_MAJOR >= 4)
cv::cvtColor(img2, img2_show, cv::COLOR_GRAY2BGR);
#else
cv::cvtColor(img2, img2_show, CV_GRAY2BGR);
#endif
```
## References
- [CV_BGR2RGB' was not declared in this scope](https://github.com/NVIDIA/DALI/issues/735)
No comments