This is the problem of running Gao Xiang’s slambook2 code, there are two methods to solve it.
error: ‘CV_GRAY2BGR’ was not declared in this scope
/home/diyu/slambook2/ch8/optical_flow.cpp: In function ‘int main(int, char**)’:
/home/diyu/slambook2/ch8/optical_flow.cpp:145:37: error: ‘CV_GRAY2BGR’ was not declared in this scope
145 | cv::cvtColor(img2, img2_single, CV_GRAY2BGR);
| ^~~~~~~~~~~
/home/diyu/slambook2/ch8/direct_method.cpp: In function ‘void DirectPoseEstimationSingleLayer(const cv::Mat&, const cv::Mat&, const VecVector2d&, std::vector<double, std::allocator >, Sophus::SE3d&)’:
/home/diyu/slambook2/ch8/direct_method.cpp:206:35: error: ‘CV_GRAY2BGR’ was not declared in this scope
206 | cv::cvtColor(img2, img2_show, CV_GRAY2BGR);
| ^~~~~~~~~~~
make[2]: *** [CMakeFiles/optical_flow.dir/build.make:63:CMakeFiles/optical_flow.dir/optical_flow.cpp.o] ERROR 1
make[1]: *** [CMakeFiles/Makefile2:105:CMakeFiles/optical_flow.dir/all] Error 2
make[1]: *** Waiting for unfinished task…
make[2]: *** [CMakeFiles /direct_method.dir/build.make:63: CMakeFiles/direct_method.dir/direct_method.cpp.o] error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/direct_method.dir/all] error 2
make: *** [Makefile:84:all] Error 2
This experiment is because the code uses opencv2, and the cmkelists.txt file is opencv4
error: ‘CV_GRAY2BGR’ was not declared in this scope
which is the usage of opencv2, now opencv3 and 4 are COLOR_GARY2BGR
So there are two Method to Solve this error
- Change the usage of opencv2 in the code to the usage of opencv3 or 4. Change the CV_GRAY2BGR in the code to COLOR_GRAY2BGR, not sure if you just need to modify this.
- Change the opencv4 in the cmakelists file to opencv2.
Here choose the second method, modify it to opencv2
Read More:
- [Solved] error: ‘xcb_generic_event_t’ was not declared in this scope
- [Solved] MIT cheetah make error: ‘ioctl’ was not declared in this scope
- How to Solve Error:‘itoa’ was not declared in this scope
- [Solved] Keil error: #101: “name“ has already been declared in the current scope
- [Solved] OpenCV ERROR: The minSdk version should not be declared in the android manifest file
- [Solved] PCH Warning: header stop not at file scope
- [Solved] Vscode Error: “export ‘default‘ (imported as ‘VueRouter‘) was not found in ‘vue-router‘
- Go declares that the local variable does not use command line arguments. Main. Go: 4:6: a declared but not used
- error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘cv::imshow‘
- [Solved] Vue3 Error: export ‘createRouter‘ was not found in ‘vue-router‘
- [Solved] Opencv Error: Error: Assertion failed (data) in cv::Mat::at, file … mat.inl.hpp, line 897(Accessed pixels of non-existent matrix)
- Echars 5.0 Import Error: “export ‘default’ (imported as ‘echarts’) was not found in ‘echarts’
- OpenCV4 Error: imread(argv[1], CV_LOAD_IMAGE_COLOR);
- [Solved] A needed class was not found. This could be due to an error in your runpath. Missing class: scala/co
- Cv2.dnn read model error [How to Solve]
- [Solved] Android Studio Error: Use of undeclared identifier ‘cv‘
- An error was reported when Maven package was running the packaged jar package: there is no main list attribute in xxx.jar, which can be solved by configuring Maven plugin
- Error c4996: ‘getversionexa’: declared rejected [How to Solve]
- [Solved] FileUploadException: the request was rejected because no multipart boundary was found
- [Solved] Compile the program error: undefined reference to `cv::dnn::dnn4_v20210301::Net::~Net()‘