forked from opencv/opencv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_winpack_run_python_sample.cmd
144 lines (122 loc) · 3.41 KB
/
_winpack_run_python_sample.cmd
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
@ECHO OFF
SETLOCAL
SET SCRIPT_DIR=%~dp0
SET "OPENCV_SETUPVARS_SCRIPT=setup_vars_opencv4.cmd"
SET "BUILD_DIR=%SCRIPT_DIR%\..\..\build"
IF NOT EXIST "%BUILD_DIR%\%OPENCV_SETUPVARS_SCRIPT%" (
:: Winpack DLDT
SET "BUILD_DIR=%SCRIPT_DIR%\..\..\..\build"
)
IF NOT EXIST "%BUILD_DIR%\%OPENCV_SETUPVARS_SCRIPT%" (
ECHO ERROR: OpenCV Winpack installation is required
pause
exit
)
:: normalize path
for %%i in ("%PACKAGE_BUILD_DIR%") do SET "PACKAGE_BUILD_DIR=%%~fi"
:: Detect Python binary
python -V 2>nul
IF %ERRORLEVEL% EQU 0 (
SET PYTHON=python
GOTO :PYTHON_FOUND
)
CALL :QUERY_PYTHON 3.8
IF %ERRORLEVEL% EQU 0 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
SET PYTHON_DIR=
CALL :regquery "HKCU\SOFTWARE\Python\PythonCore\%PY_VERSION%\InstallPath" PYTHON_DIR
IF EXIST "%PYTHON_DIR%\python.exe" (
SET "PYTHON=%PYTHON_DIR%\python.exe"
GOTO :QUERY_PYTHON_FOUND
)
CALL :regquery "HKLM\SOFTWARE\Python\PythonCore\%PY_VERSION%\InstallPath" PYTHON_DIR
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: %PYTHON%
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 "%BUILD_DIR%\%OPENCV_SETUPVARS_SCRIPT%"
:: repair SCRIPT_DIR
SET "SCRIPT_DIR=%~dp0"
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 "%BUILD_DIR%\%OPENCV_SETUPVARS_SCRIPT%"
:: repair SCRIPT_DIR
SET "SCRIPT_DIR=%~dp0"
%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
:regquery name resultVar
SETLOCAL
FOR /F "tokens=*" %%A IN ('REG QUERY "%1" /reg:64 /ve 2^>NUL ^| FIND "REG_SZ"') DO SET _val=%%A
IF "x%_val%x"=="xx" EXIT /B 1
SET _val=%_val:*REG_SZ=%
FOR /F "tokens=*" %%A IN ("%_val%") DO SET _val=%%A
ENDLOCAL & SET %2=%_val%
EXIT /B 0