86 lines
2.4 KiB
Batchfile
86 lines
2.4 KiB
Batchfile
@echo off
|
|
setlocal enabledelayedexpansion
|
|
|
|
:: Check for CUDA installation
|
|
where nvcc >nul 2>&1
|
|
if %ERRORLEVEL% neq 0 (
|
|
echo CUDA not found! Please install CUDA toolkit first.
|
|
echo Download from: https://developer.nvidia.com/cuda-downloads
|
|
exit /b 1
|
|
)
|
|
echo Found CUDA installation:
|
|
nvcc --version
|
|
|
|
:: Check for GPU
|
|
nvidia-smi >nul 2>&1
|
|
if %ERRORLEVEL% neq 0 (
|
|
echo No NVIDIA GPU found or drivers not installed!
|
|
exit /b 1
|
|
)
|
|
echo Found GPU:
|
|
nvidia-smi -L
|
|
|
|
:: Create build directory
|
|
if not exist "opencv_build" mkdir opencv_build
|
|
cd opencv_build
|
|
|
|
:: Clone OpenCV and OpenCV contrib if they don't exist
|
|
if not exist "opencv" (
|
|
git clone https://github.com/opencv/opencv.git
|
|
cd opencv
|
|
git checkout 4.8.0
|
|
cd ..
|
|
)
|
|
|
|
if not exist "opencv_contrib" (
|
|
git clone https://github.com/opencv/opencv_contrib.git
|
|
cd opencv_contrib
|
|
git checkout 4.8.0
|
|
cd ..
|
|
)
|
|
|
|
:: Create and enter build directory
|
|
cd opencv
|
|
if not exist "build" mkdir build
|
|
cd build
|
|
|
|
:: Configure OpenCV build with CMake
|
|
cmake -G "Visual Studio 17 2022" -A x64 ^
|
|
-D CMAKE_BUILD_TYPE=RELEASE ^
|
|
-D CMAKE_INSTALL_PREFIX=C:/opencv_cuda ^
|
|
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ^
|
|
-D WITH_CUDA=ON ^
|
|
-D WITH_CUDNN=OFF ^
|
|
-D OPENCV_DNN_CUDA=ON ^
|
|
-D ENABLE_FAST_MATH=1 ^
|
|
-D CUDA_FAST_MATH=1 ^
|
|
-D WITH_CUBLAS=1 ^
|
|
-D WITH_TBB=ON ^
|
|
-D WITH_OPENGL=ON ^
|
|
-D BUILD_opencv_world=ON ^
|
|
-D BUILD_opencv_python3=ON ^
|
|
-D OPENCV_ENABLE_NONFREE=ON ^
|
|
-D INSTALL_PYTHON_EXAMPLES=OFF ^
|
|
-D INSTALL_C_EXAMPLES=OFF ^
|
|
-D BUILD_EXAMPLES=OFF ^
|
|
-D PYTHON3_EXECUTABLE=%USERPROFILE%\AppData\Local\Programs\Python\Python39\python.exe ^
|
|
-D PYTHON3_INCLUDE_DIR=%USERPROFILE%\AppData\Local\Programs\Python\Python39\include ^
|
|
-D PYTHON3_LIBRARY=%USERPROFILE%\AppData\Local\Programs\Python\Python39\libs\python39.lib ^
|
|
-D PYTHON3_NUMPY_INCLUDE_DIRS=%USERPROFILE%\AppData\Local\Programs\Python\Python39\Lib\site-packages\numpy\core\include ^
|
|
..
|
|
|
|
:: Build OpenCV (adjust -j flag based on your CPU cores)
|
|
cmake --build . --config Release -j 8
|
|
|
|
:: Install
|
|
cmake --install .
|
|
|
|
:: Add OpenCV to Python path
|
|
set PYTHONPATH=C:\opencv_cuda\python;%PYTHONPATH%
|
|
|
|
echo.
|
|
echo Build complete! Please add C:\opencv_cuda\python to your PYTHONPATH
|
|
echo and ensure C:\opencv_cuda\x64\vc17\bin is in your PATH
|
|
echo.
|
|
echo You may need to restart your Python IDE for changes to take effect.
|
|
pause |