diff --git a/CreateSymlink.ps1 b/CreateSymlink.ps1 new file mode 100644 index 00000000..e168d740 --- /dev/null +++ b/CreateSymlink.ps1 @@ -0,0 +1,171 @@ +#*************************************** +#Arguments +#%1: CUDA (92,100,101,102,110,111) +#*************************************** +Param([Parameter( + Mandatory=$True, + Position = 1 + )][string] + $CUDA +) + +Set-StrictMode -Version Latest + +# For windows + +# For DlibDotNet.CUDA92 +$tmp92 = New-Object 'System.Collections.Generic.List[string]' +$tmp92.Add("$env:CUDA_PATH_V9_2\bin\cublas64_92.dll") +$tmp92.Add("$env:CUDA_PATH_V9_2\bin\cudnn64_7.dll") +$tmp92.Add("$env:CUDA_PATH_V9_2\bin\curand64_92.dll") +$tmp92.Add("$env:CUDA_PATH_V9_2\bin\cusolver64_92.dll") + +# For DlibDotNet.CUDA100 +$tmp100 = New-Object 'System.Collections.Generic.List[string]' +$tmp100.Add("$env:CUDA_PATH_V10_0\bin\cublas64_100.dll") +$tmp100.Add("$env:CUDA_PATH_V10_0\bin\cudnn64_7.dll") +$tmp100.Add("$env:CUDA_PATH_V10_0\bin\curand64_100.dll") +$tmp100.Add("$env:CUDA_PATH_V10_0\bin\cusolver64_100.dll") + +# For DlibDotNet.CUDA101 +$tmp101 = New-Object 'System.Collections.Generic.List[string]' +$tmp101.Add("$env:CUDA_PATH_V10_1\bin\cublas64_10.dll") +$tmp101.Add("$env:CUDA_PATH_V10_1\bin\cudnn64_7.dll") +$tmp101.Add("$env:CUDA_PATH_V10_1\bin\curand64_10.dll") +$tmp101.Add("$env:CUDA_PATH_V10_1\bin\cusolver64_10.dll") + +# For DlibDotNet.CUDA102 +$tmp102 = New-Object 'System.Collections.Generic.List[string]' +$tmp102.Add("$env:CUDA_PATH_V10_2\bin\cublas64_10.dll") +$tmp102.Add("$env:CUDA_PATH_V10_2\bin\cudnn64_7.dll") +$tmp102.Add("$env:CUDA_PATH_V10_2\bin\curand64_10.dll") +$tmp102.Add("$env:CUDA_PATH_V10_2\bin\cusolver64_10.dll") + +# For DlibDotNet.CUDA110 +$tmp110 = New-Object 'System.Collections.Generic.List[string]' +$tmp110.Add("$env:CUDA_PATH_V11_0\bin\cublas64_11.dll") +$tmp110.Add("$env:CUDA_PATH_V11_0\bin\cublasLt64_11.dll") +$tmp110.Add("$env:CUDA_PATH_V11_0\bin\cudnn_adv_infer64_8.dll") +$tmp110.Add("$env:CUDA_PATH_V11_0\bin\cudnn_adv_train64_8.dll") +$tmp110.Add("$env:CUDA_PATH_V11_0\bin\cudnn_cnn_infer64_8.dll") +$tmp110.Add("$env:CUDA_PATH_V11_0\bin\cudnn_cnn_train64_8.dll") +$tmp110.Add("$env:CUDA_PATH_V11_0\bin\cudnn_ops_infer64_8.dll") +$tmp110.Add("$env:CUDA_PATH_V11_0\bin\cudnn_ops_train64_8.dll") +$tmp110.Add("$env:CUDA_PATH_V11_0\bin\cudnn64_8.dll") +$tmp110.Add("$env:CUDA_PATH_V11_0\bin\curand64_10.dll") +$tmp110.Add("$env:CUDA_PATH_V11_0\bin\cusolver64_10.dll") + +# For DlibDotNet.CUDA111 +$tmp111 = New-Object 'System.Collections.Generic.List[string]' +$tmp111.Add("$env:CUDA_PATH_V11_1\bin\cublas64_11.dll") +$tmp111.Add("$env:CUDA_PATH_V11_1\bin\cublasLt64_11.dll") +$tmp111.Add("$env:CUDA_PATH_V11_1\bin\cudnn_adv_infer64_8.dll") +$tmp111.Add("$env:CUDA_PATH_V11_1\bin\cudnn_adv_train64_8.dll") +$tmp111.Add("$env:CUDA_PATH_V11_1\bin\cudnn_cnn_infer64_8.dll") +$tmp111.Add("$env:CUDA_PATH_V11_1\bin\cudnn_cnn_train64_8.dll") +$tmp111.Add("$env:CUDA_PATH_V11_1\bin\cudnn_ops_infer64_8.dll") +$tmp111.Add("$env:CUDA_PATH_V11_1\bin\cudnn_ops_train64_8.dll") +$tmp111.Add("$env:CUDA_PATH_V11_1\bin\cudnn64_8.dll") +$tmp111.Add("$env:CUDA_PATH_V11_1\bin\curand64_10.dll") +$tmp111.Add("$env:CUDA_PATH_V11_1\bin\cusolver64_11.dll") + +$BuildTargets = @() +$BuildTargets += New-Object PSObject -Property @{Package = "92"; Dependencies = $tmp92 } +$BuildTargets += New-Object PSObject -Property @{Package = "100"; Dependencies = $tmp100 } +$BuildTargets += New-Object PSObject -Property @{Package = "101"; Dependencies = $tmp101 } +$BuildTargets += New-Object PSObject -Property @{Package = "102"; Dependencies = $tmp102 } +$BuildTargets += New-Object PSObject -Property @{Package = "110"; Dependencies = $tmp110 } +$BuildTargets += New-Object PSObject -Property @{Package = "111"; Dependencies = $tmp111 } + +# Store current directory +$DlibDotNetRoot = $PSScriptRoot + +$Libraries = $Null +foreach ($Target in $BuildTargets) +{ + if ($Target.Package -eq $CUDA) + { + $Libraries = $Target.Dependencies + break + } +} + +if ($Libraries -eq $Null) +{ + Write-Host "${CUDA} is invalid parameter" -ForegroundColor Red + exit +} + +$BuildConfiguration = "Release" + +$BuildLibraryWindowsHash = +@{ + "DlibDotNet.Native" = (Join-Path $BuildConfiguration "DlibDotNetNative.dll"); + "DlibDotNet.Native.Dnn" = (Join-Path $BuildConfiguration "DlibDotNetNativeDnn.dll") +} + +$SourceDir = Join-Path $DlibDotNetRoot src +$BuildDir = "build_win_desktop_cuda-${CUDA}_x64" + +$Files = Get-ChildItem -Recurse -Name -include *.csproj + +$re = New-Object regex("(?[^<]+)") +foreach ($File in $Files) +{ + $ProjectRoot = Split-Path ${file} -Parent + $ProjectRoot = Join-Path ${DlibDotNetRoot} ${ProjectRoot} + + # check framework version + $ProjectFile = Get-Content ${file} + $Match = $re.Matches(${ProjectFile}) + if ($Match -ne $Null) + { + $Version = $Match.Groups[1].Value + + $Configurations = @( "Release", "Debug" ) + foreach ($Configuration in $Configurations) + { + $TargetDir = Join-Path $ProjectRoot bin | ` + Join-Path -ChildPath $Configuration | ` + Join-Path -ChildPath $Version + + if (!(Test-Path $TargetDir)) + { + New-Item $TargetDir -ItemType Directory | Out-Null + } + + foreach ($Library in $Libraries) + { + $FileName = Split-Path $Library -Leaf + $FilePath = Join-Path $TargetDir $FileName + + if ((Test-Path $FilePath)) + { + Remove-Item $FilePath + } + + New-Item -Value "$Library" -Path "$TargetDir" -Name "$FileName" -ItemType SymbolicLink > $null + } + + foreach ($key in $BuildLibraryWindowsHash.keys) + { + $SrcDir = Join-Path $SourceDir $key | ` + Join-Path -ChildPath $BuildDir + $Dll = $BuildLibraryWindowsHash[$key] + $FileName = Split-Path $Dll -Leaf + $FilePath = Join-Path $TargetDir $FileName + $Library = Join-Path $SrcDir $Dll + + if ((Test-Path $FilePath)) + { + Remove-Item $FilePath + } + + New-Item -Value "$Library" -Path "$TargetDir" -Name "$FileName" -ItemType SymbolicLink > $null + } + } + } +} + +# Move to Root directory +Set-Location -Path $DlibDotNetRoot \ No newline at end of file diff --git a/DlibDotNet.json b/DlibDotNet.json deleted file mode 100644 index f8f7200a..00000000 --- a/DlibDotNet.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "build" : { - "linux-node": "linux-cuda", - "osx-node": "mac", - "windows-node": "windows-cuda" - }, - "packaging" : { - "node": "windows-cuda" - }, - "test" : { - "linux-arm-node": "linux-arm-raspberrypi", - "linux-node": "linux-cuda", - "osx-node": "mac", - "windows-node": "windows-cuda", - - "uwp" : { - "thumbprint": "", - "certificateKeyFile": "", - "windowsAppCertificationKit" : { - "notCountAsFailTests" : "47,79,81" - } - } - } -} \ No newline at end of file diff --git a/DlibDotNet.sln b/DlibDotNet.sln index e957d763..fc39043f 100644 --- a/DlibDotNet.sln +++ b/DlibDotNet.sln @@ -39,8 +39,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "3DPointCloud", "examples\3D EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Surf", "examples\Surf\Surf.csproj", "{6E027771-5500-4555-822C-C7FE6AC8709D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DlibDotNet.Extensions", "src\DlibDotNet.Extensions\DlibDotNet.Extensions.csproj", "{D3BFF103-53CB-46DC-A0E8-05A01E11099B}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WinForms", "WinForms", "{4082257D-FC8E-4D37-8489-89AAFC9D4A38}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FaceDetection", "examples\WinForms\FaceDetection\FaceDetection.csproj", "{1523DA42-DB7E-47B5-8AE6-305100F3891A}" @@ -53,8 +51,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FaceLandmarkDetection", "ex EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FaceLandmarkDetection", "examples\WPF\FaceLandmarkDetection\FaceLandmarkDetection.csproj", "{9575AC94-3760-483F-9403-A77E7CFE8F47}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DlibDotNet.Extensions.Tests", "test\DlibDotNet.Extensions.Tests\DlibDotNet.Extensions.Tests.csproj", "{2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DnnFaceRecognition", "examples\DnnFaceRecognition\DnnFaceRecognition.csproj", "{C6EFE2AC-63BD-4574-B4A1-9AC80CA5AD2E}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DnnMmodFaceDetection", "examples\DnnMmodFaceDetection\DnnMmodFaceDetection.csproj", "{A6302463-CC32-4060-B8DF-466479046038}" @@ -383,22 +379,6 @@ Global {6E027771-5500-4555-822C-C7FE6AC8709D}.Release|x64.Build.0 = Release|Any CPU {6E027771-5500-4555-822C-C7FE6AC8709D}.Release|x86.ActiveCfg = Release|Any CPU {6E027771-5500-4555-822C-C7FE6AC8709D}.Release|x86.Build.0 = Release|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Debug|ARM.ActiveCfg = Debug|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Debug|ARM.Build.0 = Debug|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Debug|x64.ActiveCfg = Debug|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Debug|x64.Build.0 = Debug|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Debug|x86.ActiveCfg = Debug|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Debug|x86.Build.0 = Debug|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Release|Any CPU.Build.0 = Release|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Release|ARM.ActiveCfg = Release|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Release|ARM.Build.0 = Release|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Release|x64.ActiveCfg = Release|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Release|x64.Build.0 = Release|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Release|x86.ActiveCfg = Release|Any CPU - {D3BFF103-53CB-46DC-A0E8-05A01E11099B}.Release|x86.Build.0 = Release|Any CPU {1523DA42-DB7E-47B5-8AE6-305100F3891A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {1523DA42-DB7E-47B5-8AE6-305100F3891A}.Debug|Any CPU.Build.0 = Debug|Any CPU {1523DA42-DB7E-47B5-8AE6-305100F3891A}.Debug|ARM.ActiveCfg = Debug|Any CPU @@ -463,22 +443,6 @@ Global {9575AC94-3760-483F-9403-A77E7CFE8F47}.Release|x64.Build.0 = Release|Any CPU {9575AC94-3760-483F-9403-A77E7CFE8F47}.Release|x86.ActiveCfg = Release|Any CPU {9575AC94-3760-483F-9403-A77E7CFE8F47}.Release|x86.Build.0 = Release|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Debug|ARM.ActiveCfg = Debug|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Debug|ARM.Build.0 = Debug|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Debug|x64.ActiveCfg = Debug|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Debug|x64.Build.0 = Debug|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Debug|x86.ActiveCfg = Debug|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Debug|x86.Build.0 = Debug|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Release|Any CPU.Build.0 = Release|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Release|ARM.ActiveCfg = Release|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Release|ARM.Build.0 = Release|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Release|x64.ActiveCfg = Release|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Release|x64.Build.0 = Release|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Release|x86.ActiveCfg = Release|Any CPU - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2}.Release|x86.Build.0 = Release|Any CPU {C6EFE2AC-63BD-4574-B4A1-9AC80CA5AD2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C6EFE2AC-63BD-4574-B4A1-9AC80CA5AD2E}.Debug|Any CPU.Build.0 = Debug|Any CPU {C6EFE2AC-63BD-4574-B4A1-9AC80CA5AD2E}.Debug|ARM.ActiveCfg = Debug|Any CPU @@ -1142,14 +1106,12 @@ Global {7945CA45-B9C6-4EDF-9794-6B3B9DD9EE5E} = {19C83FDC-2BC9-42D6-9F51-3A0B822FABAD} {B16B534A-75FA-4299-9EF9-F4DF801266A0} = {19C83FDC-2BC9-42D6-9F51-3A0B822FABAD} {6E027771-5500-4555-822C-C7FE6AC8709D} = {19C83FDC-2BC9-42D6-9F51-3A0B822FABAD} - {D3BFF103-53CB-46DC-A0E8-05A01E11099B} = {A9E3AD0D-91F4-48B4-9509-5C06B54C7374} {4082257D-FC8E-4D37-8489-89AAFC9D4A38} = {19C83FDC-2BC9-42D6-9F51-3A0B822FABAD} {1523DA42-DB7E-47B5-8AE6-305100F3891A} = {4082257D-FC8E-4D37-8489-89AAFC9D4A38} {5452AAEA-A679-4056-A2F7-8B6F8137CCAC} = {19C83FDC-2BC9-42D6-9F51-3A0B822FABAD} {9575AC94-3760-483F-9403-A77E7CFE8F46} = {5452AAEA-A679-4056-A2F7-8B6F8137CCAC} {1523DA42-DB7E-47B5-8AE6-305100F3891B} = {4082257D-FC8E-4D37-8489-89AAFC9D4A38} {9575AC94-3760-483F-9403-A77E7CFE8F47} = {5452AAEA-A679-4056-A2F7-8B6F8137CCAC} - {2A75C8B3-5122-4E7E-A0CF-A0AD5FFA60B2} = {44730D39-C672-4CC0-B983-26CC9D7E59C1} {C6EFE2AC-63BD-4574-B4A1-9AC80CA5AD2E} = {19C83FDC-2BC9-42D6-9F51-3A0B822FABAD} {A6302463-CC32-4060-B8DF-466479046038} = {19C83FDC-2BC9-42D6-9F51-3A0B822FABAD} {4DF84F72-0995-44ED-AC0A-A07327F078A2} = {19C83FDC-2BC9-42D6-9F51-3A0B822FABAD} diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index d24ebdb1..00000000 --- a/Jenkinsfile +++ /dev/null @@ -1,490 +0,0 @@ -#!groovy - -def errorMessage - -def getGitUrl() -{ - return "https://github.com/takuya-takeuchi/DlibDotNet" -} - -def getGitBranch() -{ - return "develop" -} - -def getSource() -{ - def work - def dlibDotNet - def gitUrl = getGitUrl() - def gitBranch = getGitBranch() - - if(isUnix()) - { - work = env.WORKSPACE + "/work" - dlibDotNet = work + "/DlibDotNet" - - echo 'work: ' + work - echo 'dlibDotNet: ' + dlibDotNet - - if (!fileExists(work)) - { - sh 'mkdir -p ' + work - } - - if (!fileExists(dlibDotNet)) - { - dir(work) - { - sh "git clone -b ${gitBranch} ${gitUrl}" - } - } - } - else - { - work = env.WORKSPACE + "\\work" - dlibDotNet = work + "\\DlibDotNet" - - echo 'work: ' + work - echo 'dlibDotNet: ' + dlibDotNet - - if (!fileExists(work)) - { - bat 'mkdir ' + work - } - - if (!fileExists(dlibDotNet)) - { - dir(work) - { - bat "git clone -b ${gitBranch} ${gitUrl}" - } - } - } - - return dlibDotNet -} - -def initialize(root) -{ - def gitBranch = getGitBranch() - - dir(root) - { - if(isUnix()) - { - sh 'git clean -fxd nuget' - sh 'git checkout .' - sh "git checkout ${gitBranch}" - sh "git pull origin ${gitBranch}" - sh './Initialize.sh' - } - else - { - bat 'git clean -fxd nuget' - bat 'git checkout .' - bat "git checkout ${gitBranch}" - bat "git pull origin ${gitBranch}" - bat 'Initialize.bat' - } - } -} - -def preparation() -{ - def dlibDotNet = getSource() - initialize(dlibDotNet) -} - -def getNugetDir(dlibDotNet) -{ - if(isUnix()) - { - return dlibDotNet + "/nuget" - } - else - { - return dlibDotNet + "\\nuget" - } -} - -def getDockerDir(dlibDotNet) -{ - if(isUnix()) - { - return dlibDotNet + "/docker" - } - else - { - return dlibDotNet + "\\docker" - } -} - -def getArtifactsDir(dlibDotNet) -{ - if(isUnix()) - { - return getNugetDir(dlibDotNet) + "/artifacts" - } - else - { - return getNugetDir(dlibDotNet) + "\\artifacts" - } -} - -def buildContainer() -{ - def dlibDotNet - def buildWorkSpace - - stage("Initialize") - { - dlibDotNet = getSource() - initialize(dlibDotNet) - } - - stage('Build') - { - buildWorkSpace = getDockerDir(dlibDotNet) - dir(buildWorkSpace) - { - if(isUnix()) - { - sh 'pwsh build_devel.ps1' - sh 'pwsh build_runtime.ps1' - } - else - { - bat 'pwsh build_devel.ps1' - bat 'pwsh build_runtime.ps1' - } - } - } -} - -def build(script, stashName) -{ - echo 'script: ' + script - echo 'stashName: ' + stashName - - def dlibDotNet - def buildWorkSpace - def artifactsSpace - - stage("Initialize") - { - dlibDotNet = getSource() - initialize(dlibDotNet) - } - - stage('Build') - { - buildWorkSpace = getNugetDir(dlibDotNet) - artifactsSpace = getArtifactsDir(dlibDotNet) - dir(buildWorkSpace) - { - if(isUnix()) - { - sh script - } - else - { - bat script - } - } - } - - stage('Results') - { - dir(artifactsSpace) - { - stash stashName - } - } -} - -def test(script, stashName, include) -{ - echo 'script: ' + script - echo 'stashName: ' + stashName - - def dlibDotNet - def buildWorkSpace - def artifactsSpace - - stage("Initialize") - { - dlibDotNet = getSource() - initialize(dlibDotNet) - } - - stage('Test') - { - buildWorkSpace = getNugetDir(dlibDotNet) - artifactsSpace = getArtifactsDir(dlibDotNet) - - dir(buildWorkSpace) - { - if(isUnix()) - { - unstash 'nupkg' - sh 'git checkout .' - sh script - } - else - { - unstash 'nupkg' - bat 'git checkout .' - bat script - } - } - } - - stage('Results') - { - dir(buildWorkSpace) - { - stash name: stashName, includes: include, excludes: '*.log' - } - } -} - -node('master') -{ - try - { - def props - stage("Preparation") - { - if(isUnix()) - { - def file = env.JENKINS_HOME + '/DlibDotNet.json' - props = readJSON file: file - } - else - { - def file = env.JENKINS_HOME + '\\DlibDotNet.json' - props = readJSON file: file - } - } - - stage("Build Container") - { - def nodeName = props['build']['linux-node'] - node(nodeName) - { - buildContainer() - } - } - - stage("Build") - { - def builders = [:] - - builders['windows'] = - { - def nodeName = props['build']['windows-node'] - node(nodeName) - { - echo 'Build for Windows' - build('pwsh BuildWindows.ps1', 'windows') - - echo 'Build for Universal Windows Application' - build('pwsh BuildUniversalWindowsPlatform.ps1', 'uwp') - } - } - builders['linux'] = - { - def nodeName = props['build']['linux-node'] - node(nodeName) - { - echo 'Build for Linux' - build('pwsh BuildUbuntu16.ps1', 'linux') - } - } - builders['osx'] = - { - def nodeName = props['build']['osx-node'] - node(nodeName) - { - echo 'Build for OSX' - withEnv(["PATH+LOCAL=/usr/local/bin"]) - { - build('pwsh BuildOSX.ps1', 'osx') - } - } - } - - parallel builders - } - - stage("Packaging") - { - def nodeName = props['packaging']['node'] - node(nodeName) - { - echo 'Get source code' - def dlibDotNet = getSource() - initialize(dlibDotNet) - - buildWorkSpace = getNugetDir(dlibDotNet) - artifactsSpace = getArtifactsDir(dlibDotNet) - - echo 'Get artifacts' - dir(artifactsSpace) - { - unstash 'windows' - unstash 'uwp' - unstash 'linux' - unstash 'osx' - } - - echo 'Create packages' - dir(buildWorkSpace) - { - stage('Build DlibDotNet Source') - { - bat 'BuildNuspec.Pre.bat' - } - - stage('Build Native DlibDotNet Source') - { - parallel 'CPU': - { - stage('Build DlibDotNet.CPU') - { - bat 'pwsh CreatePackage.ps1 CPU' - } - }, 'CUDA': { - stage('Build DlibDotNet.CUDA') - { - bat 'pwsh CreatePackage.ps1 CUDA-92' - bat 'pwsh CreatePackage.ps1 CUDA-100' - bat 'pwsh CreatePackage.ps1 CUDA-101' - } - }, 'MKL': { - stage('Build DlibDotNet.MKL') - { - bat 'pwsh CreatePackage.ps1 MKL' - } - }, 'UWP': { - stage('Build DlibDotNet.UWP') - { - bat 'pwsh CreatePackage.ps1 UWP' - } - },'ARM': { - stage('Build DlibDotNet.ARM') - { - // bat 'pwsh CreatePackage.ps1 ARM' - } - } - } - - // delete dll, so and dylib - echo 'Clean artifacts directory' - if(isUnix()) - { - sh 'git clean -fxd artifacts' - } - else - { - bat 'git clean -fxd artifacts' - } - - stash name: 'nupkg', includes: '**/*.nupkg' - } - } - } - - stage("Test") - { - def builders = [:] - def version = params.Version - - builders['windows'] = - { - def nodeName = props['test']['windows-node'] - node(nodeName) - { - echo 'Test on Windows' - test("pwsh TestPackageWindows.ps1 ${version}", 'test-windows', 'artifacts/test/**/*.trx') - - def thumbprint = props['test']['uwp']['thumbprint'] - def certificateKeyFile = props['test']['uwp']['certificateKeyFile'] - def notCountAsFailTests = props['test']['uwp']['windowsAppCertificationKit']['notCountAsFailTests'] - echo 'Test on Universal Windows Application' - test("pwsh TestPackageUniversalWindowsPlatform.ps1 ${version} ${thumbprint} ${certificateKeyFile} ${notCountAsFailTests}", 'test-uwp', 'artifacts/test/**/*.xml') - } - } - builders['linux'] = - { - def nodeName = props['test']['linux-node'] - node(nodeName) - { - echo 'Test on Linux' - test("pwsh TestPackageUbuntu16.ps1 ${version}", 'test-linux', 'artifacts/test/**/*.trx') - } - } - // builders['linux-arm'] = - // { - // def nodeName = props['test']['linux-arm-node'] - // node(nodeName) - // { - // echo 'Test on Linux-ARM' - // withEnv(["PATH+LOCAL=/usr/local/share/dotnet"]) - // { - // test('./TestPackageRaspberryPi.sh ' + params.Version, 'test-linux-arm', 'artifacts/test/**/*.trx') - // } - // } - // } - builders['osx'] = - { - def nodeName = props['test']['osx-node'] - node(nodeName) - { - echo 'Test on OSX' - withEnv(["PATH+LOCAL=/usr/local/bin:/usr/local/share/dotnet"]) - { - test("pwsh TestPackageOSX.ps1 ${version}", 'test-osx', 'artifacts/test/**/*.trx') - } - } - } - - parallel builders - } - - stage("result") - { - def nodeName = props['packaging']['node'] - node(nodeName) - { - dir(buildWorkSpace) - { - unstash 'nupkg' - unstash 'test-windows' - unstash 'test-uwp' - unstash 'test-linux' - // unstash 'test-linux-arm' - unstash 'test-osx' - - archiveArtifacts artifacts: 'artifacts/test/**/*.*' - archiveArtifacts artifacts: '*.nupkg' - } - } - } - } - catch (err) - { - errorMessage = "${err}" - currentBuild.result = "FAILURE" - - echo errorMessage - } - finally - { - if(currentBuild.result != "FAILURE") - { - currentBuild.result = "SUCCESS" - } - } -} \ No newline at end of file diff --git a/examples/ASP.NET/FaceDetection.Client/FaceDetection.Client.csproj b/examples/ASP.NET/FaceDetection.Client/FaceDetection.Client.csproj index 87beb0ba..3dd4783e 100644 --- a/examples/ASP.NET/FaceDetection.Client/FaceDetection.Client.csproj +++ b/examples/ASP.NET/FaceDetection.Client/FaceDetection.Client.csproj @@ -17,7 +17,7 @@ - + diff --git a/examples/ASP.NET/FaceDetection.Server/FaceDetection.Server.csproj b/examples/ASP.NET/FaceDetection.Server/FaceDetection.Server.csproj index 2bed9031..44a6132b 100644 --- a/examples/ASP.NET/FaceDetection.Server/FaceDetection.Server.csproj +++ b/examples/ASP.NET/FaceDetection.Server/FaceDetection.Server.csproj @@ -21,7 +21,7 @@ - + diff --git a/examples/WPF/FaceDetection/FaceDetection.csproj b/examples/WPF/FaceDetection/FaceDetection.csproj index 2f71d665..c832408c 100644 --- a/examples/WPF/FaceDetection/FaceDetection.csproj +++ b/examples/WPF/FaceDetection/FaceDetection.csproj @@ -47,6 +47,9 @@ + + ..\..\..\packages\System.Drawing.Common.5.0.1\lib\net461\System.Drawing.Common.dll + ..\..\..\packages\Prism.Wpf.6.3.0\lib\net45\System.Windows.Interactivity.dll True @@ -107,10 +110,6 @@ - - {d3bff103-53cb-46dc-a0e8-05a01e11099b} - DlibDotNet.Extensions - {b13a6288-7b69-4b53-9138-2e20a8d5cfc5} DlibDotNet diff --git a/examples/WPF/FaceDetection/packages.config b/examples/WPF/FaceDetection/packages.config index b102b5ad..1e32c5d3 100644 --- a/examples/WPF/FaceDetection/packages.config +++ b/examples/WPF/FaceDetection/packages.config @@ -1,6 +1,7 @@ - - - - - + + + + + + \ No newline at end of file diff --git a/examples/WPF/FaceLandmarkDetection/FaceLandmarkDetection.csproj b/examples/WPF/FaceLandmarkDetection/FaceLandmarkDetection.csproj index 4b6df6d5..63284960 100644 --- a/examples/WPF/FaceLandmarkDetection/FaceLandmarkDetection.csproj +++ b/examples/WPF/FaceLandmarkDetection/FaceLandmarkDetection.csproj @@ -47,6 +47,9 @@ + + ..\..\..\packages\System.Drawing.Common.5.0.1\lib\net461\System.Drawing.Common.dll + ..\..\..\packages\Prism.Wpf.6.3.0\lib\net45\System.Windows.Interactivity.dll True @@ -107,10 +110,6 @@ - - {d3bff103-53cb-46dc-a0e8-05a01e11099b} - DlibDotNet.Extensions - {b13a6288-7b69-4b53-9138-2e20a8d5cfc5} DlibDotNet diff --git a/examples/WPF/FaceLandmarkDetection/packages.config b/examples/WPF/FaceLandmarkDetection/packages.config index b102b5ad..1e32c5d3 100644 --- a/examples/WPF/FaceLandmarkDetection/packages.config +++ b/examples/WPF/FaceLandmarkDetection/packages.config @@ -1,6 +1,7 @@ - - - - - + + + + + + \ No newline at end of file diff --git a/examples/WinForms/FaceDetection/FaceDetection.csproj b/examples/WinForms/FaceDetection/FaceDetection.csproj index c1322c38..b7d0f9a6 100644 --- a/examples/WinForms/FaceDetection/FaceDetection.csproj +++ b/examples/WinForms/FaceDetection/FaceDetection.csproj @@ -38,6 +38,9 @@ + + ..\..\..\packages\System.Drawing.Common.5.0.1\lib\net461\System.Drawing.Common.dll + @@ -61,6 +64,7 @@ True Resources.resx + SettingsSingleFileGenerator Settings.Designer.cs @@ -75,10 +79,6 @@ - - {d3bff103-53cb-46dc-a0e8-05a01e11099b} - DlibDotNet.Extensions - {b13a6288-7b69-4b53-9138-2e20a8d5cfc5} DlibDotNet diff --git a/examples/WinForms/FaceDetection/packages.config b/examples/WinForms/FaceDetection/packages.config new file mode 100644 index 00000000..584d1a3a --- /dev/null +++ b/examples/WinForms/FaceDetection/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/examples/WinForms/FaceLandmarkDetection/FaceLandmarkDetection.csproj b/examples/WinForms/FaceLandmarkDetection/FaceLandmarkDetection.csproj index 506fdf52..7f720be1 100644 --- a/examples/WinForms/FaceLandmarkDetection/FaceLandmarkDetection.csproj +++ b/examples/WinForms/FaceLandmarkDetection/FaceLandmarkDetection.csproj @@ -38,6 +38,9 @@ + + ..\..\..\packages\System.Drawing.Common.5.0.1\lib\net461\System.Drawing.Common.dll + @@ -62,6 +65,7 @@ Resources.resx True + SettingsSingleFileGenerator Settings.Designer.cs @@ -76,10 +80,6 @@ - - {d3bff103-53cb-46dc-a0e8-05a01e11099b} - DlibDotNet.Extensions - {b13a6288-7b69-4b53-9138-2e20a8d5cfc5} DlibDotNet diff --git a/examples/WinForms/FaceLandmarkDetection/packages.config b/examples/WinForms/FaceLandmarkDetection/packages.config new file mode 100644 index 00000000..584d1a3a --- /dev/null +++ b/examples/WinForms/FaceLandmarkDetection/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/nuget/nuspec/DlibDotNet.CPU.nuspec b/nuget/nuspec/DlibDotNet.CPU.nuspec index 236b3259..cf5145fb 100644 --- a/nuget/nuspec/DlibDotNet.CPU.nuspec +++ b/nuget/nuspec/DlibDotNet.CPU.nuspec @@ -2,7 +2,7 @@ DlibDotNet - 19.21.0.20210230 + 19.21.0.20210302 DlibDotNet Takuya Takeuchi Takuya Takeuchi @@ -17,6 +17,14 @@ Requirements: Visual C++ 2017 Redistributable Package © Takuya Takeuchi 2017-2021 dlib .net machinelearning true + + + + + + + + diff --git a/nuget/nuspec/DlibDotNet.CUDA-100.nuspec b/nuget/nuspec/DlibDotNet.CUDA-100.nuspec index 11e9f943..a55c8384 100644 --- a/nuget/nuspec/DlibDotNet.CUDA-100.nuspec +++ b/nuget/nuspec/DlibDotNet.CUDA-100.nuspec @@ -2,7 +2,7 @@ DlibDotNet.CUDA100 - 19.21.0.20210230 + 19.21.0.20210302 DlibDotNet for CUDA 10.0 Takuya Takeuchi Takuya Takeuchi @@ -17,6 +17,14 @@ Requirements: Visual C++ 2017 Redistributable Package, cublas64_100.dll, cudnn64 © Takuya Takeuchi 2017-2021 dlib .net machinelearning true + + + + + + + + diff --git a/nuget/nuspec/DlibDotNet.CUDA-101.nuspec b/nuget/nuspec/DlibDotNet.CUDA-101.nuspec index 29e426ab..59fcb4b6 100644 --- a/nuget/nuspec/DlibDotNet.CUDA-101.nuspec +++ b/nuget/nuspec/DlibDotNet.CUDA-101.nuspec @@ -2,7 +2,7 @@ DlibDotNet.CUDA101 - 19.21.0.20210230 + 19.21.0.20210302 DlibDotNet for CUDA 10.1 Takuya Takeuchi Takuya Takeuchi @@ -17,6 +17,14 @@ Requirements: Visual C++ 2017 Redistributable Package, cublas64_10.dll, cudnn64_ © Takuya Takeuchi 2017-2021 dlib .net machinelearning true + + + + + + + + diff --git a/nuget/nuspec/DlibDotNet.CUDA-102.nuspec b/nuget/nuspec/DlibDotNet.CUDA-102.nuspec index eba93526..1c9424df 100644 --- a/nuget/nuspec/DlibDotNet.CUDA-102.nuspec +++ b/nuget/nuspec/DlibDotNet.CUDA-102.nuspec @@ -2,7 +2,7 @@ DlibDotNet.CUDA102 - 19.21.0.20210230 + 19.21.0.20210302 DlibDotNet for CUDA 10.2 Takuya Takeuchi Takuya Takeuchi @@ -17,6 +17,14 @@ Requirements: Visual C++ 2017 Redistributable Package, cublas64_10.dll, cudnn64_ © Takuya Takeuchi 2017-2021 dlib .net machinelearning true + + + + + + + + diff --git a/nuget/nuspec/DlibDotNet.CUDA-110.nuspec b/nuget/nuspec/DlibDotNet.CUDA-110.nuspec index c7f28ddf..b10ee144 100644 --- a/nuget/nuspec/DlibDotNet.CUDA-110.nuspec +++ b/nuget/nuspec/DlibDotNet.CUDA-110.nuspec @@ -2,7 +2,7 @@ DlibDotNet.CUDA110 - 19.21.0.20210230 + 19.21.0.20210302 DlibDotNet for CUDA 11.0 Takuya Takeuchi Takuya Takeuchi @@ -17,6 +17,14 @@ Requirements: Visual C++ 2017 Redistributable Package and cudnn 8 © Takuya Takeuchi 2017-2021 dlib .net machinelearning true + + + + + + + + diff --git a/nuget/nuspec/DlibDotNet.CUDA-111.nuspec b/nuget/nuspec/DlibDotNet.CUDA-111.nuspec index a9c29b92..9e8fb73b 100644 --- a/nuget/nuspec/DlibDotNet.CUDA-111.nuspec +++ b/nuget/nuspec/DlibDotNet.CUDA-111.nuspec @@ -2,7 +2,7 @@ DlibDotNet.CUDA111 - 19.21.0.20210230 + 19.21.0.20210302 DlibDotNet for CUDA 11.1 Takuya Takeuchi Takuya Takeuchi @@ -17,6 +17,14 @@ Requirements: Visual C++ 2017 Redistributable Package and cudnn 8 © Takuya Takeuchi 2017-2021 dlib .net machinelearning true + + + + + + + + diff --git a/nuget/nuspec/DlibDotNet.CUDA-92.nuspec b/nuget/nuspec/DlibDotNet.CUDA-92.nuspec index f8d7ed17..e40ea83b 100644 --- a/nuget/nuspec/DlibDotNet.CUDA-92.nuspec +++ b/nuget/nuspec/DlibDotNet.CUDA-92.nuspec @@ -2,7 +2,7 @@ DlibDotNet.CUDA92 - 19.21.0.20210230 + 19.21.0.20210302 DlibDotNet for CUDA 9.2 Takuya Takeuchi Takuya Takeuchi @@ -17,6 +17,14 @@ Requirements: Visual C++ 2017 Redistributable Package, cublas64_92.dll, cudnn64_ © Takuya Takeuchi 2017-2021 dlib .net machinelearning true + + + + + + + + diff --git a/nuget/nuspec/DlibDotNet.MKL.nuspec b/nuget/nuspec/DlibDotNet.MKL.nuspec index 3de1c3cb..888c98b2 100644 --- a/nuget/nuspec/DlibDotNet.MKL.nuspec +++ b/nuget/nuspec/DlibDotNet.MKL.nuspec @@ -2,7 +2,7 @@ DlibDotNet.MKL - 19.21.0.20210230 + 19.21.0.20210302 DlibDotNet for MKL Takuya Takeuchi Takuya Takeuchi @@ -20,6 +20,14 @@ Requirements for OSX: Intel MKL 2020 Initial Release © Takuya Takeuchi 2017-2021 dlib .net machinelearning true + + + + + + + + diff --git a/nuget/nuspec/DlibDotNet.UWP.nuspec b/nuget/nuspec/DlibDotNet.UWP.nuspec index 0adc5984..eb9f6fbf 100644 --- a/nuget/nuspec/DlibDotNet.UWP.nuspec +++ b/nuget/nuspec/DlibDotNet.UWP.nuspec @@ -2,7 +2,7 @@ DlibDotNet.UWP - 19.21.0.20210228 + 19.21.0.20210302 DlibDotNet for UWP Takuya Takeuchi Takuya Takeuchi @@ -15,6 +15,14 @@ © Takuya Takeuchi 2017-2020 dlib .net machinelearning true + + + + + + + + diff --git a/src/DlibDotNet.Native.Dnn/CMakeLists.txt b/src/DlibDotNet.Native.Dnn/CMakeLists.txt index 158cbe41..de060bd2 100644 --- a/src/DlibDotNet.Native.Dnn/CMakeLists.txt +++ b/src/DlibDotNet.Native.Dnn/CMakeLists.txt @@ -25,7 +25,7 @@ message("-------------------------------------------------------") set(VERSION_MAJOR 19) set(VERSION_MINOR 21) set(VERSION_PATCH 0) -set(VERSION_DATE 20210230) +set(VERSION_DATE 20210302) # Only GCC requires -fPIC if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") diff --git a/src/DlibDotNet.Native/CMakeLists.txt b/src/DlibDotNet.Native/CMakeLists.txt index 7721d8fa..6ecc7476 100644 --- a/src/DlibDotNet.Native/CMakeLists.txt +++ b/src/DlibDotNet.Native/CMakeLists.txt @@ -25,7 +25,7 @@ message("-------------------------------------------------------") set(VERSION_MAJOR 19) set(VERSION_MINOR 21) set(VERSION_PATCH 0) -set(VERSION_DATE 20210230) +set(VERSION_DATE 20210302) # libjpeg-dev, libpng-dev set(DLIB_JPEG_SUPPORT True) diff --git a/src/DlibDotNet/DlibDotNet.csproj b/src/DlibDotNet/DlibDotNet.csproj index 63d5156c..fd1b3a8d 100644 --- a/src/DlibDotNet/DlibDotNet.csproj +++ b/src/DlibDotNet/DlibDotNet.csproj @@ -47,5 +47,9 @@ + + + + \ No newline at end of file diff --git a/src/DlibDotNet.Extensions/Extensions/BitmapExtensions.cs b/src/DlibDotNet/Extensions/BitmapExtensions.cs similarity index 99% rename from src/DlibDotNet.Extensions/Extensions/BitmapExtensions.cs rename to src/DlibDotNet/Extensions/BitmapExtensions.cs index 90794bc0..5cad0472 100644 --- a/src/DlibDotNet.Extensions/Extensions/BitmapExtensions.cs +++ b/src/DlibDotNet/Extensions/BitmapExtensions.cs @@ -485,4 +485,4 @@ public bool RgbReverse } -} +} \ No newline at end of file diff --git a/src/DlibDotNet/Extensions/GrayscalLumaCoefficients.cs b/src/DlibDotNet/Extensions/GrayscalLumaCoefficients.cs new file mode 100644 index 00000000..c055f75b --- /dev/null +++ b/src/DlibDotNet/Extensions/GrayscalLumaCoefficients.cs @@ -0,0 +1,30 @@ + + +// ReSharper disable once CheckNamespace +namespace DlibDotNet.Extensions +{ + + /// + /// Define the standard for converting RGB values to luminance when gray-scaled. + /// + public enum GrayscalLumaCoefficients + { + + /// + /// Operate gray-scaled by BT.601 of ITU-R (ITU Radiocommunication Sector) Recommendation. Luminance of formula is 0.299 R + 0.587 G + 0.114 B. + /// + ITU_R_BT_601, + + /// + /// Operate gray-scaled by BT.709 of ITU-R (ITU Radiocommunication Sector) Recommendation. Luminance of formula is 0.2126 R + 0.7152 G + 0.0722 B. + /// + ITU_R_BT_709, + + /// + /// Operate gray-scaled by 240M specification SMPTER (Society of Motion Picture and Television Engineers) established. Luminance of formula is 0.212 R + 0.701 G + 0.087 B. + /// + SMPTE_240M + + } + +} diff --git a/src/DlibDotNet/Matrix/Matrix.cs b/src/DlibDotNet/Matrix/Matrix.cs index 591b93b1..c7f7a417 100644 --- a/src/DlibDotNet/Matrix/Matrix.cs +++ b/src/DlibDotNet/Matrix/Matrix.cs @@ -598,7 +598,7 @@ public void SetSize(int rows, int cols) throw new ArgumentException($"{nameof(this.TemplateColumns)} or {nameof(this.TemplateRows)} is not supported."); } } - + public TElement[] ToArray() { this.ThrowIfDisposed(); diff --git a/src/DlibDotNet/PInvoke/Extensions/Dlib.cs b/src/DlibDotNet/PInvoke/Extensions/Dlib.cs new file mode 100644 index 00000000..34bec82c --- /dev/null +++ b/src/DlibDotNet/PInvoke/Extensions/Dlib.cs @@ -0,0 +1,39 @@ +using System; +using System.Runtime.InteropServices; + +// ReSharper disable once CheckNamespace +namespace DlibDotNet +{ + + internal sealed partial class NativeMethods + { + + #region Array2D + + [DllImport(NativeLibrary, CallingConvention = CallingConvention)] + public static extern void extensions_convert_array_to_managed_image(Array2DType src_type, IntPtr src, IntPtr dst, bool rgb_reverse, uint rows, uint columns, uint steps, uint channels); + + [DllImport(NativeLibrary, CallingConvention = CallingConvention)] + public static extern void extensions_convert_managed_image_to_array(IntPtr src, Array2DType dst_type, IntPtr dst, bool rgb_reverse, uint rows, uint columns, uint steps, uint channels); + + [DllImport(NativeLibrary, CallingConvention = CallingConvention)] + public static extern void extensions_convert_managed_image_to_array_by_palette(IntPtr src, Array2DType dst_type, IntPtr dst, RgbPixel[] palette, uint rows, uint columns, uint steps, uint channels); + + #endregion + + #region Matrix + + [DllImport(NativeLibrary, CallingConvention = CallingConvention)] + public static extern void extensions_convert_matrix_to_managed_image(MatrixElementType src_type, IntPtr src, IntPtr dst, bool rgb_reverse, uint rows, uint columns, uint steps, uint channels); + + [DllImport(NativeLibrary, CallingConvention = CallingConvention)] + public static extern void extensions_convert_managed_image_to_matrix(IntPtr src, MatrixElementType dst_type, IntPtr dst, bool rgb_reverse, uint rows, uint columns, uint steps, uint channels); + + [DllImport(NativeLibrary, CallingConvention = CallingConvention)] + public static extern void extensions_convert_managed_image_to_matrix_by_palette(IntPtr src, MatrixElementType dst_type, IntPtr dst, RgbPixel[] palette, uint rows, uint columns, uint steps, uint channels); + + #endregion + + } + +} \ No newline at end of file diff --git a/test/DlibDotNet.Extensions.Tests/DlibDotNet.Extensions.Tests.csproj b/test/DlibDotNet.Extensions.Tests/DlibDotNet.Extensions.Tests.csproj index 462487f6..fc98f938 100644 --- a/test/DlibDotNet.Extensions.Tests/DlibDotNet.Extensions.Tests.csproj +++ b/test/DlibDotNet.Extensions.Tests/DlibDotNet.Extensions.Tests.csproj @@ -28,10 +28,6 @@ - - - - PreserveNewest diff --git a/test/DlibDotNet.Tests/DlibDotNet.Tests.csproj b/test/DlibDotNet.Tests/DlibDotNet.Tests.csproj index 5885181f..d67521dc 100644 --- a/test/DlibDotNet.Tests/DlibDotNet.Tests.csproj +++ b/test/DlibDotNet.Tests/DlibDotNet.Tests.csproj @@ -18,7 +18,7 @@ - + diff --git a/test/DlibDotNet.Tests/Extensions/BitmapExtensionsTest.cs b/test/DlibDotNet.Tests/Extensions/BitmapExtensionsTest.cs new file mode 100644 index 00000000..925a0b01 --- /dev/null +++ b/test/DlibDotNet.Tests/Extensions/BitmapExtensionsTest.cs @@ -0,0 +1,232 @@ +using System; +using System.Drawing; +using System.Drawing.Imaging; +using System.IO; +using DlibDotNet.Extensions; +using Xunit; + +namespace DlibDotNet.Tests.Extensions +{ + + public class BitmapExtensionsTest : TestBase + { + + private const string LoadTarget = "Lenna"; + + private static bool Compare(Bitmap bitmap1, Bitmap bitmap2) + { + var pixelFormat1 = bitmap1.PixelFormat; + var pixelFormat2 = bitmap2.PixelFormat; + if (pixelFormat1 != pixelFormat2) + return false; + + var rect1 = new System.Drawing.Rectangle(0, 0, bitmap1.Width, bitmap1.Height); + var rect2 = new System.Drawing.Rectangle(0, 0, bitmap2.Width, bitmap2.Height); + if (rect1 != rect2) + return false; + + var data1 = bitmap1.LockBits(rect1, ImageLockMode.ReadOnly, bitmap1.PixelFormat); + var data2 = bitmap2.LockBits(rect2, ImageLockMode.ReadOnly, bitmap2.PixelFormat); + + try + { + var length = data1.Stride * rect1.Height; + + unsafe + { + for (var i = 0; i < length; i++) + { + var p1 = ((byte*)data1.Scan0) + i; + var p2 = ((byte*)data2.Scan0) + i; + if (*p1 != *p2) + return false; + } + } + + return true; + } + finally + { + // create pallet + + if (data1 != null) + bitmap1.UnlockBits(data1); + if (data2 != null) + bitmap2.UnlockBits(data2); + } + } + + private static Bitmap To32Rgb(Bitmap bitmap, bool withAlpha) + { + var width = bitmap.Width; + var height = bitmap.Height; + var rect = new System.Drawing.Rectangle(0, 0, width, height); + + BitmapData srcData = null; + BitmapData dstData = null; + Bitmap dst = null; + + try + { + dst = new Bitmap(width, height, withAlpha ? PixelFormat.Format32bppArgb : PixelFormat.Format32bppRgb); + + srcData = bitmap.LockBits(rect, ImageLockMode.ReadOnly, bitmap.PixelFormat); + dstData = dst.LockBits(rect, ImageLockMode.WriteOnly, dst.PixelFormat); + + var srcStride = srcData.Stride; + var dstStride = dstData.Stride; + + switch (bitmap.PixelFormat) + { + case PixelFormat.Format24bppRgb: + unsafe + { + for (var y = 0; y < height; y++) + { + var pSrc = ((byte*)srcData.Scan0) + y * srcStride; + var pDst = ((byte*)dstData.Scan0) + y * dstStride; + for (var x = 0; x < width; x++, pSrc += 3, pDst += 4) + { + pDst[0] = pSrc[0]; + pDst[1] = pSrc[1]; + pDst[2] = pSrc[2]; + } + } + } + break; + case PixelFormat.Format32bppRgb: + case PixelFormat.Format32bppArgb: + unsafe + { + for (var y = 0; y < height; y++) + { + var pSrc = ((byte*)srcData.Scan0) + y * srcStride; + var pDst = ((byte*)dstData.Scan0) + y * dstStride; + for (var x = 0; x < width; x++, pSrc += 4, pDst += 4) + { + pDst[0] = pSrc[0]; + pDst[1] = pSrc[1]; + pDst[2] = pSrc[2]; + } + } + } + break; + default: + throw new ArgumentOutOfRangeException(); + } + } + catch + { + dst?.Dispose(); + throw; + } + finally + { + // create pallet + + if (srcData != null) + bitmap.UnlockBits(srcData); + if (dstData != null) + dst.UnlockBits(dstData); + } + + return dst; + } + + [Fact] + public void To8bppIndexedGrayscale() + { + const string testName = nameof(To8bppIndexedGrayscale); + var path = this.GetDataFile($"{LoadTarget}.png"); + + using (var rgb24 = Image.FromFile(path.FullName) as Bitmap) + using (var rgb32 = To32Rgb(rgb24, false)) + { + var tests = new[] + { + new + { + Source = rgb24, ExpectResult = PixelFormat.Format8bppIndexed + }, + new + { + Source = rgb32, ExpectResult = PixelFormat.Format8bppIndexed + } + }; + + foreach (GrayscalLumaCoefficients value in Enum.GetValues(typeof(GrayscalLumaCoefficients))) + foreach (var output in tests) + { + using (var ret = output.Source.To8bppIndexedGrayscale(value)) + { + if (ret.PixelFormat != output.ExpectResult) + Assert.True(false); + + var format = output.Source.PixelFormat.ToString(); + var cof = value.ToString(); + ret.Save(Path.Combine(this.GetOutDir(testName), $"{format}_{cof}.bmp"), ImageFormat.Bmp); + } + } + + foreach (var output in tests) + output.Source.Dispose(); + } + } + + [Fact] + public void ToArray2DFrom8bppIndexed() + { + var path = this.GetDataFile($"{LoadTarget}.png"); + + using (var rgb = new Bitmap(path.FullName)) + using (var argb = To32Rgb(rgb, false)) + { + var tests = new[] + { + new { Source = rgb, ExpectResult = PixelFormat.Format8bppIndexed }, + new { Source = argb, ExpectResult = PixelFormat.Format8bppIndexed } + }; + + foreach (GrayscalLumaCoefficients value in Enum.GetValues(typeof(GrayscalLumaCoefficients))) + foreach (var output in tests) + using (var ret = output.Source.To8bppIndexedGrayscale(value)) + { + var array = ret.ToArray2D(); + if (ret.PixelFormat != output.ExpectResult) + Assert.True(false); + if (array.ImageType != ImageTypes.UInt8) + Assert.True(false); + + this.DisposeAndCheckDisposedState(array); + } + + foreach (var output in tests) + output.Source.Dispose(); + } + } + + [Fact] + public void ToBitmap() + { + var path = this.GetDataFile($"{LoadTarget}.png"); + + using (var rgb = new Bitmap(path.FullName)) + using (var array = Dlib.LoadImage(path.FullName)) + using (var test = array.ToBitmap()) + Assert.True(Compare(rgb, test)); + } + + [Fact] + public void ToBitmapAsMatrix() + { + var path = this.GetDataFile($"{LoadTarget}.png"); + + using (var rgb = new Bitmap(path.FullName)) + using (var matrix = Dlib.LoadImageAsMatrix(path.FullName)) + using (var test = matrix.ToBitmap()) + Assert.True(Compare(rgb, test)); + } + + } + +}