-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_opencv_linux.sh
More file actions
executable file
·96 lines (80 loc) · 2.75 KB
/
build_opencv_linux.sh
File metadata and controls
executable file
·96 lines (80 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/bash
set -e
# Parse command line argument
BUILD_TYPE="Release"
if [ "$1" = "debug" ]; then
BUILD_TYPE="Debug"
echo "Building in Debug mode..."
elif [ "$1" != "" ] && [ "$1" != "release" ]; then
echo "Usage: $0 [debug|release]"
echo " debug - Build debug version with symbols"
echo " release - Build optimized release version (default)"
exit 1
fi
# Configuration
OPENCV_VERSION="4.11.0"
BUILD_DIR="$HOME/opencv_build_411"
if [ "$BUILD_TYPE" = "Debug" ]; then
INSTALL_DIR="$BUILD_DIR/install_debug"
BUILD_SUBDIR="build_debug"
else
INSTALL_DIR="$BUILD_DIR/install"
BUILD_SUBDIR="build"
fi
echo "Building OpenCV ${OPENCV_VERSION} in $BUILD_TYPE mode..."
# Create and enter build directory
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
# Download sources if they don't exist
if [ ! -d "opencv-${OPENCV_VERSION}" ]; then
echo "Downloading OpenCV ${OPENCV_VERSION}..."
curl -L "https://github.com/opencv/opencv/archive/refs/tags/${OPENCV_VERSION}.tar.gz" -o "opencv-${OPENCV_VERSION}.tar.gz"
tar -xzf "opencv-${OPENCV_VERSION}.tar.gz"
fi
if [ ! -d "opencv_contrib-${OPENCV_VERSION}" ]; then
echo "Downloading OpenCV Contrib ${OPENCV_VERSION}..."
curl -L "https://github.com/opencv/opencv_contrib/archive/refs/tags/${OPENCV_VERSION}.tar.gz" -o "opencv_contrib-${OPENCV_VERSION}.tar.gz"
tar -xzf "opencv_contrib-${OPENCV_VERSION}.tar.gz"
fi
# Create build directory
mkdir -p "$BUILD_SUBDIR"
cd "$BUILD_SUBDIR"
echo "Configuring CMake for $BUILD_TYPE build..."
cmake \
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
-DBUILD_LIST=calib3d,core,features2d,highgui,imgcodecs,imgproc,video,videoio,aruco,objdetect,ml,stitching \
-DOPENCV_EXTRA_MODULES_PATH="../opencv_contrib-${OPENCV_VERSION}/modules" \
-DWITH_FFMPEG=ON \
-DWITH_GTK=OFF \
-DWITH_QT=ON \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
-DBUILD_TESTS=OFF \
-DBUILD_PERF_TESTS=OFF \
-DBUILD_EXAMPLES=OFF \
"../opencv-${OPENCV_VERSION}"
echo "Building OpenCV..."
make -j$(sysctl -n hw.logicalcpu)
echo "Installing OpenCV..."
make install
# Create symlinks for versioned libraries
echo "Creating .so version symlinks..."
cd "$INSTALL_DIR/lib"
for lib in libopencv_*.so.4.11.0; do
if [ -f "$lib" ]; then
base=$(basename "$lib" .so.4.11.0)
ln -sf "$lib" "${base}.so.4.11.0"
echo "Created symlink: ${base}.so.4.11.0 -> $lib"
fi
done
echo ""
echo "Build completed successfully!"
echo "Build type: $BUILD_TYPE"
echo "Libraries installed in: $INSTALL_DIR/lib"
echo "Headers installed in: $INSTALL_DIR/include"
if [ "$BUILD_TYPE" = "Debug" ]; then
echo ""
echo "Debug build complete. Use this path for debugging:"
echo " Libraries: $INSTALL_DIR/lib"
echo " Headers: $INSTALL_DIR/include"
fi