├── .gitignore ├── README.md ├── autoit-addon ├── CMakeLists.txt ├── addon.au3 ├── addon.cpp ├── addon.h ├── autoitdef.h ├── build.bat ├── test_addon.cc └── vswhere.exe ├── autoit-opencv-com ├── CMakeLists.txt ├── build.bat ├── cmake │ ├── FindPatch.cmake │ ├── RequireOpenCV.cmake │ ├── git_patch_once.cmake │ └── vcpkg_regex_replace_string.cmake ├── dotnet │ ├── OpenCvComInterop.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── install.bat ├── patches │ └── 001-opencv-src.patch ├── src │ ├── autoit_bridge.cpp │ ├── autoit_bridge.h │ ├── autoit_bridge_common.cpp │ ├── autoit_bridge_common.h │ ├── autoit_def.h │ ├── contrib │ │ ├── cv_extra.cpp │ │ ├── cv_extra.h │ │ ├── imgproc_extra.cpp │ │ ├── imgproc_extra.h │ │ ├── mat_extra.cpp │ │ └── mat_extra.h │ ├── cvLib.rc │ ├── cvLib.rgs │ ├── cv_extended.cpp │ ├── dllmain.cpp │ ├── dllmain.def │ ├── dllmain.h │ ├── impl_cv.cpp │ ├── impl_cv.h │ ├── impl_mat.cpp │ ├── impl_mat.h │ ├── targetver.h │ └── wgc │ │ ├── SimpleCapture.cpp │ │ ├── SimpleCapture.h │ │ ├── capture.interop.h │ │ ├── composition.interop.h │ │ ├── d3dHelpers.h │ │ └── direct3d11.interop.h ├── test │ ├── test.cpp │ ├── test.cs │ └── test.h ├── udf │ ├── cv_enums.au3 │ ├── cv_interface.au3 │ ├── docs.md │ ├── opencv_udf.au3 │ └── opencv_udf_utils.au3 └── vswhere.exe ├── opencv └── CMakeLists.txt ├── package-lock.json ├── package.json ├── project.sublime-project ├── samples ├── 01-show-image.au3 ├── 02-show-image-gui.au3 ├── 02.1-show-image-gui-autosize.au3 ├── 03-show-screen-image.au3 ├── 04-find-template.au3 ├── 05.1-video-capture-camera.au3 ├── 05.2-video-capture-file.au3 ├── 06.1-rotate-image.au3 ├── 06.2-rotate-image-bound.au3 ├── 07-resize-with-gdi-plus.au3 ├── 08-drawing-contours.au3 ├── 09-find-image-on-screen.au3 ├── 10-PixelSearch-PixelChecksum.au3 ├── Table.au3 ├── autoit │ └── kalman.au3 ├── data │ ├── Histogram_Comparison_Source_0.jpg │ ├── Histogram_Comparison_Source_1.jpg │ ├── Histogram_Comparison_Source_2.jpg │ ├── j.png │ ├── mario.png │ └── mario_coin.png ├── dnn │ └── object_detection │ │ ├── download_model.ps1 │ │ ├── download_model.py │ │ ├── models.yml │ │ ├── object_detection.au3 │ │ └── object_detection.py ├── dotnet │ ├── 01-show-image.cs │ ├── 01-show-image.ps1 │ ├── 02-video-capture-camera.cs │ ├── 02-video-capture-camera.ps1 │ ├── 03-video-capture-file.cs │ ├── 03-video-capture-file.ps1 │ ├── 04-rotate-image.cs │ ├── 04-rotate-image.ps1 │ ├── 05-drawing-contours.cs │ ├── 05-drawing-contours.ps1 │ ├── csrun.bat │ ├── csrun.ps1 │ └── opencv_utils.psm1 ├── samples.ps1 ├── samples.xlsm └── tutorial_code │ ├── Histograms_Matching │ ├── EqualizeHist_Demo.au3 │ ├── MatchTemplate_Demo.au3 │ ├── calcBackProject_Demo1.au3 │ ├── calcHist_Demo.au3 │ └── compareHist_Demo.au3 │ ├── ImgProc │ ├── Smoothing │ │ └── Smoothing.au3 │ ├── Threshold_inRange.au3 │ ├── changing_contrast_brightness_image │ │ └── changing_contrast_brightness_image.au3 │ └── morphology │ │ └── morphology.au3 │ ├── ShapeDescriptors │ └── bounding_rotated_ellipses │ │ └── generalContours_demo2.au3 │ ├── core │ ├── AddingImages │ │ └── AddingImages.au3 │ └── discrete_fourier_transform │ │ └── discrete_fourier_transform.au3 │ ├── extra │ ├── Find-Contour-Draw-Demo.au3 │ ├── MultiMatchTemplate_Demo.au3 │ └── ScaledMatchTemplate_Demo.au3 │ ├── features2D │ ├── AKAZE_match.au3 │ └── feature_homography │ │ └── matching_homography_Demo.au3 │ ├── pyimagesearch │ ├── detect_color │ │ ├── detect_color.au3 │ │ └── example_shapes.png │ ├── detect_shapes │ │ ├── detect_shapes.au3 │ │ └── shapes_and_colors.png │ ├── find_shapes │ │ ├── find_shapes.au3 │ │ └── shapes.png │ ├── opencv_haar_cascades │ │ ├── cascades │ │ │ ├── haarcascade_eye.xml │ │ │ ├── haarcascade_frontalface_default.xml │ │ │ └── haarcascade_smile.xml │ │ └── opencv_haar_cascades.au3 │ ├── scan │ │ ├── example_01.jpg │ │ ├── receipt.jpg │ │ ├── scan.au3 │ │ └── scan.py │ └── test_grader │ │ ├── images │ │ ├── example_test.png │ │ ├── test_01.png │ │ ├── test_02.png │ │ ├── test_03.png │ │ ├── test_04.png │ │ └── test_05.png │ │ └── test_grader.au3 │ ├── tapi │ └── bgfg_segm.au3 │ └── yolo │ ├── coco.txt │ ├── people-2557408_1920.jpg │ ├── scooter-5180947_1920.jpg │ ├── yolo.au3 │ ├── yolo.py │ └── yolov3.cfg ├── scripts ├── build.js ├── func_kwargs.js ├── manual.sh ├── tasks.sh ├── test.js └── version.js └── src ├── COMGenerator.js ├── CoClass.js ├── DeclProcessor.js ├── FileUtils.js ├── FunctionDeclaration.js ├── MidlCompiler.js ├── PropertyDeclaration.js ├── alias.js ├── constants.js ├── conversion.js ├── conversions ├── Mat.js ├── point.js ├── rect.js ├── size.js └── vec.js ├── custom_conversions.js ├── custom_declarations.js ├── declarations ├── HostMem.js ├── Mat.js ├── Matx.js ├── RNG.js ├── Range.js ├── RotatedRect.js ├── TermCriteria.js ├── UMat.js ├── cv.js ├── mutex.js └── structures.js ├── dependencies.js ├── doctoc.js ├── gen.js ├── ids.json ├── map_conversion.js ├── optional_conversion.js └── vector_conversion.js /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .venv 3 | /autoit-opencv-*-com-v*.7z 4 | /diff 5 | /node_modules 6 | /opencv/__build__ 7 | /opencv/build 8 | /opencv/download 9 | /opencv/install 10 | /opencv/opencv 11 | /opencv/opencv_contrib 12 | /opencv-* 13 | /samples/dotnet/*.exe 14 | /*.sublime-workspace 15 | BackUp 16 | generated 17 | *build_x64 18 | Windows.UI.Composition-Win32-Samples-* 19 | /autoit-addon/cmake 20 | /autoit-addon/patches 21 | /samples/dnn/object_detection/models 22 | *.onnx 23 | *.weights 24 | -------------------------------------------------------------------------------- /autoit-addon/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5) 2 | 3 | # Name of the project (will be the name of the plugin) 4 | project(autoit_addon) 5 | 6 | set(DEFAULT_BUILD_TYPE "Release") 7 | 8 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) 9 | message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.") 10 | set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE) 11 | # Set the possible values of build type for cmake-gui 12 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") 13 | endif() 14 | 15 | set(OpenCV_VERSION 4.10.0 CACHE STRING "Choose the OpenCV version.") 16 | file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/../autoit-opencv-com/cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake" SYMBOLIC) 17 | file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/../autoit-opencv-com/patches" "${CMAKE_CURRENT_SOURCE_DIR}/patches" SYMBOLIC) 18 | include(cmake/RequireOpenCV.cmake) 19 | include(cmake/vcpkg_regex_replace_string.cmake) 20 | 21 | vcpkg_regex_replace_string("${CMAKE_CURRENT_SOURCE_DIR}/addon.au3" "autoit_addon[0-9]+" "autoit_addon${OpenCV_DLLVERSION}") 22 | 23 | set(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}/bin" CACHE PATH "Output directory for applications") 24 | set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib" CACHE PATH "Output directory for libraries") 25 | 26 | if(CMAKE_COMPILER_IS_GNUCXX) 27 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-function") 28 | endif() 29 | 30 | # Source headers 31 | file(GLOB project_hdrs addon.h) 32 | source_group("Include" FILES ${project_hdrs}) 33 | 34 | # Source files 35 | file(GLOB project_srcs addon.cpp) 36 | source_group("Src" FILES ${project_srcs}) 37 | 38 | # Build a shared library named as the project 39 | add_library(${PROJECT_NAME} SHARED ${project_srcs} ${project_hdrs}) 40 | target_link_libraries(${PROJECT_NAME} PRIVATE ${OpenCV_LIBS}) 41 | target_compile_definitions(${PROJECT_NAME} PRIVATE AUTOIT_MODULE_NAME=${PROJECT_NAME} AUTOITAPI_EXPORTS) 42 | 43 | set_target_properties(${PROJECT_NAME} PROPERTIES 44 | OUTPUT_NAME "${PROJECT_NAME}${OpenCV_DLLVERSION}" 45 | DEBUG_POSTFIX "${OpenCV_DEBUG_POSTFIX}" 46 | COMPILE_PDB_NAME "${PROJECT_NAME}${OpenCV_DLLVERSION}" 47 | COMPILE_PDB_NAME_DEBUG "${PROJECT_NAME}${OpenCV_DLLVERSION}${OpenCV_DEBUG_POSTFIX}" 48 | ARCHIVE_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}" 49 | COMPILE_PDB_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}" 50 | LIBRARY_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}" 51 | RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}" 52 | ) 53 | 54 | # Always generate debug files 55 | if(MSVC AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") 56 | set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "/DEBUG") 57 | endif() 58 | 59 | get_filename_component(OPENCV_SAMPLES_DATA_PATH_HINT "../samples/data" REALPATH) 60 | file(TO_NATIVE_PATH "${OPENCV_SAMPLES_DATA_PATH_HINT}" OPENCV_SAMPLES_DATA_PATH_HINT) 61 | 62 | # Buil an application that uses the addon 63 | add_executable(test_addon test_addon.cc) 64 | target_link_libraries(test_addon PRIVATE ${PROJECT_NAME} ${OpenCV_LIBS}) 65 | set_target_properties(test_addon PROPERTIES 66 | OUTPUT_NAME "test_addon${OpenCV_DLLVERSION}" 67 | DEBUG_POSTFIX "${OpenCV_DEBUG_POSTFIX}" 68 | COMPILE_PDB_NAME "test_addon${OpenCV_DLLVERSION}" 69 | COMPILE_PDB_NAME_DEBUG "test_addon${OpenCV_DLLVERSION}${OpenCV_DEBUG_POSTFIX}" 70 | ARCHIVE_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}" 71 | COMPILE_PDB_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}" 72 | LIBRARY_OUTPUT_DIRECTORY "${LIBRARY_OUTPUT_PATH}" 73 | RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}" 74 | 75 | VS_DEBUGGER_ENVIRONMENT "PATH=${OpenCV_BIN_NATIVE_PATH};%PATH%\nOPENCV_SAMPLES_DATA_PATH_HINT=${OPENCV_SAMPLES_DATA_PATH_HINT}" 76 | ) 77 | set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" PROPERTY VS_STARTUP_PROJECT test_addon) 78 | 79 | # Always generate debug files 80 | if(MSVC AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug") 81 | set_target_properties(test_addon PROPERTIES LINK_FLAGS "/DEBUG") 82 | endif() 83 | -------------------------------------------------------------------------------- /autoit-addon/addon.au3: -------------------------------------------------------------------------------- 1 | #include-once 2 | 3 | Global $h_addon_dll = -1 4 | 5 | Func _Addon_DLLOpen($s_addon_dll) 6 | $h_addon_dll = _OpenCV_LoadDLL($s_addon_dll) 7 | Return $h_addon_dll <> -1 8 | EndFunc ;==>_Addon_DLLOpen 9 | 10 | Func _Addon_DLLClose() 11 | If $h_addon_dll == -1 Then Return False 12 | DllClose($h_addon_dll) 13 | $h_addon_dll = -1 14 | EndFunc ;==>_Addon_DLLClose 15 | 16 | Func _Addon_FindDLL($sFile = Default, $sFilter = Default, $sDir = Default, $bReverse = Default) 17 | If $sFile == Default Then $sFile = "autoit_addon4100*" 18 | Local $_cv_build_type = EnvGet("OPENCV_BUILD_TYPE") 19 | Local $sBuildType = $_cv_build_type == "Debug" ? "Debug" : "Release" 20 | Local $sPostfix = $_cv_build_type == "Debug" ? "d" : "" 21 | 22 | Local $aSearchPaths[] = [ _ 23 | ".", _ 24 | "autoit-addon", _ 25 | "autoit-opencv-com", _ 26 | "autoit-addon\build_x64\bin\" & $sBuildType _ 27 | ] 28 | 29 | Return _OpenCV_FindFile($sFile & $sPostfix & ".dll", $sFilter, $sDir, $FLTA_FILES, $aSearchPaths, $bReverse) 30 | EndFunc ;==>_Addon_FindDLL 31 | -------------------------------------------------------------------------------- /autoit-addon/addon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "autoitdef.h" 9 | 10 | AUTOITAPI(void) calcHist_Demo_draw( 11 | cv::Mat& histImage, 12 | int histSize, 13 | int hist_w, 14 | int hist_h, 15 | cv::Mat& b_hist, 16 | cv::Mat& g_hist, 17 | cv::Mat& r_hist 18 | ); 19 | 20 | AUTOITAPI(void) AKAZE_match_ratio_test_filtering( 21 | std::vector& matched1, 22 | std::vector& kpts1, 23 | std::vector& matched2, 24 | std::vector& kpts2, 25 | std::vector>& nn_matches, 26 | const float nn_match_ratio 27 | ); 28 | 29 | AUTOITAPI(void) AKAZE_homograpy_check( 30 | cv::Mat& homography, 31 | std::vector& matched1, 32 | std::vector& inliers1, 33 | std::vector& matched2, 34 | std::vector& inliers2, 35 | const float inlier_threshold, 36 | std::vector& good_matches 37 | ); 38 | 39 | AUTOITAPI(void) yolo_postprocess( 40 | const int spatial_width, 41 | const int spatial_height, 42 | const size_t num_classes, 43 | const int img_width, 44 | const int img_height, 45 | const float scale, 46 | const std::vector& outs, 47 | const float confidence_threshold, 48 | const float score_threshold, 49 | std::vector& class_ids, 50 | std::vector& scores, 51 | std::vector& bboxes 52 | ); 53 | 54 | AUTOITAPI(void) object_detection_postprocess( 55 | const cv::dnn::Net& net, 56 | const int inpWidth, 57 | const int inpHeight, 58 | const float imgScale, 59 | const size_t num_classes, 60 | const int background_label_id, 61 | const float confidence_threshold, 62 | const std::vector& outs, 63 | std::vector& class_ids, 64 | std::vector& confidences, 65 | std::vector& bboxes 66 | ); 67 | 68 | AUTOITAPI(void) DllTestUMat(); 69 | -------------------------------------------------------------------------------- /autoit-addon/autoitdef.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined _WIN32 4 | # define AUTOIT_CDECL __cdecl 5 | # define AUTOIT_STDCALL __stdcall 6 | #else 7 | # define AUTOIT_CDECL 8 | # define AUTOIT_STDCALL 9 | #endif 10 | 11 | #ifndef AUTOIT_EXTERN_C 12 | # ifdef __cplusplus 13 | # define AUTOIT_EXTERN_C extern "C" 14 | # else 15 | # define AUTOIT_EXTERN_C 16 | # endif 17 | #endif 18 | 19 | #ifndef AUTOIT_EXPORTS 20 | # if (defined _WIN32 || defined WINCE || defined __CYGWIN__) && defined(AUTOITAPI_EXPORTS) 21 | # define AUTOIT_EXPORTS __declspec(dllexport) 22 | # elif defined __GNUC__ && __GNUC__ >= 4 && (defined(AUTOITAPI_EXPORTS) || defined(__APPLE__)) 23 | # define AUTOIT_EXPORTS __attribute__ ((visibility ("default"))) 24 | # elif defined __clang__ 25 | # define AUTOIT_EXPORTS __attribute__ ((visibility ("default"))) 26 | # else 27 | # define AUTOIT_EXPORTS 28 | # endif 29 | #endif 30 | 31 | #ifndef AUTOITAPI 32 | # define AUTOITAPI(rettype) AUTOIT_EXTERN_C AUTOIT_EXPORTS rettype AUTOIT_CDECL 33 | #endif 34 | -------------------------------------------------------------------------------- /autoit-addon/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO off 2 | SETLOCAL enabledelayedexpansion 3 | 4 | SET BUILD_FOLDER=build_x64 5 | 6 | IF NOT DEFINED CMAKE_BUILD_TYPE SET CMAKE_BUILD_TYPE=Release 7 | SET GENERAL_CMAKE_CONFIG_FLAGS=%GENERAL_CMAKE_CONFIG_FLAGS% -DCMAKE_BUILD_TYPE:STRING="%CMAKE_BUILD_TYPE%" -DCMAKE_INSTALL_PREFIX:STRING=install 8 | 9 | PUSHD "%~dp0" 10 | CD /d %CD% 11 | SET "PATH=%CD%;%PATH%" 12 | 13 | ::Find CMake 14 | SET CMAKE="cmake.exe" 15 | IF EXIST "%PROGRAMFILES_DIR_X86%\CMake\bin\cmake.exe" SET CMAKE="%PROGRAMFILES_DIR_X86%\CMake\bin\cmake.exe" 16 | IF EXIST "%PROGRAMFILES_DIR%\CMake\bin\cmake.exe" SET CMAKE="%PROGRAMFILES_DIR%\CMake\bin\cmake.exe" 17 | IF EXIST "%PROGRAMW6432%\CMake\bin\cmake.exe" SET CMAKE="%PROGRAMW6432%\CMake\bin\cmake.exe" 18 | 19 | ::Find Visual Studio 20 | FOR /F "usebackq tokens=* USEBACKQ" %%F IN (`vswhere.exe -legacy -version [10.0^,^) -property installationVersion -latest`) DO SET VS_VERSION=%%F 21 | 22 | FOR /F "usebackq tokens=* USEBACKQ" %%F IN (`vswhere.exe -version [16.0^,^) -property installationPath -latest`) DO ( 23 | SET CMAKE_CONF="Visual Studio %VS_VERSION:~0,2%" -A x64 24 | CALL "%%F\VC\Auxiliary\Build\vcvars64.bat" 25 | GOTO MAKE 26 | EXIT /b %ERRORLEVEL% 27 | ) 28 | 29 | FOR /F "usebackq tokens=* USEBACKQ" %%F IN (`vswhere.exe -version [15.0^,16.0^) -property installationPath -latest`) DO ( 30 | SET CMAKE_CONF="Visual Studio %VS_VERSION:~0,2% Win64" 31 | CALL "%%F\VC\Auxiliary\Build\vcvars64.bat" 32 | GOTO MAKE 33 | EXIT /b %ERRORLEVEL% 34 | ) 35 | 36 | FOR /F "usebackq tokens=* USEBACKQ" %%F IN (`vswhere.exe -legacy -version [10.0^,15.0^) -property installationPath -latest`) DO ( 37 | SET CMAKE_CONF="Visual Studio %VS_VERSION:~0,2% Win64" 38 | CALL "%%F\VC\vcvarsall.bat" x64 39 | GOTO MAKE 40 | EXIT /b %ERRORLEVEL% 41 | ) 42 | 43 | ECHO Unable to find a visual studio version 44 | EXIT /B 1 45 | 46 | :MAKE 47 | IF NOT EXIST %BUILD_FOLDER% mkdir %BUILD_FOLDER% 48 | cd %BUILD_FOLDER% 49 | 50 | IF EXIST "CMakeCache.txt" del CMakeCache.txt 51 | 52 | :RUN_CMAKE 53 | %CMAKE% -G %CMAKE_CONF% %GENERAL_CMAKE_CONFIG_FLAGS% ..\ 54 | SET ERROR=%ERRORLEVEL% 55 | IF "%1%"=="-g" ( 56 | EXIT /B %ERROR% 57 | ) 58 | IF "%ERROR%" == "0" GOTO BUILD 59 | EXIT /B %ERROR% 60 | 61 | :BUILD 62 | %CMAKE% --build . --config %CMAKE_BUILD_TYPE% --target ALL_BUILD 63 | SET ERROR=%ERRORLEVEL% 64 | IF "%ERROR%" == "0" GOTO END 65 | EXIT /B %ERROR% 66 | 67 | :END 68 | POPD 69 | -------------------------------------------------------------------------------- /autoit-addon/test_addon.cc: -------------------------------------------------------------------------------- 1 | #include "addon.h" 2 | 3 | int main(int argc, char** argv) 4 | { 5 | DllTestUMat(); 6 | return EXIT_SUCCESS; 7 | } 8 | -------------------------------------------------------------------------------- /autoit-addon/vswhere.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/autoit-addon/vswhere.exe -------------------------------------------------------------------------------- /autoit-opencv-com/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | SETLOCAL enabledelayedexpansion 3 | 4 | PUSHD "%~dp0" 5 | CD /d %CD% 6 | SET "PATH=%CD%;%PATH%" 7 | SET "SCRIPTPATH=%CD%" 8 | 9 | SET skip_build=0 10 | SET skip_config=0 11 | SET TARGET=ALL_BUILD 12 | SET has_generator=0 13 | SET is_dry_run=0 14 | SET CMAKE_GENERATOR= 15 | 16 | SET nparms=20 17 | 18 | :GET_OPTS 19 | IF %nparms%==0 GOTO :MAIN 20 | 21 | SET "_param=%~1" 22 | IF ["%_param%"] == [""] GOTO :NEXT_OPT 23 | 24 | IF ["%_param:~0,2%"] == ["-D"] ( 25 | echo %_param% | find "=" 1>NUL 2>NUL 26 | if errorlevel 1 SET _param=%_param%=%~2 27 | if errorlevel 1 SET /a nparms -=1 28 | if errorlevel 1 SHIFT 29 | SET EXTRA_CMAKE_OPTIONS=%EXTRA_CMAKE_OPTIONS% "!_param!" 30 | GOTO :NEXT_OPT 31 | ) 32 | 33 | IF [%1] == [-d] SET CMAKE_BUILD_TYPE=Debug 34 | IF [%1] == [--dry-run] SET is_dry_run=1 35 | IF [%1] == [--skip-build] SET skip_build=1 36 | IF [%1] == [--skip-config] SET skip_config=1 37 | IF [%1] == [--target] ( 38 | SET TARGET=%2 39 | GOTO :NEXT_OPT 40 | ) 41 | IF [%1] == [-G] ( 42 | IF [%2-%TARGET%] == [Ninja-ALL_BUILD] SET TARGET=all 43 | SET CMAKE_GENERATOR=-G %2 44 | SET has_generator=1 45 | GOTO :NEXT_OPT 46 | ) 47 | IF ["%_param:~0,2%"] == ["-G"] ( 48 | IF ["%_param%-%TARGET%"] == ["Ninja-ALL_BUILD"] SET TARGET=all 49 | SET CMAKE_GENERATOR="%_param%" 50 | SET has_generator=1 51 | GOTO :NEXT_OPT 52 | ) 53 | IF [%1] == [-A] ( 54 | SET CMAKE_GENERATOR_PLATFORM=-A %2 55 | GOTO :NEXT_OPT 56 | ) 57 | :NEXT_OPT 58 | SET /a nparms -=1 59 | SHIFT 60 | GOTO GET_OPTS 61 | 62 | :MAIN 63 | IF ["%CMAKE_GENERATOR%-%TARGET%"] == ["-G Ninja-ALL_BUILD"] SET TARGET=all 64 | IF NOT DEFINED CMAKE_BUILD_TYPE SET CMAKE_BUILD_TYPE=Release 65 | SET BUILD_FOLDER=%CD%\build_x64 66 | SET EXTRA_CMAKE_OPTIONS=%EXTRA_CMAKE_OPTIONS% "-DCMAKE_BUILD_TYPE:STRING=%CMAKE_BUILD_TYPE%" "-DCMAKE_INSTALL_PREFIX:PATH=install" 67 | 68 | IF DEFINED VSCMD_VER GOTO Set_Generator 69 | 70 | ::Find Visual Studio 71 | FOR /F "usebackq tokens=* USEBACKQ" %%F IN (`vswhere.exe -legacy -version [10.0^,^) -property installationVersion -latest`) DO SET VS_VERSION=%%F 72 | FOR /F "usebackq tokens=* USEBACKQ" %%F IN (`vswhere.exe -legacy -version [10.0^,^) -property catalog_productLineVersion -latest`) DO SET VS_PRODUCT_VERSION=%%F 73 | FOR /F "usebackq tokens=* USEBACKQ" %%F IN (`vswhere.exe -version [16.0^,^) -property installationPath -latest`) DO ( 74 | IF NOT [%has_generator%] == [1] ( 75 | SET CMAKE_GENERATOR=-G "Visual Studio %VS_VERSION:~0,2% %VS_PRODUCT_VERSION%" 76 | SET CMAKE_GENERATOR_PLATFORM=-A x64 77 | ) 78 | SET has_generator=1 79 | CALL "%%F\VC\Auxiliary\Build\vcvars64.bat" 80 | GOTO MAKE 81 | EXIT /B %ERRORLEVEL% 82 | ) 83 | 84 | FOR /F "usebackq tokens=* USEBACKQ" %%F IN (`vswhere.exe -version [15.0^,16.0^) -property installationPath -latest`) DO ( 85 | IF NOT [%has_generator%] == [1] ( 86 | SET CMAKE_GENERATOR=-G "Visual Studio %VS_VERSION:~0,2% %VS_PRODUCT_VERSION%"" 87 | SET CMAKE_GENERATOR_PLATFORM=Win64" 88 | ) 89 | SET has_generator=1 90 | CALL "%%F\VC\Auxiliary\Build\vcvars64.bat" 91 | GOTO MAKE 92 | EXIT /B %ERRORLEVEL% 93 | ) 94 | 95 | FOR /F "usebackq tokens=* USEBACKQ" %%F IN (`vswhere.exe -legacy -version [10.0^,15.0^) -property installationPath -latest`) DO ( 96 | IF NOT [%has_generator%] == [1] ( 97 | SET CMAKE_GENERATOR=-G "Visual Studio %VS_VERSION:~0,2% %VS_PRODUCT_VERSION%"" 98 | SET CMAKE_GENERATOR_PLATFORM=Win64" 99 | ) 100 | SET has_generator=1 101 | CALL "%%F\VC\vcvarsall.bat" x64 102 | GOTO MAKE 103 | EXIT /B %ERRORLEVEL% 104 | ) 105 | 106 | ECHO Unable to find a visual studio version 107 | SET ERROR=1 108 | GOTO END 109 | 110 | :Set_Generator 111 | IF NOT DEFINED CMAKE_GENERATOR SET CMAKE_GENERATOR_PLATFORM=-A %VSCMD_ARG_TGT_ARCH% 112 | IF NOT DEFINED CMAKE_GENERATOR SET CMAKE_GENERATOR=-G "Visual Studio %VSCMD_VER:~0,2%" 113 | 114 | :MAKE 115 | ::Find CMake 116 | SET "PATH=%DevEnvDir%\CommonExtensions\Microsoft\CMake\CMake\bin;%PATH%" 117 | FOR %%X IN (cmake.exe) DO (set CMAKE="%%~$PATH:X") 118 | IF NOT DEFINED CMAKE ( 119 | IF EXIST "%PROGRAMFILES_DIR_X86%\CMake\bin\cmake.exe" SET CMAKE="%PROGRAMFILES_DIR_X86%\CMake\bin\cmake.exe" 120 | IF EXIST "%PROGRAMFILES_DIR%\CMake\bin\cmake.exe" SET CMAKE="%PROGRAMFILES_DIR%\CMake\bin\cmake.exe" 121 | IF EXIST "%PROGRAMW6432%\CMake\bin\cmake.exe" SET CMAKE="%PROGRAMW6432%\CMake\bin\cmake.exe" 122 | ) 123 | 124 | ::Find Ninja 125 | SET "PATH=%DevEnvDir%\CommonExtensions\Microsoft\CMake\Ninja;%PATH%" 126 | FOR %%X IN (ninja.exe) DO (set "NINJA=%%~$PATH:X") 127 | IF ["%CMAKE_GENERATOR:"=%"] == ["-G Ninja"] SET EXTRA_CMAKE_OPTIONS=%EXTRA_CMAKE_OPTIONS% "-DCMAKE_MAKE_PROGRAM=%NINJA%" 128 | 129 | SET ERROR=0 130 | SET TRY_RUN= 131 | IF [%is_dry_run%] == [1] SET "TRY_RUN=@ECHO " 132 | IF [%is_dry_run%] == [1] SET "CMAKE=@ECHO %CMAKE%" 133 | 134 | :MAKE_CONFIG 135 | IF NOT EXIST %BUILD_FOLDER% mkdir %BUILD_FOLDER% 136 | REM IF EXIST "%BUILD_FOLDER%\CMakeCache.txt" del "%BUILD_FOLDER%\CMakeCache.txt" 137 | 138 | IF [%skip_config%] == [1] GOTO BUILD 139 | %CMAKE% %CMAKE_GENERATOR% %CMAKE_GENERATOR_PLATFORM% %EXTRA_CMAKE_OPTIONS% -S "%SCRIPTPATH%" -B "%BUILD_FOLDER%" 140 | SET ERROR=%ERRORLEVEL% 141 | IF [%ERROR%] == [0] GOTO BUILD 142 | GOTO END 143 | 144 | :BUILD 145 | IF [%skip_build%] == [1] GOTO END 146 | %CMAKE% --build "%BUILD_FOLDER%" --config %CMAKE_BUILD_TYPE% --target %TARGET% 147 | SET ERROR=%ERRORLEVEL% 148 | 149 | :END 150 | POPD 151 | EXIT /B %ERROR% 152 | -------------------------------------------------------------------------------- /autoit-opencv-com/cmake/FindPatch.cmake: -------------------------------------------------------------------------------- 1 | find_package(Git) 2 | 3 | # https://github.com/scivision/cmake-patch-file/blob/main/cmake/PatchFile.cmake 4 | if(WIN32) 5 | # prioritize Git Patch on Windows as other Patches may be very old and incompatible. 6 | if(Git_FOUND) 7 | get_filename_component(GIT_DIR ${GIT_EXECUTABLE} DIRECTORY) 8 | get_filename_component(GIT_DIR ${GIT_DIR} DIRECTORY) 9 | endif() 10 | endif() 11 | 12 | find_program(PATCH 13 | NAMES patch 14 | HINTS ${GIT_DIR} 15 | PATH_SUFFIXES usr/bin 16 | ) 17 | 18 | if(NOT PATCH) 19 | message(FATAL_ERROR "Did not find GNU Patch") 20 | endif() 21 | -------------------------------------------------------------------------------- /autoit-opencv-com/cmake/RequireOpenCV.cmake: -------------------------------------------------------------------------------- 1 | include(cmake/FindPatch.cmake) 2 | 3 | set(BUILD_opencv OFF CACHE BOOL "Build opencv from sources.") 4 | 5 | set(OpenCV_URL_HASH_4100 bff38466091c313dac21a0b73eea8278316a89c1d434c6f0b10697e087670168) 6 | set(OpenCV_URL_HASH_490 fefddff0623fbd5a6fa0cecb9bccd4b822478354e6c587ebb6e40ab09dacba51) 7 | set(OpenCV_URL_HASH_481 037dd1c5c172237b0a00ee822684e5ac453028e1933111a2c547b62061f8b7e4) 8 | set(OpenCV_URL_HASH_480 1c8b1b78a51c46852eb5569d762bd11d0097a45c3db1f03eb41aba6f727b8942) 9 | set(OpenCV_URL_HASH_470 7fab7be68a4ab7f1b70759b0e58d4c4ffc2b8aee72642df6f2dfcc6c161b2465) 10 | set(OpenCV_URL_HASH_460 3fb046e14dc5b50719a86ea0395b5b1e3299e2343111ebd2e31828aa31d6d477) 11 | set(OpenCV_URL_HASH_455 cac31973cd1c59bfe9dc926acbde815553d23662ea355e0414b5e50d8f8aa5a8) 12 | set(OpenCV_URL_HASH_454 d49f6a8ef304de4f5617baf8d9ece51b53a76b3cf5ce26377e4ed7632f0ac467) 13 | set(OpenCV_URL_HASH_453 88eb53fcb81c40f093b18c3eaa818e33d1463d96b47c9713468a68c2c3fccaf0) 14 | set(OpenCV_URL_HASH_452 106b588a82b3045a44305ba426c281887416745d4ce8f3983156d9f82e89ff75) 15 | set(OpenCV_URL_HASH_451 32132dd0bf38c62f73a2f20a0b19785282364f35e19c403f0767aa0266ed410d) 16 | set(OpenCV_URL_HASH_450 65c6b872cfcb1f55f8bedee8b64dc9c4c549035a566ac5ace622a4627c03bcf9) 17 | 18 | set(OpenCV_VERSION 4.10.0 CACHE STRING "Choose the OpenCV version.") 19 | set_property(CACHE OpenCV_VERSION PROPERTY STRINGS "4.10.0" "4.9.0" "4.8.1" "4.8.0" "4.7.0" "4.6.0" "4.5.5" "4.5.4" "4.5.3" "4.5.2" "4.5.1" "4.5.0") 20 | string(REPLACE "." "" OpenCV_DLLVERSION ${OpenCV_VERSION}) 21 | 22 | if (OpenCV_DLLVERSION GREATER_EQUAL 470) 23 | set(OpenCV_DOWNLOAD_NAME opencv-${OpenCV_VERSION}-windows.exe) 24 | else() 25 | set(OpenCV_DOWNLOAD_NAME opencv-${OpenCV_VERSION}-vc14_vc15.exe) 26 | endif() 27 | 28 | string(REGEX REPLACE "\\.[a-zA-Z]+\$" "" OpenCV_OUTPUT_DIR "${OpenCV_DOWNLOAD_NAME}") 29 | 30 | if(BUILD_opencv AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../opencv") 31 | set(OpenCV_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../opencv/__build__") 32 | file(MAKE_DIRECTORY "${OpenCV_BUILD_DIR}") 33 | 34 | # configure OpenCV 35 | execute_process( 36 | COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" -DOpenCV_VERSION=${OpenCV_VERSION} .. 37 | WORKING_DIRECTORY "${OpenCV_BUILD_DIR}" 38 | COMMAND_ECHO STDERR 39 | ) 40 | 41 | # compile OpenCV 42 | execute_process( 43 | COMMAND "${CMAKE_COMMAND}" --build . --target ALL_BUILD 44 | WORKING_DIRECTORY "${OpenCV_BUILD_DIR}" 45 | COMMAND_ECHO STDERR 46 | ) 47 | 48 | get_filename_component(OpenCV_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../opencv/install" REALPATH) 49 | endif() 50 | 51 | # Tell cmake that we will need opencv. 52 | get_filename_component(OPENCV_DOWNLOAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" DIRECTORY) 53 | set(OpenCV_URL https://github.com/opencv/opencv/releases/download/${OpenCV_VERSION}/${OpenCV_DOWNLOAD_NAME}) 54 | set(OpenCV_URL_HASH SHA256=${OpenCV_URL_HASH_${OpenCV_DLLVERSION}}) 55 | 56 | include(FetchContent) 57 | FetchContent_Declare(opencv 58 | URL ${OpenCV_URL} 59 | URL_HASH ${OpenCV_URL_HASH} 60 | DOWNLOAD_NO_EXTRACT TRUE 61 | DOWNLOAD_DIR "${OPENCV_DOWNLOAD_DIR}" 62 | SOURCE_DIR "${OPENCV_DOWNLOAD_DIR}" 63 | PATCH_COMMAND "/${OpenCV_DOWNLOAD_NAME}" "-o/${OpenCV_OUTPUT_DIR}" -y 64 | ) 65 | 66 | include(FetchContent) 67 | FetchContent_Declare(opencv-patch 68 | URL ${OpenCV_URL} 69 | URL_HASH ${OpenCV_URL_HASH} 70 | DOWNLOAD_NO_EXTRACT TRUE 71 | DOWNLOAD_DIR "${OPENCV_DOWNLOAD_DIR}" 72 | SOURCE_DIR "${OPENCV_DOWNLOAD_DIR}" 73 | PATCH_COMMAND "${PATCH}" -p 1 -d "/${OpenCV_OUTPUT_DIR}/opencv/sources/" 74 | -i "${CMAKE_CURRENT_SOURCE_DIR}/patches/001-opencv-src.patch" 75 | ) 76 | 77 | FetchContent_Populate(opencv) 78 | FetchContent_Populate(opencv-patch) 79 | 80 | get_filename_component(OpenCV_DIR "${opencv_SOURCE_DIR}/${OpenCV_OUTPUT_DIR}/opencv/build" ABSOLUTE) 81 | find_package(OpenCV REQUIRED) 82 | 83 | get_filename_component(OpenCV_BIN_PATH "${OpenCV_LIB_PATH}/../bin" ABSOLUTE) 84 | 85 | get_filename_component(OpenCV_VC_PATH "${OpenCV_LIB_PATH}" DIRECTORY) 86 | file(RELATIVE_PATH OpenCV_VC_PATH "${OpenCV_DIR}" "${OpenCV_VC_PATH}") 87 | 88 | file(TO_NATIVE_PATH "${OpenCV_VC_PATH}" OpenCV_VC_PATH_ESC) 89 | string(REPLACE "\\" "\\\\" OpenCV_VC_PATH_ESC "${OpenCV_VC_PATH_ESC}") 90 | string(REPLACE "\\" "\\\\" OpenCV_VC_PATH_ESC_ESC "${OpenCV_VC_PATH_ESC}") 91 | 92 | set(opencv_SOURCE_DIR "${opencv_SOURCE_DIR}/${OpenCV_OUTPUT_DIR}/opencv/sources") 93 | file(TO_NATIVE_PATH "${OpenCV_BIN_PATH}" OpenCV_BIN_NATIVE_PATH) 94 | 95 | string(REPLACE "." ";" OpenCV_VERSION_LIST ${OpenCV_VERSION}) 96 | list(GET OpenCV_VERSION_LIST 0 OpenCV_VERSION_MAJOR) 97 | list(GET OpenCV_VERSION_LIST 1 OpenCV_VERSION_MINOR) 98 | list(GET OpenCV_VERSION_LIST 2 OpenCV_VERSION_PATCH) 99 | 100 | set(OpenCV_DLLVERSION "${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}") 101 | set(OpenCV_DEBUG_POSTFIX d) 102 | 103 | if(DEFINED CMAKE_DEBUG_POSTFIX) 104 | set(OpenCV_DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}") 105 | endif() 106 | 107 | if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") 108 | set(OpenCV_BUILD_DEBUG_POSTFIX "${OpenCV_DEBUG_POSTFIX}") 109 | else() 110 | set(OpenCV_BUILD_DEBUG_POSTFIX "") 111 | endif() 112 | -------------------------------------------------------------------------------- /autoit-opencv-com/cmake/git_patch_once.cmake: -------------------------------------------------------------------------------- 1 | find_package(Git) 2 | 3 | execute_process( 4 | COMMAND "${GIT_EXECUTABLE}" apply --check -R "${PATCH_FILE}" 5 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" 6 | RESULT_VARIABLE ret 7 | ERROR_QUIET 8 | ) 9 | 10 | if(NOT ${ret} EQUAL "0") 11 | execute_process( 12 | COMMAND "${GIT_EXECUTABLE}" apply --check "${PATCH_FILE}" 13 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" 14 | COMMAND_ERROR_IS_FATAL ANY 15 | ) 16 | 17 | execute_process( 18 | COMMAND "${GIT_EXECUTABLE}" apply "${PATCH_FILE}" 19 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" 20 | COMMAND_ERROR_IS_FATAL ANY 21 | ) 22 | endif() 23 | -------------------------------------------------------------------------------- /autoit-opencv-com/cmake/vcpkg_regex_replace_string.cmake: -------------------------------------------------------------------------------- 1 | function(vcpkg_regex_replace_string filename match replace) 2 | file(READ "${filename}" old_contents) 3 | string(REGEX REPLACE "${match}" "${replace}" new_contents "${old_contents}") 4 | if (NOT "${new_contents}" STREQUAL "${old_contents}") 5 | file(WRITE "${filename}" "${new_contents}") 6 | endif() 7 | endfunction() 8 | -------------------------------------------------------------------------------- /autoit-opencv-com/dotnet/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("OpenCV COM Interop")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("OpenCV COM Interop")] 15 | [assembly: AssemblyCopyright("")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | // Version information for an assembly consists of the following four values: 34 | // 35 | // Major Version 36 | // Minor Version 37 | // Build Number 38 | // Revision 39 | // 40 | // You can specify all the values or you can default the Build and Revision Numbers 41 | // by using the '*' as shown below: 42 | // [assembly: AssemblyVersion("1.0.*")] 43 | [assembly: AssemblyVersion("2.6.2.0")] 44 | [assembly: AssemblyFileVersion("2.6.2.0")] 45 | -------------------------------------------------------------------------------- /autoit-opencv-com/install.bat: -------------------------------------------------------------------------------- 1 | @GOTO :BEGIN 2 | :: install.bat /i:user 3 | :: install.bat /u:user 4 | :: install.bat /u:user /i:user 5 | :: install.bat /i 6 | :: install.bat /u 7 | :: install.bat /u /i 8 | 9 | :BEGIN 10 | @SETLOCAL enabledelayedexpansion 11 | 12 | @SET _batchFile=%~fs0 13 | 14 | :: double up any quotes 15 | @SET _batchFile=""%_batchFile:"=%"" 16 | 17 | @SET "PATH=%CD%;%PATH%" 18 | @PUSHD "%~dp0" 19 | @CD /d %CD% 20 | @SET "PATH=%CD%;%PATH%" 21 | 22 | @SET install=0 23 | @SET uninstall=0 24 | @SET install_user=0 25 | @SET uninstall_user=0 26 | @SET DEBUG_PREFIX= 27 | @SET INT_DIR=Release 28 | 29 | @SET nparms=20 30 | :LOOP 31 | @IF %nparms%==0 GOTO :mainmenu 32 | @IF [%1] == [/i] @SET install=1 33 | @IF [%1] == [/u] @SET uninstall=1 34 | @IF [%1] == [/i:user] @SET install_user=1 35 | @IF [%1] == [/u:user] @SET uninstall_user=1 36 | @IF [%1] == [/d] @SET DEBUG_PREFIX=d 37 | @IF [%1] == [/d] @SET INT_DIR=Debug 38 | @SET /a nparms -=1 39 | @SHIFT 40 | @GOTO LOOP 41 | 42 | :mainmenu 43 | @SET DLLDIRNAME= 44 | @SET DLLNAME=autoit_opencv_com4100%DEBUG_PREFIX%.dll 45 | 46 | @IF EXIST "%CD%\build_x64\%INT_DIR%\%DLLNAME%" @SET "DLLDIRNAME=%CD%\build_x64\%INT_DIR%\" 47 | @IF EXIST "%CD%\..\opencv-4.10.0-windows\opencv\build\x64\vc16\bin" @SET "PATH=%CD%\..\opencv-4.10.0-windows\opencv\build\x64\vc16\bin;%PATH%" 48 | 49 | @SET DLLNAME=%DLLDIRNAME%%DLLNAME% 50 | 51 | @IF NOT [%install%%uninstall%%install_user%%uninstall_user%] == [0000] GOTO MAIN 52 | 53 | @CLS 54 | @TITLE AutoIt OpenCV COM 55 | @ECHO. AutoIt OpenCV COM 56 | @ECHO. 57 | @ECHO. VERSION: 2.6.2 58 | @ECHO. DLLNAME: %DLLNAME% 59 | @ECHO. 60 | @ECHO. 61 | @ECHO. Choose your option... 62 | @ECHO. 63 | @ECHO. (1) Install for the current user 64 | @ECHO. (2) Uninstall for the current user 65 | @ECHO. (3) Reinstall for the current user 66 | @ECHO. (4) Install for the all users 67 | @ECHO. (5) Uninstall for the all users 68 | @ECHO. (6) Reinstall for the all users 69 | @ECHO. (0) Close the Program 70 | 71 | @SET /p userinp= ^ Make your selection: 72 | @SET userinp=%userinp:~0,1% 73 | @IF /i "%userinp%"=="1" GOTO install_user 74 | @IF /i "%userinp%"=="2" GOTO uninstall_user 75 | @IF /i "%userinp%"=="3" GOTO reinstall_user 76 | @IF /i "%userinp%"=="4" GOTO install 77 | @IF /i "%userinp%"=="5" GOTO uninstall 78 | @IF /i "%userinp%"=="6" GOTO reinstall 79 | @IF /i "%userinp%"=="0" GOTO END 80 | @GOTO mainmenu 81 | 82 | :install_user 83 | @SET install=0 84 | @SET uninstall=0 85 | @SET install_user=1 86 | @SET uninstall_user=0 87 | @GOTO mainmenu 88 | 89 | :uninstall_user 90 | @SET install=0 91 | @SET uninstall=0 92 | @SET install_user=0 93 | @SET uninstall_user=1 94 | @GOTO mainmenu 95 | 96 | :reinstall_user 97 | @SET install=0 98 | @SET uninstall=0 99 | @SET install_user=1 100 | @SET uninstall_user=1 101 | @GOTO mainmenu 102 | 103 | :install 104 | @SET install=1 105 | @SET uninstall=0 106 | @SET install_user=0 107 | @SET uninstall_user=0 108 | @GOTO mainmenu 109 | 110 | :uninstall 111 | @SET install=0 112 | @SET uninstall=1 113 | @SET install_user=0 114 | @SET uninstall_user=0 115 | @GOTO mainmenu 116 | 117 | :reinstall 118 | @SET install=1 119 | @SET uninstall=1 120 | @SET install_user=0 121 | @SET uninstall_user=0 122 | @GOTO mainmenu 123 | 124 | :MAIN 125 | 126 | :UNINSTALL 127 | @IF [%uninstall%] == [1] ( 128 | fltmc >nul 2>&1 || ( 129 | @IF [%install%] == [1] CALL :ELEVATE /u /i 130 | @IF NOT [%install%] == [1] CALL :ELEVATE /u 131 | GOTO UNINSTALL_USER 132 | GOTO END 133 | ) 134 | 135 | @ECHO regsvr32 /u /n /i %DLLNAME% 136 | regsvr32 /u /n /i %DLLNAME% 137 | ) 138 | @IF NOT [%ERRORLEVEL%] == [0] GOTO END 139 | 140 | :INSTALL 141 | @IF [%install%] == [1] ( 142 | fltmc >nul 2>&1 || ( 143 | CALL :ELEVATE /i 144 | GOTO UNINSTALL_USER 145 | GOTO END 146 | ) 147 | 148 | @ECHO regsvr32 /n /i %DLLNAME% 149 | regsvr32 /n /i %DLLNAME% 150 | ) 151 | @IF NOT [%ERRORLEVEL%] == [0] GOTO END 152 | 153 | :UNINSTALL_USER 154 | @IF [%uninstall_user%] == [1] ( 155 | @ECHO regsvr32 /u /n /i:user %DLLNAME% 156 | regsvr32 /u /n /i:user %DLLNAME% 157 | ) 158 | @IF NOT [%ERRORLEVEL%] == [0] GOTO END 159 | 160 | :INSTALL_USER 161 | @IF [%install_user%] == [1] ( 162 | @ECHO regsvr32 /n /i:user %DLLNAME% 163 | regsvr32 /n /i:user %DLLNAME% 164 | ) 165 | @IF NOT [%ERRORLEVEL%] == [0] GOTO END 166 | 167 | @GOTO END 168 | 169 | :ELEVATE 170 | ::Create and run a temporary VBScript to elevate this batch file 171 | @SET _Args=%* 172 | @SET _Args=%_Args:"=""% 173 | @Echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\~ElevateMe.vbs" 174 | @ECHO UAC.ShellExecute "cmd", "/c ""@SET ""PATH=%PATH%"" && %_batchFile% %_Args%""", "", "runas", 1 >> "%temp%\~ElevateMe.vbs" 175 | @CALL "%temp%\~ElevateMe.vbs" 176 | @DEL /f /q "%temp%\~ElevateMe.vbs" 177 | @GOTO :EOF 178 | 179 | :END 180 | @POPD 181 | @EXIT /B %ERRORLEVEL% 182 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/autoit_bridge.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "autoit_bridge_generated.h" 4 | #include "impl_mat.h" 5 | 6 | PTR_BRIDGE_DECL(cv::wgc::WGCFrameCallback) 7 | 8 | extern const bool is_assignable_from(cv::GMetaArg& out_val, VARIANT const* const& in_val, bool is_optional); 9 | extern const HRESULT autoit_to(VARIANT const* const& in_val, cv::GMetaArg& out_val); 10 | 11 | extern const HRESULT autoit_from(const cv::GMetaArg& in_val, VARIANT*& out_val); 12 | #if (CV_VERSION_MAJOR > 4) || CV_VERSION_MAJOR == 4 && (CV_VERSION_MINOR > 5 || CV_VERSION_MINOR == 5 && CV_VERSION_REVISION > 0) 13 | extern const HRESULT autoit_from(const cv::GOptRunArg& in_val, VARIANT*& out_val); 14 | extern const HRESULT autoit_from(const cv::util::variant& in_val, VARIANT*& out_val); 15 | #endif 16 | 17 | extern const bool is_assignable_from(AUTOIT_PTR& out_val, VARIANT*& in_val, bool is_optional); 18 | extern const bool is_assignable_from(AUTOIT_PTR& out_val, VARIANT*& in_val, bool is_optional); 19 | extern const bool is_assignable_from(cv::flann::IndexParams& out_val, VARIANT*& in_val, bool is_optional); 20 | extern const HRESULT autoit_to(VARIANT*& in_val, AUTOIT_PTR& out_val); 21 | extern const HRESULT autoit_to(VARIANT*& in_val, AUTOIT_PTR& out_val); 22 | extern const HRESULT autoit_to(VARIANT const* const& in_val, cv::flann::IndexParams& out_val); 23 | 24 | namespace autoit 25 | { 26 | template 27 | struct _GenericCopy { 28 | inline static HRESULT copy(destination_type* pTo, const cv::GMetaArg* pFrom) { 29 | return autoit_from(*pFrom, pTo); 30 | } 31 | }; 32 | 33 | const _variant_t fileNodeAsVariant(const cv::FileNode& node); 34 | } 35 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/autoit_def.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define AUTOIT_LIB_NAME OpenCV 6 | #define AUTOIT_LIB_VERSION CV_VERSION_MAJOR.CV_VERSION_MINOR.CV_VERSION_REVISION 7 | #define AUTOIT_PTR cv::Ptr 8 | #define AUTOIT_MAKE_PTR std::make_shared 9 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/contrib/cv_extra.cpp: -------------------------------------------------------------------------------- 1 | #include "cv_extra.h" 2 | #include 3 | 4 | using byte = unsigned char; 5 | 6 | namespace cv { 7 | double randu() { 8 | return cv::theRNG().gaussian(1.0); 9 | } 10 | 11 | void randu(int rows, int cols, cv::InputOutputArray dst, int type) { 12 | dst.create(rows, cols, type); 13 | cv::theRNG().fill(dst, cv::RNG::UNIFORM, 0, 1); 14 | } 15 | 16 | void randu(cv::Size size, cv::InputOutputArray dst, int type) { 17 | dst.create(size, type); 18 | cv::theRNG().fill(dst, cv::RNG::UNIFORM, 0, 1); 19 | } 20 | 21 | void randu(const std::vector& sizes, cv::InputOutputArray dst, int type) { 22 | dst.create(sizes.size(), sizes.data(), type); 23 | cv::theRNG().fill(dst, cv::RNG::UNIFORM, 0, 1); 24 | } 25 | 26 | double randn() { 27 | return cv::theRNG().uniform(0.0, 1.0); 28 | } 29 | 30 | void randn(int rows, int cols, cv::InputOutputArray dst, int type) { 31 | dst.create(rows, cols, type); 32 | cv::theRNG().fill(dst, cv::RNG::NORMAL, 0, 1); 33 | } 34 | 35 | void randn(cv::Size size, cv::InputOutputArray dst, int type) { 36 | dst.create(size, type); 37 | cv::theRNG().fill(dst, cv::RNG::NORMAL, 0, 1); 38 | } 39 | 40 | void randn(const std::vector& sizes, cv::InputOutputArray dst, int type) { 41 | dst.create(sizes.size(), sizes.data(), type); 42 | cv::theRNG().fill(dst, cv::RNG::NORMAL, 0, 1); 43 | } 44 | 45 | int argmax(InputArray _src, bool lastIndex) { 46 | const auto src = _src.getMat().reshape(_src.channels(), _src.total()); 47 | Mat dst; 48 | cv::reduceArgMax(src, dst, 0, lastIndex); 49 | return dst.at(0, 0); 50 | } 51 | 52 | std::variant, int> argmax(InputArray src, int axis, bool lastIndex) { 53 | const auto is1D = src.dims() == 1 || src.dims() == 2 && (src.rows() == 1 || src.cols() == 1); 54 | 55 | Mat dst; 56 | cv::reduceArgMax(src, dst, axis == 0 && is1D && src.dims() == 2 ? 1 : axis, lastIndex); 57 | 58 | if (is1D) { 59 | return dst.at(0, 0); 60 | } 61 | 62 | return std::make_shared(dst); 63 | } 64 | 65 | void bincount(InputArray _x, OutputArray out, InputArray _weights, int minlength) { 66 | // minlength must not be negative 67 | CV_Assert(minlength >= 0); 68 | 69 | const Mat x = _x.getMat(); 70 | 71 | // x must be 1-dimensional 72 | CV_Assert(x.dims <= 2 && x.channels() == 1 && x.depth() == CV_32S); 73 | CV_Assert(x.dims == 1 || x.rows == 1 || x.cols == 1); 74 | 75 | const Mat weights = _weights.getMat(); 76 | if (!weights.empty()) { 77 | // weights must be 1-dimensional 78 | CV_Assert(weights.dims <= 2 && weights.channels() == 1); 79 | CV_Assert(weights.dims == 1 || weights.rows == 1 || weights.cols == 1); 80 | 81 | // x and weights must have the same size 82 | CV_Assert(x.total() == weights.total()); 83 | } 84 | 85 | double min_x_val = 0, max_x_val = 0; 86 | minMaxLoc(x, &min_x_val, &max_x_val); 87 | 88 | // x must not contains elements with negative values 89 | CV_Assert(min_x_val >= 0); 90 | 91 | std::vector bins(std::max((int)max_x_val + 1, minlength)); 92 | const auto total = x.total(); 93 | 94 | if (weights.empty()) { 95 | for (int i = 0; i < total; i++) { 96 | bins[x.at(i)] += 1; 97 | } 98 | } 99 | else { 100 | for (int i = 0; i < total; i++) { 101 | switch (weights.depth()) { 102 | case CV_8U: 103 | bins[x.at(i)] += weights.at(i); 104 | break; 105 | case CV_8S: 106 | bins[x.at(i)] += weights.at(i); 107 | break; 108 | case CV_16U: 109 | bins[x.at(i)] += weights.at(i); 110 | break; 111 | case CV_16S: 112 | bins[x.at(i)] += weights.at(i); 113 | break; 114 | case CV_32S: 115 | bins[x.at(i)] += weights.at(i); 116 | break; 117 | case CV_32F: 118 | bins[x.at(i)] += weights.at(i); 119 | break; 120 | case CV_64F: 121 | bins[x.at(i)] += weights.at(i); 122 | break; 123 | default: 124 | cv::error(cv::Error::StsAssert, "depth must be one of CV_8U CV_8S CV_16U CV_16S CV_32S CV_32F CV_64F", CV_Func, __FILE__, __LINE__); 125 | } 126 | } 127 | } 128 | 129 | Mat _bins(Size(bins.size(), 1), CV_64F, static_cast(const_cast(bins.data()))); 130 | _bins.copyTo(out); 131 | } 132 | 133 | void ravel(const cv::Mat& src, cv::Mat& out) { 134 | if (src.isContinuous()) { 135 | out = src.reshape(src.channels(), src.total()); 136 | } else { 137 | out = src.clone().reshape(src.channels(), src.total()); 138 | } 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/contrib/cv_extra.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | // CV_EXPORTS_W : include this file in lua_generated_include 6 | 7 | namespace cv { 8 | CV_EXPORTS_W double randu(); 9 | CV_EXPORTS_W void randu(int rows, int cols, InputOutputArray dst = Mat(), int type = CV_32F); 10 | CV_EXPORTS_W void randu(Size size, InputOutputArray dst = Mat(), int type = CV_32F); 11 | CV_EXPORTS_W void randu(const std::vector& sizes, InputOutputArray dst = Mat(), int type = CV_32F); 12 | 13 | CV_EXPORTS_W double randn(); 14 | CV_EXPORTS_W void randn(int rows, int cols, InputOutputArray dst = Mat(), int type = CV_32F); 15 | CV_EXPORTS_W void randn(Size size, InputOutputArray dst = Mat(), int type = CV_32F); 16 | CV_EXPORTS_W void randn(const std::vector& sizes, InputOutputArray dst = Mat(), int type = CV_32F); 17 | 18 | CV_EXPORTS_W int argmax(InputArray src, bool lastIndex = false); 19 | CV_EXPORTS_W std::variant, int> argmax(InputArray src, int axis, bool lastIndex = false); 20 | 21 | CV_EXPORTS_W void bincount(InputArray x, OutputArray out, InputArray weights = noArray(), int minlength = 0); 22 | CV_EXPORTS_W void ravel(const cv::Mat& src, CV_OUT cv::Mat& out); 23 | } 24 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/contrib/imgproc_extra.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace cv 6 | { 7 | CV_EXPORTS_W void matchTemplateParallel(InputArray image, InputArray templ, 8 | OutputArray result, int method, InputArray mask = noArray()); 9 | 10 | CV_EXPORTS_W void searchTemplate(InputArray image, 11 | InputArray templ, 12 | OutputArray result, 13 | InputArray mask = noArray(), 14 | const std::vector& channels = std::vector(), 15 | const std::vector& ranges = std::vector(), 16 | const bool parallel = false); 17 | 18 | CV_EXPORTS_W void findTemplate( 19 | InputArray image, 20 | InputArray templ, 21 | CV_OUT std::vector>& results, 22 | double threshold = 0.95, 23 | int methodMatch = cv::TM_CCOEFF_NORMED, 24 | InputArray mask = noArray(), 25 | int limit = 20, 26 | int code = -1, 27 | float overlapping = 2.0, 28 | std::vector channels = std::vector(), 29 | std::vector histSize = std::vector(), 30 | std::vector ranges = std::vector(), 31 | int methodCompareHist = cv::HISTCMP_CORREL, 32 | int dstCn = 0, 33 | bool accumulate = false); 34 | } 35 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/contrib/mat_extra.cpp: -------------------------------------------------------------------------------- 1 | #include "mat_extra.h" 2 | 3 | namespace cvextra { 4 | std::vector mat_shape(const cv::Mat& self) { 5 | const auto dims = self.size.dims(); 6 | std::vector shape(self.size.p, self.size.p + dims); 7 | const auto channels = self.channels(); 8 | if (channels != 1) { 9 | shape.push_back(channels); 10 | } 11 | return shape; 12 | } 13 | 14 | std::vector umat_shape(const cv::UMat& self) { 15 | const auto dims = self.size.dims(); 16 | std::vector shape(self.size.p, self.size.p + dims); 17 | const auto channels = self.channels(); 18 | if (channels != 1) { 19 | shape.push_back(channels); 20 | } 21 | return shape; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/contrib/mat_extra.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | // CV_EXPORTS_W : include this file in lua_generated_include 5 | 6 | namespace cvextra { 7 | std::vector mat_shape(const cv::Mat& self); 8 | std::vector umat_shape(const cv::UMat& self); 9 | } -------------------------------------------------------------------------------- /autoit-opencv-com/src/cvLib.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | 5 | #include "resource.h" 6 | 7 | #define APSTUDIO_READONLY_SYMBOLS 8 | ///////////////////////////////////////////////////////////////////////////// 9 | // 10 | // Generated from the TEXTINCLUDE 2 resource. 11 | // 12 | #ifndef APSTUDIO_INVOKED 13 | #include "targetver.h" 14 | #endif 15 | #include "winres.h" 16 | #include "verrsrc.h" 17 | 18 | ///////////////////////////////////////////////////////////////////////////// 19 | #undef APSTUDIO_READONLY_SYMBOLS 20 | 21 | ///////////////////////////////////////////////////////////////////////////// 22 | // Français (France) resources 23 | 24 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FRA) 25 | LANGUAGE LANG_FRENCH, SUBLANG_FRENCH 26 | 27 | #ifdef APSTUDIO_INVOKED 28 | ///////////////////////////////////////////////////////////////////////////// 29 | // 30 | // TEXTINCLUDE 31 | // 32 | 33 | 1 TEXTINCLUDE 34 | BEGIN 35 | "resource.h\0" 36 | END 37 | 38 | 2 TEXTINCLUDE 39 | BEGIN 40 | "#ifndef APSTUDIO_INVOKED\r\n" 41 | "#include ""targetver.h""\r\n" 42 | "#endif\r\n" 43 | "#include ""winres.h""\r\n" 44 | "#include ""verrsrc.h""\r\n" 45 | "\0" 46 | END 47 | 48 | 3 TEXTINCLUDE 49 | BEGIN 50 | "1 TYPELIB ""cvLib.tlb""\r\n" 51 | "\0" 52 | END 53 | 54 | #endif // APSTUDIO_INVOKED 55 | 56 | 57 | ///////////////////////////////////////////////////////////////////////////// 58 | // 59 | // Version 60 | // 61 | 62 | VS_VERSION_INFO VERSIONINFO 63 | FILEVERSION 2,6,2 64 | PRODUCTVERSION 2,6,2 65 | FILEFLAGSMASK 0x3fL 66 | #ifdef _DEBUG 67 | FILEFLAGS 0x1L 68 | #else 69 | FILEFLAGS 0x0L 70 | #endif 71 | FILEOS 0x40004L 72 | FILETYPE 0x2L 73 | FILESUBTYPE 0x0L 74 | BEGIN 75 | BLOCK "StringFileInfo" 76 | BEGIN 77 | BLOCK "040C04B0" 78 | BEGIN 79 | // VALUE "CompanyName", "TODO: " 80 | VALUE "FileDescription", "COM+ for OpenCV" 81 | VALUE "FileVersion", "2.6.2" 82 | // VALUE "LegalCopyright", "TODO: (c) . Tous droits réservés." 83 | #ifdef _DEBUG 84 | VALUE "InternalName", "autoit_opencv_com4100d.dll" 85 | VALUE "OriginalFilename", "autoit_opencv_com4100d.dll" 86 | #else 87 | VALUE "InternalName", "autoit_opencv_com4100.dll" 88 | VALUE "OriginalFilename", "autoit_opencv_com4100.dll" 89 | #endif 90 | VALUE "ProductName", "AutoIt OpenCV COM" 91 | VALUE "ProductVersion", "2.6.2" 92 | END 93 | END 94 | BLOCK "VarFileInfo" 95 | BEGIN 96 | VALUE "Translation", 0x40c, 1200 97 | END 98 | END 99 | 100 | 101 | ///////////////////////////////////////////////////////////////////////////// 102 | // 103 | // REGISTRY 104 | // 105 | 106 | IDR_CV REGISTRY "cvLib.rgs" 107 | 108 | #include "registries.rgs" 109 | 110 | 111 | ///////////////////////////////////////////////////////////////////////////// 112 | // 113 | // String Table 114 | // 115 | 116 | STRINGTABLE 117 | BEGIN 118 | IDS_PROJNAME "cv" 119 | END 120 | 121 | #endif // Français (France) resources 122 | ///////////////////////////////////////////////////////////////////////////// 123 | 124 | 125 | 126 | #ifndef APSTUDIO_INVOKED 127 | ///////////////////////////////////////////////////////////////////////////// 128 | // 129 | // Generated from the TEXTINCLUDE 3 resource. 130 | // 131 | 1 TYPELIB "cvLib.tlb" 132 | 133 | ///////////////////////////////////////////////////////////////////////////// 134 | #endif // not APSTUDIO_INVOKED 135 | 136 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/cvLib.rgs: -------------------------------------------------------------------------------- 1 | HKCR 2 | { 3 | } 4 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/cv_extended.cpp: -------------------------------------------------------------------------------- 1 | #include "Cv_Object.h" 2 | 3 | STDMETHODIMP CCv_Object::get_extended(VARIANT* _retval) { 4 | VARIANT out_val = { 0 }; 5 | V_VT(&out_val) = VT_ARRAY | VT_VARIANT; 6 | V_ARRAY(&out_val) = ExtendedHolder::extended.Detach(); 7 | 8 | VariantInit(_retval); 9 | HRESULT hr = VariantCopy(_retval, &out_val); 10 | ExtendedHolder::extended.Attach(V_ARRAY(&out_val)); 11 | return hr; 12 | } 13 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/dllmain.cpp: -------------------------------------------------------------------------------- 1 | #include "dllmain.h" 2 | #include 3 | 4 | namespace fs = std::filesystem; 5 | 6 | using namespace ATL; 7 | 8 | CCvModule _AtlModule; 9 | 10 | // Point d'entrée de la DLL 11 | STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) 12 | { 13 | if (dwReason == DLL_PROCESS_ATTACH) { 14 | ExtendedHolder::CreateActivationContext(hInstance); 15 | } 16 | else if (dwReason == DLL_PROCESS_DETACH) { 17 | ExtendedHolder::_ActCtx.Set(INVALID_HANDLE_VALUE); 18 | } 19 | return _AtlModule.DllMain(dwReason, lpReserved); 20 | } 21 | 22 | // Utilisé pour déterminer si la DLL peut être déchargée par OLE. 23 | _Use_decl_annotations_ 24 | STDAPI DllCanUnloadNow(void) 25 | { 26 | return _AtlModule.DllCanUnloadNow(); 27 | } 28 | 29 | // Retourne une fabrique de classes pour créer un objet du type demandé. 30 | _Use_decl_annotations_ 31 | STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID* ppv) 32 | { 33 | return _AtlModule.DllGetClassObject(rclsid, riid, ppv); 34 | } 35 | 36 | // DllRegisterServer - Ajoute des entrées à la base de registres. 37 | _Use_decl_annotations_ 38 | STDAPI DllRegisterServer(void) 39 | { 40 | // inscrit l'objet, la typelib et toutes les interfaces dans la typelib 41 | HRESULT hr = _AtlModule.DllRegisterServer(); 42 | return hr; 43 | } 44 | 45 | // DllUnregisterServer - Supprime des entrées de la base de registres. 46 | _Use_decl_annotations_ 47 | STDAPI DllUnregisterServer(void) 48 | { 49 | HRESULT hr = _AtlModule.DllUnregisterServer(); 50 | return hr; 51 | } 52 | 53 | // DllInstall - Ajoute/supprime des entrées de la base de registres par utilisateur et par ordinateur. 54 | STDAPI DllInstall(BOOL bInstall, _In_opt_ LPCWSTR pszCmdLine) 55 | { 56 | HRESULT hr = E_FAIL; 57 | static const wchar_t szUserSwitch[] = L"user"; 58 | 59 | if (pszCmdLine != nullptr && _wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0) 60 | { 61 | ATL::AtlSetPerUserRegistration(true); 62 | } 63 | 64 | if (bInstall) 65 | { 66 | hr = DllRegisterServer(); 67 | if (FAILED(hr)) 68 | { 69 | DllUnregisterServer(); 70 | } 71 | } 72 | else 73 | { 74 | hr = DllUnregisterServer(); 75 | } 76 | 77 | return hr; 78 | } 79 | 80 | namespace { 81 | std::vector cookies; 82 | std::map handles; 83 | } 84 | 85 | STDAPI_(BOOL) DllActivateManifest(_In_opt_ LPCWSTR pManifest) 86 | { 87 | if (pManifest == nullptr || wcslen(pManifest) == 0) { 88 | PCACTCTXW pActCtx = nullptr; 89 | return DllActivateActCtx(pActCtx); 90 | } 91 | 92 | ACTCTXW actCtx; 93 | memset((void*)&actCtx, 0, sizeof(ACTCTXW)); 94 | actCtx.cbSize = sizeof(ACTCTXW); 95 | actCtx.lpSource = pManifest; 96 | return DllActivateActCtx(&actCtx); 97 | } 98 | 99 | STDAPI_(BOOL) DllActivateActCtx(_In_opt_ PCACTCTXW pActCtx) 100 | { 101 | ULONG_PTR ulpCookie = 0; 102 | BOOL activated = false; 103 | HANDLE hActCtx = INVALID_HANDLE_VALUE; 104 | 105 | if (pActCtx == nullptr) { 106 | activated = ExtendedHolder::_ActCtx.Activate(ulpCookie); 107 | } 108 | else { 109 | hActCtx = ::CreateActCtxW(pActCtx); 110 | CV_Assert(hActCtx != INVALID_HANDLE_VALUE); 111 | 112 | handles.insert_or_assign(cookies.size(), hActCtx); 113 | activated = ::ActivateActCtx(hActCtx, &ulpCookie); 114 | } 115 | 116 | CV_Assert(activated); 117 | 118 | cookies.push_back(ulpCookie); 119 | return true; 120 | } 121 | 122 | STDAPI_(BOOL) DllDeactivateActCtx() 123 | { 124 | if (cookies.empty()) { 125 | return false; 126 | } 127 | 128 | auto ulpCookie = cookies.back(); 129 | if (!::DeactivateActCtx(0, ulpCookie)) { 130 | return false; 131 | } 132 | cookies.pop_back(); 133 | 134 | if (handles.count(cookies.size())) { 135 | const auto hActCtx = handles.at(cookies.size()); 136 | 137 | ::ReleaseActCtx(hActCtx); 138 | 139 | handles.erase(cookies.size()); 140 | } 141 | 142 | return true; 143 | } 144 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/dllmain.def: -------------------------------------------------------------------------------- 1 | LIBRARY 2 | 3 | EXPORTS 4 | DllCanUnloadNow PRIVATE 5 | DllGetClassObject PRIVATE 6 | DllRegisterServer PRIVATE 7 | DllUnregisterServer PRIVATE 8 | DllInstall PRIVATE 9 | DllActivateManifest PRIVATE 10 | DllActivateActCtx PRIVATE 11 | DllDeactivateActCtx PRIVATE 12 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/dllmain.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "autoit_bridge.h" 4 | 5 | class CCvModule : public ATL::CAtlDllModuleT< CCvModule > 6 | { 7 | public: 8 | DECLARE_LIBID(LIBID_cvLib) 9 | DECLARE_REGISTRY_APPID_RESOURCEID(IDR_CV, "{fc210206-673e-4ec8-82d5-1a6ac561f3de}") 10 | }; 11 | 12 | extern class CCvModule _AtlModule; 13 | 14 | STDAPI_(BOOL) DllActivateManifest(_In_opt_ LPCWSTR pManifest); 15 | STDAPI_(BOOL) DllActivateActCtx(_In_opt_ PCACTCTXW pActCtx); 16 | STDAPI_(BOOL) DllDeactivateActCtx(); 17 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/impl_cv.cpp: -------------------------------------------------------------------------------- 1 | #include "impl_cv.h" 2 | 3 | _variant_t cv::variant(void* ptr) { 4 | return _variant_t(static_cast(ptr)); 5 | } 6 | 7 | const std::string cv::_format(const cv::InputArray& mtx, cv::Formatter::FormatType fmt) { 8 | std::string ouput; 9 | ouput << cv::format(mtx, fmt); 10 | return ouput; 11 | } 12 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/impl_cv.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace cv { 8 | CV_EXPORTS_W _variant_t variant(void* ptr); 9 | CV_EXPORTS_AS(format) const std::string _format(const cv::InputArray& mtx, cv::Formatter::FormatType fmt = cv::Formatter::FMT_NUMPY); 10 | } 11 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/impl_mat.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "autoit_bridge_common.h" 4 | #include "autoit_bridge_generated.h" 5 | 6 | class IVariantArray { 7 | public: 8 | virtual cv::_InputArray* createInputArray() = 0; 9 | virtual cv::_OutputArray* createOutputArray() = 0; 10 | virtual cv::_InputOutputArray* createInputOutputArray() = 0; 11 | }; 12 | 13 | class IVariantArrays : public IVariantArray { 14 | 15 | }; 16 | 17 | template 18 | class IVariantArrayImpl : 19 | public IVariantArray, 20 | public AutoItObject<_Tp> { 21 | public: 22 | cv::_InputArray* createInputArray() { 23 | return new cv::_InputArray(*this->__self->get()); 24 | } 25 | 26 | cv::_OutputArray* createOutputArray() { 27 | return new cv::_OutputArray(*this->__self->get()); 28 | } 29 | 30 | cv::_InputOutputArray* createInputOutputArray() { 31 | return new cv::_InputOutputArray(*this->__self->get()); 32 | } 33 | }; 34 | 35 | template 36 | class IVariantArraysImpl : 37 | public IVariantArrays, 38 | public AutoItObject<_Tp> { 39 | public: 40 | cv::_InputArray* createInputArray() { 41 | return new cv::_InputArray(*this->__self->get()); 42 | } 43 | 44 | cv::_OutputArray* createOutputArray() { 45 | return new cv::_OutputArray(*this->__self->get()); 46 | } 47 | 48 | cv::_InputOutputArray* createInputOutputArray() { 49 | return new cv::_InputOutputArray(*this->__self->get()); 50 | } 51 | }; 52 | 53 | namespace cv { 54 | template 55 | struct TypeDepth; 56 | 57 | template<> 58 | struct TypeDepth { 59 | typedef uchar value_type; 60 | }; 61 | 62 | template<> 63 | struct TypeDepth { 64 | typedef schar value_type; 65 | }; 66 | 67 | template<> 68 | struct TypeDepth { 69 | typedef ushort value_type; 70 | }; 71 | 72 | template<> 73 | struct TypeDepth { 74 | typedef short value_type; 75 | }; 76 | 77 | template<> 78 | struct TypeDepth { 79 | typedef int value_type; 80 | }; 81 | 82 | template<> 83 | struct TypeDepth { 84 | typedef float value_type; 85 | }; 86 | 87 | template<> 88 | struct TypeDepth { 89 | typedef double value_type; 90 | }; 91 | 92 | template<> 93 | struct TypeDepth { 94 | typedef float16_t value_type; 95 | }; 96 | } 97 | 98 | extern const bool is_variant_scalar(VARIANT const* const& in_val); 99 | extern const bool is_array_from(VARIANT const* const& in_val, bool is_optional); 100 | extern const bool is_arrays_from(VARIANT const* const& in_val, bool is_optional); 101 | 102 | extern const HRESULT autoit_from(cv::MatExpr& in_val, ICv_Mat_Object**& out_val); 103 | 104 | namespace cv { 105 | CV_EXPORTS_W Mat createMatFromBitmap(void* ptr, bool copy = true); 106 | } 107 | 108 | namespace autoit 109 | { 110 | 111 | template 112 | struct _GenericCopy> { 113 | inline static HRESULT copy(destination_type* pTo, const cv::Point_<_Tp>* pFrom) { 114 | return autoit_from(*pFrom, pTo); 115 | } 116 | }; 117 | 118 | template 119 | struct _GenericCopy> { 120 | inline static HRESULT copy(destination_type* pTo, const cv::Point3_<_Tp>* pFrom) { 121 | return autoit_from(static_cast>(*pFrom), pTo); 122 | } 123 | }; 124 | 125 | template 126 | struct _GenericCopy> { 127 | inline static HRESULT copy(destination_type* pTo, const cv::Rect_<_Tp>* pFrom) { 128 | return autoit_from(*pFrom, pTo); 129 | } 130 | }; 131 | 132 | template 133 | struct _GenericCopy> { 134 | inline static HRESULT copy(destination_type* pTo, const cv::Size_<_Tp>* pFrom) { 135 | return autoit_from(*pFrom, pTo); 136 | } 137 | }; 138 | 139 | template 140 | struct _GenericCopy> { 141 | inline static HRESULT copy(destination_type* pTo, const cv::Vec<_Tp, cn>* pFrom) { 142 | return autoit_from(*pFrom, pTo); 143 | } 144 | }; 145 | 146 | namespace cvextra { 147 | void convertToShow(cv::InputArray src, cv::Mat& dst, bool toRGB = true); 148 | const void* convertToBitmap(cv::InputArray src, bool copy); 149 | void GdiplusResize(cv::InputArray src, cv::Mat& dst, float newWidth, float newHeight, int interpolation); 150 | AUTOIT_PTR createFromVectorOfMat(const std::vector& vec); 151 | } 152 | } 153 | 154 | template 155 | inline const bool is_assignable_from(cv::Point3_<_Tp>& out_val, VARIANT const* const& in_val, bool is_optional) { 156 | static cv::Vec<_Tp, 3> tmp; 157 | return is_assignable_from(tmp, in_val, is_optional); 158 | } 159 | 160 | template 161 | const bool is_assignable_from(AUTOIT_PTR>& out_val, VARIANT const* const& in_val, bool is_optional) { 162 | static cv::Point3_<_Tp> tmp; 163 | return is_assignable_from(tmp, in_val, is_optional); 164 | } 165 | 166 | template 167 | inline const HRESULT autoit_to(VARIANT const* const& in_val, cv::Point3_<_Tp>& out_val) { 168 | cv::Vec<_Tp, 3> tmp; 169 | HRESULT hr = autoit_to(in_val, tmp); 170 | if (SUCCEEDED(hr)) { 171 | out_val = tmp; 172 | } 173 | return hr; 174 | } 175 | 176 | template 177 | inline const HRESULT autoit_to(VARIANT const* const& in_val, AUTOIT_PTR>& out_val) { 178 | out_val = std::make_shared>(); 179 | return autoit_to(in_val, *out_val.get()); 180 | } 181 | 182 | template 183 | inline const HRESULT autoit_from(const cv::Point3_<_Tp>& in_val, VARIANT*& out_val) { 184 | return autoit_from(cv::Vec<_Tp, 3>(in_val), out_val); 185 | } 186 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/targetver.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Si vous incluez SDKDDKVer.h, cela définit la dernière plateforme Windows disponible. 4 | 5 | // Si vous souhaitez générer votre application pour une plateforme Windows précédente, incluez WinSDKVer.h et 6 | // définissez la macro _WIN32_WINNT à la plateforme que vous souhaitez prendre en charge avant d'inclure SDKDDKVer.h. 7 | 8 | // bazel has an hardcoded _WIN32_WINNT value which makes the compilation to failed 9 | // undefine it to let winsdk set the correct value 10 | // see https://github.com/bazelbuild/bazel/issues/15024 11 | // https://github.com/bazelbuild/bazel/issues/12737 12 | #if defined(_WIN32_WINNT) && !defined(_INC_SDKDDKVER) 13 | #undef _WIN32_WINNT 14 | #endif 15 | 16 | #include 17 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/wgc/SimpleCapture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma comment(lib, "dwmapi.lib") 3 | #pragma comment(lib, "windowsapp.lib") 4 | 5 | #include "targetver.h" 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | // WinRT 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | // STL 27 | #include 28 | #include 29 | 30 | // D3D 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | // Helpers 37 | #include "composition.interop.h" 38 | #include "d3dHelpers.h" 39 | #include "direct3d11.interop.h" 40 | #include "capture.interop.h" 41 | 42 | #include 43 | 44 | namespace cv { 45 | namespace wgc { 46 | typedef void (*WGCFrameCallback)(cv::Mat* frame); 47 | 48 | class CV_EXPORTS_W SimpleCapture { 49 | public: 50 | SimpleCapture(); 51 | SimpleCapture(WGCFrameCallback handleFrame) : onFrameArrived(handleFrame) {} 52 | ~SimpleCapture(); 53 | 54 | CV_WRAP bool setHandle(HWND hWnd, WORD channels = 4); 55 | CV_WRAP bool Start(); 56 | CV_WRAP bool Pause(); 57 | CV_WRAP bool Resume(); 58 | CV_WRAP bool Stop(); 59 | 60 | CV_WRAP bool Paused() { 61 | return m_paused.load(); 62 | } 63 | 64 | public: 65 | static bool isWGCSupported; 66 | CV_PROP_RW WGCFrameCallback onFrameArrived; 67 | 68 | private: 69 | // since I don't know the copy behaviour 70 | // disable it 71 | SimpleCapture(const SimpleCapture&) = delete; 72 | SimpleCapture& operator=(const SimpleCapture&) = delete; 73 | 74 | void OnFrameArrived( 75 | winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool const& sender, 76 | winrt::Windows::Foundation::IInspectable const& args); 77 | 78 | private: 79 | WORD m_channels = 4; 80 | winrt::Windows::Graphics::DirectX::DirectXPixelFormat m_format; 81 | 82 | winrt::Windows::Graphics::Capture::GraphicsCaptureItem m_item{ nullptr }; 83 | winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool m_framePool{ nullptr }; 84 | winrt::Windows::Graphics::Capture::GraphicsCaptureSession m_session{ nullptr }; 85 | winrt::Windows::Graphics::SizeInt32 m_lastSize; 86 | 87 | winrt::Windows::Graphics::DirectX::Direct3D11::IDirect3DDevice m_device{ nullptr }; 88 | winrt::com_ptr m_d3dContext{ nullptr }; 89 | 90 | std::atomic m_closed = true; 91 | std::atomic m_paused = false; 92 | winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool::FrameArrived_revoker m_frameArrived; 93 | }; 94 | 95 | CV_EXPORTS_W bool isWGCSupported(); 96 | CV_EXPORTS_W cv::Ptr createSimpleCapture(); 97 | CV_EXPORTS_W cv::Ptr createSimpleCapture(WGCFrameCallback handleFrame); 98 | CV_EXPORTS_W void BitBltCapture(HWND hWnd, CV_OUT cv::Mat& dst, WORD channels = 4); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /autoit-opencv-com/src/wgc/capture.interop.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | inline auto CreateCaptureItemForWindow(HWND hwnd) 7 | { 8 | auto activation_factory = winrt::get_activation_factory(); 9 | auto interop_factory = activation_factory.as(); 10 | winrt::Windows::Graphics::Capture::GraphicsCaptureItem item = { nullptr }; 11 | interop_factory->CreateForWindow(hwnd, winrt::guid_of(), reinterpret_cast(winrt::put_abi(item))); 12 | return item; 13 | } -------------------------------------------------------------------------------- /autoit-opencv-com/src/wgc/composition.interop.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | inline auto CreateCompositionGraphicsDevice( 7 | winrt::Windows::UI::Composition::Compositor const& compositor, 8 | ::IUnknown* device) 9 | { 10 | winrt::Windows::UI::Composition::CompositionGraphicsDevice graphicsDevice{ nullptr }; 11 | auto compositorInterop = compositor.as(); 12 | winrt::com_ptr graphicsInterop; 13 | winrt::check_hresult(compositorInterop->CreateGraphicsDevice(device, graphicsInterop.put())); 14 | winrt::check_hresult(graphicsInterop->QueryInterface(winrt::guid_of(), 15 | reinterpret_cast(winrt::put_abi(graphicsDevice)))); 16 | return graphicsDevice; 17 | } 18 | 19 | inline void ResizeSurface( 20 | winrt::Windows::UI::Composition::CompositionDrawingSurface const& surface, 21 | winrt::Windows::Foundation::Size const& size) 22 | { 23 | auto surfaceInterop = surface.as(); 24 | SIZE newSize = {}; 25 | newSize.cx = static_cast(std::round(size.Width)); 26 | newSize.cy = static_cast(std::round(size.Height)); 27 | winrt::check_hresult(surfaceInterop->Resize(newSize)); 28 | } 29 | 30 | inline auto SurfaceBeginDraw( 31 | winrt::Windows::UI::Composition::CompositionDrawingSurface const& surface) 32 | { 33 | auto surfaceInterop = surface.as(); 34 | winrt::com_ptr context; 35 | POINT offset = {}; 36 | winrt::check_hresult(surfaceInterop->BeginDraw(nullptr, __uuidof(ID2D1DeviceContext), context.put_void(), &offset)); 37 | context->SetTransform(D2D1::Matrix3x2F::Translation((FLOAT)offset.x,(FLOAT) offset.y)); 38 | return context; 39 | } 40 | 41 | inline void SurfaceEndDraw( 42 | winrt::Windows::UI::Composition::CompositionDrawingSurface const& surface) 43 | { 44 | auto surfaceInterop = surface.as(); 45 | winrt::check_hresult(surfaceInterop->EndDraw()); 46 | } 47 | 48 | inline auto CreateCompositionSurfaceForSwapChain( 49 | winrt::Windows::UI::Composition::Compositor const& compositor, 50 | ::IUnknown* swapChain) 51 | { 52 | winrt::Windows::UI::Composition::ICompositionSurface surface{ nullptr }; 53 | auto compositorInterop = compositor.as(); 54 | winrt::com_ptr surfaceInterop; 55 | winrt::check_hresult(compositorInterop->CreateCompositionSurfaceForSwapChain(swapChain, surfaceInterop.put())); 56 | winrt::check_hresult(surfaceInterop->QueryInterface(winrt::guid_of(), 57 | reinterpret_cast(winrt::put_abi(surface)))); 58 | return surface; 59 | } -------------------------------------------------------------------------------- /autoit-opencv-com/src/wgc/d3dHelpers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "composition.interop.h" 3 | 4 | struct SurfaceContext 5 | { 6 | public: 7 | SurfaceContext(std::nullptr_t) {} 8 | SurfaceContext( 9 | winrt::Windows::UI::Composition::CompositionDrawingSurface surface) 10 | { 11 | m_surface = surface; 12 | m_d2dContext = SurfaceBeginDraw(m_surface); 13 | } 14 | ~SurfaceContext() 15 | { 16 | SurfaceEndDraw(m_surface); 17 | m_d2dContext = nullptr; 18 | m_surface = nullptr; 19 | } 20 | 21 | winrt::com_ptr GetDeviceContext() { return m_d2dContext; } 22 | 23 | private: 24 | winrt::com_ptr m_d2dContext; 25 | winrt::Windows::UI::Composition::CompositionDrawingSurface m_surface{ nullptr }; 26 | }; 27 | 28 | struct D3D11DeviceLock 29 | { 30 | public: 31 | D3D11DeviceLock(std::nullopt_t) {} 32 | D3D11DeviceLock(ID3D11Multithread* pMultithread) 33 | { 34 | m_multithread.copy_from(pMultithread); 35 | m_multithread->Enter(); 36 | } 37 | ~D3D11DeviceLock() 38 | { 39 | m_multithread->Leave(); 40 | m_multithread = nullptr; 41 | } 42 | private: 43 | winrt::com_ptr m_multithread; 44 | }; 45 | 46 | inline auto 47 | CreateWICFactory() 48 | { 49 | winrt::com_ptr wicFactory; 50 | winrt::check_hresult( 51 | ::CoCreateInstance( 52 | CLSID_WICImagingFactory, 53 | nullptr, 54 | CLSCTX_INPROC_SERVER, 55 | winrt::guid_of(), 56 | wicFactory.put_void())); 57 | 58 | return wicFactory; 59 | } 60 | 61 | inline auto 62 | CreateD2DDevice( 63 | winrt::com_ptr const& factory, 64 | winrt::com_ptr const& device) 65 | { 66 | winrt::com_ptr result; 67 | winrt::check_hresult(factory->CreateDevice(device.as().get(), result.put())); 68 | return result; 69 | } 70 | 71 | inline auto 72 | CreateD3DDevice( 73 | D3D_DRIVER_TYPE const type, 74 | winrt::com_ptr& device) 75 | { 76 | WINRT_ASSERT(!device); 77 | 78 | UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; 79 | 80 | //#ifdef _DEBUG 81 | // flags |= D3D11_CREATE_DEVICE_DEBUG; 82 | //#endif 83 | 84 | return D3D11CreateDevice( 85 | nullptr, 86 | type, 87 | nullptr, 88 | flags, 89 | nullptr, 0, 90 | D3D11_SDK_VERSION, 91 | device.put(), 92 | nullptr, 93 | nullptr); 94 | } 95 | 96 | inline auto 97 | CreateD3DDevice() 98 | { 99 | winrt::com_ptr device; 100 | HRESULT hr = CreateD3DDevice(D3D_DRIVER_TYPE_HARDWARE, device); 101 | 102 | if (DXGI_ERROR_UNSUPPORTED == hr) 103 | { 104 | hr = CreateD3DDevice(D3D_DRIVER_TYPE_WARP, device); 105 | } 106 | 107 | winrt::check_hresult(hr); 108 | return device; 109 | } 110 | 111 | inline auto 112 | CreateD2DFactory() 113 | { 114 | D2D1_FACTORY_OPTIONS options{}; 115 | 116 | //#ifdef _DEBUG 117 | // options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION; 118 | //#endif 119 | 120 | winrt::com_ptr factory; 121 | 122 | winrt::check_hresult(D2D1CreateFactory( 123 | D2D1_FACTORY_TYPE_SINGLE_THREADED, 124 | options, 125 | factory.put())); 126 | 127 | return factory; 128 | } 129 | 130 | inline auto 131 | CreateDXGISwapChain( 132 | winrt::com_ptr const& device, 133 | const DXGI_SWAP_CHAIN_DESC1* desc) 134 | { 135 | auto dxgiDevice = device.as(); 136 | winrt::com_ptr adapter; 137 | winrt::check_hresult(dxgiDevice->GetParent(winrt::guid_of(), adapter.put_void())); 138 | winrt::com_ptr factory; 139 | winrt::check_hresult(adapter->GetParent(winrt::guid_of(), factory.put_void())); 140 | 141 | winrt::com_ptr swapchain; 142 | winrt::check_hresult(factory->CreateSwapChainForComposition( 143 | device.get(), 144 | desc, 145 | nullptr, 146 | swapchain.put())); 147 | 148 | return swapchain; 149 | } 150 | 151 | inline auto 152 | CreateDXGISwapChain( 153 | winrt::com_ptr const& device, 154 | uint32_t width, 155 | uint32_t height, 156 | DXGI_FORMAT format, 157 | uint32_t bufferCount) 158 | { 159 | DXGI_SWAP_CHAIN_DESC1 desc = {}; 160 | desc.Width = width; 161 | desc.Height = height; 162 | desc.Format = format; 163 | desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 164 | desc.SampleDesc.Count = 1; 165 | desc.SampleDesc.Quality = 0; 166 | desc.BufferCount = bufferCount; 167 | desc.Scaling = DXGI_SCALING_STRETCH; 168 | desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; 169 | desc.AlphaMode = DXGI_ALPHA_MODE_PREMULTIPLIED; 170 | 171 | return CreateDXGISwapChain(device, &desc); 172 | } -------------------------------------------------------------------------------- /autoit-opencv-com/src/wgc/direct3d11.interop.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | extern "C" 5 | { 6 | HRESULT __stdcall CreateDirect3D11DeviceFromDXGIDevice(::IDXGIDevice* dxgiDevice, 7 | ::IInspectable** graphicsDevice); 8 | 9 | HRESULT __stdcall CreateDirect3D11SurfaceFromDXGISurface(::IDXGISurface* dgxiSurface, 10 | ::IInspectable** graphicsSurface); 11 | } 12 | 13 | struct __declspec(uuid("A9B3D012-3DF2-4EE3-B8D1-8695F457D3C1")) 14 | IDirect3DDxgiInterfaceAccess : ::IUnknown 15 | { 16 | virtual HRESULT __stdcall GetInterface(GUID const& id, void** object) = 0; 17 | }; 18 | 19 | inline auto CreateDirect3DDevice(IDXGIDevice* dxgi_device) 20 | { 21 | winrt::com_ptr<::IInspectable> d3d_device; 22 | winrt::check_hresult(CreateDirect3D11DeviceFromDXGIDevice(dxgi_device, d3d_device.put())); 23 | return d3d_device.as(); 24 | } 25 | 26 | inline auto CreateDirect3DSurface(IDXGISurface* dxgi_surface) 27 | { 28 | winrt::com_ptr<::IInspectable> d3d_surface; 29 | winrt::check_hresult(CreateDirect3D11SurfaceFromDXGISurface(dxgi_surface, d3d_surface.put())); 30 | return d3d_surface.as(); 31 | } 32 | 33 | template 34 | auto GetDXGIInterfaceFromObject(winrt::Windows::Foundation::IInspectable const& object) 35 | { 36 | auto access = object.as(); 37 | winrt::com_ptr result; 38 | winrt::check_hresult(access->GetInterface(winrt::guid_of(), result.put_void())); 39 | return result; 40 | } -------------------------------------------------------------------------------- /autoit-opencv-com/test/test.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #pragma comment(lib, "strmiids") 4 | #pragma comment(lib, "gdiplus") 5 | 6 | #ifndef NOMINMAX 7 | #define NOMINMAX 8 | #endif 9 | 10 | #ifndef STRICT 11 | #define STRICT 12 | #endif 13 | 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "generated_include.h" 29 | 30 | #import "cvLib.tlb" 31 | -------------------------------------------------------------------------------- /autoit-opencv-com/vswhere.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/autoit-opencv-com/vswhere.exe -------------------------------------------------------------------------------- /opencv/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.19) 2 | 3 | # Sources: https://github.com/opencv/ci-gha-workflow/blob/main/.github/workflows/OCV-WinPack-4.x-W10.yaml 4 | 5 | # Name of the project (will be the name of the plugin) 6 | project(opencv) 7 | 8 | set(DEFAULT_BUILD_TYPE "Release") 9 | 10 | if(NOT DEFINED CMAKE_BUILD_TYPE) 11 | message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.") 12 | set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build.") 13 | endif() 14 | 15 | # Set the possible values of build type for cmake-gui 16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Release;MinSizeRel;RelWithDebInfo" CACHE STRING "Configs" FORCE) 17 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "${CMAKE_CONFIGURATION_TYPES}") 18 | 19 | include(../autoit-opencv-com/FindPatch.cmake) 20 | 21 | set(OpenCV_VERSION 4.9.0 CACHE STRING "Choose the OpenCV version.") 22 | set_property(CACHE OpenCV_VERSION PROPERTY STRINGS "4.9.0" "4.8.1" "4.8.0" "4.7.0" "4.6.0" "4.5.5" "4.5.4" "4.5.3" "4.5.2" "4.5.1" "4.5.0") 23 | 24 | string(REPLACE "." ";" OpenCV_VERSION_LIST ${OpenCV_VERSION}) 25 | list(GET OpenCV_VERSION_LIST 0 OpenCV_VERSION_MAJOR) 26 | list(GET OpenCV_VERSION_LIST 1 OpenCV_VERSION_MINOR) 27 | list(GET OpenCV_VERSION_LIST 2 OpenCV_VERSION_PATCH) 28 | 29 | set(OpenCV_DLLVERSION "${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}") 30 | set(OpenCV_DEBUG_POSTFIX d) 31 | 32 | # Tell cmake we will need opencv. 33 | include(FetchContent) 34 | FetchContent_Populate(opencv 35 | GIT_REPOSITORY https://github.com/opencv/opencv.git 36 | GIT_TAG ${OpenCV_VERSION} 37 | 38 | # PATCH_COMMAND is run once for each BUILD_TYPE 39 | # however, source download is only done once when it is a git repository 40 | # use a custom patch command to perform patch only once 41 | PATCH_COMMAND "${CMAKE_COMMAND}" 42 | "-DSOURCE_DIR=" 43 | "-DGIT_EXECUTABLE=${GIT_EXECUTABLE}" 44 | "-DPATCH_FILE=${CMAKE_CURRENT_SOURCE_DIR}/../autoit-opencv-com/patches/001-opencv-src.patch" 45 | -P "${CMAKE_CURRENT_SOURCE_DIR}/../autoit-opencv-com/cmake/git_patch_once.cmake" 46 | SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/opencv" 47 | BINARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build" 48 | ) 49 | 50 | # Tell cmake that we will need opencv_contrib. 51 | include(FetchContent) 52 | FetchContent_Populate(opencv_contrib 53 | GIT_REPOSITORY https://github.com/opencv/opencv_contrib.git 54 | GIT_TAG d6102ef65f9ccdb37bba0ea9b8254951eb89dc39 55 | SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/opencv_contrib" 56 | BINARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build" 57 | ) 58 | 59 | set(opencv_BINARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/build") 60 | file(TO_NATIVE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/opencv" OPENCV_INSTALL_DATA_DIR_RELATIVE) 61 | 62 | set(EXTRA_CMAKE_OPTIONS 63 | -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} 64 | # "-DOPENCV_EXTRA_MODULES_PATH=${opencv_contrib_SOURCE_DIR}/modules" 65 | 66 | "-DOPENCV_DOWNLOAD_PATH=${CMAKE_CURRENT_SOURCE_DIR}/download" 67 | -DOPENCV_PYTHON_INSTALL_PATH=python 68 | "-DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_SOURCE_DIR}/install" 69 | -DINSTALL_PDB=ON 70 | -DINSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL=OFF 71 | "-DOPENCV_INSTALL_DATA_DIR_RELATIVE=${OPENCV_INSTALL_DATA_DIR_RELATIVE}" 72 | -DINSTALL_CREATE_DISTRIB=ON 73 | -DOPENCV_GENERATE_SETUPVARS=ON 74 | 75 | # -DVIDEOIO_PLUGIN_LIST=all 76 | -DBUILD_opencv_world=ON 77 | -DBUILD_opencv_python2=OFF 78 | -DBUILD_opencv_python3=OFF 79 | -DBUILD_opencv_java=OFF 80 | -DBUILD_opencv_apps=OFF 81 | # -DBUILD_opencv_freetype=OFF 82 | -DBUILD_SHARED_LIBS=ON 83 | -DBUILD_TESTS=OFF 84 | -DBUILD_PERF_TESTS=OFF 85 | -DBUILD_DOCS=OFF 86 | -DBUILD_EXAMPLES=OFF 87 | # -DWITH_EIGEN=ON 88 | # -DBUILD_OPENEXR=ON 89 | -DBUILD_opencv_java_bindings_generator=OFF 90 | -DBUILD_opencv_js_bindings_generator=OFF 91 | -DBUILD_opencv_objc_bindings_generator=OFF 92 | -DBUILD_opencv_python_bindings_generator=ON 93 | ) 94 | 95 | add_custom_command( 96 | OUTPUT "${opencv_BINARY_DIR}/CMakeCache.txt" 97 | COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" ${EXTRA_CMAKE_OPTIONS} "${opencv_SOURCE_DIR}" 98 | WORKING_DIRECTORY "${opencv_BINARY_DIR}" 99 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt" 100 | COMMENT "Cmake OpenCV" 101 | ) 102 | add_custom_target(configure_opencv ALL DEPENDS "${opencv_BINARY_DIR}/CMakeCache.txt") 103 | 104 | add_custom_command( 105 | OUTPUT "${opencv_BINARY_DIR}/bin/Debug/opencv_world${OpenCV_DLLVERSION}${OpenCV_DEBUG_POSTFIX}.dll" 106 | COMMAND "${CMAKE_COMMAND}" --build . --config debug --target install 107 | WORKING_DIRECTORY "${opencv_BINARY_DIR}" 108 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt" 109 | COMMENT "Compile OpenCV debug" 110 | ) 111 | add_custom_target(compile_opencv_debug ALL DEPENDS 112 | "${opencv_BINARY_DIR}/bin/Debug/opencv_world${OpenCV_DLLVERSION}${OpenCV_DEBUG_POSTFIX}.dll" 113 | configure_opencv 114 | ) 115 | 116 | add_custom_command( 117 | OUTPUT "${opencv_BINARY_DIR}/bin/Release/opencv_world${OpenCV_DLLVERSION}.dll" 118 | COMMAND "${CMAKE_COMMAND}" --build . --config release --target install 119 | WORKING_DIRECTORY "${opencv_BINARY_DIR}" 120 | DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt" 121 | COMMENT "Compile OpenCV release" 122 | ) 123 | add_custom_target(compile_opencv_release ALL DEPENDS 124 | "${opencv_BINARY_DIR}/bin/Release/opencv_world${OpenCV_DLLVERSION}.dll" 125 | compile_opencv_debug 126 | ) 127 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-autoit-opencv-com", 3 | "version": "2.6.2", 4 | "private": true, 5 | "scripts": { 6 | "build": "node scripts/build.js", 7 | "version": "node scripts/version.js", 8 | "test": "node scripts/test.js" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "async": "^3.2.0", 15 | "doctoc": "^2.1.0", 16 | "eol": "^0.9.1", 17 | "fs-explorer": "^1.4.2", 18 | "mkdirp": "^1.0.4", 19 | "node-autoit-binding-utils": "git+ssh://git@github.com:smbape/node-autoit-binding-utils.git", 20 | "semver": "^7.3.8", 21 | "uuid": "^8.3.2" 22 | }, 23 | "description": "" 24 | } 25 | -------------------------------------------------------------------------------- /project.sublime-project: -------------------------------------------------------------------------------- 1 | { 2 | "folders": 3 | [ 4 | { 5 | "path": ".", 6 | "binary_file_patterns": [ 7 | "*.jpg", 8 | "*.jpeg", 9 | "*.png", 10 | "*.gif", 11 | "*.gz", 12 | "*.ttf", 13 | "*.tga", 14 | "*.dds", 15 | "*.ico", 16 | "*.eot", 17 | "*.pdf", 18 | "*.swf", 19 | "*.jar", 20 | "*.zip", 21 | "node_modules/**" 22 | ] 23 | } 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /samples/01-show-image.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include "..\autoit-opencv-com\udf\opencv_udf_utils.au3" 9 | 10 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 11 | OnAutoItExitRegister("_OnAutoItExit") 12 | Example() 13 | 14 | Func Example() 15 | Local $cv = _OpenCV_get() 16 | If Not IsObj($cv) Then Return 17 | 18 | Local $img = _OpenCV_imread_and_check($cv.samples.findFile("lena.jpg")) 19 | $cv.imshow("Image", $img) 20 | $cv.waitKey() 21 | $cv.destroyAllWindows() 22 | EndFunc ;==>Example 23 | 24 | Func _OnAutoItExit() 25 | _OpenCV_Close() 26 | EndFunc ;==>_OnAutoItExit 27 | -------------------------------------------------------------------------------- /samples/02-show-image-gui.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include "..\autoit-opencv-com\udf\opencv_udf_utils.au3" 9 | #include 10 | 11 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 12 | OnAutoItExitRegister("_OnAutoItExit") 13 | Example() 14 | 15 | Func Example() 16 | Local $cv = _OpenCV_get() 17 | If Not IsObj($cv) Then Return 18 | 19 | #Region ### START Koda GUI section ### Form= 20 | Local $FormGUI = GUICreate("show image in autoit gui", 400, 400, 200, 200) 21 | Local $Pic = GUICtrlCreatePic("", 0, 0, 400, 400) 22 | GUISetState(@SW_SHOW) 23 | #EndRegion ### END Koda GUI section ### 24 | 25 | Local $img = _OpenCV_imread_and_check($cv.samples.findFile("lena.jpg")) 26 | 27 | _OpenCV_imshow_ControlPic($img, $FormGUI, $Pic) 28 | 29 | Local $nMsg 30 | While 1 31 | $nMsg = GUIGetMsg() 32 | Switch $nMsg 33 | Case $GUI_EVENT_CLOSE 34 | ExitLoop 35 | EndSwitch 36 | WEnd 37 | 38 | $cv.destroyAllWindows() 39 | EndFunc ;==>Example 40 | 41 | Func _OnAutoItExit() 42 | _OpenCV_Close() 43 | EndFunc ;==>_OnAutoItExit 44 | -------------------------------------------------------------------------------- /samples/02.1-show-image-gui-autosize.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include "..\autoit-opencv-com\udf\opencv_udf_utils.au3" 9 | #include 10 | 11 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 12 | OnAutoItExitRegister("_OnAutoItExit") 13 | Example() 14 | 15 | Func Example() 16 | Local $cv = _OpenCV_get() 17 | If Not IsObj($cv) Then Return 18 | 19 | #Region ### START Koda GUI section ### Form= 20 | Local $FormGUI = GUICreate("show image in autoit gui [WINDOW_AUTOSIZE]", 400, 400, 200, 200) 21 | Local $Pic = GUICtrlCreatePic("", 0, 0, 400, 400) 22 | GUISetState(@SW_SHOW) 23 | #EndRegion ### END Koda GUI section ### 24 | 25 | Local $img = _OpenCV_imread_and_check($cv.samples.findFile("lena.jpg")) 26 | 27 | ; get the image size and resize the GUI and the PIC control 28 | WinMove($FormGUI, "", Default, Default, $img.width, $img.height) 29 | GUICtrlSetPos($Pic, Default, Default, $img.width, $img.height) 30 | 31 | _OpenCV_imshow_ControlPic($img, $FormGUI, $Pic) 32 | 33 | Local $nMsg 34 | While 1 35 | $nMsg = GUIGetMsg() 36 | Switch $nMsg 37 | Case $GUI_EVENT_CLOSE 38 | ExitLoop 39 | EndSwitch 40 | WEnd 41 | 42 | $cv.destroyAllWindows() 43 | EndFunc ;==>Example 44 | 45 | Func _OnAutoItExit() 46 | _OpenCV_Close() 47 | EndFunc ;==>_OnAutoItExit 48 | -------------------------------------------------------------------------------- /samples/03-show-screen-image.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include "..\autoit-opencv-com\udf\opencv_udf_utils.au3" 9 | 10 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 11 | OnAutoItExitRegister("_OnAutoItExit") 12 | Example() 13 | 14 | Func Example() 15 | Local $cv = _OpenCV_get() 16 | If Not IsObj($cv) Then Return 17 | 18 | Local $iLeft = 200 19 | Local $iTop = 200 20 | Local $iWidth = 400 21 | Local $iHeight = 400 22 | 23 | Local $aRect[4] = [$iLeft, $iTop, $iWidth, $iHeight] 24 | Local $img = _OpenCV_GetDesktopScreenMat($aRect) 25 | 26 | $cv.imshow("Screen capture", $img) 27 | $cv.waitKey() 28 | $cv.destroyAllWindows() 29 | EndFunc ;==>Example 30 | 31 | Func _OnAutoItExit() 32 | _OpenCV_Close() 33 | EndFunc ;==>_OnAutoItExit 34 | -------------------------------------------------------------------------------- /samples/04-find-template.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include "..\autoit-opencv-com\udf\opencv_udf_utils.au3" 9 | 10 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 11 | OnAutoItExitRegister("_OnAutoItExit") 12 | Example() 13 | 14 | Func Example() 15 | Local $cv = _OpenCV_get() 16 | If Not IsObj($cv) Then Return 17 | 18 | Local $img = _OpenCV_imread_and_check($cv.samples.findFile("mario.png")) 19 | Local $tmpl = _OpenCV_imread_and_check($cv.samples.findFile("mario_coin.png")) 20 | 21 | ; The higher the value, the higher the match is exact 22 | Local $threshold = 0.8 23 | 24 | Local $aMatches = _OpenCV_FindTemplate($img, $tmpl, $threshold) 25 | 26 | Local $aRedColor = _OpenCV_RGB(255, 0, 0) 27 | Local $aMatchRect[4] = [0, 0, $tmpl.width, $tmpl.height] 28 | 29 | For $i = 0 To UBound($aMatches) - 1 30 | $aMatchRect[0] = $aMatches[$i][0] 31 | $aMatchRect[1] = $aMatches[$i][1] 32 | 33 | ; Draw a red rectangle around the matched position 34 | $cv.rectangle($img, $aMatchRect, $aRedColor) 35 | Next 36 | 37 | $cv.imshow("Find template example", $img) 38 | $cv.waitKey() 39 | 40 | $cv.destroyAllWindows() 41 | EndFunc ;==>Example 42 | 43 | Func _OnAutoItExit() 44 | _OpenCV_Close() 45 | EndFunc ;==>_OnAutoItExit 46 | -------------------------------------------------------------------------------- /samples/05.1-video-capture-camera.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include "..\autoit-opencv-com\udf\opencv_udf_utils.au3" 9 | #include 10 | 11 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 12 | OnAutoItExitRegister("_OnAutoItExit") 13 | Example() 14 | 15 | Func Example() 16 | Local $cv = _OpenCV_get() 17 | If Not IsObj($cv) Then Return 18 | 19 | Local $devices = _OpenCV_GetDevices() 20 | For $device In $devices 21 | ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : Video Device = ' & $device & @CRLF) ;### Debug Console 22 | Next 23 | 24 | Local $iCamId = 0 25 | Local $cap = $cv.VideoCapture($iCamId) 26 | If Not $cap.isOpened() Then 27 | ConsoleWriteError("!>Error: cannot open the camera." & @CRLF) 28 | Exit 29 | EndIf 30 | 31 | Local Const $CAP_FPS = 60 32 | Local Const $CAP_SPF = 1000 / $CAP_FPS 33 | 34 | $cap.set($CV_CAP_PROP_FRAME_WIDTH, 1280) 35 | $cap.set($CV_CAP_PROP_FRAME_HEIGHT, 720) 36 | $cap.set($CV_CAP_PROP_FPS, $CAP_FPS) 37 | 38 | Local $frame = $cv.Mat.zeros(1280, 720, $CV_8UC3) 39 | Local $start, $fps 40 | 41 | While 1 42 | If _IsPressed("1B") Or _IsPressed(Hex(Asc("Q"))) Then 43 | ExitLoop 44 | EndIf 45 | 46 | $start = $cv.getTickCount() 47 | If $cap.read($frame) Then 48 | ;; Flip the image horizontally to give the mirror impression 49 | $frame = $cv.flip($frame, 1) 50 | Else 51 | ConsoleWriteError("!>Error: cannot read the camera." & @CRLF) 52 | EndIf 53 | $fps = $cv.getTickFrequency() / ($cv.getTickCount() - $start) 54 | 55 | $cv.putText($frame, "FPS : " & Round($fps), _OpenCV_Point(10, 30), $CV_FONT_HERSHEY_PLAIN, 2, _OpenCV_Scalar(255, 0, 255), 3) 56 | $cv.imshow("capture camera", $frame) 57 | 58 | Sleep($CAP_SPF) 59 | WEnd 60 | 61 | $cv.destroyAllWindows() 62 | EndFunc ;==>Example 63 | 64 | Func _OnAutoItExit() 65 | _OpenCV_Close() 66 | EndFunc ;==>_OnAutoItExit 67 | -------------------------------------------------------------------------------- /samples/05.2-video-capture-file.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include "..\autoit-opencv-com\udf\opencv_udf_utils.au3" 9 | #include 10 | 11 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 12 | OnAutoItExitRegister("_OnAutoItExit") 13 | Example() 14 | 15 | Func Example() 16 | Local $cv = _OpenCV_get() 17 | If Not IsObj($cv) Then Return 18 | 19 | Local $cap = $cv.VideoCapture($cv.samples.findFile("vtest.avi")) 20 | If Not $cap.isOpened() Then 21 | ConsoleWriteError("!>Error: cannot open the video file." & @CRLF) 22 | Exit 23 | EndIf 24 | 25 | Local $frame = $cv.Mat.create() 26 | 27 | While 1 28 | If _IsPressed("1B") Or _IsPressed(Hex(Asc("Q"))) Then 29 | ExitLoop 30 | EndIf 31 | 32 | If Not $cap.read($frame) Then 33 | ConsoleWriteError("!>Error: cannot read the video or end of the video." & @CRLF) 34 | ExitLoop 35 | EndIf 36 | 37 | $cv.imshow("capture video file", $frame) 38 | 39 | Sleep(30) 40 | WEnd 41 | 42 | $cv.destroyAllWindows() 43 | EndFunc ;==>Example 44 | 45 | Func _OnAutoItExit() 46 | _OpenCV_Close() 47 | EndFunc ;==>_OnAutoItExit 48 | -------------------------------------------------------------------------------- /samples/06.1-rotate-image.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include "..\autoit-opencv-com\udf\opencv_udf_utils.au3" 9 | 10 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 11 | OnAutoItExitRegister("_OnAutoItExit") 12 | Example() 13 | 14 | Func Example() 15 | Local $cv = _OpenCV_get() 16 | If Not IsObj($cv) Then Return 17 | 18 | Local $img = _OpenCV_imread_and_check($cv.samples.findFile("lena.jpg")) 19 | Local $angle = 20 20 | Local $scale = 1 21 | 22 | Local $size[2] = [$img.width, $img.height] 23 | Local $center[2] = [$img.width / 2, $img.height / 2] 24 | Local $M = $cv.getRotationMatrix2D($center, -$angle, $scale) 25 | Local $rotated = $cv.warpAffine($img, $M, $size) 26 | 27 | $cv.imshow("Rotation", $rotated) 28 | $cv.waitKey() 29 | $cv.destroyAllWindows() 30 | EndFunc ;==>Example 31 | 32 | Func _OnAutoItExit() 33 | _OpenCV_Close() 34 | EndFunc ;==>_OnAutoItExit 35 | -------------------------------------------------------------------------------- /samples/06.2-rotate-image-bound.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include "..\autoit-opencv-com\udf\opencv_udf_utils.au3" 9 | 10 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 11 | OnAutoItExitRegister("_OnAutoItExit") 12 | Example() 13 | 14 | Func Example() 15 | Local $cv = _OpenCV_get() 16 | If Not IsObj($cv) Then Return 17 | 18 | Local $img = _OpenCV_imread_and_check($cv.samples.findFile("lena.jpg")) 19 | Local $angle = 20 20 | Local $scale = 0.8 21 | 22 | Local $rotated = _OpenCV_RotateBound($img, $angle, $scale) 23 | $cv.imshow("Bound Rotation", $rotated) 24 | $cv.waitKey() 25 | $cv.destroyAllWindows() 26 | EndFunc ;==>Example 27 | 28 | Func _OnAutoItExit() 29 | _OpenCV_Close() 30 | EndFunc ;==>_OnAutoItExit 31 | -------------------------------------------------------------------------------- /samples/07-resize-with-gdi-plus.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include "..\autoit-opencv-com\udf\opencv_udf_utils.au3" 9 | 10 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 11 | _GDIPlus_Startup() 12 | OnAutoItExitRegister("_OnAutoItExit") 13 | Example() 14 | 15 | Func Example() 16 | Local $cv = _OpenCV_get() 17 | If Not IsObj($cv) Then Return 18 | Local $bMethod = 1 19 | 20 | Local $img = _OpenCV_imread_and_check(_OpenCV_FindFile("samples\tutorial_code\yolo\scooter-5180947_1920.jpg")) 21 | 22 | Local $resized 23 | 24 | If $bMethod Then 25 | $resized = $img.GdiplusResize(600, 400) 26 | Else 27 | Local $hImage = $img.convertToBitmap() 28 | 29 | Local $hResizedImage = _GDIPlus_ImageResize($hImage, 600, 400) 30 | _GDIPlus_BitmapDispose($hImage) 31 | 32 | $resized = $cv.createMatFromBitmap($hResizedImage) 33 | _GDIPlus_BitmapDispose($hResizedImage) 34 | EndIf 35 | 36 | $cv.imshow("Resized with GDI+", $resized) 37 | $cv.waitKey() 38 | $cv.destroyAllWindows() 39 | EndFunc ;==>Example 40 | 41 | Func _OnAutoItExit() 42 | _GDIPlus_Shutdown() 43 | _OpenCV_Close() 44 | EndFunc ;==>_OnAutoItExit 45 | -------------------------------------------------------------------------------- /samples/08-drawing-contours.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include "..\autoit-opencv-com\udf\opencv_udf_utils.au3" 9 | 10 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 11 | OnAutoItExitRegister("_OnAutoItExit") 12 | Example() 13 | 14 | Func Example() 15 | Local $cv = _OpenCV_get() 16 | If Not IsObj($cv) Then Return 17 | 18 | Local $img = _OpenCV_imread_and_check($cv.samples.findFile("pic1.png")) 19 | Local $img_grey = $cv.cvtColor($img, $CV_COLOR_BGR2GRAY) 20 | $cv.threshold($img_grey, 100, 255, $CV_THRESH_BINARY) 21 | Local $thresh = $cv.extended[1] 22 | Local $contours = $cv.findContours($thresh, $CV_RETR_TREE, $CV_CHAIN_APPROX_SIMPLE) 23 | 24 | ConsoleWrite("Found " & UBound($contours) & " contours" & @CRLF & @CRLF) 25 | 26 | $cv.drawContours($img, $contours, -1, _OpenCV_Scalar(0, 0, 255), 2) 27 | 28 | $cv.imshow("Image", $img) 29 | $cv.waitKey() 30 | $cv.destroyAllWindows() 31 | EndFunc ;==>Example 32 | 33 | Func _OnAutoItExit() 34 | _OpenCV_Close() 35 | EndFunc ;==>_OnAutoItExit 36 | -------------------------------------------------------------------------------- /samples/09-find-image-on-screen.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include 9 | #include "..\autoit-opencv-com\udf\opencv_udf_utils.au3" 10 | 11 | Global $tmpl, $tSize, $tSource, $tBlend, $hWnd, $hPen, $hGui, $hDC, $hBitmap, $hGraphic, $hBMPBuff, $hGraphicGUI, $user32_dll 12 | Global $aRect, $iLeft, $iTop, $iWidth, $iHeight 13 | Global $cv 14 | 15 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 16 | _GDIPlus_Startup() 17 | OnAutoItExitRegister("_OnAutoItExit") 18 | Example() 19 | 20 | Func Example() 21 | $cv = _OpenCV_get() 22 | If Not IsObj($cv) Then Return 23 | 24 | _Initialize() 25 | 26 | Search() 27 | 28 | ; Local $aStartPos, $aEndPos 29 | 30 | Do 31 | Select 32 | Case _IsPressed("01", $user32_dll) ; Ctrl mouse button to move 33 | ClearRect() 34 | ; $aStartPos = MouseGetPos() 35 | Do 36 | Sleep(10) 37 | Until Not _IsPressed("01", $user32_dll) 38 | ; $aEndPos = MouseGetPos() 39 | 40 | ;_GDIPlus_GraphicsDrawLine($hGraphic, $aEndPos[0], $aEndPos[1], $aStartPos[0], $aStartPos[1], $hPen) 41 | Search() 42 | Case _IsPressed("04", $user32_dll) Or _IsPressed("11", $user32_dll) ; Middle mouse button 0r Ctrl key <======= Clear screen of rectangles. 43 | ClearRect() 44 | EndSelect 45 | Sleep(50) 46 | Until _IsPressed("1B", $user32_dll) ; ESC key 47 | 48 | _Release() 49 | EndFunc ;==>Example 50 | 51 | Func Search() 52 | Local $hTopTimer, $hTimer, $img 53 | 54 | $hTopTimer = TimerInit() 55 | 56 | ConsoleWrite("Rect: [" & $iWidth & " x " & $iHeight & " from (" & $iLeft & ", " & $iTop & ")]" & @CRLF) 57 | 58 | ; The higher the value, the higher the match is exact 59 | Local $threshold = 0.8 60 | 61 | $hTimer = TimerInit() 62 | $img = _OpenCV_GetDesktopScreenMat($aRect) 63 | ConsoleWrite("Capturing screen took " & TimerDiff($hTimer) & "ms" & @CRLF) 64 | 65 | ; Ignore the alpha channel when matching the template => $CV_COLOR_BGRA2BGR 66 | ; Only consider gray scale colors when matching the template => $CV_COLOR_BGRA2GRAY 67 | ; using cveCanny and/or gray scale can significantly reduce the matching time but also reduce the matching accuracy 68 | $hTimer = TimerInit() 69 | Local $aMatches = _OpenCV_FindTemplate($img, $tmpl, $threshold, Default, Default, Default, $CV_COLOR_BGRA2GRAY) 70 | ConsoleWrite("Finding matches took " & TimerDiff($hTimer) & "ms" & @CRLF) 71 | 72 | Local $iMatches = UBound($aMatches) 73 | ConsoleWrite("Number of matches: " & $iMatches & @CRLF) 74 | 75 | ; Local $aRedColor = _OpenCV_RGB(255, 0, 0) 76 | Local $aMatchRect = _OpenCV_Rect(0, 0, $tmpl.width, $tmpl.height) 77 | 78 | ; WinMove($hGui, "", $iLeft, $iTop, $iWidth, $iHeight) 79 | 80 | GUISetState(@SW_LOCK, $hGui) 81 | For $i = 0 To $iMatches - 1 82 | $aMatchRect[0] = $aMatches[$i][0] 83 | $aMatchRect[1] = $aMatches[$i][1] 84 | 85 | ; Draw a red rectangle around the matched position 86 | ; $cv.rectangle($img, $aMatchRect, $aRedColor, 1) 87 | _GDIPlus_GraphicsDrawRect($hGraphic, $aMatchRect[0], $aMatchRect[1], $aMatchRect[2], $aMatchRect[3], $hPen) 88 | Next 89 | 90 | $tSize.X = $iWidth 91 | $tSize.Y = $iHeight 92 | _WinAPI_UpdateLayeredWindow($hGui, $hWnd, 0, $tSize, $hDC, $tSource, 0, $tBlend, $ULW_ALPHA) 93 | GUISetState(@SW_UNLOCK, $hGui) 94 | 95 | ConsoleWrite("Search took " & TimerDiff($hTopTimer) & "ms" & @CRLF) 96 | ConsoleWrite(@CRLF) 97 | EndFunc ;==>Search 98 | 99 | Func ClearRect() 100 | _GDIPlus_GraphicsClear($hGraphic) 101 | _WinAPI_UpdateLayeredWindow($hGui, $hWnd, 0, $tSize, $hDC, $tSource, 0, $tBlend, $ULW_ALPHA) 102 | EndFunc ;==>ClearRect 103 | 104 | Func _Initialize() 105 | $cv.imshow("Image", $cv.imread(_OpenCV_FindFile("samples\data\mario.png"))) 106 | $tmpl = $cv.imread(_OpenCV_FindFile("samples\data\mario_coin.png")) 107 | 108 | ; Search on the first screen. Leave empty to search on all screens 109 | ; Reducing the search area improves the search time 110 | $aRect = _OpenCV_GetDesktopScreenRect(1) 111 | $iLeft = $aRect[0] 112 | $iTop = $aRect[1] 113 | $iWidth = $aRect[2] 114 | $iHeight = $aRect[3] 115 | 116 | #Region GUI 117 | $hGui = GUICreate("L1", $iWidth, $iHeight, $iLeft, $iTop, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) 118 | GUISetState(@SW_SHOW, $hGui) 119 | 120 | $tSize = DllStructCreate($tagSIZE) 121 | $tSource = DllStructCreate($tagPOINT) 122 | 123 | $tBlend = DllStructCreate($tagBLENDFUNCTION) 124 | $tBlend.Alpha = 255 125 | $tBlend.Format = 1 126 | 127 | $hWnd = _WinAPI_GetWindowDC(_WinAPI_GetDesktopWindow()) ; DC of entire screen (desktop) 128 | $hPen = _GDIPlus_PenCreate(0xFFFF0000, 1) 129 | #EndRegion GUI 130 | 131 | $hDC = _WinAPI_CreateCompatibleDC($hWnd) 132 | $hBitmap = _WinAPI_CreateCompatibleBitmap($hWnd, $iWidth, $iHeight) 133 | _WinAPI_SelectObject($hDC, $hBitmap) 134 | $hGraphic = _GDIPlus_GraphicsCreateFromHDC($hDC) 135 | $hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphic) 136 | $hGraphicGUI = _GDIPlus_ImageGetGraphicsContext($hBMPBuff) 137 | 138 | _GDIPlus_GraphicsClear($hGraphic) ; Add ,0x01000000) to disable underling desktop 139 | 140 | $user32_dll = DllOpen("user32.dll") 141 | EndFunc ;==>_Initialize 142 | 143 | Func _Release() 144 | _GDIPlus_GraphicsDispose($hGraphicGUI) 145 | _GDIPlus_BitmapDispose($hBMPBuff) 146 | _GDIPlus_GraphicsDispose($hGraphic) 147 | _WinAPI_DeleteObject($hBitmap) 148 | _WinAPI_DeleteDC($hDC) 149 | _GDIPlus_PenDispose($hPen) 150 | GUIDelete($hGui) 151 | $cv.destroyAllWindows() 152 | DllClose($user32_dll) 153 | EndFunc ;==>_Release 154 | 155 | Func _OnAutoItExit() 156 | _GDIPlus_Shutdown() 157 | _OpenCV_Close() 158 | EndFunc ;==>_OnAutoItExit 159 | -------------------------------------------------------------------------------- /samples/10-PixelSearch-PixelChecksum.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include 9 | #include "..\autoit-opencv-com\udf\opencv_udf_utils.au3" 10 | 11 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 12 | OnAutoItExitRegister("_OnAutoItExit") 13 | Example() 14 | 15 | Func Example() 16 | Local $cv = _OpenCV_get() 17 | If Not IsObj($cv) Then Return 18 | 19 | Local $hTimer, $img, $aPos, $iChecksum 20 | 21 | ; Search on the first screen. Leave empty to search on all screens 22 | ; Reducing the search area improves the search time 23 | Local $aRect = _OpenCV_GetDesktopScreenRect(1) 24 | 25 | Local $iLeft = $aRect[0] 26 | Local $iTop = $aRect[1] 27 | Local $iWidth = $aRect[2] 28 | Local $iHeight = $aRect[3] 29 | Local $iColor = PixelGetColor($iLeft + $iWidth - 1, $iTop + $iHeight - 1) 30 | 31 | ConsoleWrite("Rect: [" & $iWidth & " x " & $iHeight & " from (" & $iLeft & ", " & $iTop & ")]" & @CRLF) 32 | ConsoleWrite("Color: 0x" & Hex($iColor, 6) & @CRLF) 33 | 34 | $hTimer = TimerInit() 35 | $img = _OpenCV_GetDesktopScreenMat($aRect) 36 | ConsoleWrite("Capturing screen took " & TimerDiff($hTimer) & "ms" & @CRLF) 37 | 38 | $hTimer = TimerInit() 39 | $aPos = PixelSearch($iLeft, $iTop, $iLeft + $iWidth - 1, $iTop + $iHeight - 1, $iColor) 40 | ConsoleWrite("PixelSearch took " & TimerDiff($hTimer) & "ms" & @CRLF) 41 | If IsArray($aPos) Then ConsoleWrite(' @@ Debug(' & @ScriptLineNumber & ') : $aPos = [' & $aPos[0] & ', ' & $aPos[1] & ']' & @CRLF) ;### Debug Console 42 | 43 | $hTimer = TimerInit() 44 | $aPos = $img.PixelSearch(_ColorGetCOLORREF($iColor)) 45 | ConsoleWrite("cv.Mat.PixelSearch took " & TimerDiff($hTimer) & "ms" & @CRLF) 46 | If IsArray($aPos) Then ConsoleWrite(' @@ Debug(' & @ScriptLineNumber & ') : $aPos = [' & ($iLeft + $aPos[0]) & ', ' & ($iTop + $aPos[1]) & ']' & @CRLF) ;### Debug Console 47 | 48 | $hTimer = TimerInit() 49 | $iChecksum = PixelChecksum($iLeft, $iTop, $iLeft + $iWidth - 1, $iTop + $iHeight - 1) 50 | ConsoleWrite("PixelChecksum ADLER32 " & TimerDiff($hTimer) & "ms" & @CRLF) 51 | ConsoleWrite(' @@ Debug(' & @ScriptLineNumber & ') : $iChecksum = 0x' & Hex(Ptr($iChecksum), 8) & @CRLF) ;### Debug Console 52 | 53 | $hTimer = TimerInit() 54 | $iChecksum = $img.PixelChecksum() 55 | ConsoleWrite("cv.Mat.PixelChecksum ADLER32 " & TimerDiff($hTimer) & "ms" & @CRLF) 56 | ConsoleWrite(' @@ Debug(' & @ScriptLineNumber & ') : $iChecksum = 0x' & Hex(Ptr($iChecksum), 8) & @CRLF) ;### Debug Console 57 | 58 | $hTimer = TimerInit() 59 | $iChecksum = PixelChecksum($iLeft, $iTop, $iLeft + $iWidth - 1, $iTop + $iHeight - 1, Default, Default, 1) 60 | ConsoleWrite("PixelChecksum CRC32 " & TimerDiff($hTimer) & "ms" & @CRLF) 61 | ConsoleWrite(' @@ Debug(' & @ScriptLineNumber & ') : $iChecksum = 0x' & Hex(Ptr($iChecksum), 8) & @CRLF) ;### Debug Console 62 | 63 | $hTimer = TimerInit() 64 | $iChecksum = $img.PixelChecksum(Default, Default, Default, Default, Default, 1) 65 | ConsoleWrite("cv.Mat.PixelChecksum CRC32 " & TimerDiff($hTimer) & "ms" & @CRLF) 66 | ConsoleWrite(' @@ Debug(' & @ScriptLineNumber & ') : $iChecksum = 0x' & Hex(Ptr($iChecksum), 8) & @CRLF) ;### Debug Console 67 | EndFunc ;==>Example 68 | 69 | Func _OnAutoItExit() 70 | _OpenCV_Close() 71 | EndFunc ;==>_OnAutoItExit 72 | -------------------------------------------------------------------------------- /samples/data/Histogram_Comparison_Source_0.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/data/Histogram_Comparison_Source_0.jpg -------------------------------------------------------------------------------- /samples/data/Histogram_Comparison_Source_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/data/Histogram_Comparison_Source_1.jpg -------------------------------------------------------------------------------- /samples/data/Histogram_Comparison_Source_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/data/Histogram_Comparison_Source_2.jpg -------------------------------------------------------------------------------- /samples/data/j.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/data/j.png -------------------------------------------------------------------------------- /samples/data/mario.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/data/mario.png -------------------------------------------------------------------------------- /samples/data/mario_coin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/data/mario_coin.png -------------------------------------------------------------------------------- /samples/dnn/object_detection/download_model.ps1: -------------------------------------------------------------------------------- 1 | #requires -version 5.0 2 | 3 | [CmdletBinding()] 4 | param ( 5 | [Parameter(Position=0, Mandatory)][string] $Model, 6 | [Parameter(Position=1)][string] $Destination = "", 7 | [string] $Zoo = "", 8 | [string] $Python = "python", 9 | [boolean] $Force = $False 10 | ) 11 | # "powershell.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 12 | # "pwsh.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 13 | 14 | $ErrorActionPreference = "Stop" 15 | Set-StrictMode -Version 3.0 16 | trap { throw $Error[0] } 17 | 18 | Import-Module "$PSScriptRoot/../../dotnet/opencv_utils.psm1" 19 | 20 | if ([string]::IsNullOrEmpty($Destination)) { 21 | $Destination = Join-Path $PSScriptRoot "models" 22 | } 23 | 24 | if ([string]::IsNullOrEmpty($Zoo)) { 25 | $Zoo = Join-Path $PSScriptRoot "models.yml" 26 | } 27 | 28 | $DNN_ROOT_PATH = _OpenCV_FindFile -Path "samples/dnn" -SearchPaths @( 29 | "opencv\sources" 30 | "opencv-4.10.0-*\opencv\sources" 31 | ) 32 | 33 | $SAMPLES_PATH = _OpenCV_FindFile -Path "samples" 34 | $PYTHON_VENV_PATH = Join-Path $SAMPLES_PATH ".venv" 35 | 36 | if (!(Test-Path -Path $PYTHON_VENV_PATH)) { 37 | foreach($exe in (where.exe "$Python")) { 38 | $PythonCmd = Get-Command "$exe" 39 | break 40 | } 41 | 42 | Write-Host "$($PythonCmd.Source) -m venv $PYTHON_VENV_PATH" 43 | & $PythonCmd.Source -m venv "$PYTHON_VENV_PATH" 44 | attrib +h "$PYTHON_VENV_PATH" 45 | 46 | # Activate venv 47 | & "$PYTHON_VENV_PATH\Scripts\Activate.ps1" 48 | 49 | python -m pip install --upgrade pip 50 | python -m pip install --upgrade opencv-python PyYAML requests 51 | } else { 52 | # Activate venv 53 | & "$PYTHON_VENV_PATH\Scripts\Activate.ps1" 54 | } 55 | 56 | if (!(Test-Path -Path $Destination)) { 57 | mkdir $Destination 58 | } 59 | cd "$Destination" 60 | 61 | $Env:PYTHONPATH = "$DNN_ROOT_PATH" 62 | $script = Join-Path $PSScriptRoot download_model.py 63 | python $script $Model --zoo $Zoo 64 | -------------------------------------------------------------------------------- /samples/dotnet/01-show-image.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using OpenCV.InteropServices; 4 | 5 | public static class Test 6 | { 7 | private static void CompiletimeExample(string image) 8 | { 9 | ICv_Object cv = new Cv_Object(); 10 | 11 | var img = cv.imread(image); 12 | cv.imshow("image", img); 13 | cv.waitKey(); 14 | cv.destroyAllWindows(); 15 | } 16 | 17 | private static void RuntimeExample(string image) 18 | { 19 | var cv = OpenCvComInterop.ObjCreate("cv"); 20 | if (ReferenceEquals(cv, null)) 21 | { 22 | throw new Win32Exception("Failed to create cv object"); 23 | } 24 | 25 | var img = cv.imread(image); 26 | cv.imshow("image", img); 27 | cv.waitKey(); 28 | cv.destroyAllWindows(); 29 | } 30 | 31 | static void Main(string[] args) 32 | { 33 | string opencv_world_dll = null; 34 | string opencv_com_dll = null; 35 | var register = false; 36 | var unregister = false; 37 | string buildType = null; 38 | string image = OpenCvComInterop.FindFile("samples\\data\\lena.jpg", new string[] { "opencv-4.10.0-*\\opencv\\sources" }); 39 | 40 | for (int i = 0; i < args.Length; i += 1) 41 | { 42 | switch (args[i]) 43 | { 44 | 45 | case "--image": 46 | if (i + 1 == args.Length) 47 | { 48 | throw new ArgumentException("Unexpected argument " + args[i]); 49 | } 50 | image = args[i + 1]; 51 | i += 1; 52 | break; 53 | 54 | case "--opencv-world-dll": 55 | if (i + 1 == args.Length) 56 | { 57 | throw new ArgumentException("Unexpected argument " + args[i]); 58 | } 59 | opencv_world_dll = args[i + 1]; 60 | i += 1; 61 | break; 62 | 63 | case "--opencv-com-dll": 64 | if (i + 1 == args.Length) 65 | { 66 | throw new ArgumentException("Unexpected argument " + args[i]); 67 | } 68 | opencv_com_dll = args[i + 1]; 69 | i += 1; 70 | break; 71 | 72 | case "--build-type": 73 | if (i + 1 == args.Length) 74 | { 75 | throw new ArgumentException("Unexpected argument " + args[i]); 76 | } 77 | buildType = args[i + 1]; 78 | i += 1; 79 | break; 80 | 81 | case "--register": 82 | register = true; 83 | break; 84 | 85 | case "--unregister": 86 | unregister = true; 87 | break; 88 | 89 | default: 90 | throw new ArgumentException("Unexpected argument " + args[i]); 91 | } 92 | } 93 | 94 | OpenCvComInterop.DllOpen( 95 | string.IsNullOrWhiteSpace(opencv_world_dll) ? OpenCvComInterop.FindDLL("opencv_world4100*", null, null, buildType) : opencv_world_dll, 96 | string.IsNullOrWhiteSpace(opencv_com_dll) ? OpenCvComInterop.FindDLL("autoit_opencv_com4100*", null, null, buildType) : opencv_com_dll 97 | ); 98 | 99 | if (register) { 100 | OpenCvComInterop.Register(); 101 | } 102 | 103 | OpenCvComInterop.DllActivateManifest(); 104 | try { 105 | CompiletimeExample(image); 106 | } 107 | finally 108 | { 109 | OpenCvComInterop.DllDeactivateActCtx(); 110 | } 111 | 112 | try 113 | {; 114 | RuntimeExample(image); 115 | } 116 | finally 117 | { 118 | if (unregister) { 119 | OpenCvComInterop.Unregister(); 120 | } 121 | OpenCvComInterop.DllClose(); 122 | } 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /samples/dotnet/01-show-image.ps1: -------------------------------------------------------------------------------- 1 | #requires -version 5.0 2 | 3 | [CmdletBinding()] 4 | param ( 5 | [Parameter(Position=0)][string] $Image = $null, 6 | [string] $BuildType = $Env:BUILD_TYPE, 7 | [string] $OpenCVWorldDll = $null, 8 | [string] $OpenCVComDll = $null, 9 | [switch] $Register, 10 | [switch] $Unregister 11 | ) 12 | # "powershell.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 13 | # "pwsh.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 14 | 15 | $ErrorActionPreference = "Stop" 16 | Set-StrictMode -Version 3.0 17 | trap { throw $Error[0] } 18 | 19 | Import-Module "$PSScriptRoot\opencv_utils.psm1" -ArgumentList $BuildType 20 | 21 | $BuildType = if ($BuildType -eq "Debug") { "Debug" } else { "Release" } 22 | 23 | $OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL -Path "opencv_world4100*" -BuildType $BuildType } else { $OpenCVWorldDll } 24 | $OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL -Path "autoit_opencv_com4100*" -BuildType $BuildType } else { $OpenCVComDll } 25 | $Image = if ([string]::IsNullOrEmpty($Image)) { _OpenCV_FindFile -Path "samples\data\lena.jpg" -SearchPaths @("opencv-4.10.0-*\opencv\sources") } else { $Image } 26 | 27 | function Example() { 28 | $cv = [OpenCvComInterop]::ObjCreate("cv") 29 | $img = $cv.imread($Image) 30 | $cv.imshow("Image", $img) 31 | $cv.waitKey() | Out-Null 32 | $cv.destroyAllWindows() 33 | } 34 | 35 | [OpenCvComInterop]::DllOpen($OpenCVWorldDll, $OpenCVComDll) 36 | 37 | if ($Register) { 38 | [OpenCvComInterop]::Register() 39 | } 40 | 41 | Example 42 | 43 | if ($Unregister) { 44 | [OpenCvComInterop]::Unregister() 45 | } 46 | 47 | [OpenCvComInterop]::DllClose() 48 | -------------------------------------------------------------------------------- /samples/dotnet/02-video-capture-camera.ps1: -------------------------------------------------------------------------------- 1 | #requires -version 5.0 2 | 3 | [CmdletBinding()] 4 | param ( 5 | [Parameter(Position=0)][int] $Camera = 0, 6 | [string] $BuildType = $Env:BUILD_TYPE, 7 | [string] $OpenCVWorldDll = $null, 8 | [string] $OpenCVComDll = $null, 9 | [switch] $Register, 10 | [switch] $Unregister 11 | ) 12 | # "powershell.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 13 | # "pwsh.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 14 | 15 | $ErrorActionPreference = "Stop" 16 | Set-StrictMode -Version 3.0 17 | trap { throw $Error[0] } 18 | 19 | Import-Module "$PSScriptRoot\opencv_utils.psm1" -ArgumentList $BuildType 20 | 21 | $BuildType = if ($BuildType -eq "Debug") { "Debug" } else { "Release" } 22 | 23 | $OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL -Path "opencv_world4100*" -BuildType $BuildType } else { $OpenCVWorldDll } 24 | $OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL -Path "autoit_opencv_com4100*" -BuildType $BuildType } else { $OpenCVComDll } 25 | 26 | function Example() { 27 | $cv = [OpenCvComInterop]::ObjCreate("cv") 28 | $cap = $cv.VideoCapture($Camera) 29 | if (!$cap.isOpened()) { 30 | Write-Error "!>Error: cannot open the camera $Camera." 31 | return 32 | } 33 | 34 | $CAP_FPS = 60 35 | $CAP_SPF = 1000 / $CAP_FPS 36 | 37 | $cap.set($cv.enums.CAP_PROP_FRAME_WIDTH, 1280) | Out-Null 38 | $cap.set($cv.enums.CAP_PROP_FRAME_HEIGHT, 720) | Out-Null 39 | $cap.set($cv.enums.CAP_PROP_FPS, $CAP_FPS) | Out-Null 40 | 41 | $frame = [OpenCvComInterop]::ObjCreate("cv.Mat") 42 | 43 | while ($true) { 44 | $start = $cv.getTickCount() 45 | if ($cap.read($frame)) { 46 | # Flip the image horizontally to give the mirror impression 47 | $oldframe = $frame 48 | $frame = $cv.flip($frame, 1) 49 | 50 | # Memory leak without this 51 | [System.Runtime.InteropServices.Marshal]::ReleaseComObject($oldframe) | Out-Null 52 | } else { 53 | Write-Error "!>Error: cannot read the camera $Camera." 54 | } 55 | $fps = $cv.getTickFrequency() / ($cv.getTickCount() - $start) 56 | 57 | $cv.putText($frame, "FPS : $([Math]::Round($fps))", @(10, 30), $cv.enums.FONT_HERSHEY_PLAIN, 2, @(255, 0, 255), 3) | Out-Null 58 | $cv.imshow("capture camera", $frame) 59 | 60 | $key = $cv.waitKey($CAP_SPF) 61 | if (($key -eq 27) -or ($key -eq [byte][char]'q') -or ($key -eq [byte][char]'Q')) { 62 | break 63 | } 64 | } 65 | 66 | # Mimic what is done in c# 67 | [System.Runtime.InteropServices.Marshal]::ReleaseComObject($frame) | Out-Null 68 | [System.Runtime.InteropServices.Marshal]::ReleaseComObject($cap) | Out-Null 69 | [System.Runtime.InteropServices.Marshal]::ReleaseComObject($cv) | Out-Null 70 | } 71 | 72 | [OpenCvComInterop]::DllOpen($OpenCVWorldDll, $OpenCVComDll) 73 | 74 | if ($Register) { 75 | [OpenCvComInterop]::Register() 76 | } 77 | 78 | Example 79 | 80 | if ($Unregister) { 81 | [OpenCvComInterop]::Unregister() 82 | } 83 | 84 | [OpenCvComInterop]::DllClose() 85 | -------------------------------------------------------------------------------- /samples/dotnet/03-video-capture-file.ps1: -------------------------------------------------------------------------------- 1 | #requires -version 5.0 2 | 3 | [CmdletBinding()] 4 | param ( 5 | [Parameter(Position=0)][string] $Video = $null, 6 | [string] $BuildType = $Env:BUILD_TYPE, 7 | [string] $OpenCVWorldDll = $null, 8 | [string] $OpenCVComDll = $null, 9 | [switch] $Register, 10 | [switch] $Unregister 11 | ) 12 | # "powershell.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 13 | # "pwsh.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 14 | 15 | $ErrorActionPreference = "Stop" 16 | Set-StrictMode -Version 3.0 17 | trap { throw $Error[0] } 18 | 19 | Import-Module "$PSScriptRoot\opencv_utils.psm1" -ArgumentList $BuildType 20 | 21 | $BuildType = if ($BuildType -eq "Debug") { "Debug" } else { "Release" } 22 | 23 | $OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL -Path "opencv_world4100*" -BuildType $BuildType } else { $OpenCVWorldDll } 24 | $OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL -Path "autoit_opencv_com4100*" -BuildType $BuildType } else { $OpenCVComDll } 25 | $Video = if ([string]::IsNullOrEmpty($Video)) { _OpenCV_FindFile -Path "samples\data\vtest.avi" -SearchPaths @("opencv-4.10.0-*\opencv\sources") } else { $Video } 26 | 27 | function Example() { 28 | $cv = [OpenCvComInterop]::ObjCreate("cv") 29 | $cap = $cv.VideoCapture($Video) 30 | if (!$cap.isOpened()) { 31 | Write-Error "!>Error: cannot open the video file $Video." 32 | return 33 | } 34 | 35 | $frame = [OpenCvComInterop]::ObjCreate("cv.Mat") 36 | 37 | while ($true) { 38 | if (-not $cap.read($frame)) { 39 | Write-Error "!>Error: cannot read the video or end of the video." 40 | break 41 | } 42 | 43 | $cv.imshow("capture video file", $frame) 44 | $key = $cv.waitKey(30) 45 | if (($key -eq 27) -or ($key -eq [byte][char]'q') -or ($key -eq [byte][char]'Q')) { 46 | break 47 | } 48 | } 49 | 50 | # Mimic what is done in c# 51 | [System.Runtime.InteropServices.Marshal]::ReleaseComObject($frame) | Out-Null 52 | [System.Runtime.InteropServices.Marshal]::ReleaseComObject($cap) | Out-Null 53 | [System.Runtime.InteropServices.Marshal]::ReleaseComObject($cv) | Out-Null 54 | } 55 | 56 | [OpenCvComInterop]::DllOpen($OpenCVWorldDll, $OpenCVComDll) 57 | 58 | if ($Register) { 59 | [OpenCvComInterop]::Register() 60 | } 61 | 62 | Example 63 | 64 | if ($Unregister) { 65 | [OpenCvComInterop]::Unregister() 66 | } 67 | 68 | [OpenCvComInterop]::DllClose() 69 | -------------------------------------------------------------------------------- /samples/dotnet/04-rotate-image.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Runtime.InteropServices; 4 | using OpenCV.InteropServices; 5 | 6 | public static class Test 7 | { 8 | private static void CompiletimeExample(string image) 9 | { 10 | ICv_Object cv = new Cv_Object(); 11 | var img = cv.imread(image); 12 | var angle = 20; 13 | var scale = 1; 14 | 15 | dynamic[] size = {img.width, img.height}; 16 | dynamic[] center = {img.width / 2, img.height / 2}; 17 | var M = cv.getRotationMatrix2D(center, -angle, scale); 18 | var rotated = cv.warpAffine(img, M, size); 19 | 20 | cv.imshow("Rotation", rotated); 21 | cv.waitKey(); 22 | cv.destroyAllWindows(); 23 | } 24 | 25 | private static void RuntimeExample(string image) 26 | { 27 | var cv = OpenCvComInterop.ObjCreate("cv"); 28 | var img = cv.imread(image); 29 | var angle = 20; 30 | var scale = 1; 31 | 32 | dynamic[] size = {img.width, img.height}; 33 | dynamic[] center = {img.width / 2, img.height / 2}; 34 | var M = cv.getRotationMatrix2D(center, -angle, scale); 35 | var rotated = cv.warpAffine(img, M, size); 36 | 37 | cv.imshow("Rotation", rotated); 38 | cv.waitKey(); 39 | cv.destroyAllWindows(); 40 | } 41 | 42 | static void Main(string[] args) 43 | { 44 | string opencv_world_dll = null; 45 | string opencv_com_dll = null; 46 | var register = false; 47 | var unregister = false; 48 | string buildType = null; 49 | string image = OpenCvComInterop.FindFile("samples\\data\\lena.jpg", new string[] { "opencv-4.10.0-*\\opencv\\sources" }); 50 | 51 | for (int i = 0; i < args.Length; i += 1) 52 | { 53 | switch (args[i]) 54 | { 55 | 56 | case "--image": 57 | if (i + 1 == args.Length) 58 | { 59 | throw new ArgumentException("Unexpected argument " + args[i]); 60 | } 61 | image = args[i + 1]; 62 | i += 1; 63 | break; 64 | 65 | case "--opencv-world-dll": 66 | if (i + 1 == args.Length) 67 | { 68 | throw new ArgumentException("Unexpected argument " + args[i]); 69 | } 70 | opencv_world_dll = args[i + 1]; 71 | i += 1; 72 | break; 73 | 74 | case "--opencv-com-dll": 75 | if (i + 1 == args.Length) 76 | { 77 | throw new ArgumentException("Unexpected argument " + args[i]); 78 | } 79 | opencv_com_dll = args[i + 1]; 80 | i += 1; 81 | break; 82 | 83 | case "--build-type": 84 | if (i + 1 == args.Length) 85 | { 86 | throw new ArgumentException("Unexpected argument " + args[i]); 87 | } 88 | buildType = args[i + 1]; 89 | i += 1; 90 | break; 91 | 92 | case "--register": 93 | register = true; 94 | break; 95 | 96 | case "--unregister": 97 | unregister = true; 98 | break; 99 | 100 | default: 101 | throw new ArgumentException("Unexpected argument " + args[i]); 102 | } 103 | } 104 | 105 | OpenCvComInterop.DllOpen( 106 | string.IsNullOrWhiteSpace(opencv_world_dll) ? OpenCvComInterop.FindDLL("opencv_world4100*", null, null, buildType) : opencv_world_dll, 107 | string.IsNullOrWhiteSpace(opencv_com_dll) ? OpenCvComInterop.FindDLL("autoit_opencv_com4100*", null, null, buildType) : opencv_com_dll 108 | ); 109 | 110 | if (register) { 111 | OpenCvComInterop.Register(); 112 | } 113 | 114 | OpenCvComInterop.DllActivateManifest(); 115 | try { 116 | CompiletimeExample(image); 117 | } 118 | finally 119 | { 120 | OpenCvComInterop.DllDeactivateActCtx(); 121 | } 122 | 123 | try 124 | { 125 | RuntimeExample(image); 126 | } 127 | finally 128 | { 129 | if (unregister) { 130 | OpenCvComInterop.Unregister(); 131 | } 132 | OpenCvComInterop.DllClose(); 133 | } 134 | } 135 | 136 | } 137 | -------------------------------------------------------------------------------- /samples/dotnet/04-rotate-image.ps1: -------------------------------------------------------------------------------- 1 | #requires -version 5.0 2 | 3 | [CmdletBinding()] 4 | param ( 5 | [Parameter(Position=0)][string] $Image = $null, 6 | [string] $BuildType = $Env:BUILD_TYPE, 7 | [string] $OpenCVWorldDll = $null, 8 | [string] $OpenCVComDll = $null, 9 | [switch] $Register, 10 | [switch] $Unregister 11 | ) 12 | # "powershell.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 13 | # "pwsh.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 14 | 15 | $ErrorActionPreference = "Stop" 16 | Set-StrictMode -Version 3.0 17 | trap { throw $Error[0] } 18 | 19 | Import-Module "$PSScriptRoot\opencv_utils.psm1" -ArgumentList $BuildType 20 | 21 | $BuildType = if ($BuildType -eq "Debug") { "Debug" } else { "Release" } 22 | 23 | $OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL -Path "opencv_world4100*" -BuildType $BuildType } else { $OpenCVWorldDll } 24 | $OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL -Path "autoit_opencv_com4100*" -BuildType $BuildType } else { $OpenCVComDll } 25 | $Image = if ([string]::IsNullOrEmpty($Image)) { _OpenCV_FindFile -Path "samples\data\lena.jpg" -SearchPaths @("opencv-4.10.0-*\opencv\sources") } else { $Image } 26 | 27 | function Example() { 28 | $cv = [OpenCvComInterop]::ObjCreate("cv") 29 | $img = $cv.imread($Image) 30 | $angle = 20 31 | $scale = 1 32 | 33 | $size = @($img.width, $img.height) 34 | $center = @(($img.width / 2), ($img.height / 2)) 35 | $M = $cv.getRotationMatrix2D($center, -$angle, $scale) 36 | $rotated = $cv.warpAffine($img, $M, $size) 37 | 38 | $cv.imshow("Rotation", $rotated) 39 | $cv.waitKey() | Out-Null 40 | $cv.destroyAllWindows() 41 | } 42 | 43 | [OpenCvComInterop]::DllOpen($OpenCVWorldDll, $OpenCVComDll) 44 | 45 | if ($Register) { 46 | [OpenCvComInterop]::Register() 47 | } 48 | 49 | Example 50 | 51 | if ($Unregister) { 52 | [OpenCvComInterop]::Unregister() 53 | } 54 | 55 | [OpenCvComInterop]::DllClose() 56 | -------------------------------------------------------------------------------- /samples/dotnet/05-drawing-contours.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Runtime.InteropServices; 4 | using OpenCV.InteropServices; 5 | 6 | public static class Test 7 | { 8 | private static void CompiletimeExample(string image) 9 | { 10 | ICv_Object cv = new Cv_Object(); 11 | var img = cv.imread(image); 12 | var img_grey = cv.cvtColor(img, cv.enums.COLOR_BGR2GRAY); 13 | cv.threshold(img_grey, 100, 255, cv.enums.THRESH_BINARY); 14 | var thresh = cv.extended[1]; 15 | var contours = cv.findContours(thresh, cv.enums.RETR_TREE, cv.enums.CHAIN_APPROX_SIMPLE); 16 | 17 | Console.WriteLine($"Found ({contours.Length}) contours"); 18 | 19 | dynamic[] color = {0, 0, 255}; 20 | cv.drawContours(img, contours, -1, color, 2); 21 | cv.imshow("Image", img); 22 | cv.waitKey(); 23 | cv.destroyAllWindows(); 24 | } 25 | 26 | private static void RuntimeExample(string image) 27 | { 28 | var cv = OpenCvComInterop.ObjCreate("cv"); 29 | var img = cv.imread(image); 30 | var img_grey = cv.cvtColor(img, cv.enums.COLOR_BGR2GRAY); 31 | cv.threshold(img_grey, 100, 255, cv.enums.THRESH_BINARY); 32 | var thresh = cv.extended[1]; 33 | var contours = cv.findContours(thresh, cv.enums.RETR_TREE, cv.enums.CHAIN_APPROX_SIMPLE); 34 | 35 | Console.WriteLine($"Found ({contours.Length}) contours"); 36 | 37 | dynamic[] color = {0, 0, 255}; 38 | cv.drawContours(img, contours, -1, color, 2); 39 | cv.imshow("Image", img); 40 | cv.waitKey(); 41 | cv.destroyAllWindows(); 42 | } 43 | 44 | static void Main(string[] args) 45 | { 46 | string opencv_world_dll = null; 47 | string opencv_com_dll = null; 48 | var register = false; 49 | var unregister = false; 50 | string buildType = null; 51 | string image = OpenCvComInterop.FindFile("samples\\data\\pic1.png", new string[] { "opencv-4.10.0-*\\opencv\\sources" }); 52 | 53 | for (int i = 0; i < args.Length; i += 1) 54 | { 55 | switch (args[i]) 56 | { 57 | 58 | case "--image": 59 | if (i + 1 == args.Length) 60 | { 61 | throw new ArgumentException("Unexpected argument " + args[i]); 62 | } 63 | image = args[i + 1]; 64 | i += 1; 65 | break; 66 | 67 | case "--opencv-world-dll": 68 | if (i + 1 == args.Length) 69 | { 70 | throw new ArgumentException("Unexpected argument " + args[i]); 71 | } 72 | opencv_world_dll = args[i + 1]; 73 | i += 1; 74 | break; 75 | 76 | case "--opencv-com-dll": 77 | if (i + 1 == args.Length) 78 | { 79 | throw new ArgumentException("Unexpected argument " + args[i]); 80 | } 81 | opencv_com_dll = args[i + 1]; 82 | i += 1; 83 | break; 84 | 85 | case "--build-type": 86 | if (i + 1 == args.Length) 87 | { 88 | throw new ArgumentException("Unexpected argument " + args[i]); 89 | } 90 | buildType = args[i + 1]; 91 | i += 1; 92 | break; 93 | 94 | case "--register": 95 | register = true; 96 | break; 97 | 98 | case "--unregister": 99 | unregister = true; 100 | break; 101 | 102 | default: 103 | throw new ArgumentException("Unexpected argument " + args[i]); 104 | } 105 | } 106 | 107 | OpenCvComInterop.DllOpen( 108 | string.IsNullOrWhiteSpace(opencv_world_dll) ? OpenCvComInterop.FindDLL("opencv_world4100*", null, null, buildType) : opencv_world_dll, 109 | string.IsNullOrWhiteSpace(opencv_com_dll) ? OpenCvComInterop.FindDLL("autoit_opencv_com4100*", null, null, buildType) : opencv_com_dll 110 | ); 111 | 112 | if (register) { 113 | OpenCvComInterop.Register(); 114 | } 115 | 116 | OpenCvComInterop.DllActivateManifest(); 117 | try { 118 | CompiletimeExample(image); 119 | } 120 | finally 121 | { 122 | OpenCvComInterop.DllDeactivateActCtx(); 123 | } 124 | 125 | try 126 | { 127 | RuntimeExample(image); 128 | } 129 | finally 130 | { 131 | if (unregister) { 132 | OpenCvComInterop.Unregister(); 133 | } 134 | OpenCvComInterop.DllClose(); 135 | } 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /samples/dotnet/05-drawing-contours.ps1: -------------------------------------------------------------------------------- 1 | #requires -version 5.0 2 | 3 | [CmdletBinding()] 4 | param ( 5 | [Parameter(Position=0)][string] $Image = $null, 6 | [string] $BuildType = $Env:BUILD_TYPE, 7 | [string] $OpenCVWorldDll = $null, 8 | [string] $OpenCVComDll = $null, 9 | [switch] $Register, 10 | [switch] $Unregister 11 | ) 12 | # "powershell.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 13 | # "pwsh.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 14 | 15 | $ErrorActionPreference = "Stop" 16 | Set-StrictMode -Version 3.0 17 | trap { throw $Error[0] } 18 | 19 | Import-Module "$PSScriptRoot\opencv_utils.psm1" -ArgumentList $BuildType 20 | 21 | $BuildType = if ($BuildType -eq "Debug") { "Debug" } else { "Release" } 22 | 23 | $OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL -Path "opencv_world4100*" -BuildType $BuildType } else { $OpenCVWorldDll } 24 | $OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL -Path "autoit_opencv_com4100*" -BuildType $BuildType } else { $OpenCVComDll } 25 | $Image = if ([string]::IsNullOrEmpty($Image)) { _OpenCV_FindFile -Path "samples\data\pic1.png" -SearchPaths @("opencv-4.10.0-*\opencv\sources") } else { $Image } 26 | 27 | function Example() { 28 | $cv = [OpenCvComInterop]::ObjCreate("cv") 29 | $img = $cv.imread($Image) 30 | $img_grey = $cv.cvtColor($img, $cv.enums.COLOR_BGR2GRAY) 31 | $cv.threshold($img_grey, 100, 255, $cv.enums.THRESH_BINARY) | Out-Null 32 | $thresh = $cv.extended[1] 33 | $contours = $cv.findContours($thresh, $cv.enums.RETR_TREE, $cv.enums.CHAIN_APPROX_SIMPLE) 34 | 35 | Write-Output "Found $($contours.Count) contours" 36 | 37 | $cv.drawContours($img, $contours, -1, @(0, 0, 255), 2) | Out-Null 38 | $cv.imshow("Image", $img) 39 | $cv.waitKey() | Out-Null 40 | $cv.destroyAllWindows() 41 | } 42 | 43 | [OpenCvComInterop]::DllOpen($OpenCVWorldDll, $OpenCVComDll) 44 | 45 | if ($Register) { 46 | [OpenCvComInterop]::Register() 47 | } 48 | 49 | Example 50 | 51 | if ($Unregister) { 52 | [OpenCvComInterop]::Unregister() 53 | } 54 | 55 | [OpenCvComInterop]::DllClose() 56 | -------------------------------------------------------------------------------- /samples/dotnet/csrun.bat: -------------------------------------------------------------------------------- 1 | @GOTO :BEGIN 2 | :: csrun.bat 01-show-image.cs 3 | 4 | :BEGIN 5 | @SETLOCAL enabledelayedexpansion 6 | 7 | @SET CWD=%CD% 8 | @SET "PATH=%CD%;%PATH%" 9 | 10 | @PUSHD "%~dp0" 11 | @CD /d %CD% 12 | 13 | @SET SCRIPTDIR=%CD% 14 | @SET "PATH=%SCRIPTDIR%;%PATH%" 15 | 16 | @POPD 17 | @CD /d %CD% 18 | 19 | @CALL powershell.exe -ExecutionPolicy UnRestricted -File "%SCRIPTDIR%\csrun.ps1" %* 20 | 21 | :END 22 | @POPD 23 | @EXIT /B %ERRORLEVEL% 24 | -------------------------------------------------------------------------------- /samples/dotnet/csrun.ps1: -------------------------------------------------------------------------------- 1 | #requires -version 5.0 2 | 3 | [CmdletBinding()] 4 | param ( 5 | [Parameter(Mandatory, Position=0)][string] $File, 6 | [string] $BuildType = $Env:BUILD_TYPE, 7 | [Parameter(ValueFromRemainingArguments=$true)][string[]] $argv 8 | ) 9 | # "powershell.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 10 | # "pwsh.exe -ExecutionPolicy UnRestricted -File $PSCommandPath" 11 | 12 | $ErrorActionPreference = "Stop" 13 | Set-StrictMode -Version 3.0 14 | trap { throw $Error[0] } 15 | 16 | Import-Module "$PSScriptRoot\opencv_utils.psm1" -ArgumentList $BuildType 17 | 18 | $ExeFile = "$($File.Substring(0, $File.Length - 3)).exe" 19 | 20 | $Env:Path = 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn;' + $Env:Path 21 | $Env:Path = 'C:\Program Files\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Roslyn;' + $Env:Path 22 | $Env:Path = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\bin\Roslyn;' + $Env:Path 23 | $Env:Path = 'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\bin\Roslyn;' + $Env:Path 24 | 25 | $OpenCvComInterop = _OpenCV_FindFile -Path "dotnet\OpenCvComInterop.cs" -SearchPaths @( 26 | "." 27 | "autoit-opencv-com" 28 | ) 29 | 30 | $OpenCVInteropServices = _OpenCV_FindFile -Path "dotnet\OpenCV.InteropServices.dll" -SearchPaths @( 31 | "." 32 | "autoit-opencv-com" 33 | "autoit-opencv-com\generated" 34 | ) 35 | 36 | csc.exe @( 37 | "/link:$OpenCVInteropServices" 38 | "/out:$ExeFile" 39 | "$OpenCvComInterop" 40 | "$File" 41 | ) 42 | 43 | if ($lastexitcode -eq 0) { 44 | & "$ExeFile" --build-type `"$BuildType`" @argv 45 | } 46 | 47 | exit $lastexitcode 48 | -------------------------------------------------------------------------------- /samples/samples.xlsm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/samples.xlsm -------------------------------------------------------------------------------- /samples/tutorial_code/Histograms_Matching/EqualizeHist_Demo.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include 9 | #include 10 | #include "..\..\..\autoit-opencv-com\udf\opencv_udf_utils.au3" 11 | 12 | ;~ Sources: 13 | ;~ https://docs.opencv.org/4.10.0/d4/d1b/tutorial_histogram_equalization.html 14 | ;~ https://github.com/opencv/opencv/blob/4.10.0/samples/cpp/tutorial_code/Histograms_Matching/EqualizeHist_Demo.cpp 15 | 16 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 17 | _GDIPlus_Startup() 18 | OnAutoItExitRegister("_OnAutoItExit") 19 | 20 | Global $cv = _OpenCV_get() 21 | 22 | Global Const $OPENCV_SAMPLES_DATA_PATH = _OpenCV_FindFile("samples\data") 23 | 24 | #Region ### START Koda GUI section ### Form= 25 | Global $FormGUI = GUICreate("Histogram Equalization", 1065, 617, 192, 124) 26 | 27 | Global $InputSource = GUICtrlCreateInput($cv.samples.findFile("lena.jpg"), 264, 24, 449, 21) 28 | GUICtrlSetState(-1, $GUI_DISABLE) 29 | Global $BtnSource = GUICtrlCreateButton("Open", 723, 22, 75, 25) 30 | 31 | Global $LabelSource = GUICtrlCreateLabel("Source Image", 231, 60, 100, 20) 32 | GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") 33 | Global $GroupSource = GUICtrlCreateGroup("", 20, 83, 510, 516) 34 | Global $PicSource = GUICtrlCreatePic("", 25, 94, 500, 500) 35 | GUICtrlCreateGroup("", -99, -99, 1, 1) 36 | 37 | Global $LabelResult = GUICtrlCreateLabel("Equalized Image", 735, 60, 120, 20) 38 | GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") 39 | Global $GroupResult = GUICtrlCreateGroup("", 532, 83, 510, 516) 40 | Global $PicResult = GUICtrlCreatePic("", 537, 94, 500, 500) 41 | GUICtrlCreateGroup("", -99, -99, 1, 1) 42 | 43 | GUISetState(@SW_SHOW) 44 | #EndRegion ### END Koda GUI section ### 45 | 46 | Global $sImage = "" 47 | Global $nMsg 48 | 49 | Main() 50 | 51 | While 1 52 | $nMsg = GUIGetMsg() 53 | Switch $nMsg 54 | Case $GUI_EVENT_CLOSE 55 | ExitLoop 56 | Case $BtnSource 57 | $sImage = ControlGetText($FormGUI, "", $InputSource) 58 | $sImage = FileOpenDialog("Select an image", $OPENCV_SAMPLES_DATA_PATH, "Image files (*.bmp;*.dlib;*.jpg;*.jpeg;*.png;*.pbm;*.pgm;*.ppm;*.pxm;*.pnm;*.pfm;*.sr;*.ras;*.tiff;*.tif;*.exr;*.hdr;.pic)", $FD_FILEMUSTEXIST, $sImage) 59 | If @error Then 60 | $sImage = "" 61 | Else 62 | ControlSetText($FormGUI, "", $InputSource, $sImage) 63 | Main() 64 | EndIf 65 | EndSwitch 66 | WEnd 67 | 68 | Func Main() 69 | $sImage = ControlGetText($FormGUI, "", $InputSource) 70 | If $sImage == "" Then Return 71 | 72 | ;;! [Load image] 73 | Local $src = _OpenCV_imread_and_check($sImage, $CV_IMREAD_COLOR) 74 | If @error Then Return 75 | ;;! [Load image] 76 | 77 | ;;! [Convert to grayscale] 78 | $src = $cv.cvtColor($src, $CV_COLOR_BGR2GRAY) 79 | ;;! [Convert to grayscale] 80 | 81 | ;;! [Apply Histogram Equalization] 82 | Local $dst = $cv.equalizeHist($src) 83 | ;;! [Apply Histogram Equalization] 84 | 85 | ;;! [Display] 86 | _OpenCV_imshow_ControlPic($src, $FormGUI, $PicSource) 87 | _OpenCV_imshow_ControlPic($dst, $FormGUI, $PicResult) 88 | ;;! [Display] 89 | EndFunc ;==>Main 90 | 91 | Func _OnAutoItExit() 92 | _GDIPlus_Shutdown() 93 | _OpenCV_Close() 94 | EndFunc ;==>_OnAutoItExit 95 | -------------------------------------------------------------------------------- /samples/tutorial_code/ImgProc/Smoothing/Smoothing.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include 9 | #include 10 | #include 11 | #include "..\..\..\..\autoit-opencv-com\udf\opencv_udf_utils.au3" 12 | 13 | ;~ Sources: 14 | ;~ https://docs.opencv.org/4.10.0/dc/dd3/tutorial_gausian_median_blur_bilateral_filter.html 15 | ;~ https://github.com/opencv/opencv/blob/4.10.0/samples/cpp/tutorial_code/ImgProc/Smoothing/Smoothing.cpp 16 | 17 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 18 | _GDIPlus_Startup() 19 | OnAutoItExitRegister("_OnAutoItExit") 20 | 21 | Global $cv = _OpenCV_get() 22 | 23 | Global Const $OPENCV_SAMPLES_DATA_PATH = _OpenCV_FindFile("samples\data") 24 | 25 | #Region ### START Koda GUI section ### Form= 26 | Global $FormGUI = GUICreate("Smoothing Images", 1067, 641, 192, 124) 27 | 28 | Global $InputSource = GUICtrlCreateInput($cv.samples.findFile("lena.jpg"), 264, 24, 449, 21) 29 | GUICtrlSetState(-1, $GUI_DISABLE) 30 | Global $BtnSource = GUICtrlCreateButton("Open", 723, 22, 75, 25) 31 | 32 | Global $LabelMethod = GUICtrlCreateLabel("Method:", 504, 61, 59, 20) 33 | GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") 34 | Global $ComboMethod = GUICtrlCreateCombo("", 568, 61, 145, 25, BitOR($GUI_SS_DEFAULT_COMBO, $CBS_SIMPLE)) 35 | GUICtrlSetData(-1, "Homogeneous Blur|Gaussian Blur|Median Blur|Bilateral Blur") 36 | 37 | Global $BtnReplay = GUICtrlCreateButton("Replay", 723, 59, 75, 25) 38 | 39 | Global $LabelSource = GUICtrlCreateLabel("Source Image", 231, 92, 100, 20) 40 | GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") 41 | Global $GroupSource = GUICtrlCreateGroup("", 20, 115, 510, 516) 42 | Global $PicSource = GUICtrlCreatePic("", 25, 126, 500, 500) 43 | GUICtrlCreateGroup("", -99, -99, 1, 1) 44 | 45 | Global $LabelResult = GUICtrlCreateLabel("Smoothing Demo", 735, 92, 120, 20) 46 | GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") 47 | Global $GroupResult = GUICtrlCreateGroup("", 532, 115, 510, 516) 48 | Global $PicResult = GUICtrlCreatePic("", 537, 126, 500, 500) 49 | GUICtrlCreateGroup("", -99, -99, 1, 1) 50 | 51 | GUISetState(@SW_SHOW) 52 | #EndRegion ### END Koda GUI section ### 53 | 54 | Global $sImage = "" 55 | Global $nMsg 56 | 57 | Global $src 58 | 59 | Global $DELAY_BLUR = 100 ; 60 | Global $MAX_KERNEL_LENGTH = 31 ; 61 | 62 | Global $aMethods[4] = ["Homogeneous Blur", "Gaussian Blur", "Median Blur", "Bilateral Blur"] 63 | _GUICtrlComboBox_SetCurSel($ComboMethod, 0) 64 | 65 | Main() 66 | 67 | While 1 68 | $nMsg = GUIGetMsg() 69 | Switch $nMsg 70 | Case $GUI_EVENT_CLOSE 71 | Exit 72 | Case $BtnSource 73 | $sImage = ControlGetText($FormGUI, "", $InputSource) 74 | $sImage = FileOpenDialog("Select an image", $OPENCV_SAMPLES_DATA_PATH, "Image files (*.bmp;*.dlib;*.jpg;*.jpeg;*.png;*.pbm;*.pgm;*.ppm;*.pxm;*.pnm;*.pfm;*.sr;*.ras;*.tiff;*.tif;*.exr;*.hdr;.pic)", $FD_FILEMUSTEXIST, $sImage) 75 | If Not @error Then 76 | ControlSetText($FormGUI, "", $InputSource, $sImage) 77 | Main() 78 | EndIf 79 | Case $BtnReplay 80 | Smooth() 81 | Case $ComboMethod 82 | Smooth() 83 | EndSwitch 84 | WEnd 85 | 86 | Func Main() 87 | $sImage = ControlGetText($FormGUI, "", $InputSource) 88 | If $sImage == "" Then Return 89 | 90 | ;;! [Load image] 91 | $src = _OpenCV_imread_and_check($sImage, $CV_IMREAD_COLOR) 92 | If @error Then 93 | $sImage = "" 94 | Return 95 | EndIf 96 | ;;! [Load image] 97 | 98 | ;;! [Display] 99 | ; _cveImshowMat("Source image", $src ); 100 | _OpenCV_imshow_ControlPic($src, $FormGUI, $PicSource) 101 | ;;! [Display] 102 | 103 | Smooth() 104 | EndFunc ;==>Main 105 | 106 | Func Smooth() 107 | If $sImage == "" Then Return 108 | 109 | Local $smooth_method = $aMethods[_GUICtrlComboBox_GetCurSel($ComboMethod)] 110 | Local $dst 111 | 112 | Switch $smooth_method 113 | Case "Homogeneous Blur" 114 | ;;![blur] 115 | For $i = 1 To $MAX_KERNEL_LENGTH - 1 Step 2 116 | $dst = $cv.blur($src, _OpenCV_Size($i, $i)) 117 | _OpenCV_imshow_ControlPic($dst, $FormGUI, $PicResult) 118 | Sleep($DELAY_BLUR) 119 | Next 120 | ;;![blur] 121 | Case "Gaussian Blur" 122 | ;;![gaussianblur] 123 | For $i = 1 To $MAX_KERNEL_LENGTH - 1 Step 2 124 | $dst = $cv.GaussianBlur($src, _OpenCV_Size($i, $i), 0) 125 | _OpenCV_imshow_ControlPic($dst, $FormGUI, $PicResult) 126 | Sleep($DELAY_BLUR) 127 | Next 128 | ;;![gaussianblur] 129 | Case "Median Blur" 130 | ;;![medianblur] 131 | For $i = 1 To $MAX_KERNEL_LENGTH - 1 Step 2 132 | $dst = $cv.medianBlur($src, $i) ; 133 | _OpenCV_imshow_ControlPic($dst, $FormGUI, $PicResult) 134 | Sleep($DELAY_BLUR) 135 | Next 136 | ;;![medianblur] 137 | Case "Bilateral Blur" 138 | ;;![bilateralfilter] 139 | For $i = 1 To $MAX_KERNEL_LENGTH - 1 Step 2 140 | $dst = $cv.bilateralFilter($src, $i, $i * 2, $i / 2) 141 | _OpenCV_imshow_ControlPic($dst, $FormGUI, $PicResult) 142 | Sleep($DELAY_BLUR) 143 | Next 144 | ;;![bilateralfilter] 145 | EndSwitch 146 | EndFunc ;==>Smooth 147 | 148 | Func _OnAutoItExit() 149 | _GDIPlus_Shutdown() 150 | _OpenCV_Close() 151 | EndFunc ;==>_OnAutoItExit 152 | -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/detect_color/example_shapes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/tutorial_code/pyimagesearch/detect_color/example_shapes.png -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/detect_shapes/detect_shapes.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include 9 | #include 10 | #include 11 | #include "..\..\..\..\autoit-opencv-com\udf\opencv_udf_utils.au3" 12 | 13 | ;~ Sources: 14 | ;~ https://www.pyimagesearch.com/2016/02/08/opencv-shape-detection/ 15 | 16 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 17 | _GDIPlus_Startup() 18 | OnAutoItExitRegister("_OnAutoItExit") 19 | 20 | Global $cv = _OpenCV_get() 21 | 22 | Global Const $OPENCV_SAMPLES_DATA_PATH = _OpenCV_FindFile("samples\data") 23 | 24 | #Region ### START Koda GUI section ### Form= 25 | Global $FormGUI = GUICreate("OpenCV shape detection", 1065, 617, 192, 124) 26 | 27 | Global $InputSource = GUICtrlCreateInput($cv.samples.findFile("shapes_and_colors.png"), 264, 24, 449, 21) 28 | GUICtrlSetState(-1, $GUI_DISABLE) 29 | Global $BtnSource = GUICtrlCreateButton("Open", 723, 22, 75, 25) 30 | 31 | Global $LabelSource = GUICtrlCreateLabel("Source Image", 231, 60, 100, 20) 32 | GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") 33 | Global $GroupSource = GUICtrlCreateGroup("", 20, 83, 510, 516) 34 | Global $PicSource = GUICtrlCreatePic("", 25, 94, 500, 500) 35 | GUICtrlCreateGroup("", -99, -99, 1, 1) 36 | 37 | Global $LabelResult = GUICtrlCreateLabel("Shape detection", 735, 60, 120, 20) 38 | GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") 39 | Global $GroupResult = GUICtrlCreateGroup("", 532, 83, 510, 516) 40 | Global $PicResult = GUICtrlCreatePic("", 537, 94, 500, 500) 41 | GUICtrlCreateGroup("", -99, -99, 1, 1) 42 | 43 | GUISetState(@SW_SHOW) 44 | #EndRegion ### END Koda GUI section ### 45 | 46 | Global $sImage = "" 47 | Global $nMsg 48 | 49 | Main() 50 | 51 | While 1 52 | $nMsg = GUIGetMsg() 53 | Switch $nMsg 54 | Case $GUI_EVENT_CLOSE 55 | ExitLoop 56 | Case $BtnSource 57 | $sImage = ControlGetText($FormGUI, "", $InputSource) 58 | $sImage = FileOpenDialog("Select an image", $OPENCV_SAMPLES_DATA_PATH, "Image files (*.bmp;*.dlib;*.jpg;*.jpeg;*.png;*.pbm;*.pgm;*.ppm;*.pxm;*.pnm;*.pfm;*.sr;*.ras;*.tiff;*.tif;*.exr;*.hdr;.pic)", $FD_FILEMUSTEXIST, $sImage) 59 | If @error Then 60 | $sImage = "" 61 | Else 62 | ControlSetText($FormGUI, "", $InputSource, $sImage) 63 | Main() 64 | EndIf 65 | EndSwitch 66 | WEnd 67 | 68 | Func Main() 69 | $sImage = ControlGetText($FormGUI, "", $InputSource) 70 | If $sImage == "" Then Return 71 | 72 | ;;! [Load image] 73 | Local $image = _OpenCV_imread_and_check($sImage) 74 | If @error Then Return 75 | _OpenCV_imshow_ControlPic($image, $FormGUI, $PicSource) 76 | ;;! [Load image] 77 | 78 | ;; resize it to a smaller factor so that 79 | ;; the shapes can be approximated better 80 | Local $resized = _OpenCV_resizeAndCenter($image, 300) 81 | Local $ratio = $image.width / $resized.width 82 | 83 | ;; convert the resized image to grayscale, blur it slightly, 84 | ;; and threshold it 85 | Local $gray = $cv.cvtColor($resized, $CV_COLOR_BGR2GRAY) 86 | Local $blurred = $cv.GaussianBlur($gray, _OpenCV_Size(5, 5), 0) 87 | $cv.threshold($blurred, 60, 255, $CV_THRESH_BINARY) 88 | Local $thresh = $cv.extended[1] 89 | 90 | ;; find contours in the thresholded image and initialize the 91 | ;; shape detector 92 | Local $cnts = $cv.findContours($thresh, $CV_RETR_EXTERNAL, $CV_CHAIN_APPROX_SIMPLE) 93 | Local $tmp[1] 94 | 95 | For $i = 0 To UBound($cnts) - 1 96 | Local $c = $cnts[$i] 97 | 98 | ;; compute the center of the contour, then detect the name of the 99 | ;; shape using only the contour 100 | Local $M = $cv.moments($c) 101 | Local $cY = ($M.m01 / $M.m00) * $ratio 102 | Local $cX = ($M.m10 / $M.m00) * $ratio 103 | Local $shape = detect($c) 104 | 105 | ;; multiply the contour (x, y)-coordinates by the resize ratio, 106 | ;; then draw the contours and the name of the shape on the image 107 | $tmp[0] = $c.convertTo(-1, _OpenCV_Params("alpha", $ratio)) 108 | $cv.drawContours($image, $tmp, -1, _OpenCV_Scalar(0, 255, 0), 2) 109 | $cv.putText($image, $shape, _OpenCV_Point($cX, $cY), $CV_FONT_HERSHEY_SIMPLEX, 0.5, _OpenCV_Scalar(255, 255, 255), 2) 110 | Next 111 | 112 | ;; show the output image 113 | _OpenCV_imshow_ControlPic($image, $FormGUI, $PicResult) 114 | EndFunc ;==>Main 115 | 116 | Func detect($c) 117 | Local $shape = "undefined" 118 | Local $peri = $cv.arcLength($c, True) 119 | Local $approx = $cv.approxPolyDP($c, 0.04 * $peri, True) 120 | Local $rect, $ar 121 | 122 | Switch $approx.rows 123 | Case 3 124 | $shape = "triangle" 125 | Case 4 126 | ;; compute the bounding box of the contour and use the 127 | ;; bounding box to compute the aspect ratio 128 | $rect = $cv.boundingRect($approx) 129 | $ar = $rect[2] / $rect[3] 130 | 131 | ;; a square will have an aspect ratio that is approximately 132 | ;; equal to one, otherwise, the shape is a rectangle 133 | $shape = ($ar >= 0.95 And $ar <= 1.05) ? "square" : "rectangle" 134 | Case 5 135 | $shape = "pentagon" 136 | Case Else 137 | $shape = "circle" 138 | EndSwitch 139 | 140 | Return $shape 141 | EndFunc ;==>detect 142 | 143 | Func _OnAutoItExit() 144 | _GDIPlus_Shutdown() 145 | _OpenCV_Close() 146 | EndFunc ;==>_OnAutoItExit 147 | -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/detect_shapes/shapes_and_colors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/tutorial_code/pyimagesearch/detect_shapes/shapes_and_colors.png -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/find_shapes/find_shapes.au3: -------------------------------------------------------------------------------- 1 | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** 2 | #AutoIt3Wrapper_UseX64=y 3 | #AutoIt3Wrapper_Change2CUI=y 4 | #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 5 | #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y 6 | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** 7 | 8 | #include 9 | #include 10 | #include 11 | #include "..\..\..\..\autoit-opencv-com\udf\opencv_udf_utils.au3" 12 | 13 | ;~ Sources: 14 | ;~ https://www.pyimagesearch.com/2016/02/08/opencv-shape-detection/ 15 | 16 | _OpenCV_Open(_OpenCV_FindDLL("opencv_world4100*"), _OpenCV_FindDLL("autoit_opencv_com4100*")) 17 | _GDIPlus_Startup() 18 | OnAutoItExitRegister("_OnAutoItExit") 19 | 20 | Global $cv = _OpenCV_get() 21 | 22 | Global Const $OPENCV_SAMPLES_DATA_PATH = _OpenCV_FindFile("samples\data") 23 | 24 | #Region ### START Koda GUI section ### Form= 25 | Global $FormGUI = GUICreate("Finding Shapes in images", 1065, 617, 192, 124) 26 | 27 | Global $InputSource = GUICtrlCreateInput(_PathFull($cv.samples.findFile("shapes.png")), 264, 24, 449, 21) 28 | GUICtrlSetState(-1, $GUI_DISABLE) 29 | Global $BtnSource = GUICtrlCreateButton("Open", 723, 22, 75, 25) 30 | 31 | Global $LabelSource = GUICtrlCreateLabel("Source Image", 231, 60, 100, 20) 32 | GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") 33 | Global $GroupSource = GUICtrlCreateGroup("", 20, 83, 510, 516) 34 | Global $PicSource = GUICtrlCreatePic("", 25, 94, 500, 500) 35 | GUICtrlCreateGroup("", -99, -99, 1, 1) 36 | 37 | Global $LabelResult = GUICtrlCreateLabel("Shape detection", 735, 60, 120, 20) 38 | GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") 39 | Global $GroupResult = GUICtrlCreateGroup("", 532, 83, 510, 516) 40 | Global $PicResult = GUICtrlCreatePic("", 537, 94, 500, 500) 41 | GUICtrlCreateGroup("", -99, -99, 1, 1) 42 | 43 | GUISetState(@SW_SHOW) 44 | #EndRegion ### END Koda GUI section ### 45 | 46 | Global $sImage = "" 47 | Global $nMsg 48 | 49 | Main() 50 | 51 | While 1 52 | $nMsg = GUIGetMsg() 53 | Switch $nMsg 54 | Case $GUI_EVENT_CLOSE 55 | ExitLoop 56 | Case $BtnSource 57 | $sImage = ControlGetText($FormGUI, "", $InputSource) 58 | $sImage = FileOpenDialog("Select an image", $OPENCV_SAMPLES_DATA_PATH, "Image files (*.bmp;*.dlib;*.jpg;*.jpeg;*.png;*.pbm;*.pgm;*.ppm;*.pxm;*.pnm;*.pfm;*.sr;*.ras;*.tiff;*.tif;*.exr;*.hdr;.pic)", $FD_FILEMUSTEXIST, $sImage) 59 | If @error Then 60 | $sImage = "" 61 | Else 62 | ControlSetText($FormGUI, "", $InputSource, $sImage) 63 | Main() 64 | EndIf 65 | EndSwitch 66 | WEnd 67 | 68 | Func Main() 69 | $sImage = ControlGetText($FormGUI, "", $InputSource) 70 | If $sImage == "" Then Return 71 | 72 | ;;! [Load image] 73 | Local $image = _OpenCV_imread_and_check($sImage) 74 | If @error Then Return 75 | _OpenCV_imshow_ControlPic($image, $FormGUI, $PicSource) 76 | ;;! [Load image] 77 | 78 | ;; find all the 'black' shapes in the image 79 | Local $lower = _OpenCV_Scalar(0, 0, 0) 80 | Local $upper = _OpenCV_Scalar(15, 15, 15) 81 | Local $shapeMask = $cv.inRange($image, $lower, $upper) 82 | 83 | ;; find the contours in the mask 84 | Local $cnts = $cv.findContours($shapeMask, $CV_RETR_EXTERNAL, $CV_CHAIN_APPROX_SIMPLE) 85 | 86 | ;; draw the contour 87 | $cv.drawContours($image, $cnts, -1, _OpenCV_Scalar(0, 255, 0), 2) 88 | 89 | ;; show the output image 90 | _OpenCV_imshow_ControlPic($image, $FormGUI, $PicResult) 91 | EndFunc ;==>Main 92 | 93 | Func _OnAutoItExit() 94 | _GDIPlus_Shutdown() 95 | _OpenCV_Close() 96 | EndFunc ;==>_OnAutoItExit 97 | -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/find_shapes/shapes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/tutorial_code/pyimagesearch/find_shapes/shapes.png -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/scan/example_01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/tutorial_code/pyimagesearch/scan/example_01.jpg -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/scan/receipt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/tutorial_code/pyimagesearch/scan/receipt.jpg -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/scan/scan.py: -------------------------------------------------------------------------------- 1 | # import the necessary packages 2 | from scipy.spatial import distance as dist 3 | import numpy as np 4 | import cv2 5 | import argparse 6 | import imutils 7 | 8 | def order_points(pts): 9 | # sort the points based on their x-coordinates 10 | xSorted = pts[np.argsort(pts[:, 0]), :] 11 | 12 | # grab the left-most and right-most points from the sorted 13 | # x-roodinate points 14 | leftMost = xSorted[:2, :] 15 | rightMost = xSorted[2:, :] 16 | 17 | # now, sort the left-most coordinates according to their 18 | # y-coordinates so we can grab the top-left and bottom-left 19 | # points, respectively 20 | leftMost = leftMost[np.argsort(leftMost[:, 1]), :] 21 | (tl, bl) = leftMost 22 | 23 | # now that we have the top-left coordinate, use it as an 24 | # anchor to calculate the Euclidean distance between the 25 | # top-left and right-most points; by the Pythagorean 26 | # theorem, the point with the largest distance will be 27 | # our bottom-right point 28 | D = dist.cdist(tl[np.newaxis], rightMost, "euclidean")[0] 29 | (br, tr) = rightMost[np.argsort(D)[::-1], :] 30 | 31 | # return the coordinates in top-left, top-right, 32 | # bottom-right, and bottom-left order 33 | return np.array([tl, tr, br, bl], dtype="float32") 34 | 35 | def four_point_transform(image, pts): 36 | # obtain a consistent order of the points and unpack them 37 | # individually 38 | rect = order_points(pts) 39 | (tl, tr, br, bl) = rect 40 | 41 | # compute the width of the new image, which will be the 42 | # maximum distance between bottom-right and bottom-left 43 | # x-coordiates or the top-right and top-left x-coordinates 44 | widthA = np.sqrt(((br[0] - bl[0]) ** 2) + ((br[1] - bl[1]) ** 2)) 45 | widthB = np.sqrt(((tr[0] - tl[0]) ** 2) + ((tr[1] - tl[1]) ** 2)) 46 | maxWidth = max(int(widthA), int(widthB)) 47 | 48 | # compute the height of the new image, which will be the 49 | # maximum distance between the top-right and bottom-right 50 | # y-coordinates or the top-left and bottom-left y-coordinates 51 | heightA = np.sqrt(((tr[0] - br[0]) ** 2) + ((tr[1] - br[1]) ** 2)) 52 | heightB = np.sqrt(((tl[0] - bl[0]) ** 2) + ((tl[1] - bl[1]) ** 2)) 53 | maxHeight = max(int(heightA), int(heightB)) 54 | 55 | # now that we have the dimensions of the new image, construct 56 | # the set of destination points to obtain a "birds eye view", 57 | # (i.e. top-down view) of the image, again specifying points 58 | # in the top-left, top-right, bottom-right, and bottom-left 59 | # order 60 | dst = np.array([ 61 | [0, 0], 62 | [maxWidth - 1, 0], 63 | [maxWidth - 1, maxHeight - 1], 64 | [0, maxHeight - 1]], dtype = "float32") 65 | 66 | # compute the perspective transform matrix and then apply it 67 | M = cv2.getPerspectiveTransform(rect, dst) 68 | warped = cv2.warpPerspective(image, M, (maxWidth, maxHeight)) 69 | 70 | # return the warped image 71 | return warped 72 | 73 | # construct the argument parser and parse the arguments 74 | ap = argparse.ArgumentParser() 75 | ap.add_argument("-i", "--image", required = True, 76 | help = "Path to the image to be scanned") 77 | args = vars(ap.parse_args()) 78 | 79 | # load the image and compute the ratio of the old height 80 | # to the new height, clone it, and resize it 81 | image = cv2.imread(args["image"]) 82 | ratio = image.shape[0] / 500.0 83 | orig = image.copy() 84 | image = imutils.resize(image, height = 500) 85 | 86 | # convert the image to grayscale, blur it, and find edges 87 | # in the image 88 | gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) 89 | gray = cv2.GaussianBlur(gray, (5, 5), 0) 90 | edged = cv2.Canny(gray, 75, 200) 91 | 92 | # show the original image and the edge detected image 93 | print("STEP 1: Edge Detection") 94 | cv2.imshow("Image", image) 95 | cv2.imshow("Edged", edged) 96 | cv2.waitKey(0) 97 | cv2.destroyAllWindows() 98 | 99 | # find the contours in the edged image, keeping only the 100 | # largest ones, and initialize the screen contour 101 | cnts = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) 102 | cnts = imutils.grab_contours(cnts) 103 | cnts = sorted(cnts, key = cv2.contourArea, reverse = True)[:5] 104 | 105 | screenCnt = None 106 | 107 | # loop over the contours 108 | for c in cnts: 109 | # approximate the contour 110 | peri = cv2.arcLength(c, True) 111 | approx = cv2.approxPolyDP(c, 0.02 * peri, True) 112 | 113 | # if our approximated contour has four points, then we 114 | # can assume that we have found our screen 115 | if len(approx) == 4: 116 | screenCnt = approx 117 | break 118 | 119 | # show the contour (outline) of the piece of paper 120 | print("STEP 2: Find contours of paper") 121 | cv2.drawContours(image, [screenCnt], -1, (0, 255, 0), 2) 122 | cv2.imshow("Outline", image) 123 | cv2.waitKey(0) 124 | cv2.destroyAllWindows() 125 | -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/test_grader/images/example_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/tutorial_code/pyimagesearch/test_grader/images/example_test.png -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/test_grader/images/test_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/tutorial_code/pyimagesearch/test_grader/images/test_01.png -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/test_grader/images/test_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/tutorial_code/pyimagesearch/test_grader/images/test_02.png -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/test_grader/images/test_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/tutorial_code/pyimagesearch/test_grader/images/test_03.png -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/test_grader/images/test_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/tutorial_code/pyimagesearch/test_grader/images/test_04.png -------------------------------------------------------------------------------- /samples/tutorial_code/pyimagesearch/test_grader/images/test_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/tutorial_code/pyimagesearch/test_grader/images/test_05.png -------------------------------------------------------------------------------- /samples/tutorial_code/yolo/coco.txt: -------------------------------------------------------------------------------- 1 | person 2 | bicycle 3 | car 4 | motorcycle 5 | airplane 6 | bus 7 | train 8 | truck 9 | boat 10 | traffic light 11 | fire hydrant 12 | stop sign 13 | parking meter 14 | bench 15 | bird 16 | cat 17 | dog 18 | horse 19 | sheep 20 | cow 21 | elephant 22 | bear 23 | zebra 24 | giraffe 25 | backpack 26 | umbrella 27 | handbag 28 | tie 29 | suitcase 30 | frisbee 31 | skis 32 | snowboard 33 | sports ball 34 | kite 35 | baseball bat 36 | baseball glove 37 | skateboard 38 | surfboard 39 | tennis racket 40 | bottle 41 | wine glass 42 | cup 43 | fork 44 | knife 45 | spoon 46 | bowl 47 | banana 48 | apple 49 | sandwich 50 | orange 51 | broccoli 52 | carrot 53 | hot dog 54 | pizza 55 | donut 56 | cake 57 | chair 58 | couch 59 | potted plant 60 | bed 61 | dining table 62 | toilet 63 | tv 64 | laptop 65 | mouse 66 | remote 67 | keyboard 68 | cell phone 69 | microwave 70 | oven 71 | toaster 72 | sink 73 | refrigerator 74 | book 75 | clock 76 | vase 77 | scissors 78 | teddy bear 79 | hair drier 80 | toothbrush -------------------------------------------------------------------------------- /samples/tutorial_code/yolo/people-2557408_1920.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/tutorial_code/yolo/people-2557408_1920.jpg -------------------------------------------------------------------------------- /samples/tutorial_code/yolo/scooter-5180947_1920.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/smbape/node-autoit-opencv-com/64c3dbf5c5b08cc89b40e23d808d431b2e5f5a1d/samples/tutorial_code/yolo/scooter-5180947_1920.jpg -------------------------------------------------------------------------------- /samples/tutorial_code/yolo/yolo.py: -------------------------------------------------------------------------------- 1 | # import the necessary packages 2 | import numpy as np 3 | import cv2 as cv 4 | import datetime 5 | 6 | # Remove the bounding boxes with low confidence using non-maxima suppression 7 | def postprocess(frame, outs): 8 | frameHeight = frame.shape[0] 9 | frameWidth = frame.shape[1] 10 | 11 | # Scan through all the bounding boxes output from the network and keep only the 12 | # ones with high confidence scores. Assign the box's class label as the class with the highest score. 13 | classIds = [] 14 | confidences = [] 15 | boxes = [] 16 | for out in outs: 17 | for detection in out: 18 | scores = detection[5:] 19 | classId = np.argmax(scores) 20 | confidence = scores[classId] 21 | if confidence > confThreshold: 22 | center_x = int(detection[0] * frameWidth) 23 | center_y = int(detection[1] * frameHeight) 24 | width = int(detection[2] * frameWidth) 25 | height = int(detection[3] * frameHeight) 26 | left = int(center_x - width / 2) 27 | top = int(center_y - height / 2) 28 | classIds.append(classId) 29 | confidences.append(float(confidence)) 30 | boxes.append([left, top, width, height]) 31 | 32 | # Perform non maximum suppression to eliminate redundant overlapping boxes with 33 | # lower confidences. 34 | indices = cv.dnn.NMSBoxes(boxes, confidences, confThreshold, nmsThreshold) 35 | for i in indices: 36 | box = boxes[i] 37 | left = box[0] 38 | top = box[1] 39 | width = box[2] 40 | height = box[3] 41 | drawPred(classIds[i], confidences[i], left, top, left + width, top + height) 42 | 43 | # Draw the predicted bounding box 44 | def drawPred(classId, conf, left, top, right, bottom): 45 | # Draw a bounding box. 46 | cv.rectangle(frame, (left, top), (right, bottom), (255, 178, 50), 3) 47 | 48 | label = '%.2f' % conf 49 | 50 | # Get the label for the class name and its confidence 51 | if classes: 52 | assert(classId < len(classes)) 53 | label = '%s:%s' % (classes[classId], label) 54 | 55 | #Display the label at the top of the bounding box 56 | labelSize, baseLine = cv.getTextSize(label, cv.FONT_HERSHEY_SIMPLEX, 0.5, 1) 57 | top = max(top, labelSize[1]) 58 | cv.rectangle(frame, (left, top - round(1.5*labelSize[1])), (left + round(1.5*labelSize[0]), top + baseLine), (255, 255, 255), cv.FILLED) 59 | cv.putText(frame, label, (left, top), cv.FONT_HERSHEY_SIMPLEX, 0.75, (0,0,0), 1) 60 | 61 | # Initialize the parameters 62 | confThreshold = 0.5 #Confidence threshold 63 | nmsThreshold = 0.4 #Non-maximum suppression threshold 64 | inpWidth = 416 #Width of network's input image 65 | inpHeight = 416 #Height of network's input image 66 | 67 | # Load names of classes 68 | classesFile = "yolov3.txt"; 69 | classes = None 70 | with open(classesFile, 'rt') as f: 71 | classes = f.read().rstrip('\n').split('\n') 72 | 73 | # Give the configuration and weight files for the model and load the network using them. 74 | modelConfiguration = "yolov3.cfg"; 75 | modelWeights = "yolov3.weights"; 76 | 77 | timer = datetime.datetime.now() 78 | net = cv.dnn.readNetFromDarknet(modelConfiguration, modelWeights) 79 | net.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV) 80 | net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU) 81 | print("readNetFromDarknet " + str((datetime.datetime.now() - timer).total_seconds() * 1000)) 82 | 83 | # timer = datetime.datetime.now() 84 | # net = cv.dnn.readNet(modelWeights, modelConfiguration) 85 | # print("readNet " + str((datetime.datetime.now() - timer).total_seconds() * 1000)) 86 | 87 | frame = cv.imread("scooter-5180947_1920.jpg") 88 | 89 | # Create a 4D blob from a frame. 90 | blob = cv.dnn.blobFromImage(frame, 1/255, (inpWidth, inpHeight), [0,0,0], 1, crop=False) 91 | 92 | # Sets the input to the network 93 | net.setInput(blob) 94 | 95 | # Runs the forward pass to get output of the output layers 96 | timer = datetime.datetime.now() 97 | outs = net.forward(net.getUnconnectedOutLayersNames()) 98 | print("forward " + str((datetime.datetime.now() - timer).total_seconds() * 1000)) 99 | 100 | # Remove the bounding boxes with low confidence 101 | timer = datetime.datetime.now() 102 | postprocess(frame, outs) 103 | print("postprocess " + str((datetime.datetime.now() - timer).total_seconds() * 1000)) 104 | 105 | # Put efficiency information. The function getPerfProfile returns the overall time for inference(t) and the timings for each of the layers(in layersTimes) 106 | t, _ = net.getPerfProfile() 107 | label = 'Inference time: %.2f ms' % (t * 1000.0 / cv.getTickFrequency()) 108 | cv.putText(frame, label, (0, 15), cv.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255)) 109 | 110 | cv.imshow("object detection", frame) 111 | cv.waitKey() 112 | -------------------------------------------------------------------------------- /scripts/build.js: -------------------------------------------------------------------------------- 1 | const { spawn } = require("node:child_process"); 2 | const sysPath = require("node:path"); 3 | const eachOfLimit = require("async/eachOfLimit"); 4 | 5 | const version = process.env.npm_package_version || require("../package.json").version; 6 | 7 | const OpenCV_VERSION = "opencv-4.10.0"; 8 | const OpenCV_DLLVERSION = OpenCV_VERSION.slice("opencv-".length).replaceAll(".", ""); 9 | 10 | const sources = sysPath.resolve(__dirname, ".."); 11 | const archive = sysPath.join(sources, `autoit-${ OpenCV_VERSION }-com-v${ version }.7z`); 12 | const project = sysPath.join(sources, "autoit-opencv-com"); 13 | 14 | const files = [ 15 | [project, "install.bat"], 16 | [project, "udf/*.au3", "udf/*.md"], 17 | [project, "dotnet/*.cs"], 18 | [sysPath.join(sources, "samples"), "dotnet/*.psm1"], 19 | [sysPath.join(project, "generated"), "*.tlb", "dotnet/*.dll"], 20 | [sysPath.join(project, "build_x64", "bin", "Debug"), `autoit*${ OpenCV_DLLVERSION }*`, "dotnet/*", "opencv_*"], 21 | [sysPath.join(project, "build_x64", "bin", "Release"), `autoit*${ OpenCV_DLLVERSION }*`, "dotnet/*", "opencv_*"], 22 | [sysPath.join(sources, "autoit-addon", "build_x64", "bin", "Debug"), `autoit*${ OpenCV_DLLVERSION }*`], 23 | [sysPath.join(sources, "autoit-addon", "build_x64", "bin", "Release"), `autoit*${ OpenCV_DLLVERSION }*`], 24 | ]; 25 | 26 | eachOfLimit(files, 1, ([cwd, ...args], i, next) => { 27 | const child = spawn("7z", ["a", archive, ...args], { 28 | cwd, 29 | stdio: "inherit" 30 | }); 31 | 32 | child.on("close", () => { 33 | if (next !== null) { 34 | next(); 35 | } 36 | }); 37 | child.on("error", err => { 38 | if (next !== null) { 39 | next(err); 40 | next = null; 41 | } else { 42 | console.error(err); 43 | } 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /scripts/func_kwargs.js: -------------------------------------------------------------------------------- 1 | const genFunc = (libname, fname, args) => { 2 | return ` 3 | Func _${ libname }_${ fname }(${ args.map(([argname, , defval]) => `$${ argname }${ defval == null ? "" : " = Default" }`).join(", ") }) 4 | Local Static $NamedParameters = _${ libname }_ObjCreate("NamedParameters") 5 | 6 | Local $kwargs = Default 7 | Switch @NumParams 8 | ${ args.map(([argname], i) => ` 9 | Case ${ i + 1 } 10 | $kwargs = $NamedParameters.isNamedParameters($${ argname }) ? $${ argname } : Default 11 | `.replace(/^ {4}/mg, "").trim()).join(`\n${ " ".repeat(8) }`) } 12 | EndSwitch 13 | 14 | Local $has_kwarg = $kwargs <> Default 15 | If $kwargs == Default Then $kwargs = $NamedParameters 16 | Local $usedkw = 0 17 | 18 | ${ args.map(([argname, kwname, defval], i) => ` 19 | ; get argument ${ kwname || argname } 20 | If (Not $has_kwarg) Or @NumParams > ${ i + 1 } Then 21 | ; positional parameter should not be a named parameter 22 | If $has_kwarg And $kwargs.count("${ kwname || argname }") Then 23 | ConsoleWriteError('@@ Debug(' & @ScriptLineNumber & ') : ${ kwname || argname } was both specified as a Positional and NamedParameter' & @CRLF) 24 | Exit(1) 25 | EndIf 26 | Else 27 | ; named parameter 28 | If $kwargs.has("${ kwname || argname }") Then 29 | $${ argname } = $kwargs.Item("${ kwname || argname }") 30 | $usedkw += 1 31 | EndIf 32 | EndIf 33 | ${ defval == null || defval === "Default" ? "" : `If $${ argname } == Default Then $${ argname } = ${ defval }` } 34 | `.replace(/^ {4}/mg, "").trim()).join(`\n\n${ " ".repeat(4) }`) } 35 | 36 | If $usedkw <> $kwargs.size() Then 37 | ConsoleWriteError('@@ Debug(' & @ScriptLineNumber & ') : there are ' & ($kwargs.size() - $usedkw) & ' unknown named parameters' & @CRLF) 38 | Exit (1) 39 | EndIf 40 | 41 | ; ... YOUR CODE HERE 42 | EndFunc ;==>_${ libname }_${ fname } 43 | `.trim(); 44 | }; 45 | 46 | const [,, libname, fname, ...args] = process.argv; 47 | console.log(genFunc(libname, fname, args.map(arg => eval(arg)))); 48 | -------------------------------------------------------------------------------- /scripts/manual.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # ================================ 4 | # stash for release 5 | # ================================ 6 | git stash push --include-untracked 7 | 8 | 9 | # ================================ 10 | # tidy 11 | # ================================ 12 | node ../${ESLINT_CONFIG_PROJECT}/node_modules/eslint/bin/eslint.js --config=../${ESLINT_CONFIG_PROJECT}/.eslintrc --fix 'src/**/*.js' 'scripts/*.js' 13 | find samples autoit-opencv-com/udf autoit-addon -type d -name 'BackUp' -prune -o -type f -name '*.au3' -not -name 'Table.au3' -a -not -name '*test.au3' -a -not -name 'Find-Contour-Draw-Demo.au3' -print | xargs -I '{}' 'C:\Program Files (x86)\AutoIt3\AutoIt3.exe' 'C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3' //Tidy //in '{}' 14 | find samples autoit-opencv-com/udf autoit-addon -type d -name 'BackUp' | xargs -I '{}' rm -rf '{}' 15 | 16 | 17 | # ================================ 18 | # generate doctoc 19 | # ================================ 20 | node node_modules/doctoc/doctoc.js README.md && dos2unix README.md 21 | 22 | 23 | # ================================ 24 | # create a new version 25 | # ================================ 26 | npm version patch 27 | 28 | 29 | # ================================ 30 | # build 31 | # ================================ 32 | rm -rf opencv-4.*.0-windows autoit-opencv-com/{build_x64,generated,opencv-4.*.0-build_x64} && \ 33 | set -o pipefail && \ 34 | time CMAKE_BUILD_TYPE=Release ./autoit-*-com/build.bat && time CMAKE_BUILD_TYPE=Debug ./autoit-*-com/build.bat && \ 35 | time CMAKE_BUILD_TYPE=Release ./autoit-addon/build.bat && time CMAKE_BUILD_TYPE=Debug ./autoit-addon/build.bat && \ 36 | find samples autoit-opencv-com/udf autoit-addon -type d -name 'BackUp' -prune -o -type f -name '*.au3' -not -name 'Table.au3' -a -not -name '*test.au3' -a -not -name 'Find-Contour-Draw-Demo.au3' -print | xargs -I '{}' 'C:\Program Files (x86)\AutoIt3\AutoIt3.exe' 'C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3' //Tidy //in '{}' && \ 37 | find samples autoit-opencv-com/udf autoit-addon -type d -name 'BackUp' | xargs -I '{}' rm -rf '{}' && \ 38 | dos2unix autoit-opencv-com/udf/docs.md README.md 39 | 40 | 41 | # ================================ 42 | # test local 43 | # ================================ 44 | node scripts/test.js --bash > $(for ifile in autoit-*-com/build_x64/bin; do echo $ifile/test_all.sh; done) && \ 45 | ./autoit-*-com/build_x64/bin/test_all.sh 46 | 47 | 48 | # ================================ 49 | # pack release 50 | # ================================ 51 | node scripts/build.js 52 | 53 | 54 | # ================================ 55 | # test release 56 | # ================================ 57 | test -d /d/Programs/AutoIt/UDF/opencv-udf-test/opencv-4.10.0-windows || ./opencv-4.10.0-windows.exe -o/d/Programs/AutoIt/UDF/opencv-udf-test/opencv-4.10.0-windows -y && \ 58 | rm -rf /d/Programs/AutoIt/UDF/opencv-udf-test/autoit-* /d/Programs/AutoIt/UDF/opencv-udf-test/samples && \ 59 | git archive --format zip --output /d/Programs/AutoIt/UDF/opencv-udf-test/autoit-opencv-com.zip main && \ 60 | 7z x autoit-opencv-*.7z -aoa -o/d/Programs/AutoIt/UDF/opencv-udf-test/autoit-opencv-com && \ 61 | 7z x /d/Programs/AutoIt/UDF/opencv-udf-test/autoit-opencv-com.zip -aoa -o/d/Programs/AutoIt/UDF/opencv-udf-test 'autoit-addon\*' 'samples\*' && \ 62 | node scripts/test.js --bash /d/Programs/AutoIt/UDF/opencv-udf-test > $(for ifile in autoit-*-com/build_x64/bin; do echo $ifile/test_all.sh; done) && \ 63 | ./autoit-*-com/build_x64/bin/test_all.sh 64 | 65 | 66 | # ================================ 67 | # test release with dlib 68 | # ================================ 69 | rm -rf /d/development/git/node-autoit-dlib-com/autoit-opencv-com && \ 70 | cp -f autoit-opencv-*.7z /d/development/git/node-autoit-dlib-com/ && \ 71 | 7z x autoit-opencv-*.7z -aoa -o/d/development/git/node-autoit-dlib-com/autoit-opencv-com 72 | 73 | 74 | # ================================ 75 | # test release with mediapipe 76 | # ================================ 77 | rm -rf /d/development/git/node-autoit-mediapipe-com/autoit-opencv-com && \ 78 | cp -f autoit-opencv-*.7z /d/development/git/node-autoit-mediapipe-com/ && \ 79 | 7z x autoit-opencv-*.7z -aoa -o/d/development/git/node-autoit-mediapipe-com/autoit-opencv-com 80 | -------------------------------------------------------------------------------- /scripts/version.js: -------------------------------------------------------------------------------- 1 | const { spawn } = require("node:child_process"); 2 | const sysPath = require("node:path"); 3 | const fs = require("node:fs"); 4 | const waterfall = require("async/waterfall"); 5 | const doctoc = require("../src/doctoc"); 6 | 7 | const regexEscape = str => { 8 | return str.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); 9 | }; 10 | 11 | const version = process.env.npm_package_version || require("../package.json").version; 12 | const readme = sysPath.join(__dirname, "..", "README.md"); 13 | 14 | const updateContent = (file, replacer, cb) => { 15 | waterfall([ 16 | next => { 17 | fs.readFile(file, next); 18 | }, 19 | 20 | (buffer, next) => { 21 | const oldContent = buffer.toString(); 22 | const newContent = replacer(oldContent); 23 | 24 | if (newContent === oldContent) { 25 | next(null, false); 26 | return; 27 | } 28 | 29 | fs.writeFile(file, newContent, err => { 30 | next(err, true); 31 | }); 32 | }, 33 | 34 | (hasChanged, next) => { 35 | if (!hasChanged) { 36 | next(null, hasChanged); 37 | return; 38 | } 39 | 40 | const child = spawn("git", ["add", file], { 41 | stdio: "inherit" 42 | }); 43 | 44 | child.on("error", next); 45 | child.on("close", () => { 46 | next(null, hasChanged); 47 | }); 48 | } 49 | ], cb); 50 | }; 51 | 52 | waterfall([ 53 | next => { 54 | const oldContent = fs.readFileSync(readme).toString(); 55 | const pos = oldContent.indexOf("/node-autoit-opencv-com/releases/download/v"); 56 | if (pos === -1) { 57 | next(null, false); 58 | return; 59 | } 60 | 61 | const start = pos + "/node-autoit-opencv-com/releases/download/v".length; 62 | const end = oldContent.indexOf("/", start); 63 | if (end === -1) { 64 | next(null, false); 65 | return; 66 | } 67 | 68 | const oldVersion = oldContent.slice(start, end); 69 | next(null, oldVersion); 70 | }, 71 | 72 | (oldVersion, next) => { 73 | if (!oldVersion) { 74 | next(); 75 | return; 76 | } 77 | 78 | waterfall([ 79 | next => { 80 | updateContent(readme, oldContent => { 81 | const replacer = new RegExp(regexEscape(oldVersion), "g"); 82 | return oldContent.replace(replacer, version); 83 | }, next); 84 | }, 85 | 86 | (hasChanged, next) => { 87 | doctoc.transformAndSave([readme], (err, transformed) => { 88 | if (!transformed) { 89 | next(null, transformed); 90 | return; 91 | } 92 | 93 | const child = spawn("git", ["add", readme], { 94 | stdio: "inherit" 95 | }); 96 | 97 | child.on("error", next); 98 | child.on("close", () => { 99 | next(null, transformed); 100 | }); 101 | 102 | next(err, transformed); 103 | }); 104 | }, 105 | 106 | (hasChanged, next) => { 107 | updateContent(sysPath.join(__dirname, "..", "autoit-opencv-com", "install.bat"), oldContent => { 108 | return oldContent.replace(/VERSION: \S+/, `VERSION: ${ version }`); 109 | }, next); 110 | }, 111 | 112 | (hasChanged, next) => { 113 | updateContent(sysPath.join(__dirname, "..", "autoit-opencv-com", "src", "cvLib.rc"), oldContent => { 114 | const vsversion = version.split(".").join(",").replace(/[^\d,]/g, ""); 115 | return oldContent 116 | .replace(/(FILE|PRODUCT)VERSION \S+/g, `$1VERSION ${ vsversion }`) 117 | .replace(/"(File|Product)Version", "\S+"/g, `"$1Version", "${ version }"`); 118 | }, next); 119 | }, 120 | 121 | (hasChanged, next) => { 122 | updateContent(sysPath.join(__dirname, "..", "autoit-opencv-com", "dotnet", "Properties", "AssemblyInfo.cs"), oldContent => { 123 | return oldContent.replace(/(Assembly|AssemblyFile)Version\("[^"\s*]+"\)/g, `$1Version("${ version }.0")`); 124 | }, next); 125 | }, 126 | ], next); 127 | } 128 | ], err => { 129 | if (err) { 130 | throw err; 131 | } 132 | }); 133 | -------------------------------------------------------------------------------- /src/MidlCompiler.js: -------------------------------------------------------------------------------- 1 | const sysPath = require("node:path"); 2 | const {spawn} = require("node:child_process"); 3 | 4 | const exec = (file, argv, cb) => { 5 | console.log(file, argv.map(arg => (arg.includes(" ") ? `"${ arg }"` : arg)).join(" ")); 6 | const child = spawn(file, argv); 7 | 8 | const stdout = []; 9 | let nout = 0; 10 | const stderr = []; 11 | let nerr = 0; 12 | 13 | child.stdout.on("data", chunk => { 14 | nout += chunk.length; 15 | stdout.push(chunk); 16 | }); 17 | 18 | child.stderr.on("data", chunk => { 19 | nerr += chunk.length; 20 | stderr.push(chunk); 21 | }); 22 | 23 | const next = (err, ...args) => { 24 | if (err) { 25 | if (nout !== 0) { 26 | process.stdout.write(Buffer.concat(stdout, nout)); 27 | } 28 | 29 | if (nerr !== 0) { 30 | process.stderr.write(Buffer.concat(stderr, nerr)); 31 | } 32 | } 33 | 34 | cb(err); 35 | }; 36 | 37 | child.on("error", next); 38 | child.on("close", next); 39 | }; 40 | 41 | exports.compile = (filename, options, cb) => { 42 | const dirname = sysPath.dirname(filename); 43 | const basename = sysPath.basename(filename, ".idl"); 44 | const {includes} = options; 45 | 46 | // https://stackoverflow.com/questions/26302927/midl-changes-the-interface-name 47 | const argv = includes.map(path => `/I${ path }`).concat([ 48 | `/I${ dirname }`, 49 | "/W1", "/nologo", 50 | "/char", "signed", 51 | "/env", "x64", 52 | "/h", `${ basename }.h`, 53 | "/iid", `${ basename }_i.c`, 54 | "/proxy", `${ basename }_p.c`, 55 | "/tlb", `${ basename }.tlb`, 56 | "/target", "NT100", 57 | `/out${ dirname }`, 58 | filename 59 | ]); 60 | 61 | if (options.save === false) { 62 | console.log("midl.exe", argv); 63 | cb(); 64 | return; 65 | } 66 | 67 | exec("midl.exe", argv, cb); 68 | }; 69 | -------------------------------------------------------------------------------- /src/alias.js: -------------------------------------------------------------------------------- 1 | exports.removeNamespaces = (str, options = {}) => { 2 | if (!options.remove_namespaces || options.remove_namespaces.size === 0) { 3 | return str; 4 | } 5 | 6 | const reg = new RegExp(`\\b(?:${ Array.from(options.remove_namespaces).sort((a, b) => b.length - a.length).join("|") })::`, "g"); 7 | 8 | return str.replace(reg, ""); 9 | }; 10 | 11 | const MAX_ARGS = 10; 12 | const EXPANSION_REG = [...Array(MAX_ARGS).keys()].map(i => new RegExp(`\\$(?:${ i }\\b|\\{${ i }\\})`, "g")); 13 | 14 | exports.makeExpansion = (str, ...args) => { 15 | str = str.replace(EXPANSION_REG[0], args.join(", ")); 16 | for (let i = 0; i < args.length && i + 1 < EXPANSION_REG.length; i++) { 17 | str = str.replace(EXPANSION_REG[i + 1], args[i]); 18 | } 19 | return str; 20 | }; 21 | 22 | const useNamspace = (namespaces, namespace) => { 23 | const parts = namespace.split("::"); 24 | for (let i = 0; i < parts.length; i++) { 25 | namespaces.add(`using namespace ${ parts.slice(0, parts.length - i).join("::") };`); 26 | } 27 | }; 28 | 29 | exports.useNamespaces = (body, method, processor, coclass) => { 30 | const namespaces = new Set(); 31 | 32 | if (coclass.namespace) { 33 | // useNamspace(namespaces, coclass.namespace); 34 | namespaces.add(`using namespace ${ coclass.namespace };`); 35 | } 36 | 37 | if (coclass.include && coclass.include.namespace) { 38 | namespaces.add(`using namespace ${ coclass.include.namespace };`); 39 | } 40 | 41 | if (processor.namespace) { 42 | namespaces.add(`using namespace ${ processor.namespace };`); 43 | } 44 | 45 | if (namespaces.size !== 0) { 46 | namespaces.add(""); 47 | } 48 | 49 | body[method](...Array.from(namespaces).sort((a, b) => { 50 | if (a.length === 0) { 51 | return 1; 52 | } 53 | 54 | if (b.length === 0) { 55 | return -1; 56 | } 57 | 58 | const aLen = a.split("::").length; 59 | const bLen = b.split("::").length; 60 | 61 | if (aLen > bLen) { 62 | return -1; 63 | } 64 | 65 | if (aLen < bLen) { 66 | return 1; 67 | } 68 | 69 | return a < b ? -1 : a > b ? 1 : 0; 70 | })); 71 | }; 72 | 73 | exports.getTypeDef = (type, options) => { 74 | let type_def = type 75 | .replace(/\b(u?int(?:8|16|32|64))_t\b/g, "$1") 76 | .replaceAll("std::map", "MapOf") 77 | .replaceAll("std::pair", "PairOf") 78 | .replaceAll("std::vector", "VectorOf") 79 | .replaceAll("std::shared_ptr", "SharedPtrOf") 80 | .replaceAll(options.shared_ptr, "SharedPtrOf") 81 | .replaceAll("std::variant", "VariantOf"); 82 | 83 | type_def = exports.removeNamespaces(type_def, options) 84 | .replace(/\b_variant_t\b/g, "Variant") 85 | .replace(/::/g, "_") 86 | .replace(/\b[a-z]/g, m => m.toUpperCase()) 87 | .replace(/, /g, "And") 88 | .replace(/[<>]/g, ""); 89 | 90 | return type_def; 91 | }; 92 | 93 | const {ALIASES} = require("./constants"); 94 | 95 | exports.getAlias = str => { 96 | str = str.trim(); 97 | return ALIASES.has(str) ? ALIASES.get(str) : str; 98 | }; 99 | -------------------------------------------------------------------------------- /src/conversions/Mat.js: -------------------------------------------------------------------------------- 1 | module.exports = (header = [], impl = [], options = {}) => { 2 | impl.push(` 3 | #include "Cv_Mat_Object.h" 4 | `.trim().replace(/^ {8}/mg, "")); 5 | 6 | impl.push(""); 7 | 8 | for (const args of [ 9 | [ 10 | ["int", "i0", "", []], 11 | ], 12 | [ 13 | ["int", "row", "", []], 14 | ["int", "col", "", []], 15 | ], 16 | [ 17 | ["int", "i0", "", []], 18 | ["int", "i1", "", []], 19 | ["int", "i2", "", []], 20 | ], 21 | [ 22 | ["cv::Point", "pt", "", []], 23 | ], 24 | [ 25 | ["std::vector", "idx", "", ["/Ref", "/C", "/Expr=idx.data()"]] 26 | ], 27 | ]) { 28 | const argdecl = args.map(([argtype, argname]) => `${ argtype === "std::vector" ? "const " : "" }${ argtype }${ argtype !== "int" ? "&" : "" } ${ argname }`).join(", "); 29 | const argexpr = args.map(([, callarg, , arg_modifiers]) => { 30 | for (const modifier of arg_modifiers) { 31 | if (modifier.startsWith("/Expr=")) { 32 | callarg = modifier.slice("/Expr=".length); 33 | } 34 | } 35 | return callarg; 36 | }).join(", "); 37 | 38 | impl.push(` 39 | const cv::Point2d CCv_Mat_Object::Point_at(${ argdecl }, HRESULT& hr) { 40 | using namespace cv; 41 | const auto& m = *__self->get(); 42 | 43 | switch (m.depth()) { 44 | case CV_8U: 45 | return Point2d(m.at(${ argexpr })[0], m.at(${ argexpr })[1]); 46 | case CV_8S: 47 | return Point2d(m.at>(${ argexpr })[0], m.at>(${ argexpr })[1]); 48 | case CV_16U: 49 | return Point2d(m.at(${ argexpr })[0], m.at(${ argexpr })[1]); 50 | case CV_16S: 51 | return Point2d(m.at(${ argexpr })[0], m.at(${ argexpr })[1]); 52 | case CV_32S: 53 | return Point2d(m.at(${ argexpr })[0], m.at(${ argexpr })[1]); 54 | case CV_32F: 55 | return Point2d(m.at(${ argexpr })[0], m.at(${ argexpr })[1]); 56 | case CV_64F: 57 | return Point2d(m.at(${ argexpr })[0], m.at(${ argexpr })[1]); 58 | default: 59 | hr = E_INVALIDARG; 60 | return Point2d(); 61 | } 62 | } 63 | 64 | const double CCv_Mat_Object::at(${ argdecl }, HRESULT& hr) { 65 | const auto& m = *__self->get(); 66 | 67 | switch (m.depth()) { 68 | case CV_8U: 69 | return m.at(${ argexpr }); 70 | case CV_8S: 71 | return m.at(${ argexpr }); 72 | case CV_16U: 73 | return m.at(${ argexpr }); 74 | case CV_16S: 75 | return m.at(${ argexpr }); 76 | case CV_32S: 77 | return m.at(${ argexpr }); 78 | case CV_32F: 79 | return m.at(${ argexpr }); 80 | case CV_64F: 81 | return m.at(${ argexpr }); 82 | default: 83 | hr = E_INVALIDARG; 84 | return 0; 85 | } 86 | } 87 | 88 | void CCv_Mat_Object::set_at(${ argdecl }, double value, HRESULT& hr) { 89 | auto& m = *__self->get(); 90 | 91 | switch (m.depth()) { 92 | case CV_8U: 93 | m.at(${ argexpr }) = static_cast(value); 94 | break; 95 | case CV_8S: 96 | m.at(${ argexpr }) = static_cast(value); 97 | break; 98 | case CV_16U: 99 | m.at(${ argexpr }) = static_cast(value); 100 | break; 101 | case CV_16S: 102 | m.at(${ argexpr }) = static_cast(value); 103 | break; 104 | case CV_32S: 105 | m.at(${ argexpr }) = static_cast(value); 106 | break; 107 | case CV_32F: 108 | m.at(${ argexpr }) = static_cast(value); 109 | break; 110 | case CV_64F: 111 | m.at(${ argexpr }) = value; 112 | break; 113 | default: 114 | hr = E_INVALIDARG; 115 | } 116 | } 117 | 118 | `.trim().replace(/^ {12}/mg, ""), ""); 119 | } 120 | 121 | return [header.join("\n"), impl.join("\n")]; 122 | }; 123 | -------------------------------------------------------------------------------- /src/conversions/point.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-magic-numbers */ 2 | 3 | const optional = require("../optional_conversion"); 4 | 5 | module.exports = (header = [], impl = [], options = {}) => { 6 | header.push(` 7 | template 8 | const bool is_assignable_from(cv::Point_<_Tp>& out_val, VARIANT const* const& in_val, bool is_optional) { 9 | ${ optional.check.join(`\n${ " ".repeat(12) }`) } 10 | 11 | if ((V_VT(in_val) & VT_ARRAY) != VT_ARRAY || (V_VT(in_val) ^ VT_ARRAY) != VT_VARIANT) { 12 | return false; 13 | } 14 | 15 | HRESULT hr = S_OK; 16 | 17 | typename ATL::template CComSafeArray vArray; 18 | vArray.Attach(V_ARRAY(in_val)); 19 | 20 | LONG lLower = vArray.GetLowerBound(); 21 | LONG lUpper = vArray.GetUpperBound(); 22 | 23 | if (lUpper - lLower >= 2) { 24 | vArray.Detach(); 25 | return false; 26 | } 27 | 28 | _Tp value; 29 | 30 | for (LONG i = lLower; i <= lUpper; i++) { 31 | auto& v = vArray.GetAt(i); 32 | VARIANT *pv = &v; 33 | if (!is_assignable_from(value, pv, false)) { 34 | hr = E_INVALIDARG; 35 | break; 36 | } 37 | } 38 | 39 | vArray.Detach(); 40 | return SUCCEEDED(hr); 41 | } 42 | 43 | template 44 | inline const bool is_assignable_from(AUTOIT_PTR>& out_val, VARIANT const* const& in_val, bool is_optional) { 45 | static cv::Point_<_Tp> tmp; 46 | return is_assignable_from(tmp, in_val, is_optional); 47 | } 48 | 49 | template 50 | const HRESULT autoit_to(VARIANT const* const& in_val, cv::Point_<_Tp>& out_val) { 51 | ${ optional.assign.join(`\n${ " ".repeat(12) }`) } 52 | 53 | if ((V_VT(in_val) & VT_ARRAY) != VT_ARRAY || (V_VT(in_val) ^ VT_ARRAY) != VT_VARIANT) { 54 | return E_INVALIDARG; 55 | } 56 | 57 | HRESULT hr = S_OK; 58 | 59 | typename ATL::template CComSafeArray vArray; 60 | vArray.Attach(V_ARRAY(in_val)); 61 | 62 | LONG lLower = vArray.GetLowerBound(); 63 | LONG lUpper = vArray.GetUpperBound(); 64 | 65 | if (lUpper - lLower >= 2) { 66 | vArray.Detach(); 67 | return E_INVALIDARG; 68 | } 69 | 70 | _Tp value; 71 | 72 | for (LONG i = lLower; i <= lUpper; i++) { 73 | auto& v = vArray.GetAt(i); 74 | VARIANT *pv = &v; 75 | hr = autoit_to(pv, value); 76 | if (FAILED(hr)) { 77 | break; 78 | } 79 | 80 | switch (i) { 81 | case 0: 82 | out_val.x = value; 83 | break; 84 | case 1: 85 | out_val.y = value; 86 | break; 87 | } 88 | } 89 | 90 | vArray.Detach(); 91 | return hr; 92 | } 93 | 94 | template 95 | inline const HRESULT autoit_to(VARIANT const* const& in_val, AUTOIT_PTR>& out_val) { 96 | out_val = ${ options.make_shared }>(); 97 | return autoit_to(in_val, *out_val.get()); 98 | } 99 | 100 | template 101 | const HRESULT autoit_from(const cv::Point_<_Tp>& in_val, VARIANT*& out_val) { 102 | if (${ optional.condition("out_val") }) { 103 | V_VT(out_val) = VT_ARRAY | VT_VARIANT; 104 | typename ATL::template CComSafeArray vArray((ULONG) 2); 105 | V_ARRAY(out_val) = vArray.Detach(); 106 | } 107 | 108 | if ((V_VT(out_val) & VT_ARRAY) != VT_ARRAY || (V_VT(out_val) ^ VT_ARRAY) != VT_VARIANT) { 109 | return E_INVALIDARG; 110 | } 111 | 112 | HRESULT hr = S_OK; 113 | 114 | typename ATL::template CComSafeArray vArray; 115 | vArray.Attach(V_ARRAY(out_val)); 116 | vArray.Resize(2); 117 | 118 | for (LONG i = 0; i < 2; i++) { 119 | VARIANT value = { VT_EMPTY }; 120 | auto *pvalue = &value; 121 | 122 | switch (i) { 123 | case 0: 124 | hr = autoit_from(in_val.x, pvalue); 125 | break; 126 | case 1: 127 | hr = autoit_from(in_val.y, pvalue); 128 | break; 129 | } 130 | 131 | if (FAILED(hr)) { 132 | AUTOIT_ERROR("Failed to get value a index " << i); 133 | VariantClear(&value); 134 | break; 135 | } 136 | 137 | hr = vArray.SetAt(i, value); 138 | if (FAILED(hr)) { 139 | AUTOIT_ERROR("Failed to set value a index " << i); 140 | VariantClear(&value); 141 | break; 142 | } 143 | 144 | VariantClear(&value); 145 | } 146 | 147 | vArray.Detach(); 148 | return hr; 149 | } 150 | `.replace(/^ {8}/mg, "") 151 | ); 152 | 153 | return [header.join("\n"), impl.join("\n")]; 154 | }; 155 | -------------------------------------------------------------------------------- /src/conversions/size.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-magic-numbers */ 2 | 3 | const optional = require("../optional_conversion"); 4 | 5 | module.exports = (header = [], impl = [], options = {}) => { 6 | header.push(` 7 | template 8 | const bool is_assignable_from(cv::Size_<_Tp>& out_val, VARIANT const* const& in_val, bool is_optional) { 9 | ${ optional.check.join(`\n${ " ".repeat(12) }`) } 10 | 11 | if ((V_VT(in_val) & VT_ARRAY) != VT_ARRAY || (V_VT(in_val) ^ VT_ARRAY) != VT_VARIANT) { 12 | return false; 13 | } 14 | 15 | HRESULT hr = S_OK; 16 | 17 | typename ATL::template CComSafeArray vArray; 18 | vArray.Attach(V_ARRAY(in_val)); 19 | 20 | LONG lLower = vArray.GetLowerBound(); 21 | LONG lUpper = vArray.GetUpperBound(); 22 | 23 | if (lUpper - lLower >= 2) { 24 | vArray.Detach(); 25 | return false; 26 | } 27 | 28 | _Tp value; 29 | 30 | for (LONG i = lLower; i <= lUpper; i++) { 31 | auto& v = vArray.GetAt(i); 32 | VARIANT *pv = &v; 33 | if (!is_assignable_from(value, pv, false)) { 34 | hr = E_INVALIDARG; 35 | break; 36 | } 37 | } 38 | 39 | vArray.Detach(); 40 | return SUCCEEDED(hr); 41 | } 42 | 43 | template 44 | inline const bool is_assignable_from(AUTOIT_PTR>& out_val, VARIANT const* const& in_val, bool is_optional) { 45 | static cv::Size_<_Tp> tmp; 46 | return is_assignable_from(tmp, in_val, is_optional); 47 | } 48 | 49 | template 50 | const HRESULT autoit_to(VARIANT const* const& in_val, cv::Size_<_Tp>& out_val) { 51 | ${ optional.assign.join(`\n${ " ".repeat(12) }`) } 52 | 53 | if ((V_VT(in_val) & VT_ARRAY) != VT_ARRAY || (V_VT(in_val) ^ VT_ARRAY) != VT_VARIANT) { 54 | return E_INVALIDARG; 55 | } 56 | 57 | HRESULT hr = S_OK; 58 | 59 | typename ATL::template CComSafeArray vArray; 60 | vArray.Attach(V_ARRAY(in_val)); 61 | 62 | LONG lLower = vArray.GetLowerBound(); 63 | LONG lUpper = vArray.GetUpperBound(); 64 | 65 | if (lUpper - lLower >= 2) { 66 | vArray.Detach(); 67 | return E_INVALIDARG; 68 | } 69 | 70 | _Tp value; 71 | 72 | for (LONG i = lLower; i <= lUpper; i++) { 73 | auto& v = vArray.GetAt(i); 74 | VARIANT *pv = &v; 75 | hr = autoit_to(pv, value); 76 | if (FAILED(hr)) { 77 | break; 78 | } 79 | 80 | switch (i) { 81 | case 0: 82 | out_val.width = value; 83 | break; 84 | case 1: 85 | out_val.height = value; 86 | break; 87 | } 88 | } 89 | 90 | vArray.Detach(); 91 | return hr; 92 | } 93 | 94 | template 95 | inline const HRESULT autoit_to(VARIANT const* const& in_val, AUTOIT_PTR>& out_val) { 96 | out_val = ${ options.make_shared }>(); 97 | return autoit_to(in_val, *out_val.get()); 98 | } 99 | 100 | template 101 | const HRESULT autoit_from(const cv::Size_<_Tp>& in_val, VARIANT*& out_val) { 102 | if (${ optional.condition("out_val") }) { 103 | V_VT(out_val) = VT_ARRAY | VT_VARIANT; 104 | typename ATL::template CComSafeArray vArray((ULONG) 2); 105 | V_ARRAY(out_val) = vArray.Detach(); 106 | } 107 | 108 | if ((V_VT(out_val) & VT_ARRAY) != VT_ARRAY || (V_VT(out_val) ^ VT_ARRAY) != VT_VARIANT) { 109 | return E_INVALIDARG; 110 | } 111 | 112 | HRESULT hr = S_OK; 113 | 114 | typename ATL::template CComSafeArray vArray; 115 | vArray.Attach(V_ARRAY(out_val)); 116 | vArray.Resize(2); 117 | 118 | for (LONG i = 0; i < 2; i++) { 119 | VARIANT value = { VT_EMPTY }; 120 | auto *pvalue = &value; 121 | 122 | switch (i) { 123 | case 0: 124 | hr = autoit_from(in_val.width, pvalue); 125 | break; 126 | case 1: 127 | hr = autoit_from(in_val.height, pvalue); 128 | break; 129 | } 130 | 131 | if (FAILED(hr)) { 132 | AUTOIT_ERROR("Failed to get value a index " << i); 133 | VariantClear(&value); 134 | break; 135 | } 136 | 137 | hr = vArray.SetAt(i, value); 138 | if (FAILED(hr)) { 139 | AUTOIT_ERROR("Failed to set value a index " << i); 140 | VariantClear(&value); 141 | break; 142 | } 143 | 144 | VariantClear(&value); 145 | } 146 | 147 | vArray.Detach(); 148 | return hr; 149 | } 150 | `.replace(/^ {8}/mg, "") 151 | ); 152 | 153 | return [header.join("\n"), impl.join("\n")]; 154 | }; 155 | -------------------------------------------------------------------------------- /src/custom_conversions.js: -------------------------------------------------------------------------------- 1 | const fs = require("node:fs"); 2 | const sysPath = require("node:path"); 3 | 4 | const files = fs.readdirSync(sysPath.join(__dirname, "conversions")); 5 | 6 | const conversions = []; 7 | 8 | for (const file of files) { 9 | conversions.push(require(sysPath.join(__dirname, "conversions", file))); 10 | } 11 | 12 | module.exports = conversions; 13 | -------------------------------------------------------------------------------- /src/custom_declarations.js: -------------------------------------------------------------------------------- 1 | const fs = require("node:fs"); 2 | const sysPath = require("node:path"); 3 | 4 | const files = fs.existsSync(sysPath.join(__dirname, "declarations")) ? fs.readdirSync(sysPath.join(__dirname, "declarations")) : []; 5 | const default_declarations = []; 6 | 7 | exports.push = (...declarations) => { 8 | default_declarations.push(...declarations); 9 | }; 10 | 11 | exports.load = options => { 12 | const declarations = [...default_declarations]; 13 | 14 | for (const file of files) { 15 | let decls = require(sysPath.join(__dirname, "declarations", file)); 16 | if (typeof decls === "function") { 17 | decls = decls(options); 18 | } 19 | declarations.push(...decls); 20 | } 21 | 22 | return declarations; 23 | }; 24 | -------------------------------------------------------------------------------- /src/declarations/HostMem.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | ["cv.cuda.HostMem.HostMem", "", [], [ 3 | ["HostMem", "m", "", []] 4 | ], "", ""], 5 | ]; 6 | -------------------------------------------------------------------------------- /src/declarations/Matx.js: -------------------------------------------------------------------------------- 1 | const Matx = (type, m, n) => { 2 | const fqn = `cv.Matx${ m }${ n }${ type[0] }`; 3 | const name = fqn.slice(fqn.lastIndexOf(".") + 1); 4 | const cpptype = fqn.replaceAll(".", "::"); 5 | 6 | const declarations = [ 7 | [`class ${ fqn }`, "", ["/Simple"], [ 8 | ["int", "rows", "", ["/R", "/S"]], 9 | ["int", "cols", "", ["/R", "/S"]], 10 | ["int", "channels", "", ["/R", "/S"]], 11 | ["int", "shortdim", "", ["/R", "/S"]], 12 | ], "", ""], 13 | 14 | //! default constructor 15 | [`${ fqn }.${ name }`, "", [], [], "", ""], 16 | 17 | [`${ fqn }.all`, cpptype, ["/S"], [ 18 | [type, "alpha", "", []], 19 | ], "", ""], 20 | 21 | [`${ fqn }.zeros`, cpptype, ["/S"], [], "", ""], 22 | [`${ fqn }.ones`, cpptype, ["/S"], [], "", ""], 23 | [`${ fqn }.eye`, cpptype, ["/S"], [], "", ""], 24 | 25 | [`${ fqn }.randu`, cpptype, ["/S"], [ 26 | [type, "a", "", []], 27 | [type, "b", "", []], 28 | ], "", ""], 29 | 30 | [`${ fqn }.randn`, cpptype, ["/S"], [ 31 | [type, "a", "", []], 32 | [type, "b", "", []], 33 | ], "", ""], 34 | 35 | [`${ fqn }.dot`, type, [], [ 36 | [cpptype, "v", "", ["/Ref"]], 37 | ], "", ""], 38 | 39 | [`${ fqn }.ddot`, "double", [], [ 40 | [cpptype, "v", "", ["/Ref"]], 41 | ], "", ""], 42 | 43 | [`${ fqn }.mul`, cpptype, [], [ 44 | [cpptype, "a", "", ["/Ref"]], 45 | ], "", ""], 46 | 47 | [`${ fqn }.div`, cpptype, [], [ 48 | [cpptype, "a", "", ["/Ref"]], 49 | ], "", ""], 50 | ]; 51 | 52 | const argdecl = [ 53 | [ 54 | ["int", "row", "", []], 55 | ["int", "col", "", []], 56 | ] 57 | ]; 58 | 59 | if (m === 1 || n === 1) { 60 | argdecl.unshift([ 61 | ["int", "i", "", []], 62 | ]); 63 | } 64 | 65 | for (const args of argdecl) { 66 | const argexpr = args.map(([, argname]) => argname).join(", "); 67 | 68 | declarations.push(...[ 69 | [`${ fqn }.operator()`, type, ["/attr=propget", "=get_Item", "/idlname=Item", "/id=DISPID_VALUE"], args, "", ""], 70 | [`${ fqn }.operator()`, "void", ["/attr=propput", "=put_Item", "/idlname=Item", "/id=DISPID_VALUE", `/Expr=${ argexpr }) = (value`], args.concat([[type, "value", "", []]]), "", ""], 71 | ]); 72 | } 73 | 74 | return declarations; 75 | }; 76 | 77 | const declarations = []; 78 | 79 | for (const [m, n] of [ 80 | [1, 2], 81 | [1, 3], 82 | [1, 4], 83 | [1, 6], 84 | [2, 1], 85 | [3, 1], 86 | [4, 1], 87 | [6, 1], 88 | [2, 2], 89 | [2, 3], 90 | [3, 2], 91 | [3, 3], 92 | [3, 4], 93 | [4, 3], 94 | [4, 4], 95 | [6, 6], 96 | ]) { 97 | for (const type of ["float", "double"]) { 98 | declarations.push(...Matx(type, m, n)); 99 | } 100 | } 101 | 102 | module.exports = declarations; 103 | -------------------------------------------------------------------------------- /src/declarations/RNG.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | ["class cv.RNG", "", ["/Simple", "/Ptr"], [ 3 | ["uint64", "state", "", ["/RW"]], 4 | ], "", ""], 5 | ["cv.RNG.RNG", "", [], [], "", ""], 6 | ["cv.RNG.RNG", "", [], [ 7 | ["uint64", "state", "", []] 8 | ], "", ""], 9 | ["cv.RNG.fill", "void", [], [ 10 | ["InputOutputArray", "mat", "", []], 11 | ["int", "distType", "", []], 12 | ["InputArray", "a", "", []], 13 | ["InputArray", "b", "", []], 14 | ["bool", "saturateRange", "false", []], 15 | ], "", ""], 16 | ["cv.RNG.gaussian", "double", [], [ 17 | ["double", "sigma", "", []], 18 | ], "", ""], 19 | ["cv.RNG.next", "uint", [], [], "", ""], 20 | ["cv.RNG.uniform", "int", ["=uniform_int"], [ 21 | ["int", "a", "", []], 22 | ["int", "b", "", []], 23 | ], "", ""], 24 | ["cv.RNG.uniform", "float", ["=uniform_float"], [ 25 | ["float", "a", "", []], 26 | ["float", "b", "", []], 27 | ], "", ""], 28 | ["cv.RNG.uniform", "double", [], [ 29 | ["double", "a", "", []], 30 | ["double", "b", "", []], 31 | ], "", ""], 32 | ["cv.theRNG", "cv::Ptr", ["/Ref", "/WrapAs=::autoit::reference_internal"], [], "", ""], 33 | ]; 34 | -------------------------------------------------------------------------------- /src/declarations/Range.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | ["class cv.Range", "", ["/Simple"], [ 3 | ["int", "start", "", ["/RW"]], 4 | ["int", "end", "", ["/RW"]], 5 | ], "", ""], 6 | 7 | ["cv.Range.Range", "", [], [], "", ""], 8 | 9 | ["cv.Range.Range", "", [], [ 10 | ["int", "start", "", []], 11 | ["int", "end", "", []], 12 | ], "", ""], 13 | 14 | ["cv.Range.size", "int", [], [], "", ""], 15 | ["cv.Range.empty", "bool", [], [], "", ""], 16 | 17 | ["cv.Range.all", "Range", ["/S"], [], "", ""], 18 | ]; 19 | -------------------------------------------------------------------------------- /src/declarations/RotatedRect.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | ["class cv.RotatedRect", "", ["/Simple"], [ 3 | ["Point2f", "center", "", ["/RW"]], 4 | ["Size2f", "size", "", ["/RW"]], 5 | ["float", "angle", "", ["/RW"]], 6 | ], "", ""], 7 | 8 | ["cv.RotatedRect.RotatedRect", "", [], [], "", ""], 9 | 10 | ["cv.RotatedRect.RotatedRect", "", [], [ 11 | ["Point2f", "center", "", []], 12 | ["Size2f", "size", "", []], 13 | ["float", "angle", "", []], 14 | ], "", ""], 15 | 16 | ["cv.RotatedRect.RotatedRect", "", [], [ 17 | ["Point2f", "point1", "", []], 18 | ["Point2f", "point2", "", []], 19 | ["Point2f", "point3", "", []], 20 | ], "", ""], 21 | 22 | ["cv.RotatedRect.boundingRect", "Rect", [], [], "", ""], 23 | 24 | ]; 25 | -------------------------------------------------------------------------------- /src/declarations/TermCriteria.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | ["class cv.TermCriteria", "", ["/Simple", "/DC"], [ 3 | ["int", "type", "", ["/RW"]], 4 | ["int", "maxCount", "", ["/RW"]], 5 | ["double", "epsilon", "", ["/RW"]], 6 | ], "", ""], 7 | 8 | ["cv.TermCriteria.TermCriteria", "", [], [], "", ""], 9 | 10 | ["cv.TermCriteria.TermCriteria", "", [], [ 11 | ["int", "type", "", []], 12 | ["int", "maxCount", "", []], 13 | ["double", "epsilon", "", []], 14 | ], "", ""], 15 | ]; 16 | -------------------------------------------------------------------------------- /src/declarations/mutex.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | ["class std.mutex", "", [], [], "", ""], 3 | ["std.mutex.mutex", "", [], [], "", ""], 4 | ["std.mutex.lock", "void", [], [], "", ""], 5 | ["std.mutex.try_lock", "bool", [], [], "", ""], 6 | ["std.mutex.unlock", "void", [], [], "", ""], 7 | 8 | ["class std.timed_mutex", "", [], [], "", ""], 9 | ["std.timed_mutex.timed_mutex", "", [], [], "", ""], 10 | ["std.timed_mutex.lock", "void", [], [], "", ""], 11 | ["std.timed_mutex.try_lock", "bool", [], [], "", ""], 12 | ["std.timed_mutex.try_lock_for", "bool", [], [ 13 | ["int", "duration", "", ["/Cast=std::chrono::milliseconds"]], 14 | ], "", ""], 15 | ["std.timed_mutex.unlock", "void", [], [], "", ""], 16 | ]; 17 | -------------------------------------------------------------------------------- /src/declarations/structures.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | ["struct cv.GCompileArg", "", ["/Simple"], [], "", ""], 3 | ["struct cv.GRunArg", "", ["/Simple"], [], "", ""], 4 | ]; 5 | -------------------------------------------------------------------------------- /src/dependencies.js: -------------------------------------------------------------------------------- 1 | const orderDependencies = (_dependencies, _dependents, result = []) => { 2 | const stack = []; 3 | 4 | for (const fqn of _dependencies.keys()) { 5 | if (_dependencies.get(fqn).size === 0) { 6 | stack.push(fqn); 7 | _dependencies.delete(fqn); 8 | } 9 | } 10 | 11 | while (stack.length !== 0) { 12 | const fqn = stack.shift(); 13 | 14 | result.push(fqn); 15 | 16 | if (!_dependents.has(fqn)) { 17 | continue; 18 | } 19 | 20 | for (const dependent of _dependents.get(fqn)) { 21 | const dependencies = _dependencies.get(dependent); 22 | dependencies.delete(fqn); 23 | 24 | if (dependencies.size === 0) { 25 | stack.push(dependent); 26 | _dependencies.delete(dependent); 27 | } 28 | } 29 | 30 | _dependents.delete(fqn); 31 | } 32 | 33 | processCircular(_dependencies, _dependents, result); // eslint-disable-line no-use-before-define 34 | 35 | for (const fqn of _dependencies.keys()) { 36 | result.push(fqn); 37 | _dependencies.delete(fqn); 38 | _dependents.delete(fqn); 39 | } 40 | 41 | return result; 42 | }; 43 | 44 | const processCircular = (_dependencies, _dependents, result) => { 45 | let size = 0; 46 | while (_dependencies.size !== size) { 47 | size = _dependencies.size; 48 | for (const fqn of _dependencies.keys()) { 49 | disjoin(_dependencies, _dependents, result, fqn); // eslint-disable-line no-use-before-define 50 | } 51 | } 52 | }; 53 | 54 | const disjoin = (_dependencies, _dependents, result, node) => { 55 | const nodes = new Set(); 56 | walk(_dependencies, _dependents, nodes, node); // eslint-disable-line no-use-before-define 57 | if (nodes.size === _dependencies.size) { 58 | return; 59 | } 60 | 61 | const _new_dependencies = new Map(); 62 | const _new_dependents = new Map(); 63 | 64 | for (const fqn of nodes) { 65 | _new_dependencies.set(fqn, new Set()); 66 | _new_dependents.set(fqn, new Set()); 67 | } 68 | 69 | for (const fqn of nodes) { 70 | for (const other of _dependencies.get(fqn)) { 71 | _new_dependencies.get(fqn).add(other); 72 | _new_dependents.get(other).add(fqn); 73 | } 74 | 75 | if (!_dependents.has(fqn)) { 76 | continue; 77 | } 78 | 79 | for (const other of _dependents.get(fqn)) { 80 | if (nodes.has(other)) { 81 | _new_dependencies.get(other).add(fqn); 82 | _new_dependents.get(fqn).add(other); 83 | } else { 84 | _dependencies.get(other).delete(fqn); 85 | } 86 | } 87 | } 88 | 89 | for (const fqn of nodes) { 90 | _dependencies.delete(fqn); 91 | _dependents.delete(fqn); 92 | } 93 | 94 | orderDependencies(_new_dependencies, _new_dependents, result); 95 | }; 96 | 97 | /** 98 | * walk until already encountered of no dependencies 99 | * @param {[type]} _dependencies [description] 100 | * @param {[type]} _dependents [description] 101 | * @param {[type]} nodes [description] 102 | * @param {[type]} fqn [description] 103 | * @return {[type]} [description] 104 | */ 105 | const walk = (_dependencies, _dependents, nodes, node) => { 106 | if (nodes.has(node)) { 107 | return; 108 | } 109 | nodes.add(node); 110 | 111 | for (const next of _dependencies.get(node)) { 112 | walk(_dependencies, _dependents, nodes, next); 113 | } 114 | }; 115 | 116 | exports.orderDependencies = orderDependencies; 117 | -------------------------------------------------------------------------------- /src/doctoc.js: -------------------------------------------------------------------------------- 1 | const fs = require("node:fs"); 2 | const cpus = require("node:os").cpus().length; 3 | const transform = require("doctoc/lib/transform"); 4 | const eachOfLimit = require("async/eachOfLimit"); 5 | const waterfall = require("async/waterfall"); 6 | 7 | exports.modes = { 8 | bitbucket: "bitbucket.org", 9 | nodejs: "nodejs.org", 10 | github: "github.com", 11 | gitlab: "gitlab.com", 12 | ghost: "ghost.org" 13 | }; 14 | 15 | exports.transformAndSave = (files, cb, mode = exports.modes.github, maxHeaderLevel = undefined, title = undefined, notitle = false, entryPrefix = "-", processAll = false, stdOut = false, updateOnly = false) => { 16 | if (processAll) { 17 | console.log("--all flag is enabled. Including headers before the TOC location."); 18 | } 19 | 20 | if (updateOnly) { 21 | console.log("--update-only flag is enabled. Only updating files that already have a TOC."); 22 | } 23 | 24 | eachOfLimit(files, stdOut ? 1 : cpus, (file, i, next) => { 25 | console.log("DocToccing file \"%s\" for %s.", file, mode); 26 | 27 | waterfall([ 28 | next => { 29 | fs.readFile(file, next); 30 | }, 31 | 32 | (buffer, next) => { 33 | const content = buffer.toString(); 34 | const result = transform(content, mode, maxHeaderLevel, title, notitle, entryPrefix, processAll, updateOnly); 35 | const shouldUpdate = result.transformed && content !== result.data; 36 | 37 | if (stdOut) { 38 | console.log(result.toc); 39 | if (shouldUpdate) { 40 | console.log("==================\n\n\"%s\" should be updated", file); 41 | } 42 | next(null, result.transformed); 43 | return; 44 | } 45 | 46 | if (shouldUpdate) { 47 | console.log("\"%s\" will be updated", file); 48 | fs.writeFile(file, result.data, err => { 49 | next(err, true); 50 | }); 51 | return; 52 | } 53 | 54 | console.log("\"%s\" is up to date", file); 55 | next(null, false); 56 | } 57 | ], next); 58 | }, cb); 59 | }; 60 | -------------------------------------------------------------------------------- /src/optional_conversion.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-magic-numbers */ 2 | 3 | exports.check = ` 4 | if (PARAMETER_MISSING(in_val)) { 5 | return is_optional; 6 | } 7 | `.replace(/^ {4}/mg, "").trim().split("\n"); 8 | 9 | exports.assign = ` 10 | if (PARAMETER_MISSING(in_val)) { 11 | return S_OK; 12 | } 13 | `.replace(/^ {4}/mg, "").trim().split("\n"); 14 | 15 | exports.condition = value => { 16 | return `PARAMETER_MISSING(${ value })`; 17 | }; 18 | --------------------------------------------------------------------------------