Skip to content

Commit

Permalink
refactor powershell examples
Browse files Browse the repository at this point in the history
  • Loading branch information
smbape committed Dec 18, 2022
1 parent bda50b7 commit 4c8c265
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 434 deletions.
24 changes: 15 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,21 +122,27 @@ EndFunc ;==>_OnAutoItExit
### PowerShell

```powershell
# Opencv bin dir must be in your path and you must have registered the autoit_opencv_com460.dll dll
#requires -version 5.0
function _OpenCV_ObjCreate($sClassname) {
New-Object -ComObject "OpenCV.$sClassname"
}
Import-Module .\autoit-opencv-com\dotnet\opencv_utils.psm1
function Example1() {
$cv = _OpenCV_ObjCreate("cv")
$img = $cv.imread("samples\data\lena.jpg")
$cv.imshow("image", $img)
function Example() {
$cv = [OpenCvComInterop]::ObjCreate("cv")
$img = $cv.imread(( _OpenCV_FindFile "samples\data\lena.jpg" ))
$cv.imshow("Image", $img)
$cv.waitKey() | Out-Null
$cv.destroyAllWindows()
}
Example1
[OpenCvComInterop]::DllOpen("opencv-4.6.0-vc14_vc15\opencv\build\x64\vc15\bin\opencv_world460.dll", "autoit-opencv-com\autoit_opencv_com460.dll")
[OpenCvComInterop]::Register()
Example
[OpenCvComInterop]::Unregister()
[OpenCvComInterop]::DllClose()
```

## Running examples
Expand Down
30 changes: 26 additions & 4 deletions autoit-opencv-com/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,13 @@ target_precompile_headers(${PROJECT_NAME} PRIVATE
target_link_libraries(${PROJECT_NAME} ${OpenCV_LIBS})

set(OpenCV_DLLVERSION "${OpenCV_VERSION_MAJOR}${OpenCV_VERSION_MINOR}${OpenCV_VERSION_PATCH}")
set(OpenCV_DEBUG_POSTFIX d)
set(DEBUG_POSTFIX d)

set_target_properties(${PROJECT_NAME} PROPERTIES
OUTPUT_NAME "${PROJECT_NAME}${OpenCV_DLLVERSION}"
DEBUG_POSTFIX "${OpenCV_DEBUG_POSTFIX}"
DEBUG_POSTFIX "${DEBUG_POSTFIX}"
COMPILE_PDB_NAME "${PROJECT_NAME}${OpenCV_DLLVERSION}"
COMPILE_PDB_NAME_DEBUG "${PROJECT_NAME}${OpenCV_DLLVERSION}${OpenCV_DEBUG_POSTFIX}"
COMPILE_PDB_NAME_DEBUG "${PROJECT_NAME}${OpenCV_DLLVERSION}${DEBUG_POSTFIX}"
VS_DEBUGGER_ENVIRONMENT "PATH=${OpenCV_BINARY_DIR};%PATH%"
)

Expand Down Expand Up @@ -210,15 +210,36 @@ IF ((WIN32) AND CMAKE_GENERATOR STREQUAL Ninja)
target_compile_definitions(cpp_test PRIVATE _WINDOWS)
ENDIF()

if (CMAKE_GENERATOR MATCHES "Visual Studio")
# ===============
# C# Interop target
# ===============
include(CSharpUtilities)
enable_language(CSharp)

file(GLOB cs_files "dotnet/*.cs")
add_library(interop_opencv SHARED ${cs_files})

set_target_properties(interop_opencv PROPERTIES
OUTPUT_NAME "interop.opencv-${OpenCV_VERSION_MAJOR}"
DEBUG_POSTFIX "${DEBUG_POSTFIX}"
VS_DOTNET_REFERENCES "Microsoft.CSharp;System"
)

foreach( BUILD_TYPE ${CMAKE_CONFIGURATION_TYPES} )
string( TOUPPER ${BUILD_TYPE} BUILD_TYPE_UPPER )
set_target_properties(interop_opencv PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${BUILD_TYPE_UPPER} "${CMAKE_BINARY_DIR}/${BUILD_TYPE}/dotnet")
endforeach()

# ===============
# cs_test target
# ===============
if (CMAKE_GENERATOR MATCHES "Visual Studio")
include(CSharpUtilities)
enable_language(CSharp)

file(GLOB test_files "test/*.cs")
add_executable(cs_test ${test_files})
target_link_libraries(cs_test interop_opencv)

get_filename_component(OPENCV_SAMPLES_DATA_PATH "../samples/data" REALPATH)
file(TO_NATIVE_PATH "${OPENCV_SAMPLES_DATA_PATH}" OPENCV_SAMPLES_DATA_PATH)
Expand All @@ -228,4 +249,5 @@ set_target_properties(cs_test PROPERTIES
VS_DOTNET_REFERENCES "Microsoft.CSharp;System"
)
# set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT cs_test)

endif()
File renamed without changes.
8 changes: 4 additions & 4 deletions samples/dotnet/01-show-image.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ $ErrorActionPreference = "Stop"
Set-StrictMode -Version 3.0
trap { throw $Error[0] }

Import-Module "$PSScriptRoot\opencv_utils.psm1"
Import-Module "$PSScriptRoot\opencv_utils.psm1" -ArgumentList $BuildType

$BuildType = if ($BuildType -eq "Debug") { "Debug" } else { "RelWithDebInfo" }

$OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL "opencv_world4*" "opencv-4.*\opencv" -BuildType $BuildType } else { $OpenCVWorldDll }
$OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL "autoit_opencv_com4*" -BuildType $BuildType } else { $OpenCVComDll }
$Image = if ([string]::IsNullOrEmpty($Image)) { _OpenCV_FindFile "samples\data\lena.jpg" } else { $Image }
$OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL -Path "opencv_world4*" -Filter "opencv-4.*\opencv" -BuildType $BuildType } else { $OpenCVWorldDll }
$OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL -Path "autoit_opencv_com4*" -BuildType $BuildType } else { $OpenCVComDll }
$Image = if ([string]::IsNullOrEmpty($Image)) { _OpenCV_FindFile -Path "samples\data\lena.jpg" } else { $Image }

function Example() {
$cv = [OpenCvComInterop]::ObjCreate("cv")
Expand Down
6 changes: 3 additions & 3 deletions samples/dotnet/02-video-capture-camera.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ $ErrorActionPreference = "Stop"
Set-StrictMode -Version 3.0
trap { throw $Error[0] }

Import-Module "$PSScriptRoot\opencv_utils.psm1"
Import-Module "$PSScriptRoot\opencv_utils.psm1" -ArgumentList $BuildType

$BuildType = if ($BuildType -eq "Debug") { "Debug" } else { "RelWithDebInfo" }

$OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL "opencv_world4*" "opencv-4.*\opencv" -BuildType $BuildType } else { $OpenCVWorldDll }
$OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL "autoit_opencv_com4*" -BuildType $BuildType } else { $OpenCVComDll }
$OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL -Path "opencv_world4*" -Filter "opencv-4.*\opencv" -BuildType $BuildType } else { $OpenCVWorldDll }
$OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL -Path "autoit_opencv_com4*" -BuildType $BuildType } else { $OpenCVComDll }

function Example() {
$cv = [OpenCvComInterop]::ObjCreate("cv")
Expand Down
8 changes: 4 additions & 4 deletions samples/dotnet/03-video-capture-file.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ $ErrorActionPreference = "Stop"
Set-StrictMode -Version 3.0
trap { throw $Error[0] }

Import-Module "$PSScriptRoot\opencv_utils.psm1"
Import-Module "$PSScriptRoot\opencv_utils.psm1" -ArgumentList $BuildType

$BuildType = if ($BuildType -eq "Debug") { "Debug" } else { "RelWithDebInfo" }

$OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL "opencv_world4*" "opencv-4.*\opencv" -BuildType $BuildType } else { $OpenCVWorldDll }
$OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL "autoit_opencv_com4*" -BuildType $BuildType } else { $OpenCVComDll }
$Video = if ([string]::IsNullOrEmpty($Video)) { _OpenCV_FindFile "samples\data\vtest.avi" } else { $Video }
$OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL -Path "opencv_world4*" -Filter "opencv-4.*\opencv" -BuildType $BuildType } else { $OpenCVWorldDll }
$OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL -Path "autoit_opencv_com4*" -BuildType $BuildType } else { $OpenCVComDll }
$Video = if ([string]::IsNullOrEmpty($Video)) { _OpenCV_FindFile -Path "samples\data\vtest.avi" } else { $Video }

function Example() {
$cv = [OpenCvComInterop]::ObjCreate("cv")
Expand Down
8 changes: 4 additions & 4 deletions samples/dotnet/04-rotate-image.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ $ErrorActionPreference = "Stop"
Set-StrictMode -Version 3.0
trap { throw $Error[0] }

Import-Module "$PSScriptRoot\opencv_utils.psm1"
Import-Module "$PSScriptRoot\opencv_utils.psm1" -ArgumentList $BuildType

$BuildType = if ($BuildType -eq "Debug") { "Debug" } else { "RelWithDebInfo" }

$OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL "opencv_world4*" "opencv-4.*\opencv" -BuildType $BuildType } else { $OpenCVWorldDll }
$OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL "autoit_opencv_com4*" -BuildType $BuildType } else { $OpenCVComDll }
$Image = if ([string]::IsNullOrEmpty($Image)) { _OpenCV_FindFile "samples\data\lena.jpg" } else { $Image }
$OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL -Path "opencv_world4*" -Filter "opencv-4.*\opencv" -BuildType $BuildType } else { $OpenCVWorldDll }
$OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL -Path "autoit_opencv_com4*" -BuildType $BuildType } else { $OpenCVComDll }
$Image = if ([string]::IsNullOrEmpty($Image)) { _OpenCV_FindFile -Path "samples\data\lena.jpg" } else { $Image }

function Example() {
$cv = [OpenCvComInterop]::ObjCreate("cv")
Expand Down
8 changes: 4 additions & 4 deletions samples/dotnet/05-drawing-contours.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ $ErrorActionPreference = "Stop"
Set-StrictMode -Version 3.0
trap { throw $Error[0] }

Import-Module "$PSScriptRoot\opencv_utils.psm1"
Import-Module "$PSScriptRoot\opencv_utils.psm1" -ArgumentList $BuildType

$BuildType = if ($BuildType -eq "Debug") { "Debug" } else { "RelWithDebInfo" }

$OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL "opencv_world4*" "opencv-4.*\opencv" -BuildType $BuildType } else { $OpenCVWorldDll }
$OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL "autoit_opencv_com4*" -BuildType $BuildType } else { $OpenCVComDll }
$Image = if ([string]::IsNullOrEmpty($Image)) { _OpenCV_FindFile "samples\data\pic1.png" } else { $Image }
$OpenCVWorldDll = if ([string]::IsNullOrEmpty($OpenCVWorldDll)) { _OpenCV_FindDLL -Path "opencv_world4*" -Filter "opencv-4.*\opencv" -BuildType $BuildType } else { $OpenCVWorldDll }
$OpenCVComDll = if ([string]::IsNullOrEmpty($OpenCVComDll)) { _OpenCV_FindDLL -Path "autoit_opencv_com4*" -BuildType $BuildType } else { $OpenCVComDll }
$Image = if ([string]::IsNullOrEmpty($Image)) { _OpenCV_FindFile -Path "samples\data\pic1.png" } else { $Image }

function Example() {
$cv = [OpenCvComInterop]::ObjCreate("cv")
Expand Down
Loading

0 comments on commit 4c8c265

Please sign in to comment.