-
Notifications
You must be signed in to change notification settings - Fork 1
Build OpenCV from source and run examples
Ash Babu edited this page Sep 14, 2022
·
9 revisions
git clone [email protected]:opencv/opencv.git
git checkout 4.x
- [optional]
git clone [email protected]:opencv/opencv_contrib.git
git checkout 4.x
cd ~/opencv && mkdir build && cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_GENERATE_PKGCONFIG=YES OPENCV_EXTRA_MODULES_PATH=~/.../opencv_contrib/modules/ BUILD_EXAMPLES=true ..
make -j$(nproc)
-
sudo make install
if need to install else inCMakeLists.txt
, add the followingset(OpenCV_DIR "/path_to_/opencv/build")
find_package(OpenCV x.y REQUIRED )
wherex.y
is the version, for instance 4.6 orfind_package(OpenCV REQUIRED )
should also work.
To build OpenCV with CUDA
-
cmake -D WITH_CUDA=ON OPENCV_EXTRA_MODULES_PATH=~/.../opencv_contrib/modules/ ..
# dont enable other flags
Note: There is a high chance that if there's any existing OpenCV installations (maybe ros specific), make sure to uninstall with sudo apt-get remove opencv* libopencv*
sudo apt remove libopencv-dev python3-opencv
. Check again if there are existing installations using dpkg -l | grep libopencv
and pkg-config --libs opencv/opencv4
and pkg-config --modversion opencv/opencv4
. All the above should return none. After the installation pkg-config --modversion opencv/opencv4
will show opencv 3/4.4.16
. Then compile librealsense
. Since by now, ROS would have stopped working, so go to catkin_ws
and use rosdep install --from-paths src --ignore-src -r -y
from catkin_ws
to re-install all ros dependencies
After building opencv,
cd opencv/samples
- Open with CLion by
Load CMake Project
of theCMakeLists.txt
under thesamples
folder - This will load
example_dnn_object_detection
but requires certain command line arguments - Run
example_dnn_object_detection --config=/home/ash/Ash/repo/librealsense/wrappers/opencv/ash-yolov4/models/yolov4.cfg --model=/home/ash/Ash/repo/librealsense/wrappers/opencv/ash-yolov4/models/yolov4.weights --classes=/home/ash/Ash/repo/librealsense/wrappers/opencv/ash-yolov4/coco.names --width=416 --height=416 --scale=0.00392 --rgb
where the arguments are to be set inRun--> Program arguments
- The example can be found here