I need help updating 10 deprecated (OpenCV 3.2.0) lines of code found in https://github.com/yirgagithub/Cat-and-Dog-SVM-classifier (their last commit was on Mar 1, 2017) to work with OpenCV 4 on Ubuntu 20.04 LTS, because this is one of the few GitHub projects that uses C++ (NOT Python) to do image classification (in this case distinguising pictures of dogs and cats). I am taking a Udacity C++ online nanodegree course and for their capstone project they suggest either making a computer game or creating an AI. I have decided to create an image classifier AI starting from https://github.com/yirgagithub/Cat-and-Dog-SVM-classifier because that is the closest to what I might do when I get a job.
I understand that there are OpenCV courses (https://opencv.org/courses/) that if I spent weeks or months on I might figure this out on my own, but I have already taken several R Studio and Python (Spyder) AI online courses (that did not use OpenCV they used TensorFlow, etc.) so I do not want to spend time on more. I looked for C++ TensorFlow GitHub image classifier projects and that is not promising.
Below is my Fork of https://github.com/yirgagithub/Cat-and-Dog-SVM-classifier. The fork has the settings.json and launch.json in the .vscode directory and I updated some deprecated #include to their new locations in OpenCV 4. I ran cmake (below) and got stuck (errors) on the 12 deprecated elements:
cmake ..
cmake --build . --config Release
My Fork: https://github.com/ProfHariSeldon/CppND-Capstone-Hello-World
You can skip the Install Instructions and just look at DEPRICIATED: to see the code I need help with. I have confirmed that Visual Studio Code recognizes the OpenCV #include (I added that path "/home/tlroot/installation/OpenCV-master/include/opencv4/" to settings.json) and that cmake finds the OpenCV files too (I added that path "/home/tlroot/installation/OpenCV-master/" to CMakeLists.txt). I also don't really understand my CMakeLists.txt this is my first time building one from scratch. I got it working but if you have advice please let me know.
Install instructions
How to upgrade to Ubuntu 20.04 LTS sudo do-release-upgrade -d -f DistUpgradeViewGtk3
How to Install OpenCV 4 on Ubuntu Instructions here: https://www.learnopencv.com/install-opencv-4-on-ubuntu-18-04/
building from Source in my home directory I guess that's OK
$ cd /home/tlroot
$ sudo chmod +x ./installOpenCV-4-on-Ubuntu-18-04.sh
$ sudo bash installOpenCV-4-on-Ubuntu-18-04.sh
$ cd /home/tlroot/installation
$ sudo ldconfig
$ cd /home/tlroot/C++/Capstone
$ git clone https://github.com/yirgagithub/Cat-and-Dog-SVM-classifier.git
The CMakeLists.txt file to use
# see CMake Lists.txt file in /home/tlroot/Documents/C++/OOP/Project/CppND-System-Monitor
# https://www.learnopencv.com/install-opencv-4-on-ubuntu-18-04/
cmake_minimum_required(VERSION 3.1)
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
SET(OpenCV_DIR /home/tlroot/installation/OpenCV-master/include/opencv4/)
# https://stackoverflow.com/questions/53528125/fatal-error-no-such-file-or-directory-when-im-sure-i-have-set-find-package-cor
find_package( OpenCV REQUIRED PATHS "/home/tlroot/installation/OpenCV-master/")
project(classifier)
file(GLOB SOURCES "dictionary/*.cpp")
add_executable(classifier ${SOURCES})
# https://docs.opencv.org/2.4/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html
target_link_libraries( classifier ${OpenCV_LIBS} )
# add_executable( DisplayImage DisplayImage.cpp )
How to get to settings.json
GUI instructions: Visual Studio Code -> File -> Preferences -> Settings -> User -> Extensions -> C/C++ -> Edit in settings.json https://stackoverflow.com/questions/37522462/visual-studio-code-includepath
settings.json to use
{ "files.associations": { "iostream": "cpp" }, "[cpp]": { "editor.defaultFormatter": "xaver.clang-format" }, "C_Cpp.default.includePath": ["/home/tlroot/installation/OpenCV-master/include/opencv4/"] }
How to build the project
$ mkdir build && cd build
$ cmake ..
$ cmake --build . --config Release
How to get to launch.json
GUI instructions: Visual Studio Code -> Run -> Open Configurations
launch.json to use
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "g++ build and debug active file", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder}/build/classifier", "args": [], "stopAtEntry": true, "cwd": "${workspaceFolder}/build", "environment": [], "externalConsole": false, "MIMode": "gdb", "setupCommands": [ { "description": "Enable pretty-printing for gdb", "text": "-enable-pretty-printing", "ignoreFailures": true } ], "preLaunchTask": "g++ build active file", "miDebuggerPath": "/usr/bin/gdb" } ] }
#include changes
This change is based on: https://stackoverflow.com/questions/27418668/nonfree-module-is-missing-in-opencv-3-0
"#include < opencv2/nonfree/features2d.hpp >" to "#include < opencv2/xfeatures2d.hpp >"
This change is based on looking in: https://github.com/opencv/opencv_contrib/tree/master/modules/xfeatures2d/include/opencv2
"#include < opencv2/nonfree/nonfree.hpp >" to "#include < opencv2/xfeatures2d/nonfree.hpp >"
DEPRICIATED:
main.cpp:
26: cv::SiftFeatureDetector sift(300);
300
no instance of constructor "cv::SIFT::SIFT" matches the argument list -- argument types are: (int)
PredictImage.cpp
27: cv::Ptr<cv::featuredetector> siftFeatureDetector(new cv::SiftFeatureDetector(300));
cv::SiftFeatureDetector
no instance of constructor "cv::SIFT::SIFT" matches the argument list -- argument types are: (int)
49: cv::SVM svm;
SVM
namespace "cv" has no member "SVM"
svm
expected a ';'
50: svm.load("svmtrained.yml");
svm.load
identifier "svm" is undefined
TrainSVM.cpp
33: cv::Ptr<cv::featuredetector> siftFeatureDetector(new cv::SiftFeatureDetector(300));
cv::SiftFeatureDetector
no instance of constructor "cv::SIFT::SIFT" matches the argument list -- argument types are: (int)
62: cv::SVMParams svmParam;
SVMParams
namespace "cv" has no member "SVMParams"
84: svmParam.svm_type=cv::SVM::C_SVC;
SVM
name followed by '::' must be a class or namespace name
85: svmParam.kernel_type=cv::SVM::LINEAR;
SVM
name followed by '::' must be a class or namespace name
89: cv::SVM svm;
SVM
namespace "cv" has no member "SVM"
svm
expected a ';'
90: bool trainSvm=svm.train(samples,labelsMat,cv::Mat(),cv::Mat(),svmParam);
svm.train
identifier "svm" is undefined
CMake warnings
As I said I don't really understand CMakeLists.txt I got it working but I did get many warnings about STATIC not SHARED library:
CMake Warning (dev) at /home/tlroot/installation/OpenCV-master/lib/cmake/opencv4/OpenCVModules.cmake:435 (add_library): ADD_LIBRARY called with SHARED option but the target platform does not support dynamic linking. Building a STATIC library instead. This may lead to problems. Call Stack (most recent call first): /home/tlroot/installation/OpenCV-master/lib/cmake/opencv4/OpenCVConfig.cmake:126 (include) CMakeLists.txt:11 (find_package) This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at /home/tlroot/installation/OpenCV-master/lib/cmake/opencv4/OpenCVModules.cmake:442 (add_library): ADD_LIBRARY called with SHARED option but the target platform does not support dynamic linking. Building a STATIC library instead. This may lead to problems. Call Stack (most recent call first): /home/tlroot/installation/OpenCV-master/lib/cmake/opencv4/OpenCVConfig.cmake:126 (include) CMakeLists.txt:11 (find_package) This warning is for project developers. Use -Wno-dev to suppress it.