From 3c5fec6746241677d107631d612c64dbe27085a8 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 31 Mar 2020 12:19:34 +0000 Subject: [PATCH] build: updates for winpack dldt --- CMakeLists.txt | 4 +-- modules/videoio/CMakeLists.txt | 3 +- samples/_winpack_build_sample.cmd | 45 ++++++++++++++++++++------ samples/_winpack_run_python_sample.cmd | 24 ++++++++++++-- samples/python/demo.py | 22 ++++++++++--- 5 files changed, 77 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5c486415f..4c0b3880fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -946,11 +946,11 @@ endif() # for UNIX it does not make sense as LICENSE and readme will be part of the package automatically if(ANDROID OR NOT UNIX) install(FILES ${OPENCV_LICENSE_FILE} - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ DESTINATION ./ COMPONENT libs) if(OPENCV_README_FILE) install(FILES ${OPENCV_README_FILE} - PERMISSIONS OWNER_READ GROUP_READ WORLD_READ + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ DESTINATION ./ COMPONENT libs) endif() endif() diff --git a/modules/videoio/CMakeLists.txt b/modules/videoio/CMakeLists.txt index 7c72786521..c1c67543f6 100644 --- a/modules/videoio/CMakeLists.txt +++ b/modules/videoio/CMakeLists.txt @@ -221,7 +221,6 @@ if(WIN32 AND HAVE_FFMPEG_WRAPPER) endif() install(FILES "${ffmpeg_path}" DESTINATION ${OPENCV_BIN_INSTALL_PATH} COMPONENT libs RENAME "${ffmpeg_bare_name_ver}") if(INSTALL_CREATE_DISTRIB) - install(FILES "${ffmpeg_dir}/opencv_videoio_ffmpeg.dll" DESTINATION "bin/" COMPONENT libs RENAME "opencv_videoio_ffmpeg${OPENCV_DLLVERSION}.dll") - install(FILES "${ffmpeg_dir}/opencv_videoio_ffmpeg_64.dll" DESTINATION "bin/" COMPONENT libs RENAME "opencv_videoio_ffmpeg${OPENCV_DLLVERSION}_64.dll") + install(FILES "${ffmpeg_dir}/opencv_videoio_ffmpeg${FFMPEG_SUFFIX}.dll" DESTINATION "bin/" COMPONENT libs RENAME "opencv_videoio_ffmpeg${OPENCV_DLLVERSION}${FFMPEG_SUFFIX}.dll") endif() endif() diff --git a/samples/_winpack_build_sample.cmd b/samples/_winpack_build_sample.cmd index b1b4da528e..8d50ed5fb6 100644 --- a/samples/_winpack_build_sample.cmd +++ b/samples/_winpack_build_sample.cmd @@ -4,16 +4,24 @@ :: - > _winpack_build_sample.cmd cpp\opencv_version.cpp :: Requires: :: - CMake -:: - MSVS 2015/2017 +:: - MSVS 2015/2017/2019 :: (tools are searched on default paths or environment should be pre-configured) @echo off setlocal -set SCRIPTDIR=%~dp0 -if NOT exist "%SCRIPTDIR%\..\..\build" ( +SET SCRIPT_DIR=%~dp0 +SET "OPENCV_SETUPVARS_SCRIPT=setup_vars_opencv4.cmd" +SET "PACKAGE_BUILD_DIR=%SCRIPT_DIR%\..\..\build" +IF NOT EXIST "%PACKAGE_BUILD_DIR%\%OPENCV_SETUPVARS_SCRIPT%" ( + :: Winpack DLDT + SET "PACKAGE_BUILD_DIR=%SCRIPT_DIR%\..\..\..\build" +) +IF NOT EXIST "%PACKAGE_BUILD_DIR%\%OPENCV_SETUPVARS_SCRIPT%" ( set "MSG=OpenCV Winpack installation is required" goto die ) +:: normalize path +for %%i in ("%PACKAGE_BUILD_DIR%") do SET "PACKAGE_BUILD_DIR=%%~fi" if [%1]==[] ( set "MSG=Sample path is required" @@ -35,8 +43,8 @@ set "SRC_NAME=%~n1" echo SRC_NAME=%SRC_NAME% echo ================================================================================ -:: Path to FFMPEG binary files -set "PATH=%PATH%;%SCRIPTDIR%\..\..\build\bin\" +:: Path to root 'bin' dir +set "PATH=%PACKAGE_BUILD_DIR%\bin;%PATH%" :: Detect compiler cl /? >NUL 2>NUL nul @@ -80,7 +88,11 @@ 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_opencv4.cmd" + +CALL "%BUILD_DIR%\%OPENCV_SETUPVARS_SCRIPT%" +:: repair SCRIPT_DIR +SET "SCRIPT_DIR=%~dp0" + ECHO Run: %* %PYTHON% %* SET result=%errorlevel% @@ -94,17 +106,23 @@ IF %result% NEQ 0 ( cmd /k echo Current directory: %CD% ) ) + POPD EXIT /B %result% :rundemo PUSHD "%SCRIPT_DIR%\python" -CALL "%SCRIPT_DIR%\..\..\build\setup_vars_opencv4.cmd" + +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% diff --git a/samples/python/demo.py b/samples/python/demo.py index a57a5d3ea2..a56614ce4d 100755 --- a/samples/python/demo.py +++ b/samples/python/demo.py @@ -114,12 +114,24 @@ class App: def on_demo_select(self, evt): name = self.demos_lb.get( self.demos_lb.curselection()[0] ) fn = self.samples[name] - loc = {} + + descr = "" try: - execfile(fn, loc) # Python 2 - except NameError: - exec(open(fn).read(), loc) # Python 3 - descr = loc.get('__doc__', 'no-description') + if sys.version_info[0] > 2: + # Python 3.x + module_globals = {} + module_locals = {} + with open(fn, 'r') as f: + module_code = f.read() + exec(compile(module_code, fn, 'exec'), module_globals, module_locals) + descr = module_locals.get('__doc__', 'no-description') + else: + # Python 2 + module_globals = {} + execfile(fn, module_globals) # noqa: F821 + descr = module_globals.get('__doc__', 'no-description') + except Exception as e: + descr = str(e) self.linker.reset() self.text.config(state='normal')