mirror of https://github.com/opencv/opencv.git
parent
3d68b5baa1
commit
5cf84c3765
3 changed files with 117 additions and 62 deletions
@ -0,0 +1,114 @@ |
||||
@ECHO OFF |
||||
SETLOCAL |
||||
|
||||
SET SCRIPT_DIR=%~dp0 |
||||
IF NOT EXIST "%SCRIPT_DIR%\..\..\build\setup_vars_opencv3.cmd" ( |
||||
ECHO ERROR: OpenCV Winpack installation is required |
||||
pause |
||||
exit |
||||
) |
||||
|
||||
:: Detect Python binary |
||||
python -V 2>nul |
||||
IF %ERRORLEVEL% EQU 0 ( |
||||
SET PYTHON=python |
||||
GOTO :PYTHON_FOUND |
||||
) |
||||
|
||||
CALL :QUERY_PYTHON 3.7 |
||||
IF %ERRORLEVEL% EQU 0 GOTO :PYTHON_FOUND |
||||
CALL :QUERY_PYTHON 3.6 |
||||
IF %ERRORLEVEL% EQU 0 GOTO :PYTHON_FOUND |
||||
CALL :QUERY_PYTHON 3.5 |
||||
IF %ERRORLEVEL% EQU 0 GOTO :PYTHON_FOUND |
||||
CALL :QUERY_PYTHON 3.4 |
||||
IF %ERRORLEVEL% EQU 0 GOTO :PYTHON_FOUND |
||||
CALL :QUERY_PYTHON 2.7 |
||||
IF %ERRORLEVEL% EQU 0 GOTO :PYTHON_FOUND |
||||
GOTO :PYTHON_NOT_FOUND |
||||
|
||||
:QUERY_PYTHON |
||||
SETLOCAL |
||||
SET PY_VERSION=%1 |
||||
FOR /F "tokens=2*" %%A IN ('REG QUERY "HKCU\SOFTWARE\Python\PythonCore\%PY_VERSION%\InstallPath" /reg:64 /ve 2^>NUL ^| FIND "REG_SZ"') DO SET PYTHON_DIR=%%B |
||||
IF EXIST "%PYTHON_DIR%\python.exe" ( |
||||
SET "PYTHON=%PYTHON_DIR%\python.exe" |
||||
GOTO :QUERY_PYTHON_FOUND |
||||
) |
||||
FOR /F "tokens=2*" %%A IN ('REG QUERY "HKLM\SOFTWARE\Python\PythonCore\%PY_VERSION%\InstallPath" /reg:64 /ve 2^>NUL ^| FIND "REG_SZ"') DO SET PYTHON_DIR=%%B |
||||
IF EXIST "%PYTHON_DIR%\python.exe" ( |
||||
SET "PYTHON=%PYTHON_DIR%\python.exe" |
||||
GOTO :QUERY_PYTHON_FOUND |
||||
) |
||||
|
||||
::echo Python %PY_VERSION% is not detected |
||||
ENDLOCAL |
||||
EXIT /B 1 |
||||
|
||||
:QUERY_PYTHON_FOUND |
||||
ECHO Found Python %PY_VERSION% from Windows Registry |
||||
ENDLOCAL & SET PYTHON=%PYTHON% |
||||
EXIT /B 0 |
||||
|
||||
IF exist C:\Python27-x64\python.exe ( |
||||
SET PYTHON=C:\Python27-x64\python.exe |
||||
GOTO :PYTHON_FOUND |
||||
) |
||||
IF exist C:\Python27\python.exe ( |
||||
SET PYTHON=C:\Python27\python.exe |
||||
GOTO :PYTHON_FOUND |
||||
) |
||||
|
||||
:PYTHON_NOT_FOUND |
||||
ECHO ERROR: Python not found |
||||
IF NOT DEFINED OPENCV_BATCH_MODE ( pause ) |
||||
EXIT /B |
||||
|
||||
:PYTHON_FOUND |
||||
ECHO Using Python: %PYTHON% |
||||
|
||||
:: Don't generate unnecessary .pyc cache files |
||||
SET PYTHONDONTWRITEBYTECODE=1 |
||||
|
||||
IF [%1]==[] goto rundemo |
||||
|
||||
set SRC_FILENAME=%~dpnx1 |
||||
echo SRC_FILENAME=%SRC_FILENAME% |
||||
call :dirname "%SRC_FILENAME%" SRC_DIR |
||||
call :dirname "%PYTHON%" PYTHON_DIR |
||||
PUSHD %SRC_DIR% |
||||
CALL "%SCRIPT_DIR%\..\..\build\setup_vars_opencv3.cmd" |
||||
ECHO Run: %* |
||||
%PYTHON% %* |
||||
SET result=%errorlevel% |
||||
IF %result% NEQ 0 ( |
||||
IF NOT DEFINED OPENCV_BATCH_MODE ( |
||||
SET "PATH=%PYTHON_DIR%;%PATH%" |
||||
echo ================================================================================ |
||||
echo ** Type 'python sample_name.py' to run sample |
||||
echo ** Type 'exit' to exit from interactive shell and open the build directory |
||||
echo ================================================================================ |
||||
cmd /k echo Current directory: %CD% |
||||
) |
||||
) |
||||
POPD |
||||
EXIT /B %result% |
||||
|
||||
:rundemo |
||||
PUSHD "%SCRIPT_DIR%\python" |
||||
CALL "%SCRIPT_DIR%\..\..\build\setup_vars_opencv3.cmd" |
||||
%PYTHON% demo.py |
||||
SET result=%errorlevel% |
||||
IF %result% NEQ 0 ( |
||||
IF NOT DEFINED OPENCV_BATCH_MODE ( pause ) |
||||
) |
||||
POPD |
||||
EXIT /B %result% |
||||
|
||||
|
||||
:dirname file resultVar |
||||
setlocal |
||||
set _dir=%~dp1 |
||||
set _dir=%_dir:~0,-1% |
||||
endlocal & set %2=%_dir% |
||||
EXIT /B 0 |
@ -0,0 +1,3 @@ |
||||
@echo off |
||||
call ..\_winpack_run_python_sample.cmd %* |
||||
exit /B |
@ -1,62 +0,0 @@ |
||||
@echo off |
||||
setlocal enableDelayedExpansion |
||||
|
||||
set SCRIPTDIR=%~dp0 |
||||
if NOT exist %SCRIPTDIR%\..\..\..\build ( |
||||
echo ERROR: OpenCV Winpack installation is required |
||||
pause |
||||
exit |
||||
) |
||||
|
||||
:: Path to FFMPEG binary files |
||||
set PATH=%PATH%;%SCRIPTDIR%\..\..\..\build\bin\ |
||||
|
||||
:: Detect Python binary |
||||
python -V |
||||
if %ERRORLEVEL% EQU 0 ( |
||||
set PYTHON=python |
||||
) else ( |
||||
if exist C:\Python27-x64\python.exe ( |
||||
set PYTHON=C:\Python27-x64\python.exe |
||||
) else ( |
||||
if exist C:\Python27\python.exe ( |
||||
set PYTHON=C:\Python27\python.exe |
||||
) else ( |
||||
echo ERROR: Python not found |
||||
pause |
||||
exit |
||||
) |
||||
) |
||||
) |
||||
echo Using python: %PYTHON% |
||||
|
||||
:: Detect python architecture |
||||
%PYTHON% -c "import platform; exit(64 if platform.architecture()[0] == '64bit' else 32)" |
||||
if %ERRORLEVEL% EQU 32 ( |
||||
echo Detected: Python 32-bit |
||||
set PYTHONPATH=%CD%\..\..\..\build\python\2.7\x86 |
||||
) else ( |
||||
if %ERRORLEVEL% EQU 64 ( |
||||
echo Detected: Python 64-bit |
||||
set PYTHONPATH=%CD%\..\..\..\build\python\2.7\x64 |
||||
) else ( |
||||
echo ERROR: Unknown python arch |
||||
pause |
||||
exit |
||||
) |
||||
) |
||||
|
||||
:: Don't generate unnecessary .pyc cache files |
||||
set PYTHONDONTWRITEBYTECODE=1 |
||||
|
||||
if [%1]==[] goto rundemo |
||||
%PYTHON% %* |
||||
set result=%errorlevel% |
||||
IF %result% NEQ 0 (pause) |
||||
EXIT /B %result% |
||||
|
||||
:rundemo |
||||
%PYTHON% demo.py |
||||
set result=%errorlevel% |
||||
IF %result% NEQ 0 (pause) |
||||
EXIT /B %result% |
Loading…
Reference in new issue