mirror of
https://github.com/storytold/LiveScan3D.git
synced 2026-10-09 00:09:58 +00:00
Moved to Visual Studio 2015, OpenCV 3.2.0, x64
This commit is contained in:
+109
-4
@@ -1,41 +1,74 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release DLL|Win32">
|
||||
<Configuration>Release DLL</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release DLL|x64">
|
||||
<Configuration>Release DLL</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{973EE923-B423-4BCD-AA08-B03DA40CB51F}</ProjectGuid>
|
||||
<RootNamespace>ICP</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|x64'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
@@ -45,23 +78,42 @@
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<TargetName>$(ProjectName)</TargetName>
|
||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<TargetName>$(ProjectName)</TargetName>
|
||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|Win32'">
|
||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|x64'">
|
||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
@@ -76,6 +128,20 @@
|
||||
<AdditionalDependencies>opencv_core248d.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include\ICP;$(SolutionDir)\include</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;ICP_DLL_EXPORTS;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>opencv_world320d.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
@@ -96,6 +162,26 @@
|
||||
<AdditionalDependencies>opencv_core248.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include\ICP;$(SolutionDir)\include</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;ICP_DLL_EXPORTS;_MBCS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
|
||||
<OpenMPSupport>true</OpenMPSupport>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)\lib;</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>opencv_world320.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
@@ -115,6 +201,25 @@
|
||||
<AdditionalDependencies>opencv_core248.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release DLL|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include\ICP;$(SolutionDir)\include</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;ICP_DLL_EXPORTS;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<OpenMPSupport>true</OpenMPSupport>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)\lib;</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>opencv_world320.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\include\ICP\icp.h" />
|
||||
<ClInclude Include="..\include\nanoflann.h" />
|
||||
|
||||
+29
-26
@@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2013
|
||||
VisualStudioVersion = 12.0.21005.1
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LiveScanClient", "LiveScanClient\KinectClient.vcxproj", "{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}"
|
||||
EndProject
|
||||
@@ -16,32 +16,35 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiveScanPlayer", "LiveScanP
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release ICP as exe|Win32 = Release ICP as exe|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
Debug|x64 = Debug|x64
|
||||
Release ICP as exe|x64 = Release ICP as exe|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}.Release ICP as exe|Win32.ActiveCfg = Release|Win32
|
||||
{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}.Release|Win32.Build.0 = Release|Win32
|
||||
{78422B2C-0EF1-4A28-A40E-2A7C4A9204B1}.Debug|Win32.ActiveCfg = Debug|Any CPU
|
||||
{78422B2C-0EF1-4A28-A40E-2A7C4A9204B1}.Debug|Win32.Build.0 = Debug|Any CPU
|
||||
{78422B2C-0EF1-4A28-A40E-2A7C4A9204B1}.Release ICP as exe|Win32.ActiveCfg = Release|Any CPU
|
||||
{78422B2C-0EF1-4A28-A40E-2A7C4A9204B1}.Release|Win32.ActiveCfg = Release|Any CPU
|
||||
{78422B2C-0EF1-4A28-A40E-2A7C4A9204B1}.Release|Win32.Build.0 = Release|Any CPU
|
||||
{973EE923-B423-4BCD-AA08-B03DA40CB51F}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{973EE923-B423-4BCD-AA08-B03DA40CB51F}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{973EE923-B423-4BCD-AA08-B03DA40CB51F}.Release ICP as exe|Win32.ActiveCfg = Release|Win32
|
||||
{973EE923-B423-4BCD-AA08-B03DA40CB51F}.Release ICP as exe|Win32.Build.0 = Release|Win32
|
||||
{973EE923-B423-4BCD-AA08-B03DA40CB51F}.Release|Win32.ActiveCfg = Release DLL|Win32
|
||||
{973EE923-B423-4BCD-AA08-B03DA40CB51F}.Release|Win32.Build.0 = Release DLL|Win32
|
||||
{E52AB19C-F67D-4932-90BD-CC549C1FEC8B}.Debug|Win32.ActiveCfg = Debug|Any CPU
|
||||
{E52AB19C-F67D-4932-90BD-CC549C1FEC8B}.Debug|Win32.Build.0 = Debug|Any CPU
|
||||
{E52AB19C-F67D-4932-90BD-CC549C1FEC8B}.Release ICP as exe|Win32.ActiveCfg = Release|Any CPU
|
||||
{E52AB19C-F67D-4932-90BD-CC549C1FEC8B}.Release|Win32.ActiveCfg = Release|Any CPU
|
||||
{E52AB19C-F67D-4932-90BD-CC549C1FEC8B}.Release|Win32.Build.0 = Release|Any CPU
|
||||
{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}.Debug|x64.Build.0 = Debug|x64
|
||||
{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}.Release ICP as exe|x64.ActiveCfg = Release|x64
|
||||
{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}.Release ICP as exe|x64.Build.0 = Release|x64
|
||||
{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}.Release|x64.ActiveCfg = Release|x64
|
||||
{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}.Release|x64.Build.0 = Release|x64
|
||||
{78422B2C-0EF1-4A28-A40E-2A7C4A9204B1}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{78422B2C-0EF1-4A28-A40E-2A7C4A9204B1}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{78422B2C-0EF1-4A28-A40E-2A7C4A9204B1}.Release ICP as exe|x64.ActiveCfg = Release|Any CPU
|
||||
{78422B2C-0EF1-4A28-A40E-2A7C4A9204B1}.Release ICP as exe|x64.Build.0 = Release|Any CPU
|
||||
{78422B2C-0EF1-4A28-A40E-2A7C4A9204B1}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{78422B2C-0EF1-4A28-A40E-2A7C4A9204B1}.Release|x64.Build.0 = Release|Any CPU
|
||||
{973EE923-B423-4BCD-AA08-B03DA40CB51F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{973EE923-B423-4BCD-AA08-B03DA40CB51F}.Debug|x64.Build.0 = Debug|x64
|
||||
{973EE923-B423-4BCD-AA08-B03DA40CB51F}.Release ICP as exe|x64.ActiveCfg = Release|x64
|
||||
{973EE923-B423-4BCD-AA08-B03DA40CB51F}.Release ICP as exe|x64.Build.0 = Release|x64
|
||||
{973EE923-B423-4BCD-AA08-B03DA40CB51F}.Release|x64.ActiveCfg = Release DLL|x64
|
||||
{973EE923-B423-4BCD-AA08-B03DA40CB51F}.Release|x64.Build.0 = Release DLL|x64
|
||||
{E52AB19C-F67D-4932-90BD-CC549C1FEC8B}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{E52AB19C-F67D-4932-90BD-CC549C1FEC8B}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{E52AB19C-F67D-4932-90BD-CC549C1FEC8B}.Release ICP as exe|x64.ActiveCfg = Release|Any CPU
|
||||
{E52AB19C-F67D-4932-90BD-CC549C1FEC8B}.Release ICP as exe|x64.Build.0 = Release|Any CPU
|
||||
{E52AB19C-F67D-4932-90BD-CC549C1FEC8B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{E52AB19C-F67D-4932-90BD-CC549C1FEC8B}.Release|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\include\LiveScanClient\calibration.h" />
|
||||
@@ -49,18 +57,32 @@
|
||||
<ProjectGuid>{9B550BBA-EAFB-4D12-8B1C-8FDA39361F52}</ProjectGuid>
|
||||
<RootNamespace>KinectClient</RootNamespace>
|
||||
<ProjectName>LiveScanClient</ProjectName>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v140</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
@@ -70,18 +92,32 @@
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||
<TargetName>$(ProjectName)D</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<TargetName>$(ProjectName)D</TargetName>
|
||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||
<TargetName>$(ProjectName)</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<TargetName>$(ProjectName)</TargetName>
|
||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
@@ -97,6 +133,21 @@
|
||||
<SubSystem>NotSet</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(KINECTSDK20_DIR)\inc;$(SolutionDir)\include\LiveScanClient;$(SolutionDir)\include;$(ProjectDir)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(KINECTSDK20_DIR)\lib\x64;$(SolutionDir)lib</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>opencv_world320d.lib;kinect20.lib;libzstd.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<SubSystem>NotSet</SubSystem>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
@@ -117,6 +168,26 @@
|
||||
<AdditionalLibraryDirectories>c:\Program Files\Microsoft SDKs\Kinect\v2.0_1409\Lib\x86\;D:\opencv\build\x86\vc12\lib;$(KINECTSDK20_DIR)\lib\x86;$(SolutionDir)lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>$(KINECTSDK20_DIR)\inc;$(SolutionDir)\include\LiveScanClient;$(SolutionDir)\include;$(ProjectDir)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_UNICODE;UNICODE;_WINSOCK_DEPRACATED_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<OpenMPSupport>true</OpenMPSupport>
|
||||
<EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>opencv_world320.lib;kinect20.lib;libzstd.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(KINECTSDK20_DIR)\lib\x64;$(SolutionDir)lib</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
@@ -23,7 +23,7 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+5
-14
@@ -40,8 +40,8 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_OLD_CV_H__
|
||||
#define __OPENCV_OLD_CV_H__
|
||||
#ifndef OPENCV_OLD_CV_H
|
||||
#define OPENCV_OLD_CV_H
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define CV_DO_PRAGMA(x) __pragma(x)
|
||||
@@ -61,22 +61,13 @@
|
||||
//CV_WARNING("This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module")
|
||||
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/video/tracking.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/flann/flann.hpp"
|
||||
#include "opencv2/calib3d/calib3d.hpp"
|
||||
#include "opencv2/objdetect/objdetect.hpp"
|
||||
#include "opencv2/legacy/compat.hpp"
|
||||
#include "opencv2/photo/photo_c.h"
|
||||
#include "opencv2/video/tracking_c.h"
|
||||
#include "opencv2/objdetect/objdetect_c.h"
|
||||
|
||||
#if !defined(CV_IMPL)
|
||||
#define CV_IMPL extern "C"
|
||||
#endif //CV_IMPL
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#include "opencv2/core/internal.hpp"
|
||||
#endif //__cplusplus
|
||||
|
||||
#endif // __OPENCV_OLD_CV_H_
|
||||
|
||||
+11
-3
@@ -40,13 +40,21 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_OLD_CV_HPP__
|
||||
#define __OPENCV_OLD_CV_HPP__
|
||||
#ifndef OPENCV_OLD_CV_HPP
|
||||
#define OPENCV_OLD_CV_HPP
|
||||
|
||||
//#if defined(__GNUC__)
|
||||
//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module"
|
||||
//#endif
|
||||
|
||||
#include <cv.h>
|
||||
#include "cv.h"
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/video.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
#include "opencv2/features2d.hpp"
|
||||
#include "opencv2/calib3d.hpp"
|
||||
#include "opencv2/objdetect.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
+5
-13
@@ -39,26 +39,18 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_OLD_AUX_H__
|
||||
#define __OPENCV_OLD_AUX_H__
|
||||
#ifndef OPENCV_OLD_AUX_H
|
||||
#define OPENCV_OLD_AUX_H
|
||||
|
||||
//#if defined(__GNUC__)
|
||||
//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module"
|
||||
//#endif
|
||||
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/imgproc/imgproc_c.h"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/video/tracking.hpp"
|
||||
#include "opencv2/video/background_segm.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/calib3d/calib3d.hpp"
|
||||
#include "opencv2/objdetect/objdetect.hpp"
|
||||
#include "opencv2/legacy/legacy.hpp"
|
||||
#include "opencv2/legacy/compat.hpp"
|
||||
#include "opencv2/legacy/blobtrack.hpp"
|
||||
#include "opencv2/contrib/contrib.hpp"
|
||||
#include "opencv2/photo/photo_c.h"
|
||||
#include "opencv2/video/tracking_c.h"
|
||||
#include "opencv2/objdetect/objdetect_c.h"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -39,13 +39,14 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_OLD_AUX_HPP__
|
||||
#define __OPENCV_OLD_AUX_HPP__
|
||||
#ifndef OPENCV_OLD_AUX_HPP
|
||||
#define OPENCV_OLD_AUX_HPP
|
||||
|
||||
//#if defined(__GNUC__)
|
||||
//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module"
|
||||
//#endif
|
||||
|
||||
#include <cvaux.h>
|
||||
#include "cvaux.h"
|
||||
#include "opencv2/core/utility.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
|
||||
|
||||
#ifndef __OPENCV_OLD_WIMAGE_HPP__
|
||||
#define __OPENCV_OLD_WIMAGE_HPP__
|
||||
#ifndef OPENCV_OLD_WIMAGE_HPP
|
||||
#define OPENCV_OLD_WIMAGE_HPP
|
||||
|
||||
#include "opencv2/core/wimage.hpp"
|
||||
|
||||
|
||||
@@ -40,14 +40,13 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_OLD_CXCORE_H__
|
||||
#define __OPENCV_OLD_CXCORE_H__
|
||||
#ifndef OPENCV_OLD_CXCORE_H
|
||||
#define OPENCV_OLD_CXCORE_H
|
||||
|
||||
//#if defined(__GNUC__)
|
||||
//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module"
|
||||
//#endif
|
||||
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -40,13 +40,14 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_OLD_CXCORE_HPP__
|
||||
#define __OPENCV_OLD_CXCORE_HPP__
|
||||
#ifndef OPENCV_OLD_CXCORE_HPP
|
||||
#define OPENCV_OLD_CXCORE_HPP
|
||||
|
||||
//#if defined(__GNUC__)
|
||||
//#warning "This is a deprecated opencv header provided for compatibility. Please include a header from a corresponding opencv module"
|
||||
//#endif
|
||||
|
||||
#include <cxcore.h>
|
||||
#include "cxcore.h"
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
@@ -40,8 +40,8 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_OLD_EIGEN_HPP__
|
||||
#define __OPENCV_OLD_EIGEN_HPP__
|
||||
#ifndef OPENCV_OLD_EIGEN_HPP
|
||||
#define OPENCV_OLD_EIGEN_HPP
|
||||
|
||||
#include "opencv2/core/eigen.hpp"
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef __OPENCV_OLD_CXMISC_H__
|
||||
#define __OPENCV_OLD_CXMISC_H__
|
||||
#ifndef OPENCV_OLD_CXMISC_H
|
||||
#define OPENCV_OLD_CXMISC_H
|
||||
|
||||
#include "opencv2/core/internal.hpp"
|
||||
#ifdef __cplusplus
|
||||
# include "opencv2/core/utility.hpp"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -39,12 +39,10 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_OLD_HIGHGUI_H__
|
||||
#define __OPENCV_OLD_HIGHGUI_H__
|
||||
#ifndef OPENCV_OLD_HIGHGUI_H
|
||||
#define OPENCV_OLD_HIGHGUI_H
|
||||
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/highgui/highgui_c.h"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
+3
-4
@@ -38,11 +38,10 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_OLD_ML_H__
|
||||
#define __OPENCV_OLD_ML_H__
|
||||
#ifndef OPENCV_OLD_ML_H
|
||||
#define OPENCV_OLD_ML_H
|
||||
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/ml/ml.hpp"
|
||||
#include "opencv2/ml.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,11 +7,12 @@
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -40,712 +41,8 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_CALIB3D_HPP__
|
||||
#define __OPENCV_CALIB3D_HPP__
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#ifdef __OPENCV_BUILD
|
||||
#error this is a compatibility header which should not be used inside the OpenCV library
|
||||
#endif
|
||||
|
||||
/****************************************************************************************\
|
||||
* Camera Calibration, Pose Estimation and Stereo *
|
||||
\****************************************************************************************/
|
||||
|
||||
typedef struct CvPOSITObject CvPOSITObject;
|
||||
|
||||
/* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */
|
||||
CVAPI(CvPOSITObject*) cvCreatePOSITObject( CvPoint3D32f* points, int point_count );
|
||||
|
||||
|
||||
/* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of
|
||||
an object given its model and projection in a weak-perspective case */
|
||||
CVAPI(void) cvPOSIT( CvPOSITObject* posit_object, CvPoint2D32f* image_points,
|
||||
double focal_length, CvTermCriteria criteria,
|
||||
float* rotation_matrix, float* translation_vector);
|
||||
|
||||
/* Releases CvPOSITObject structure */
|
||||
CVAPI(void) cvReleasePOSITObject( CvPOSITObject** posit_object );
|
||||
|
||||
/* updates the number of RANSAC iterations */
|
||||
CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob,
|
||||
int model_points, int max_iters );
|
||||
|
||||
CVAPI(void) cvConvertPointsHomogeneous( const CvMat* src, CvMat* dst );
|
||||
|
||||
/* Calculates fundamental matrix given a set of corresponding points */
|
||||
#define CV_FM_7POINT 1
|
||||
#define CV_FM_8POINT 2
|
||||
|
||||
#define CV_LMEDS 4
|
||||
#define CV_RANSAC 8
|
||||
|
||||
#define CV_FM_LMEDS_ONLY CV_LMEDS
|
||||
#define CV_FM_RANSAC_ONLY CV_RANSAC
|
||||
#define CV_FM_LMEDS CV_LMEDS
|
||||
#define CV_FM_RANSAC CV_RANSAC
|
||||
|
||||
enum
|
||||
{
|
||||
CV_ITERATIVE = 0,
|
||||
CV_EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation"
|
||||
CV_P3P = 2 // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem"
|
||||
};
|
||||
|
||||
CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2,
|
||||
CvMat* fundamental_matrix,
|
||||
int method CV_DEFAULT(CV_FM_RANSAC),
|
||||
double param1 CV_DEFAULT(3.), double param2 CV_DEFAULT(0.99),
|
||||
CvMat* status CV_DEFAULT(NULL) );
|
||||
|
||||
/* For each input point on one of images
|
||||
computes parameters of the corresponding
|
||||
epipolar line on the other image */
|
||||
CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points,
|
||||
int which_image,
|
||||
const CvMat* fundamental_matrix,
|
||||
CvMat* correspondent_lines );
|
||||
|
||||
/* Triangulation functions */
|
||||
|
||||
CVAPI(void) cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2,
|
||||
CvMat* projPoints1, CvMat* projPoints2,
|
||||
CvMat* points4D);
|
||||
|
||||
CVAPI(void) cvCorrectMatches(CvMat* F, CvMat* points1, CvMat* points2,
|
||||
CvMat* new_points1, CvMat* new_points2);
|
||||
|
||||
|
||||
/* Computes the optimal new camera matrix according to the free scaling parameter alpha:
|
||||
alpha=0 - only valid pixels will be retained in the undistorted image
|
||||
alpha=1 - all the source image pixels will be retained in the undistorted image
|
||||
*/
|
||||
CVAPI(void) cvGetOptimalNewCameraMatrix( const CvMat* camera_matrix,
|
||||
const CvMat* dist_coeffs,
|
||||
CvSize image_size, double alpha,
|
||||
CvMat* new_camera_matrix,
|
||||
CvSize new_imag_size CV_DEFAULT(cvSize(0,0)),
|
||||
CvRect* valid_pixel_ROI CV_DEFAULT(0),
|
||||
int center_principal_point CV_DEFAULT(0));
|
||||
|
||||
/* Converts rotation vector to rotation matrix or vice versa */
|
||||
CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst,
|
||||
CvMat* jacobian CV_DEFAULT(0) );
|
||||
|
||||
/* Finds perspective transformation between the object plane and image (view) plane */
|
||||
CVAPI(int) cvFindHomography( const CvMat* src_points,
|
||||
const CvMat* dst_points,
|
||||
CvMat* homography,
|
||||
int method CV_DEFAULT(0),
|
||||
double ransacReprojThreshold CV_DEFAULT(3),
|
||||
CvMat* mask CV_DEFAULT(0));
|
||||
|
||||
/* Computes RQ decomposition for 3x3 matrices */
|
||||
CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ,
|
||||
CvMat *matrixQx CV_DEFAULT(NULL),
|
||||
CvMat *matrixQy CV_DEFAULT(NULL),
|
||||
CvMat *matrixQz CV_DEFAULT(NULL),
|
||||
CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
|
||||
|
||||
/* Computes projection matrix decomposition */
|
||||
CVAPI(void) cvDecomposeProjectionMatrix( const CvMat *projMatr, CvMat *calibMatr,
|
||||
CvMat *rotMatr, CvMat *posVect,
|
||||
CvMat *rotMatrX CV_DEFAULT(NULL),
|
||||
CvMat *rotMatrY CV_DEFAULT(NULL),
|
||||
CvMat *rotMatrZ CV_DEFAULT(NULL),
|
||||
CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
|
||||
|
||||
/* Computes d(AB)/dA and d(AB)/dB */
|
||||
CVAPI(void) cvCalcMatMulDeriv( const CvMat* A, const CvMat* B, CvMat* dABdA, CvMat* dABdB );
|
||||
|
||||
/* Computes r3 = rodrigues(rodrigues(r2)*rodrigues(r1)),
|
||||
t3 = rodrigues(r2)*t1 + t2 and the respective derivatives */
|
||||
CVAPI(void) cvComposeRT( const CvMat* _rvec1, const CvMat* _tvec1,
|
||||
const CvMat* _rvec2, const CvMat* _tvec2,
|
||||
CvMat* _rvec3, CvMat* _tvec3,
|
||||
CvMat* dr3dr1 CV_DEFAULT(0), CvMat* dr3dt1 CV_DEFAULT(0),
|
||||
CvMat* dr3dr2 CV_DEFAULT(0), CvMat* dr3dt2 CV_DEFAULT(0),
|
||||
CvMat* dt3dr1 CV_DEFAULT(0), CvMat* dt3dt1 CV_DEFAULT(0),
|
||||
CvMat* dt3dr2 CV_DEFAULT(0), CvMat* dt3dt2 CV_DEFAULT(0) );
|
||||
|
||||
/* Projects object points to the view plane using
|
||||
the specified extrinsic and intrinsic camera parameters */
|
||||
CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector,
|
||||
const CvMat* translation_vector, const CvMat* camera_matrix,
|
||||
const CvMat* distortion_coeffs, CvMat* image_points,
|
||||
CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL),
|
||||
CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL),
|
||||
CvMat* dpddist CV_DEFAULT(NULL),
|
||||
double aspect_ratio CV_DEFAULT(0));
|
||||
|
||||
/* Finds extrinsic camera parameters from
|
||||
a few known corresponding point pairs and intrinsic parameters */
|
||||
CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points,
|
||||
const CvMat* image_points,
|
||||
const CvMat* camera_matrix,
|
||||
const CvMat* distortion_coeffs,
|
||||
CvMat* rotation_vector,
|
||||
CvMat* translation_vector,
|
||||
int use_extrinsic_guess CV_DEFAULT(0) );
|
||||
|
||||
/* Computes initial estimate of the intrinsic camera parameters
|
||||
in case of planar calibration target (e.g. chessboard) */
|
||||
CVAPI(void) cvInitIntrinsicParams2D( const CvMat* object_points,
|
||||
const CvMat* image_points,
|
||||
const CvMat* npoints, CvSize image_size,
|
||||
CvMat* camera_matrix,
|
||||
double aspect_ratio CV_DEFAULT(1.) );
|
||||
|
||||
#define CV_CALIB_CB_ADAPTIVE_THRESH 1
|
||||
#define CV_CALIB_CB_NORMALIZE_IMAGE 2
|
||||
#define CV_CALIB_CB_FILTER_QUADS 4
|
||||
#define CV_CALIB_CB_FAST_CHECK 8
|
||||
|
||||
// Performs a fast check if a chessboard is in the input image. This is a workaround to
|
||||
// a problem of cvFindChessboardCorners being slow on images with no chessboard
|
||||
// - src: input image
|
||||
// - size: chessboard size
|
||||
// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called,
|
||||
// 0 if there is no chessboard, -1 in case of error
|
||||
CVAPI(int) cvCheckChessboard(IplImage* src, CvSize size);
|
||||
|
||||
/* Detects corners on a chessboard calibration pattern */
|
||||
CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size,
|
||||
CvPoint2D32f* corners,
|
||||
int* corner_count CV_DEFAULT(NULL),
|
||||
int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+CV_CALIB_CB_NORMALIZE_IMAGE) );
|
||||
|
||||
/* Draws individual chessboard corners or the whole chessboard detected */
|
||||
CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size,
|
||||
CvPoint2D32f* corners,
|
||||
int count, int pattern_was_found );
|
||||
|
||||
#define CV_CALIB_USE_INTRINSIC_GUESS 1
|
||||
#define CV_CALIB_FIX_ASPECT_RATIO 2
|
||||
#define CV_CALIB_FIX_PRINCIPAL_POINT 4
|
||||
#define CV_CALIB_ZERO_TANGENT_DIST 8
|
||||
#define CV_CALIB_FIX_FOCAL_LENGTH 16
|
||||
#define CV_CALIB_FIX_K1 32
|
||||
#define CV_CALIB_FIX_K2 64
|
||||
#define CV_CALIB_FIX_K3 128
|
||||
#define CV_CALIB_FIX_K4 2048
|
||||
#define CV_CALIB_FIX_K5 4096
|
||||
#define CV_CALIB_FIX_K6 8192
|
||||
#define CV_CALIB_RATIONAL_MODEL 16384
|
||||
|
||||
/* Finds intrinsic and extrinsic camera parameters
|
||||
from a few views of known calibration pattern */
|
||||
CVAPI(double) cvCalibrateCamera2( const CvMat* object_points,
|
||||
const CvMat* image_points,
|
||||
const CvMat* point_counts,
|
||||
CvSize image_size,
|
||||
CvMat* camera_matrix,
|
||||
CvMat* distortion_coeffs,
|
||||
CvMat* rotation_vectors CV_DEFAULT(NULL),
|
||||
CvMat* translation_vectors CV_DEFAULT(NULL),
|
||||
int flags CV_DEFAULT(0),
|
||||
CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(
|
||||
CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,DBL_EPSILON)) );
|
||||
|
||||
/* Computes various useful characteristics of the camera from the data computed by
|
||||
cvCalibrateCamera2 */
|
||||
CVAPI(void) cvCalibrationMatrixValues( const CvMat *camera_matrix,
|
||||
CvSize image_size,
|
||||
double aperture_width CV_DEFAULT(0),
|
||||
double aperture_height CV_DEFAULT(0),
|
||||
double *fovx CV_DEFAULT(NULL),
|
||||
double *fovy CV_DEFAULT(NULL),
|
||||
double *focal_length CV_DEFAULT(NULL),
|
||||
CvPoint2D64f *principal_point CV_DEFAULT(NULL),
|
||||
double *pixel_aspect_ratio CV_DEFAULT(NULL));
|
||||
|
||||
#define CV_CALIB_FIX_INTRINSIC 256
|
||||
#define CV_CALIB_SAME_FOCAL_LENGTH 512
|
||||
|
||||
/* Computes the transformation from one camera coordinate system to another one
|
||||
from a few correspondent views of the same calibration target. Optionally, calibrates
|
||||
both cameras */
|
||||
CVAPI(double) cvStereoCalibrate( const CvMat* object_points, const CvMat* image_points1,
|
||||
const CvMat* image_points2, const CvMat* npoints,
|
||||
CvMat* camera_matrix1, CvMat* dist_coeffs1,
|
||||
CvMat* camera_matrix2, CvMat* dist_coeffs2,
|
||||
CvSize image_size, CvMat* R, CvMat* T,
|
||||
CvMat* E CV_DEFAULT(0), CvMat* F CV_DEFAULT(0),
|
||||
CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(
|
||||
CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,1e-6)),
|
||||
int flags CV_DEFAULT(CV_CALIB_FIX_INTRINSIC));
|
||||
|
||||
#define CV_CALIB_ZERO_DISPARITY 1024
|
||||
|
||||
/* Computes 3D rotations (+ optional shift) for each camera coordinate system to make both
|
||||
views parallel (=> to make all the epipolar lines horizontal or vertical) */
|
||||
CVAPI(void) cvStereoRectify( const CvMat* camera_matrix1, const CvMat* camera_matrix2,
|
||||
const CvMat* dist_coeffs1, const CvMat* dist_coeffs2,
|
||||
CvSize image_size, const CvMat* R, const CvMat* T,
|
||||
CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2,
|
||||
CvMat* Q CV_DEFAULT(0),
|
||||
int flags CV_DEFAULT(CV_CALIB_ZERO_DISPARITY),
|
||||
double alpha CV_DEFAULT(-1),
|
||||
CvSize new_image_size CV_DEFAULT(cvSize(0,0)),
|
||||
CvRect* valid_pix_ROI1 CV_DEFAULT(0),
|
||||
CvRect* valid_pix_ROI2 CV_DEFAULT(0));
|
||||
|
||||
/* Computes rectification transformations for uncalibrated pair of images using a set
|
||||
of point correspondences */
|
||||
CVAPI(int) cvStereoRectifyUncalibrated( const CvMat* points1, const CvMat* points2,
|
||||
const CvMat* F, CvSize img_size,
|
||||
CvMat* H1, CvMat* H2,
|
||||
double threshold CV_DEFAULT(5));
|
||||
|
||||
|
||||
|
||||
/* stereo correspondence parameters and functions */
|
||||
|
||||
#define CV_STEREO_BM_NORMALIZED_RESPONSE 0
|
||||
#define CV_STEREO_BM_XSOBEL 1
|
||||
|
||||
/* Block matching algorithm structure */
|
||||
typedef struct CvStereoBMState
|
||||
{
|
||||
// pre-filtering (normalization of input images)
|
||||
int preFilterType; // =CV_STEREO_BM_NORMALIZED_RESPONSE now
|
||||
int preFilterSize; // averaging window size: ~5x5..21x21
|
||||
int preFilterCap; // the output of pre-filtering is clipped by [-preFilterCap,preFilterCap]
|
||||
|
||||
// correspondence using Sum of Absolute Difference (SAD)
|
||||
int SADWindowSize; // ~5x5..21x21
|
||||
int minDisparity; // minimum disparity (can be negative)
|
||||
int numberOfDisparities; // maximum disparity - minimum disparity (> 0)
|
||||
|
||||
// post-filtering
|
||||
int textureThreshold; // the disparity is only computed for pixels
|
||||
// with textured enough neighborhood
|
||||
int uniquenessRatio; // accept the computed disparity d* only if
|
||||
// SAD(d) >= SAD(d*)*(1 + uniquenessRatio/100.)
|
||||
// for any d != d*+/-1 within the search range.
|
||||
int speckleWindowSize; // disparity variation window
|
||||
int speckleRange; // acceptable range of variation in window
|
||||
|
||||
int trySmallerWindows; // if 1, the results may be more accurate,
|
||||
// at the expense of slower processing
|
||||
CvRect roi1, roi2;
|
||||
int disp12MaxDiff;
|
||||
|
||||
// temporary buffers
|
||||
CvMat* preFilteredImg0;
|
||||
CvMat* preFilteredImg1;
|
||||
CvMat* slidingSumBuf;
|
||||
CvMat* cost;
|
||||
CvMat* disp;
|
||||
} CvStereoBMState;
|
||||
|
||||
#define CV_STEREO_BM_BASIC 0
|
||||
#define CV_STEREO_BM_FISH_EYE 1
|
||||
#define CV_STEREO_BM_NARROW 2
|
||||
|
||||
CVAPI(CvStereoBMState*) cvCreateStereoBMState(int preset CV_DEFAULT(CV_STEREO_BM_BASIC),
|
||||
int numberOfDisparities CV_DEFAULT(0));
|
||||
|
||||
CVAPI(void) cvReleaseStereoBMState( CvStereoBMState** state );
|
||||
|
||||
CVAPI(void) cvFindStereoCorrespondenceBM( const CvArr* left, const CvArr* right,
|
||||
CvArr* disparity, CvStereoBMState* state );
|
||||
|
||||
CVAPI(CvRect) cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity,
|
||||
int numberOfDisparities, int SADWindowSize );
|
||||
|
||||
CVAPI(void) cvValidateDisparity( CvArr* disparity, const CvArr* cost,
|
||||
int minDisparity, int numberOfDisparities,
|
||||
int disp12MaxDiff CV_DEFAULT(1) );
|
||||
|
||||
/* Reprojects the computed disparity image to the 3D space using the specified 4x4 matrix */
|
||||
CVAPI(void) cvReprojectImageTo3D( const CvArr* disparityImage,
|
||||
CvArr* _3dImage, const CvMat* Q,
|
||||
int handleMissingValues CV_DEFAULT(0) );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
class CV_EXPORTS CvLevMarq
|
||||
{
|
||||
public:
|
||||
CvLevMarq();
|
||||
CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria=
|
||||
cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
|
||||
bool completeSymmFlag=false );
|
||||
~CvLevMarq();
|
||||
void init( int nparams, int nerrs, CvTermCriteria criteria=
|
||||
cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
|
||||
bool completeSymmFlag=false );
|
||||
bool update( const CvMat*& param, CvMat*& J, CvMat*& err );
|
||||
bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm );
|
||||
|
||||
void clear();
|
||||
void step();
|
||||
enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 };
|
||||
|
||||
cv::Ptr<CvMat> mask;
|
||||
cv::Ptr<CvMat> prevParam;
|
||||
cv::Ptr<CvMat> param;
|
||||
cv::Ptr<CvMat> J;
|
||||
cv::Ptr<CvMat> err;
|
||||
cv::Ptr<CvMat> JtJ;
|
||||
cv::Ptr<CvMat> JtJN;
|
||||
cv::Ptr<CvMat> JtErr;
|
||||
cv::Ptr<CvMat> JtJV;
|
||||
cv::Ptr<CvMat> JtJW;
|
||||
double prevErrNorm, errNorm;
|
||||
int lambdaLg10;
|
||||
CvTermCriteria criteria;
|
||||
int state;
|
||||
int iters;
|
||||
bool completeSymmFlag;
|
||||
};
|
||||
|
||||
namespace cv
|
||||
{
|
||||
//! converts rotation vector to rotation matrix or vice versa using Rodrigues transformation
|
||||
CV_EXPORTS_W void Rodrigues(InputArray src, OutputArray dst, OutputArray jacobian=noArray());
|
||||
|
||||
//! type of the robust estimation algorithm
|
||||
enum
|
||||
{
|
||||
LMEDS=CV_LMEDS, //!< least-median algorithm
|
||||
RANSAC=CV_RANSAC //!< RANSAC algorithm
|
||||
};
|
||||
|
||||
//! computes the best-fit perspective transformation mapping srcPoints to dstPoints.
|
||||
CV_EXPORTS_W Mat findHomography( InputArray srcPoints, InputArray dstPoints,
|
||||
int method=0, double ransacReprojThreshold=3,
|
||||
OutputArray mask=noArray());
|
||||
|
||||
//! variant of findHomography for backward compatibility
|
||||
CV_EXPORTS Mat findHomography( InputArray srcPoints, InputArray dstPoints,
|
||||
OutputArray mask, int method=0, double ransacReprojThreshold=3);
|
||||
|
||||
//! Computes RQ decomposition of 3x3 matrix
|
||||
CV_EXPORTS_W Vec3d RQDecomp3x3( InputArray src, OutputArray mtxR, OutputArray mtxQ,
|
||||
OutputArray Qx=noArray(),
|
||||
OutputArray Qy=noArray(),
|
||||
OutputArray Qz=noArray());
|
||||
|
||||
//! Decomposes the projection matrix into camera matrix and the rotation martix and the translation vector
|
||||
CV_EXPORTS_W void decomposeProjectionMatrix( InputArray projMatrix, OutputArray cameraMatrix,
|
||||
OutputArray rotMatrix, OutputArray transVect,
|
||||
OutputArray rotMatrixX=noArray(),
|
||||
OutputArray rotMatrixY=noArray(),
|
||||
OutputArray rotMatrixZ=noArray(),
|
||||
OutputArray eulerAngles=noArray() );
|
||||
|
||||
//! computes derivatives of the matrix product w.r.t each of the multiplied matrix coefficients
|
||||
CV_EXPORTS_W void matMulDeriv( InputArray A, InputArray B,
|
||||
OutputArray dABdA,
|
||||
OutputArray dABdB );
|
||||
|
||||
//! composes 2 [R|t] transformations together. Also computes the derivatives of the result w.r.t the arguments
|
||||
CV_EXPORTS_W void composeRT( InputArray rvec1, InputArray tvec1,
|
||||
InputArray rvec2, InputArray tvec2,
|
||||
OutputArray rvec3, OutputArray tvec3,
|
||||
OutputArray dr3dr1=noArray(), OutputArray dr3dt1=noArray(),
|
||||
OutputArray dr3dr2=noArray(), OutputArray dr3dt2=noArray(),
|
||||
OutputArray dt3dr1=noArray(), OutputArray dt3dt1=noArray(),
|
||||
OutputArray dt3dr2=noArray(), OutputArray dt3dt2=noArray() );
|
||||
|
||||
//! projects points from the model coordinate space to the image coordinates. Also computes derivatives of the image coordinates w.r.t the intrinsic and extrinsic camera parameters
|
||||
CV_EXPORTS_W void projectPoints( InputArray objectPoints,
|
||||
InputArray rvec, InputArray tvec,
|
||||
InputArray cameraMatrix, InputArray distCoeffs,
|
||||
OutputArray imagePoints,
|
||||
OutputArray jacobian=noArray(),
|
||||
double aspectRatio=0 );
|
||||
|
||||
//! computes the camera pose from a few 3D points and the corresponding projections. The outliers are not handled.
|
||||
enum
|
||||
{
|
||||
ITERATIVE=CV_ITERATIVE,
|
||||
EPNP=CV_EPNP,
|
||||
P3P=CV_P3P
|
||||
};
|
||||
CV_EXPORTS_W bool solvePnP( InputArray objectPoints, InputArray imagePoints,
|
||||
InputArray cameraMatrix, InputArray distCoeffs,
|
||||
OutputArray rvec, OutputArray tvec,
|
||||
bool useExtrinsicGuess=false, int flags=ITERATIVE);
|
||||
|
||||
//! computes the camera pose from a few 3D points and the corresponding projections. The outliers are possible.
|
||||
CV_EXPORTS_W void solvePnPRansac( InputArray objectPoints,
|
||||
InputArray imagePoints,
|
||||
InputArray cameraMatrix,
|
||||
InputArray distCoeffs,
|
||||
OutputArray rvec,
|
||||
OutputArray tvec,
|
||||
bool useExtrinsicGuess = false,
|
||||
int iterationsCount = 100,
|
||||
float reprojectionError = 8.0,
|
||||
int minInliersCount = 100,
|
||||
OutputArray inliers = noArray(),
|
||||
int flags = ITERATIVE);
|
||||
|
||||
//! initializes camera matrix from a few 3D points and the corresponding projections.
|
||||
CV_EXPORTS_W Mat initCameraMatrix2D( InputArrayOfArrays objectPoints,
|
||||
InputArrayOfArrays imagePoints,
|
||||
Size imageSize, double aspectRatio=1. );
|
||||
|
||||
enum { CALIB_CB_ADAPTIVE_THRESH = 1, CALIB_CB_NORMALIZE_IMAGE = 2,
|
||||
CALIB_CB_FILTER_QUADS = 4, CALIB_CB_FAST_CHECK = 8 };
|
||||
|
||||
//! finds checkerboard pattern of the specified size in the image
|
||||
CV_EXPORTS_W bool findChessboardCorners( InputArray image, Size patternSize,
|
||||
OutputArray corners,
|
||||
int flags=CALIB_CB_ADAPTIVE_THRESH+CALIB_CB_NORMALIZE_IMAGE );
|
||||
|
||||
//! finds subpixel-accurate positions of the chessboard corners
|
||||
CV_EXPORTS bool find4QuadCornerSubpix(InputArray img, InputOutputArray corners, Size region_size);
|
||||
|
||||
//! draws the checkerboard pattern (found or partly found) in the image
|
||||
CV_EXPORTS_W void drawChessboardCorners( InputOutputArray image, Size patternSize,
|
||||
InputArray corners, bool patternWasFound );
|
||||
|
||||
enum { CALIB_CB_SYMMETRIC_GRID = 1, CALIB_CB_ASYMMETRIC_GRID = 2,
|
||||
CALIB_CB_CLUSTERING = 4 };
|
||||
|
||||
//! finds circles' grid pattern of the specified size in the image
|
||||
CV_EXPORTS_W bool findCirclesGrid( InputArray image, Size patternSize,
|
||||
OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID,
|
||||
const Ptr<FeatureDetector> &blobDetector = new SimpleBlobDetector());
|
||||
|
||||
//! the deprecated function. Use findCirclesGrid() instead of it.
|
||||
CV_EXPORTS_W bool findCirclesGridDefault( InputArray image, Size patternSize,
|
||||
OutputArray centers, int flags=CALIB_CB_SYMMETRIC_GRID );
|
||||
enum
|
||||
{
|
||||
CALIB_USE_INTRINSIC_GUESS = CV_CALIB_USE_INTRINSIC_GUESS,
|
||||
CALIB_FIX_ASPECT_RATIO = CV_CALIB_FIX_ASPECT_RATIO,
|
||||
CALIB_FIX_PRINCIPAL_POINT = CV_CALIB_FIX_PRINCIPAL_POINT,
|
||||
CALIB_ZERO_TANGENT_DIST = CV_CALIB_ZERO_TANGENT_DIST,
|
||||
CALIB_FIX_FOCAL_LENGTH = CV_CALIB_FIX_FOCAL_LENGTH,
|
||||
CALIB_FIX_K1 = CV_CALIB_FIX_K1,
|
||||
CALIB_FIX_K2 = CV_CALIB_FIX_K2,
|
||||
CALIB_FIX_K3 = CV_CALIB_FIX_K3,
|
||||
CALIB_FIX_K4 = CV_CALIB_FIX_K4,
|
||||
CALIB_FIX_K5 = CV_CALIB_FIX_K5,
|
||||
CALIB_FIX_K6 = CV_CALIB_FIX_K6,
|
||||
CALIB_RATIONAL_MODEL = CV_CALIB_RATIONAL_MODEL,
|
||||
// only for stereo
|
||||
CALIB_FIX_INTRINSIC = CV_CALIB_FIX_INTRINSIC,
|
||||
CALIB_SAME_FOCAL_LENGTH = CV_CALIB_SAME_FOCAL_LENGTH,
|
||||
// for stereo rectification
|
||||
CALIB_ZERO_DISPARITY = CV_CALIB_ZERO_DISPARITY
|
||||
};
|
||||
|
||||
//! finds intrinsic and extrinsic camera parameters from several fews of a known calibration pattern.
|
||||
CV_EXPORTS_W double calibrateCamera( InputArrayOfArrays objectPoints,
|
||||
InputArrayOfArrays imagePoints,
|
||||
Size imageSize,
|
||||
CV_OUT InputOutputArray cameraMatrix,
|
||||
CV_OUT InputOutputArray distCoeffs,
|
||||
OutputArrayOfArrays rvecs, OutputArrayOfArrays tvecs,
|
||||
int flags=0, TermCriteria criteria = TermCriteria(
|
||||
TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON) );
|
||||
|
||||
//! computes several useful camera characteristics from the camera matrix, camera frame resolution and the physical sensor size.
|
||||
CV_EXPORTS_W void calibrationMatrixValues( InputArray cameraMatrix,
|
||||
Size imageSize,
|
||||
double apertureWidth,
|
||||
double apertureHeight,
|
||||
CV_OUT double& fovx,
|
||||
CV_OUT double& fovy,
|
||||
CV_OUT double& focalLength,
|
||||
CV_OUT Point2d& principalPoint,
|
||||
CV_OUT double& aspectRatio );
|
||||
|
||||
//! finds intrinsic and extrinsic parameters of a stereo camera
|
||||
CV_EXPORTS_W double stereoCalibrate( InputArrayOfArrays objectPoints,
|
||||
InputArrayOfArrays imagePoints1,
|
||||
InputArrayOfArrays imagePoints2,
|
||||
CV_OUT InputOutputArray cameraMatrix1,
|
||||
CV_OUT InputOutputArray distCoeffs1,
|
||||
CV_OUT InputOutputArray cameraMatrix2,
|
||||
CV_OUT InputOutputArray distCoeffs2,
|
||||
Size imageSize, OutputArray R,
|
||||
OutputArray T, OutputArray E, OutputArray F,
|
||||
TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 1e-6),
|
||||
int flags=CALIB_FIX_INTRINSIC );
|
||||
|
||||
|
||||
//! computes the rectification transformation for a stereo camera from its intrinsic and extrinsic parameters
|
||||
CV_EXPORTS_W void stereoRectify( InputArray cameraMatrix1, InputArray distCoeffs1,
|
||||
InputArray cameraMatrix2, InputArray distCoeffs2,
|
||||
Size imageSize, InputArray R, InputArray T,
|
||||
OutputArray R1, OutputArray R2,
|
||||
OutputArray P1, OutputArray P2,
|
||||
OutputArray Q, int flags=CALIB_ZERO_DISPARITY,
|
||||
double alpha=-1, Size newImageSize=Size(),
|
||||
CV_OUT Rect* validPixROI1=0, CV_OUT Rect* validPixROI2=0 );
|
||||
|
||||
//! computes the rectification transformation for an uncalibrated stereo camera (zero distortion is assumed)
|
||||
CV_EXPORTS_W bool stereoRectifyUncalibrated( InputArray points1, InputArray points2,
|
||||
InputArray F, Size imgSize,
|
||||
OutputArray H1, OutputArray H2,
|
||||
double threshold=5 );
|
||||
|
||||
//! computes the rectification transformations for 3-head camera, where all the heads are on the same line.
|
||||
CV_EXPORTS_W float rectify3Collinear( InputArray cameraMatrix1, InputArray distCoeffs1,
|
||||
InputArray cameraMatrix2, InputArray distCoeffs2,
|
||||
InputArray cameraMatrix3, InputArray distCoeffs3,
|
||||
InputArrayOfArrays imgpt1, InputArrayOfArrays imgpt3,
|
||||
Size imageSize, InputArray R12, InputArray T12,
|
||||
InputArray R13, InputArray T13,
|
||||
OutputArray R1, OutputArray R2, OutputArray R3,
|
||||
OutputArray P1, OutputArray P2, OutputArray P3,
|
||||
OutputArray Q, double alpha, Size newImgSize,
|
||||
CV_OUT Rect* roi1, CV_OUT Rect* roi2, int flags );
|
||||
|
||||
//! returns the optimal new camera matrix
|
||||
CV_EXPORTS_W Mat getOptimalNewCameraMatrix( InputArray cameraMatrix, InputArray distCoeffs,
|
||||
Size imageSize, double alpha, Size newImgSize=Size(),
|
||||
CV_OUT Rect* validPixROI=0, bool centerPrincipalPoint=false);
|
||||
|
||||
//! converts point coordinates from normal pixel coordinates to homogeneous coordinates ((x,y)->(x,y,1))
|
||||
CV_EXPORTS_W void convertPointsToHomogeneous( InputArray src, OutputArray dst );
|
||||
|
||||
//! converts point coordinates from homogeneous to normal pixel coordinates ((x,y,z)->(x/z, y/z))
|
||||
CV_EXPORTS_W void convertPointsFromHomogeneous( InputArray src, OutputArray dst );
|
||||
|
||||
//! for backward compatibility
|
||||
CV_EXPORTS void convertPointsHomogeneous( InputArray src, OutputArray dst );
|
||||
|
||||
//! the algorithm for finding fundamental matrix
|
||||
enum
|
||||
{
|
||||
FM_7POINT = CV_FM_7POINT, //!< 7-point algorithm
|
||||
FM_8POINT = CV_FM_8POINT, //!< 8-point algorithm
|
||||
FM_LMEDS = CV_FM_LMEDS, //!< least-median algorithm
|
||||
FM_RANSAC = CV_FM_RANSAC //!< RANSAC algorithm
|
||||
};
|
||||
|
||||
//! finds fundamental matrix from a set of corresponding 2D points
|
||||
CV_EXPORTS_W Mat findFundamentalMat( InputArray points1, InputArray points2,
|
||||
int method=FM_RANSAC,
|
||||
double param1=3., double param2=0.99,
|
||||
OutputArray mask=noArray());
|
||||
|
||||
//! variant of findFundamentalMat for backward compatibility
|
||||
CV_EXPORTS Mat findFundamentalMat( InputArray points1, InputArray points2,
|
||||
OutputArray mask, int method=FM_RANSAC,
|
||||
double param1=3., double param2=0.99);
|
||||
|
||||
//! finds coordinates of epipolar lines corresponding the specified points
|
||||
CV_EXPORTS_W void computeCorrespondEpilines( InputArray points,
|
||||
int whichImage, InputArray F,
|
||||
OutputArray lines );
|
||||
|
||||
CV_EXPORTS_W void triangulatePoints( InputArray projMatr1, InputArray projMatr2,
|
||||
InputArray projPoints1, InputArray projPoints2,
|
||||
OutputArray points4D );
|
||||
|
||||
CV_EXPORTS_W void correctMatches( InputArray F, InputArray points1, InputArray points2,
|
||||
OutputArray newPoints1, OutputArray newPoints2 );
|
||||
|
||||
template<> CV_EXPORTS void Ptr<CvStereoBMState>::delete_obj();
|
||||
|
||||
/*!
|
||||
Block Matching Stereo Correspondence Algorithm
|
||||
|
||||
The class implements BM stereo correspondence algorithm by K. Konolige.
|
||||
*/
|
||||
class CV_EXPORTS_W StereoBM
|
||||
{
|
||||
public:
|
||||
enum { PREFILTER_NORMALIZED_RESPONSE = 0, PREFILTER_XSOBEL = 1,
|
||||
BASIC_PRESET=0, FISH_EYE_PRESET=1, NARROW_PRESET=2 };
|
||||
|
||||
//! the default constructor
|
||||
CV_WRAP StereoBM();
|
||||
//! the full constructor taking the camera-specific preset, number of disparities and the SAD window size
|
||||
CV_WRAP StereoBM(int preset, int ndisparities=0, int SADWindowSize=21);
|
||||
//! the method that reinitializes the state. The previous content is destroyed
|
||||
void init(int preset, int ndisparities=0, int SADWindowSize=21);
|
||||
//! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair
|
||||
CV_WRAP_AS(compute) void operator()( InputArray left, InputArray right,
|
||||
OutputArray disparity, int disptype=CV_16S );
|
||||
|
||||
//! pointer to the underlying CvStereoBMState
|
||||
Ptr<CvStereoBMState> state;
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
Semi-Global Block Matching Stereo Correspondence Algorithm
|
||||
|
||||
The class implements the original SGBM stereo correspondence algorithm by H. Hirschmuller and some its modification.
|
||||
*/
|
||||
class CV_EXPORTS_W StereoSGBM
|
||||
{
|
||||
public:
|
||||
enum { DISP_SHIFT=4, DISP_SCALE = (1<<DISP_SHIFT) };
|
||||
|
||||
//! the default constructor
|
||||
CV_WRAP StereoSGBM();
|
||||
|
||||
//! the full constructor taking all the necessary algorithm parameters
|
||||
CV_WRAP StereoSGBM(int minDisparity, int numDisparities, int SADWindowSize,
|
||||
int P1=0, int P2=0, int disp12MaxDiff=0,
|
||||
int preFilterCap=0, int uniquenessRatio=0,
|
||||
int speckleWindowSize=0, int speckleRange=0,
|
||||
bool fullDP=false);
|
||||
//! the destructor
|
||||
virtual ~StereoSGBM();
|
||||
|
||||
//! the stereo correspondence operator that computes disparity map for the specified rectified stereo pair
|
||||
CV_WRAP_AS(compute) virtual void operator()(InputArray left, InputArray right,
|
||||
OutputArray disp);
|
||||
|
||||
CV_PROP_RW int minDisparity;
|
||||
CV_PROP_RW int numberOfDisparities;
|
||||
CV_PROP_RW int SADWindowSize;
|
||||
CV_PROP_RW int preFilterCap;
|
||||
CV_PROP_RW int uniquenessRatio;
|
||||
CV_PROP_RW int P1;
|
||||
CV_PROP_RW int P2;
|
||||
CV_PROP_RW int speckleWindowSize;
|
||||
CV_PROP_RW int speckleRange;
|
||||
CV_PROP_RW int disp12MaxDiff;
|
||||
CV_PROP_RW bool fullDP;
|
||||
|
||||
protected:
|
||||
Mat buffer;
|
||||
};
|
||||
|
||||
//! filters off speckles (small regions of incorrectly computed disparity)
|
||||
CV_EXPORTS_W void filterSpeckles( InputOutputArray img, double newVal, int maxSpeckleSize, double maxDiff,
|
||||
InputOutputArray buf=noArray() );
|
||||
|
||||
//! computes valid disparity ROI from the valid ROIs of the rectified images (that are returned by cv::stereoRectify())
|
||||
CV_EXPORTS_W Rect getValidDisparityROI( Rect roi1, Rect roi2,
|
||||
int minDisparity, int numberOfDisparities,
|
||||
int SADWindowSize );
|
||||
|
||||
//! validates disparity using the left-right check. The matrix "cost" should be computed by the stereo correspondence algorithm
|
||||
CV_EXPORTS_W void validateDisparity( InputOutputArray disparity, InputArray cost,
|
||||
int minDisparity, int numberOfDisparities,
|
||||
int disp12MaxDisp=1 );
|
||||
|
||||
//! reprojects disparity image to 3D: (x,y,d)->(X,Y,Z) using the matrix Q returned by cv::stereoRectify
|
||||
CV_EXPORTS_W void reprojectImageTo3D( InputArray disparity,
|
||||
OutputArray _3dImage, InputArray Q,
|
||||
bool handleMissingValues=false,
|
||||
int ddepth=-1 );
|
||||
|
||||
CV_EXPORTS_W int estimateAffine3D(InputArray src, InputArray dst,
|
||||
OutputArray out, OutputArray inliers,
|
||||
double ransacThreshold=3, double confidence=0.99);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#include "opencv2/calib3d.hpp"
|
||||
|
||||
@@ -0,0 +1,426 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CALIB3D_C_H
|
||||
#define OPENCV_CALIB3D_C_H
|
||||
|
||||
#include "opencv2/core/core_c.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @addtogroup calib3d_c
|
||||
@{
|
||||
*/
|
||||
|
||||
/****************************************************************************************\
|
||||
* Camera Calibration, Pose Estimation and Stereo *
|
||||
\****************************************************************************************/
|
||||
|
||||
typedef struct CvPOSITObject CvPOSITObject;
|
||||
|
||||
/* Allocates and initializes CvPOSITObject structure before doing cvPOSIT */
|
||||
CVAPI(CvPOSITObject*) cvCreatePOSITObject( CvPoint3D32f* points, int point_count );
|
||||
|
||||
|
||||
/* Runs POSIT (POSe from ITeration) algorithm for determining 3d position of
|
||||
an object given its model and projection in a weak-perspective case */
|
||||
CVAPI(void) cvPOSIT( CvPOSITObject* posit_object, CvPoint2D32f* image_points,
|
||||
double focal_length, CvTermCriteria criteria,
|
||||
float* rotation_matrix, float* translation_vector);
|
||||
|
||||
/* Releases CvPOSITObject structure */
|
||||
CVAPI(void) cvReleasePOSITObject( CvPOSITObject** posit_object );
|
||||
|
||||
/* updates the number of RANSAC iterations */
|
||||
CVAPI(int) cvRANSACUpdateNumIters( double p, double err_prob,
|
||||
int model_points, int max_iters );
|
||||
|
||||
CVAPI(void) cvConvertPointsHomogeneous( const CvMat* src, CvMat* dst );
|
||||
|
||||
/* Calculates fundamental matrix given a set of corresponding points */
|
||||
#define CV_FM_7POINT 1
|
||||
#define CV_FM_8POINT 2
|
||||
|
||||
#define CV_LMEDS 4
|
||||
#define CV_RANSAC 8
|
||||
|
||||
#define CV_FM_LMEDS_ONLY CV_LMEDS
|
||||
#define CV_FM_RANSAC_ONLY CV_RANSAC
|
||||
#define CV_FM_LMEDS CV_LMEDS
|
||||
#define CV_FM_RANSAC CV_RANSAC
|
||||
|
||||
enum
|
||||
{
|
||||
CV_ITERATIVE = 0,
|
||||
CV_EPNP = 1, // F.Moreno-Noguer, V.Lepetit and P.Fua "EPnP: Efficient Perspective-n-Point Camera Pose Estimation"
|
||||
CV_P3P = 2, // X.S. Gao, X.-R. Hou, J. Tang, H.-F. Chang; "Complete Solution Classification for the Perspective-Three-Point Problem"
|
||||
CV_DLS = 3 // Joel A. Hesch and Stergios I. Roumeliotis. "A Direct Least-Squares (DLS) Method for PnP"
|
||||
};
|
||||
|
||||
CVAPI(int) cvFindFundamentalMat( const CvMat* points1, const CvMat* points2,
|
||||
CvMat* fundamental_matrix,
|
||||
int method CV_DEFAULT(CV_FM_RANSAC),
|
||||
double param1 CV_DEFAULT(3.), double param2 CV_DEFAULT(0.99),
|
||||
CvMat* status CV_DEFAULT(NULL) );
|
||||
|
||||
/* For each input point on one of images
|
||||
computes parameters of the corresponding
|
||||
epipolar line on the other image */
|
||||
CVAPI(void) cvComputeCorrespondEpilines( const CvMat* points,
|
||||
int which_image,
|
||||
const CvMat* fundamental_matrix,
|
||||
CvMat* correspondent_lines );
|
||||
|
||||
/* Triangulation functions */
|
||||
|
||||
CVAPI(void) cvTriangulatePoints(CvMat* projMatr1, CvMat* projMatr2,
|
||||
CvMat* projPoints1, CvMat* projPoints2,
|
||||
CvMat* points4D);
|
||||
|
||||
CVAPI(void) cvCorrectMatches(CvMat* F, CvMat* points1, CvMat* points2,
|
||||
CvMat* new_points1, CvMat* new_points2);
|
||||
|
||||
|
||||
/* Computes the optimal new camera matrix according to the free scaling parameter alpha:
|
||||
alpha=0 - only valid pixels will be retained in the undistorted image
|
||||
alpha=1 - all the source image pixels will be retained in the undistorted image
|
||||
*/
|
||||
CVAPI(void) cvGetOptimalNewCameraMatrix( const CvMat* camera_matrix,
|
||||
const CvMat* dist_coeffs,
|
||||
CvSize image_size, double alpha,
|
||||
CvMat* new_camera_matrix,
|
||||
CvSize new_imag_size CV_DEFAULT(cvSize(0,0)),
|
||||
CvRect* valid_pixel_ROI CV_DEFAULT(0),
|
||||
int center_principal_point CV_DEFAULT(0));
|
||||
|
||||
/* Converts rotation vector to rotation matrix or vice versa */
|
||||
CVAPI(int) cvRodrigues2( const CvMat* src, CvMat* dst,
|
||||
CvMat* jacobian CV_DEFAULT(0) );
|
||||
|
||||
/* Finds perspective transformation between the object plane and image (view) plane */
|
||||
CVAPI(int) cvFindHomography( const CvMat* src_points,
|
||||
const CvMat* dst_points,
|
||||
CvMat* homography,
|
||||
int method CV_DEFAULT(0),
|
||||
double ransacReprojThreshold CV_DEFAULT(3),
|
||||
CvMat* mask CV_DEFAULT(0),
|
||||
int maxIters CV_DEFAULT(2000),
|
||||
double confidence CV_DEFAULT(0.995));
|
||||
|
||||
/* Computes RQ decomposition for 3x3 matrices */
|
||||
CVAPI(void) cvRQDecomp3x3( const CvMat *matrixM, CvMat *matrixR, CvMat *matrixQ,
|
||||
CvMat *matrixQx CV_DEFAULT(NULL),
|
||||
CvMat *matrixQy CV_DEFAULT(NULL),
|
||||
CvMat *matrixQz CV_DEFAULT(NULL),
|
||||
CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
|
||||
|
||||
/* Computes projection matrix decomposition */
|
||||
CVAPI(void) cvDecomposeProjectionMatrix( const CvMat *projMatr, CvMat *calibMatr,
|
||||
CvMat *rotMatr, CvMat *posVect,
|
||||
CvMat *rotMatrX CV_DEFAULT(NULL),
|
||||
CvMat *rotMatrY CV_DEFAULT(NULL),
|
||||
CvMat *rotMatrZ CV_DEFAULT(NULL),
|
||||
CvPoint3D64f *eulerAngles CV_DEFAULT(NULL));
|
||||
|
||||
/* Computes d(AB)/dA and d(AB)/dB */
|
||||
CVAPI(void) cvCalcMatMulDeriv( const CvMat* A, const CvMat* B, CvMat* dABdA, CvMat* dABdB );
|
||||
|
||||
/* Computes r3 = rodrigues(rodrigues(r2)*rodrigues(r1)),
|
||||
t3 = rodrigues(r2)*t1 + t2 and the respective derivatives */
|
||||
CVAPI(void) cvComposeRT( const CvMat* _rvec1, const CvMat* _tvec1,
|
||||
const CvMat* _rvec2, const CvMat* _tvec2,
|
||||
CvMat* _rvec3, CvMat* _tvec3,
|
||||
CvMat* dr3dr1 CV_DEFAULT(0), CvMat* dr3dt1 CV_DEFAULT(0),
|
||||
CvMat* dr3dr2 CV_DEFAULT(0), CvMat* dr3dt2 CV_DEFAULT(0),
|
||||
CvMat* dt3dr1 CV_DEFAULT(0), CvMat* dt3dt1 CV_DEFAULT(0),
|
||||
CvMat* dt3dr2 CV_DEFAULT(0), CvMat* dt3dt2 CV_DEFAULT(0) );
|
||||
|
||||
/* Projects object points to the view plane using
|
||||
the specified extrinsic and intrinsic camera parameters */
|
||||
CVAPI(void) cvProjectPoints2( const CvMat* object_points, const CvMat* rotation_vector,
|
||||
const CvMat* translation_vector, const CvMat* camera_matrix,
|
||||
const CvMat* distortion_coeffs, CvMat* image_points,
|
||||
CvMat* dpdrot CV_DEFAULT(NULL), CvMat* dpdt CV_DEFAULT(NULL),
|
||||
CvMat* dpdf CV_DEFAULT(NULL), CvMat* dpdc CV_DEFAULT(NULL),
|
||||
CvMat* dpddist CV_DEFAULT(NULL),
|
||||
double aspect_ratio CV_DEFAULT(0));
|
||||
|
||||
/* Finds extrinsic camera parameters from
|
||||
a few known corresponding point pairs and intrinsic parameters */
|
||||
CVAPI(void) cvFindExtrinsicCameraParams2( const CvMat* object_points,
|
||||
const CvMat* image_points,
|
||||
const CvMat* camera_matrix,
|
||||
const CvMat* distortion_coeffs,
|
||||
CvMat* rotation_vector,
|
||||
CvMat* translation_vector,
|
||||
int use_extrinsic_guess CV_DEFAULT(0) );
|
||||
|
||||
/* Computes initial estimate of the intrinsic camera parameters
|
||||
in case of planar calibration target (e.g. chessboard) */
|
||||
CVAPI(void) cvInitIntrinsicParams2D( const CvMat* object_points,
|
||||
const CvMat* image_points,
|
||||
const CvMat* npoints, CvSize image_size,
|
||||
CvMat* camera_matrix,
|
||||
double aspect_ratio CV_DEFAULT(1.) );
|
||||
|
||||
#define CV_CALIB_CB_ADAPTIVE_THRESH 1
|
||||
#define CV_CALIB_CB_NORMALIZE_IMAGE 2
|
||||
#define CV_CALIB_CB_FILTER_QUADS 4
|
||||
#define CV_CALIB_CB_FAST_CHECK 8
|
||||
|
||||
// Performs a fast check if a chessboard is in the input image. This is a workaround to
|
||||
// a problem of cvFindChessboardCorners being slow on images with no chessboard
|
||||
// - src: input image
|
||||
// - size: chessboard size
|
||||
// Returns 1 if a chessboard can be in this image and findChessboardCorners should be called,
|
||||
// 0 if there is no chessboard, -1 in case of error
|
||||
CVAPI(int) cvCheckChessboard(IplImage* src, CvSize size);
|
||||
|
||||
/* Detects corners on a chessboard calibration pattern */
|
||||
CVAPI(int) cvFindChessboardCorners( const void* image, CvSize pattern_size,
|
||||
CvPoint2D32f* corners,
|
||||
int* corner_count CV_DEFAULT(NULL),
|
||||
int flags CV_DEFAULT(CV_CALIB_CB_ADAPTIVE_THRESH+CV_CALIB_CB_NORMALIZE_IMAGE) );
|
||||
|
||||
/* Draws individual chessboard corners or the whole chessboard detected */
|
||||
CVAPI(void) cvDrawChessboardCorners( CvArr* image, CvSize pattern_size,
|
||||
CvPoint2D32f* corners,
|
||||
int count, int pattern_was_found );
|
||||
|
||||
#define CV_CALIB_USE_INTRINSIC_GUESS 1
|
||||
#define CV_CALIB_FIX_ASPECT_RATIO 2
|
||||
#define CV_CALIB_FIX_PRINCIPAL_POINT 4
|
||||
#define CV_CALIB_ZERO_TANGENT_DIST 8
|
||||
#define CV_CALIB_FIX_FOCAL_LENGTH 16
|
||||
#define CV_CALIB_FIX_K1 32
|
||||
#define CV_CALIB_FIX_K2 64
|
||||
#define CV_CALIB_FIX_K3 128
|
||||
#define CV_CALIB_FIX_K4 2048
|
||||
#define CV_CALIB_FIX_K5 4096
|
||||
#define CV_CALIB_FIX_K6 8192
|
||||
#define CV_CALIB_RATIONAL_MODEL 16384
|
||||
#define CV_CALIB_THIN_PRISM_MODEL 32768
|
||||
#define CV_CALIB_FIX_S1_S2_S3_S4 65536
|
||||
#define CV_CALIB_TILTED_MODEL 262144
|
||||
#define CV_CALIB_FIX_TAUX_TAUY 524288
|
||||
|
||||
#define CV_CALIB_NINTRINSIC 18
|
||||
|
||||
/* Finds intrinsic and extrinsic camera parameters
|
||||
from a few views of known calibration pattern */
|
||||
CVAPI(double) cvCalibrateCamera2( const CvMat* object_points,
|
||||
const CvMat* image_points,
|
||||
const CvMat* point_counts,
|
||||
CvSize image_size,
|
||||
CvMat* camera_matrix,
|
||||
CvMat* distortion_coeffs,
|
||||
CvMat* rotation_vectors CV_DEFAULT(NULL),
|
||||
CvMat* translation_vectors CV_DEFAULT(NULL),
|
||||
int flags CV_DEFAULT(0),
|
||||
CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(
|
||||
CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,DBL_EPSILON)) );
|
||||
|
||||
/* Computes various useful characteristics of the camera from the data computed by
|
||||
cvCalibrateCamera2 */
|
||||
CVAPI(void) cvCalibrationMatrixValues( const CvMat *camera_matrix,
|
||||
CvSize image_size,
|
||||
double aperture_width CV_DEFAULT(0),
|
||||
double aperture_height CV_DEFAULT(0),
|
||||
double *fovx CV_DEFAULT(NULL),
|
||||
double *fovy CV_DEFAULT(NULL),
|
||||
double *focal_length CV_DEFAULT(NULL),
|
||||
CvPoint2D64f *principal_point CV_DEFAULT(NULL),
|
||||
double *pixel_aspect_ratio CV_DEFAULT(NULL));
|
||||
|
||||
#define CV_CALIB_FIX_INTRINSIC 256
|
||||
#define CV_CALIB_SAME_FOCAL_LENGTH 512
|
||||
|
||||
/* Computes the transformation from one camera coordinate system to another one
|
||||
from a few correspondent views of the same calibration target. Optionally, calibrates
|
||||
both cameras */
|
||||
CVAPI(double) cvStereoCalibrate( const CvMat* object_points, const CvMat* image_points1,
|
||||
const CvMat* image_points2, const CvMat* npoints,
|
||||
CvMat* camera_matrix1, CvMat* dist_coeffs1,
|
||||
CvMat* camera_matrix2, CvMat* dist_coeffs2,
|
||||
CvSize image_size, CvMat* R, CvMat* T,
|
||||
CvMat* E CV_DEFAULT(0), CvMat* F CV_DEFAULT(0),
|
||||
int flags CV_DEFAULT(CV_CALIB_FIX_INTRINSIC),
|
||||
CvTermCriteria term_crit CV_DEFAULT(cvTermCriteria(
|
||||
CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,30,1e-6)) );
|
||||
|
||||
#define CV_CALIB_ZERO_DISPARITY 1024
|
||||
|
||||
/* Computes 3D rotations (+ optional shift) for each camera coordinate system to make both
|
||||
views parallel (=> to make all the epipolar lines horizontal or vertical) */
|
||||
CVAPI(void) cvStereoRectify( const CvMat* camera_matrix1, const CvMat* camera_matrix2,
|
||||
const CvMat* dist_coeffs1, const CvMat* dist_coeffs2,
|
||||
CvSize image_size, const CvMat* R, const CvMat* T,
|
||||
CvMat* R1, CvMat* R2, CvMat* P1, CvMat* P2,
|
||||
CvMat* Q CV_DEFAULT(0),
|
||||
int flags CV_DEFAULT(CV_CALIB_ZERO_DISPARITY),
|
||||
double alpha CV_DEFAULT(-1),
|
||||
CvSize new_image_size CV_DEFAULT(cvSize(0,0)),
|
||||
CvRect* valid_pix_ROI1 CV_DEFAULT(0),
|
||||
CvRect* valid_pix_ROI2 CV_DEFAULT(0));
|
||||
|
||||
/* Computes rectification transformations for uncalibrated pair of images using a set
|
||||
of point correspondences */
|
||||
CVAPI(int) cvStereoRectifyUncalibrated( const CvMat* points1, const CvMat* points2,
|
||||
const CvMat* F, CvSize img_size,
|
||||
CvMat* H1, CvMat* H2,
|
||||
double threshold CV_DEFAULT(5));
|
||||
|
||||
|
||||
|
||||
/* stereo correspondence parameters and functions */
|
||||
|
||||
#define CV_STEREO_BM_NORMALIZED_RESPONSE 0
|
||||
#define CV_STEREO_BM_XSOBEL 1
|
||||
|
||||
/* Block matching algorithm structure */
|
||||
typedef struct CvStereoBMState
|
||||
{
|
||||
// pre-filtering (normalization of input images)
|
||||
int preFilterType; // =CV_STEREO_BM_NORMALIZED_RESPONSE now
|
||||
int preFilterSize; // averaging window size: ~5x5..21x21
|
||||
int preFilterCap; // the output of pre-filtering is clipped by [-preFilterCap,preFilterCap]
|
||||
|
||||
// correspondence using Sum of Absolute Difference (SAD)
|
||||
int SADWindowSize; // ~5x5..21x21
|
||||
int minDisparity; // minimum disparity (can be negative)
|
||||
int numberOfDisparities; // maximum disparity - minimum disparity (> 0)
|
||||
|
||||
// post-filtering
|
||||
int textureThreshold; // the disparity is only computed for pixels
|
||||
// with textured enough neighborhood
|
||||
int uniquenessRatio; // accept the computed disparity d* only if
|
||||
// SAD(d) >= SAD(d*)*(1 + uniquenessRatio/100.)
|
||||
// for any d != d*+/-1 within the search range.
|
||||
int speckleWindowSize; // disparity variation window
|
||||
int speckleRange; // acceptable range of variation in window
|
||||
|
||||
int trySmallerWindows; // if 1, the results may be more accurate,
|
||||
// at the expense of slower processing
|
||||
CvRect roi1, roi2;
|
||||
int disp12MaxDiff;
|
||||
|
||||
// temporary buffers
|
||||
CvMat* preFilteredImg0;
|
||||
CvMat* preFilteredImg1;
|
||||
CvMat* slidingSumBuf;
|
||||
CvMat* cost;
|
||||
CvMat* disp;
|
||||
} CvStereoBMState;
|
||||
|
||||
#define CV_STEREO_BM_BASIC 0
|
||||
#define CV_STEREO_BM_FISH_EYE 1
|
||||
#define CV_STEREO_BM_NARROW 2
|
||||
|
||||
CVAPI(CvStereoBMState*) cvCreateStereoBMState(int preset CV_DEFAULT(CV_STEREO_BM_BASIC),
|
||||
int numberOfDisparities CV_DEFAULT(0));
|
||||
|
||||
CVAPI(void) cvReleaseStereoBMState( CvStereoBMState** state );
|
||||
|
||||
CVAPI(void) cvFindStereoCorrespondenceBM( const CvArr* left, const CvArr* right,
|
||||
CvArr* disparity, CvStereoBMState* state );
|
||||
|
||||
CVAPI(CvRect) cvGetValidDisparityROI( CvRect roi1, CvRect roi2, int minDisparity,
|
||||
int numberOfDisparities, int SADWindowSize );
|
||||
|
||||
CVAPI(void) cvValidateDisparity( CvArr* disparity, const CvArr* cost,
|
||||
int minDisparity, int numberOfDisparities,
|
||||
int disp12MaxDiff CV_DEFAULT(1) );
|
||||
|
||||
/* Reprojects the computed disparity image to the 3D space using the specified 4x4 matrix */
|
||||
CVAPI(void) cvReprojectImageTo3D( const CvArr* disparityImage,
|
||||
CvArr* _3dImage, const CvMat* Q,
|
||||
int handleMissingValues CV_DEFAULT(0) );
|
||||
|
||||
/** @} calib3d_c */
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
class CV_EXPORTS CvLevMarq
|
||||
{
|
||||
public:
|
||||
CvLevMarq();
|
||||
CvLevMarq( int nparams, int nerrs, CvTermCriteria criteria=
|
||||
cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
|
||||
bool completeSymmFlag=false );
|
||||
~CvLevMarq();
|
||||
void init( int nparams, int nerrs, CvTermCriteria criteria=
|
||||
cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER,30,DBL_EPSILON),
|
||||
bool completeSymmFlag=false );
|
||||
bool update( const CvMat*& param, CvMat*& J, CvMat*& err );
|
||||
bool updateAlt( const CvMat*& param, CvMat*& JtJ, CvMat*& JtErr, double*& errNorm );
|
||||
|
||||
void clear();
|
||||
void step();
|
||||
enum { DONE=0, STARTED=1, CALC_J=2, CHECK_ERR=3 };
|
||||
|
||||
cv::Ptr<CvMat> mask;
|
||||
cv::Ptr<CvMat> prevParam;
|
||||
cv::Ptr<CvMat> param;
|
||||
cv::Ptr<CvMat> J;
|
||||
cv::Ptr<CvMat> err;
|
||||
cv::Ptr<CvMat> JtJ;
|
||||
cv::Ptr<CvMat> JtJN;
|
||||
cv::Ptr<CvMat> JtErr;
|
||||
cv::Ptr<CvMat> JtJV;
|
||||
cv::Ptr<CvMat> JtJW;
|
||||
double prevErrNorm, errNorm;
|
||||
int lambdaLg10;
|
||||
CvTermCriteria criteria;
|
||||
int state;
|
||||
int iters;
|
||||
bool completeSymmFlag;
|
||||
int solveMethod;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* OPENCV_CALIB3D_C_H */
|
||||
@@ -1,985 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_CONTRIB_HPP__
|
||||
#define __OPENCV_CONTRIB_HPP__
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/objdetect/objdetect.hpp"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
/****************************************************************************************\
|
||||
* Adaptive Skin Detector *
|
||||
\****************************************************************************************/
|
||||
|
||||
class CV_EXPORTS CvAdaptiveSkinDetector
|
||||
{
|
||||
private:
|
||||
enum {
|
||||
GSD_HUE_LT = 3,
|
||||
GSD_HUE_UT = 33,
|
||||
GSD_INTENSITY_LT = 15,
|
||||
GSD_INTENSITY_UT = 250
|
||||
};
|
||||
|
||||
class CV_EXPORTS Histogram
|
||||
{
|
||||
private:
|
||||
enum {
|
||||
HistogramSize = (GSD_HUE_UT - GSD_HUE_LT + 1)
|
||||
};
|
||||
|
||||
protected:
|
||||
int findCoverageIndex(double surfaceToCover, int defaultValue = 0);
|
||||
|
||||
public:
|
||||
CvHistogram *fHistogram;
|
||||
Histogram();
|
||||
virtual ~Histogram();
|
||||
|
||||
void findCurveThresholds(int &x1, int &x2, double percent = 0.05);
|
||||
void mergeWith(Histogram *source, double weight);
|
||||
};
|
||||
|
||||
int nStartCounter, nFrameCount, nSkinHueLowerBound, nSkinHueUpperBound, nMorphingMethod, nSamplingDivider;
|
||||
double fHistogramMergeFactor, fHuePercentCovered;
|
||||
Histogram histogramHueMotion, skinHueHistogram;
|
||||
IplImage *imgHueFrame, *imgSaturationFrame, *imgLastGrayFrame, *imgMotionFrame, *imgFilteredFrame;
|
||||
IplImage *imgShrinked, *imgTemp, *imgGrayFrame, *imgHSVFrame;
|
||||
|
||||
protected:
|
||||
void initData(IplImage *src, int widthDivider, int heightDivider);
|
||||
void adaptiveFilter();
|
||||
|
||||
public:
|
||||
|
||||
enum {
|
||||
MORPHING_METHOD_NONE = 0,
|
||||
MORPHING_METHOD_ERODE = 1,
|
||||
MORPHING_METHOD_ERODE_ERODE = 2,
|
||||
MORPHING_METHOD_ERODE_DILATE = 3
|
||||
};
|
||||
|
||||
CvAdaptiveSkinDetector(int samplingDivider = 1, int morphingMethod = MORPHING_METHOD_NONE);
|
||||
virtual ~CvAdaptiveSkinDetector();
|
||||
|
||||
virtual void process(IplImage *inputBGRImage, IplImage *outputHueMask);
|
||||
};
|
||||
|
||||
|
||||
/****************************************************************************************\
|
||||
* Fuzzy MeanShift Tracker *
|
||||
\****************************************************************************************/
|
||||
|
||||
class CV_EXPORTS CvFuzzyPoint {
|
||||
public:
|
||||
double x, y, value;
|
||||
|
||||
CvFuzzyPoint(double _x, double _y);
|
||||
};
|
||||
|
||||
class CV_EXPORTS CvFuzzyCurve {
|
||||
private:
|
||||
std::vector<CvFuzzyPoint> points;
|
||||
double value, centre;
|
||||
|
||||
bool between(double x, double x1, double x2);
|
||||
|
||||
public:
|
||||
CvFuzzyCurve();
|
||||
~CvFuzzyCurve();
|
||||
|
||||
void setCentre(double _centre);
|
||||
double getCentre();
|
||||
void clear();
|
||||
void addPoint(double x, double y);
|
||||
double calcValue(double param);
|
||||
double getValue();
|
||||
void setValue(double _value);
|
||||
};
|
||||
|
||||
class CV_EXPORTS CvFuzzyFunction {
|
||||
public:
|
||||
std::vector<CvFuzzyCurve> curves;
|
||||
|
||||
CvFuzzyFunction();
|
||||
~CvFuzzyFunction();
|
||||
void addCurve(CvFuzzyCurve *curve, double value = 0);
|
||||
void resetValues();
|
||||
double calcValue();
|
||||
CvFuzzyCurve *newCurve();
|
||||
};
|
||||
|
||||
class CV_EXPORTS CvFuzzyRule {
|
||||
private:
|
||||
CvFuzzyCurve *fuzzyInput1, *fuzzyInput2;
|
||||
CvFuzzyCurve *fuzzyOutput;
|
||||
public:
|
||||
CvFuzzyRule();
|
||||
~CvFuzzyRule();
|
||||
void setRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1);
|
||||
double calcValue(double param1, double param2);
|
||||
CvFuzzyCurve *getOutputCurve();
|
||||
};
|
||||
|
||||
class CV_EXPORTS CvFuzzyController {
|
||||
private:
|
||||
std::vector<CvFuzzyRule*> rules;
|
||||
public:
|
||||
CvFuzzyController();
|
||||
~CvFuzzyController();
|
||||
void addRule(CvFuzzyCurve *c1, CvFuzzyCurve *c2, CvFuzzyCurve *o1);
|
||||
double calcOutput(double param1, double param2);
|
||||
};
|
||||
|
||||
class CV_EXPORTS CvFuzzyMeanShiftTracker
|
||||
{
|
||||
private:
|
||||
class FuzzyResizer
|
||||
{
|
||||
private:
|
||||
CvFuzzyFunction iInput, iOutput;
|
||||
CvFuzzyController fuzzyController;
|
||||
public:
|
||||
FuzzyResizer();
|
||||
int calcOutput(double edgeDensity, double density);
|
||||
};
|
||||
|
||||
class SearchWindow
|
||||
{
|
||||
public:
|
||||
FuzzyResizer *fuzzyResizer;
|
||||
int x, y;
|
||||
int width, height, maxWidth, maxHeight, ellipseHeight, ellipseWidth;
|
||||
int ldx, ldy, ldw, ldh, numShifts, numIters;
|
||||
int xGc, yGc;
|
||||
long m00, m01, m10, m11, m02, m20;
|
||||
double ellipseAngle;
|
||||
double density;
|
||||
unsigned int depthLow, depthHigh;
|
||||
int verticalEdgeLeft, verticalEdgeRight, horizontalEdgeTop, horizontalEdgeBottom;
|
||||
|
||||
SearchWindow();
|
||||
~SearchWindow();
|
||||
void setSize(int _x, int _y, int _width, int _height);
|
||||
void initDepthValues(IplImage *maskImage, IplImage *depthMap);
|
||||
bool shift();
|
||||
void extractInfo(IplImage *maskImage, IplImage *depthMap, bool initDepth);
|
||||
void getResizeAttribsEdgeDensityLinear(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh);
|
||||
void getResizeAttribsInnerDensity(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh);
|
||||
void getResizeAttribsEdgeDensityFuzzy(int &resizeDx, int &resizeDy, int &resizeDw, int &resizeDh);
|
||||
bool meanShift(IplImage *maskImage, IplImage *depthMap, int maxIteration, bool initDepth);
|
||||
};
|
||||
|
||||
public:
|
||||
enum TrackingState
|
||||
{
|
||||
tsNone = 0,
|
||||
tsSearching = 1,
|
||||
tsTracking = 2,
|
||||
tsSetWindow = 3,
|
||||
tsDisabled = 10
|
||||
};
|
||||
|
||||
enum ResizeMethod {
|
||||
rmEdgeDensityLinear = 0,
|
||||
rmEdgeDensityFuzzy = 1,
|
||||
rmInnerDensity = 2
|
||||
};
|
||||
|
||||
enum {
|
||||
MinKernelMass = 1000
|
||||
};
|
||||
|
||||
SearchWindow kernel;
|
||||
int searchMode;
|
||||
|
||||
private:
|
||||
enum
|
||||
{
|
||||
MaxMeanShiftIteration = 5,
|
||||
MaxSetSizeIteration = 5
|
||||
};
|
||||
|
||||
void findOptimumSearchWindow(SearchWindow &searchWindow, IplImage *maskImage, IplImage *depthMap, int maxIteration, int resizeMethod, bool initDepth);
|
||||
|
||||
public:
|
||||
CvFuzzyMeanShiftTracker();
|
||||
~CvFuzzyMeanShiftTracker();
|
||||
|
||||
void track(IplImage *maskImage, IplImage *depthMap, int resizeMethod, bool resetSearch, int minKernelMass = MinKernelMass);
|
||||
};
|
||||
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
class CV_EXPORTS Octree
|
||||
{
|
||||
public:
|
||||
struct Node
|
||||
{
|
||||
Node() {}
|
||||
int begin, end;
|
||||
float x_min, x_max, y_min, y_max, z_min, z_max;
|
||||
int maxLevels;
|
||||
bool isLeaf;
|
||||
int children[8];
|
||||
};
|
||||
|
||||
Octree();
|
||||
Octree( const vector<Point3f>& points, int maxLevels = 10, int minPoints = 20 );
|
||||
virtual ~Octree();
|
||||
|
||||
virtual void buildTree( const vector<Point3f>& points, int maxLevels = 10, int minPoints = 20 );
|
||||
virtual void getPointsWithinSphere( const Point3f& center, float radius,
|
||||
vector<Point3f>& points ) const;
|
||||
const vector<Node>& getNodes() const { return nodes; }
|
||||
private:
|
||||
int minPoints;
|
||||
vector<Point3f> points;
|
||||
vector<Node> nodes;
|
||||
|
||||
virtual void buildNext(size_t node_ind);
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS Mesh3D
|
||||
{
|
||||
public:
|
||||
struct EmptyMeshException {};
|
||||
|
||||
Mesh3D();
|
||||
Mesh3D(const vector<Point3f>& vtx);
|
||||
~Mesh3D();
|
||||
|
||||
void buildOctree();
|
||||
void clearOctree();
|
||||
float estimateResolution(float tryRatio = 0.1f);
|
||||
void computeNormals(float normalRadius, int minNeighbors = 20);
|
||||
void computeNormals(const vector<int>& subset, float normalRadius, int minNeighbors = 20);
|
||||
|
||||
void writeAsVrml(const String& file, const vector<Scalar>& colors = vector<Scalar>()) const;
|
||||
|
||||
vector<Point3f> vtx;
|
||||
vector<Point3f> normals;
|
||||
float resolution;
|
||||
Octree octree;
|
||||
|
||||
const static Point3f allzero;
|
||||
};
|
||||
|
||||
class CV_EXPORTS SpinImageModel
|
||||
{
|
||||
public:
|
||||
|
||||
/* model parameters, leave unset for default or auto estimate */
|
||||
float normalRadius;
|
||||
int minNeighbors;
|
||||
|
||||
float binSize;
|
||||
int imageWidth;
|
||||
|
||||
float lambda;
|
||||
float gamma;
|
||||
|
||||
float T_GeometriccConsistency;
|
||||
float T_GroupingCorespondances;
|
||||
|
||||
/* public interface */
|
||||
SpinImageModel();
|
||||
explicit SpinImageModel(const Mesh3D& mesh);
|
||||
~SpinImageModel();
|
||||
|
||||
void setLogger(std::ostream* log);
|
||||
void selectRandomSubset(float ratio);
|
||||
void setSubset(const vector<int>& subset);
|
||||
void compute();
|
||||
|
||||
void match(const SpinImageModel& scene, vector< vector<Vec2i> >& result);
|
||||
|
||||
Mat packRandomScaledSpins(bool separateScale = false, size_t xCount = 10, size_t yCount = 10) const;
|
||||
|
||||
size_t getSpinCount() const { return spinImages.rows; }
|
||||
Mat getSpinImage(size_t index) const { return spinImages.row((int)index); }
|
||||
const Point3f& getSpinVertex(size_t index) const { return mesh.vtx[subset[index]]; }
|
||||
const Point3f& getSpinNormal(size_t index) const { return mesh.normals[subset[index]]; }
|
||||
|
||||
const Mesh3D& getMesh() const { return mesh; }
|
||||
Mesh3D& getMesh() { return mesh; }
|
||||
|
||||
/* static utility functions */
|
||||
static bool spinCorrelation(const Mat& spin1, const Mat& spin2, float lambda, float& result);
|
||||
|
||||
static Point2f calcSpinMapCoo(const Point3f& point, const Point3f& vertex, const Point3f& normal);
|
||||
|
||||
static float geometricConsistency(const Point3f& pointScene1, const Point3f& normalScene1,
|
||||
const Point3f& pointModel1, const Point3f& normalModel1,
|
||||
const Point3f& pointScene2, const Point3f& normalScene2,
|
||||
const Point3f& pointModel2, const Point3f& normalModel2);
|
||||
|
||||
static float groupingCreteria(const Point3f& pointScene1, const Point3f& normalScene1,
|
||||
const Point3f& pointModel1, const Point3f& normalModel1,
|
||||
const Point3f& pointScene2, const Point3f& normalScene2,
|
||||
const Point3f& pointModel2, const Point3f& normalModel2,
|
||||
float gamma);
|
||||
protected:
|
||||
void defaultParams();
|
||||
|
||||
void matchSpinToModel(const Mat& spin, vector<int>& indeces,
|
||||
vector<float>& corrCoeffs, bool useExtremeOutliers = true) const;
|
||||
|
||||
void repackSpinImages(const vector<uchar>& mask, Mat& spinImages, bool reAlloc = true) const;
|
||||
|
||||
vector<int> subset;
|
||||
Mesh3D mesh;
|
||||
Mat spinImages;
|
||||
std::ostream* out;
|
||||
};
|
||||
|
||||
class CV_EXPORTS TickMeter
|
||||
{
|
||||
public:
|
||||
TickMeter();
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
int64 getTimeTicks() const;
|
||||
double getTimeMicro() const;
|
||||
double getTimeMilli() const;
|
||||
double getTimeSec() const;
|
||||
int64 getCounter() const;
|
||||
|
||||
void reset();
|
||||
private:
|
||||
int64 counter;
|
||||
int64 sumTime;
|
||||
int64 startTime;
|
||||
};
|
||||
|
||||
CV_EXPORTS std::ostream& operator<<(std::ostream& out, const TickMeter& tm);
|
||||
|
||||
class CV_EXPORTS SelfSimDescriptor
|
||||
{
|
||||
public:
|
||||
SelfSimDescriptor();
|
||||
SelfSimDescriptor(int _ssize, int _lsize,
|
||||
int _startDistanceBucket=DEFAULT_START_DISTANCE_BUCKET,
|
||||
int _numberOfDistanceBuckets=DEFAULT_NUM_DISTANCE_BUCKETS,
|
||||
int _nangles=DEFAULT_NUM_ANGLES);
|
||||
SelfSimDescriptor(const SelfSimDescriptor& ss);
|
||||
virtual ~SelfSimDescriptor();
|
||||
SelfSimDescriptor& operator = (const SelfSimDescriptor& ss);
|
||||
|
||||
size_t getDescriptorSize() const;
|
||||
Size getGridSize( Size imgsize, Size winStride ) const;
|
||||
|
||||
virtual void compute(const Mat& img, vector<float>& descriptors, Size winStride=Size(),
|
||||
const vector<Point>& locations=vector<Point>()) const;
|
||||
virtual void computeLogPolarMapping(Mat& mappingMask) const;
|
||||
virtual void SSD(const Mat& img, Point pt, Mat& ssd) const;
|
||||
|
||||
int smallSize;
|
||||
int largeSize;
|
||||
int startDistanceBucket;
|
||||
int numberOfDistanceBuckets;
|
||||
int numberOfAngles;
|
||||
|
||||
enum { DEFAULT_SMALL_SIZE = 5, DEFAULT_LARGE_SIZE = 41,
|
||||
DEFAULT_NUM_ANGLES = 20, DEFAULT_START_DISTANCE_BUCKET = 3,
|
||||
DEFAULT_NUM_DISTANCE_BUCKETS = 7 };
|
||||
};
|
||||
|
||||
|
||||
typedef bool (*BundleAdjustCallback)(int iteration, double norm_error, void* user_data);
|
||||
|
||||
class CV_EXPORTS LevMarqSparse {
|
||||
public:
|
||||
LevMarqSparse();
|
||||
LevMarqSparse(int npoints, // number of points
|
||||
int ncameras, // number of cameras
|
||||
int nPointParams, // number of params per one point (3 in case of 3D points)
|
||||
int nCameraParams, // number of parameters per one camera
|
||||
int nErrParams, // number of parameters in measurement vector
|
||||
// for 1 point at one camera (2 in case of 2D projections)
|
||||
Mat& visibility, // visibility matrix. rows correspond to points, columns correspond to cameras
|
||||
// 1 - point is visible for the camera, 0 - invisible
|
||||
Mat& P0, // starting vector of parameters, first cameras then points
|
||||
Mat& X, // measurements, in order of visibility. non visible cases are skipped
|
||||
TermCriteria criteria, // termination criteria
|
||||
|
||||
// callback for estimation of Jacobian matrices
|
||||
void (CV_CDECL * fjac)(int i, int j, Mat& point_params,
|
||||
Mat& cam_params, Mat& A, Mat& B, void* data),
|
||||
// callback for estimation of backprojection errors
|
||||
void (CV_CDECL * func)(int i, int j, Mat& point_params,
|
||||
Mat& cam_params, Mat& estim, void* data),
|
||||
void* data, // user-specific data passed to the callbacks
|
||||
BundleAdjustCallback cb, void* user_data
|
||||
);
|
||||
|
||||
virtual ~LevMarqSparse();
|
||||
|
||||
virtual void run( int npoints, // number of points
|
||||
int ncameras, // number of cameras
|
||||
int nPointParams, // number of params per one point (3 in case of 3D points)
|
||||
int nCameraParams, // number of parameters per one camera
|
||||
int nErrParams, // number of parameters in measurement vector
|
||||
// for 1 point at one camera (2 in case of 2D projections)
|
||||
Mat& visibility, // visibility matrix. rows correspond to points, columns correspond to cameras
|
||||
// 1 - point is visible for the camera, 0 - invisible
|
||||
Mat& P0, // starting vector of parameters, first cameras then points
|
||||
Mat& X, // measurements, in order of visibility. non visible cases are skipped
|
||||
TermCriteria criteria, // termination criteria
|
||||
|
||||
// callback for estimation of Jacobian matrices
|
||||
void (CV_CDECL * fjac)(int i, int j, Mat& point_params,
|
||||
Mat& cam_params, Mat& A, Mat& B, void* data),
|
||||
// callback for estimation of backprojection errors
|
||||
void (CV_CDECL * func)(int i, int j, Mat& point_params,
|
||||
Mat& cam_params, Mat& estim, void* data),
|
||||
void* data // user-specific data passed to the callbacks
|
||||
);
|
||||
|
||||
virtual void clear();
|
||||
|
||||
// useful function to do simple bundle adjustment tasks
|
||||
static void bundleAdjust(vector<Point3d>& points, // positions of points in global coordinate system (input and output)
|
||||
const vector<vector<Point2d> >& imagePoints, // projections of 3d points for every camera
|
||||
const vector<vector<int> >& visibility, // visibility of 3d points for every camera
|
||||
vector<Mat>& cameraMatrix, // intrinsic matrices of all cameras (input and output)
|
||||
vector<Mat>& R, // rotation matrices of all cameras (input and output)
|
||||
vector<Mat>& T, // translation vector of all cameras (input and output)
|
||||
vector<Mat>& distCoeffs, // distortion coefficients of all cameras (input and output)
|
||||
const TermCriteria& criteria=
|
||||
TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, DBL_EPSILON),
|
||||
BundleAdjustCallback cb = 0, void* user_data = 0);
|
||||
|
||||
public:
|
||||
virtual void optimize(CvMat &_vis); //main function that runs minimization
|
||||
|
||||
//iteratively asks for measurement for visible camera-point pairs
|
||||
void ask_for_proj(CvMat &_vis,bool once=false);
|
||||
//iteratively asks for Jacobians for every camera_point pair
|
||||
void ask_for_projac(CvMat &_vis);
|
||||
|
||||
CvMat* err; //error X-hX
|
||||
double prevErrNorm, errNorm;
|
||||
double lambda;
|
||||
CvTermCriteria criteria;
|
||||
int iters;
|
||||
|
||||
CvMat** U; //size of array is equal to number of cameras
|
||||
CvMat** V; //size of array is equal to number of points
|
||||
CvMat** inv_V_star; //inverse of V*
|
||||
|
||||
CvMat** A;
|
||||
CvMat** B;
|
||||
CvMat** W;
|
||||
|
||||
CvMat* X; //measurement
|
||||
CvMat* hX; //current measurement extimation given new parameter vector
|
||||
|
||||
CvMat* prevP; //current already accepted parameter.
|
||||
CvMat* P; // parameters used to evaluate function with new params
|
||||
// this parameters may be rejected
|
||||
|
||||
CvMat* deltaP; //computed increase of parameters (result of normal system solution )
|
||||
|
||||
CvMat** ea; // sum_i AijT * e_ij , used as right part of normal equation
|
||||
// length of array is j = number of cameras
|
||||
CvMat** eb; // sum_j BijT * e_ij , used as right part of normal equation
|
||||
// length of array is i = number of points
|
||||
|
||||
CvMat** Yj; //length of array is i = num_points
|
||||
|
||||
CvMat* S; //big matrix of block Sjk , each block has size num_cam_params x num_cam_params
|
||||
|
||||
CvMat* JtJ_diag; //diagonal of JtJ, used to backup diagonal elements before augmentation
|
||||
|
||||
CvMat* Vis_index; // matrix which element is index of measurement for point i and camera j
|
||||
|
||||
int num_cams;
|
||||
int num_points;
|
||||
int num_err_param;
|
||||
int num_cam_param;
|
||||
int num_point_param;
|
||||
|
||||
//target function and jacobian pointers, which needs to be initialized
|
||||
void (*fjac)(int i, int j, Mat& point_params, Mat& cam_params, Mat& A, Mat& B, void* data);
|
||||
void (*func)(int i, int j, Mat& point_params, Mat& cam_params, Mat& estim, void* data);
|
||||
|
||||
void* data;
|
||||
|
||||
BundleAdjustCallback cb;
|
||||
void* user_data;
|
||||
};
|
||||
|
||||
CV_EXPORTS_W int chamerMatching( Mat& img, Mat& templ,
|
||||
CV_OUT vector<vector<Point> >& results, CV_OUT vector<float>& cost,
|
||||
double templScale=1, int maxMatches = 20,
|
||||
double minMatchDistance = 1.0, int padX = 3,
|
||||
int padY = 3, int scales = 5, double minScale = 0.6, double maxScale = 1.6,
|
||||
double orientationWeight = 0.5, double truncate = 20);
|
||||
|
||||
|
||||
class CV_EXPORTS_W StereoVar
|
||||
{
|
||||
public:
|
||||
// Flags
|
||||
enum {USE_INITIAL_DISPARITY = 1, USE_EQUALIZE_HIST = 2, USE_SMART_ID = 4, USE_AUTO_PARAMS = 8, USE_MEDIAN_FILTERING = 16};
|
||||
enum {CYCLE_O, CYCLE_V};
|
||||
enum {PENALIZATION_TICHONOV, PENALIZATION_CHARBONNIER, PENALIZATION_PERONA_MALIK};
|
||||
|
||||
//! the default constructor
|
||||
CV_WRAP StereoVar();
|
||||
|
||||
//! the full constructor taking all the necessary algorithm parameters
|
||||
CV_WRAP StereoVar(int levels, double pyrScale, int nIt, int minDisp, int maxDisp, int poly_n, double poly_sigma, float fi, float lambda, int penalization, int cycle, int flags);
|
||||
|
||||
//! the destructor
|
||||
virtual ~StereoVar();
|
||||
|
||||
//! the stereo correspondence operator that computes disparity map for the specified rectified stereo pair
|
||||
CV_WRAP_AS(compute) virtual void operator()(const Mat& left, const Mat& right, CV_OUT Mat& disp);
|
||||
|
||||
CV_PROP_RW int levels;
|
||||
CV_PROP_RW double pyrScale;
|
||||
CV_PROP_RW int nIt;
|
||||
CV_PROP_RW int minDisp;
|
||||
CV_PROP_RW int maxDisp;
|
||||
CV_PROP_RW int poly_n;
|
||||
CV_PROP_RW double poly_sigma;
|
||||
CV_PROP_RW float fi;
|
||||
CV_PROP_RW float lambda;
|
||||
CV_PROP_RW int penalization;
|
||||
CV_PROP_RW int cycle;
|
||||
CV_PROP_RW int flags;
|
||||
|
||||
private:
|
||||
void autoParams();
|
||||
void FMG(Mat &I1, Mat &I2, Mat &I2x, Mat &u, int level);
|
||||
void VCycle_MyFAS(Mat &I1_h, Mat &I2_h, Mat &I2x_h, Mat &u_h, int level);
|
||||
void VariationalSolver(Mat &I1_h, Mat &I2_h, Mat &I2x_h, Mat &u_h, int level);
|
||||
};
|
||||
|
||||
CV_EXPORTS void polyfit(const Mat& srcx, const Mat& srcy, Mat& dst, int order);
|
||||
|
||||
class CV_EXPORTS Directory
|
||||
{
|
||||
public:
|
||||
static std::vector<std::string> GetListFiles ( const std::string& path, const std::string & exten = "*", bool addPath = true );
|
||||
static std::vector<std::string> GetListFilesR ( const std::string& path, const std::string & exten = "*", bool addPath = true );
|
||||
static std::vector<std::string> GetListFolders( const std::string& path, const std::string & exten = "*", bool addPath = true );
|
||||
};
|
||||
|
||||
/*
|
||||
* Generation of a set of different colors by the following way:
|
||||
* 1) generate more then need colors (in "factor" times) in RGB,
|
||||
* 2) convert them to Lab,
|
||||
* 3) choose the needed count of colors from the set that are more different from
|
||||
* each other,
|
||||
* 4) convert the colors back to RGB
|
||||
*/
|
||||
CV_EXPORTS void generateColors( std::vector<Scalar>& colors, size_t count, size_t factor=100 );
|
||||
|
||||
|
||||
/*
|
||||
* Estimate the rigid body motion from frame0 to frame1. The method is based on the paper
|
||||
* "Real-Time Visual Odometry from Dense RGB-D Images", F. Steinbucker, J. Strum, D. Cremers, ICCV, 2011.
|
||||
*/
|
||||
enum { ROTATION = 1,
|
||||
TRANSLATION = 2,
|
||||
RIGID_BODY_MOTION = 4
|
||||
};
|
||||
CV_EXPORTS bool RGBDOdometry( Mat& Rt, const Mat& initRt,
|
||||
const Mat& image0, const Mat& depth0, const Mat& mask0,
|
||||
const Mat& image1, const Mat& depth1, const Mat& mask1,
|
||||
const Mat& cameraMatrix, float minDepth=0.f, float maxDepth=4.f, float maxDepthDiff=0.07f,
|
||||
const std::vector<int>& iterCounts=std::vector<int>(),
|
||||
const std::vector<float>& minGradientMagnitudes=std::vector<float>(),
|
||||
int transformType=RIGID_BODY_MOTION );
|
||||
|
||||
/**
|
||||
*Bilinear interpolation technique.
|
||||
*
|
||||
*The value of a desired cortical pixel is obtained through a bilinear interpolation of the values
|
||||
*of the four nearest neighbouring Cartesian pixels to the center of the RF.
|
||||
*The same principle is applied to the inverse transformation.
|
||||
*
|
||||
*More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5
|
||||
*/
|
||||
class CV_EXPORTS LogPolar_Interp
|
||||
{
|
||||
public:
|
||||
|
||||
LogPolar_Interp() {}
|
||||
|
||||
/**
|
||||
*Constructor
|
||||
*\param w the width of the input image
|
||||
*\param h the height of the input image
|
||||
*\param center the transformation center: where the output precision is maximal
|
||||
*\param R the number of rings of the cortical image (default value 70 pixel)
|
||||
*\param ro0 the radius of the blind spot (default value 3 pixel)
|
||||
*\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle.
|
||||
* \a 0 means that the retinal image is computed within the inscribed circle.
|
||||
*\param S the number of sectors of the cortical image (default value 70 pixel).
|
||||
* Its value is usually internally computed to obtain a pixel aspect ratio equals to 1.
|
||||
*\param sp \a 1 (default value) means that the parameter \a S is internally computed.
|
||||
* \a 0 means that the parameter \a S is provided by the user.
|
||||
*/
|
||||
LogPolar_Interp(int w, int h, Point2i center, int R=70, double ro0=3.0,
|
||||
int interp=INTER_LINEAR, int full=1, int S=117, int sp=1);
|
||||
/**
|
||||
*Transformation from Cartesian image to cortical (log-polar) image.
|
||||
*\param source the Cartesian image
|
||||
*\return the transformed image (cortical image)
|
||||
*/
|
||||
const Mat to_cortical(const Mat &source);
|
||||
/**
|
||||
*Transformation from cortical image to retinal (inverse log-polar) image.
|
||||
*\param source the cortical image
|
||||
*\return the transformed image (retinal image)
|
||||
*/
|
||||
const Mat to_cartesian(const Mat &source);
|
||||
/**
|
||||
*Destructor
|
||||
*/
|
||||
~LogPolar_Interp();
|
||||
|
||||
protected:
|
||||
|
||||
Mat Rsri;
|
||||
Mat Csri;
|
||||
|
||||
int S, R, M, N;
|
||||
int top, bottom,left,right;
|
||||
double ro0, romax, a, q;
|
||||
int interp;
|
||||
|
||||
Mat ETAyx;
|
||||
Mat CSIyx;
|
||||
|
||||
void create_map(int M, int N, int R, int S, double ro0);
|
||||
};
|
||||
|
||||
/**
|
||||
*Overlapping circular receptive fields technique
|
||||
*
|
||||
*The Cartesian plane is divided in two regions: the fovea and the periphery.
|
||||
*The fovea (oversampling) is handled by using the bilinear interpolation technique described above, whereas in
|
||||
*the periphery we use the overlapping Gaussian circular RFs.
|
||||
*
|
||||
*More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5
|
||||
*/
|
||||
class CV_EXPORTS LogPolar_Overlapping
|
||||
{
|
||||
public:
|
||||
LogPolar_Overlapping() {}
|
||||
|
||||
/**
|
||||
*Constructor
|
||||
*\param w the width of the input image
|
||||
*\param h the height of the input image
|
||||
*\param center the transformation center: where the output precision is maximal
|
||||
*\param R the number of rings of the cortical image (default value 70 pixel)
|
||||
*\param ro0 the radius of the blind spot (default value 3 pixel)
|
||||
*\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle.
|
||||
* \a 0 means that the retinal image is computed within the inscribed circle.
|
||||
*\param S the number of sectors of the cortical image (default value 70 pixel).
|
||||
* Its value is usually internally computed to obtain a pixel aspect ratio equals to 1.
|
||||
*\param sp \a 1 (default value) means that the parameter \a S is internally computed.
|
||||
* \a 0 means that the parameter \a S is provided by the user.
|
||||
*/
|
||||
LogPolar_Overlapping(int w, int h, Point2i center, int R=70,
|
||||
double ro0=3.0, int full=1, int S=117, int sp=1);
|
||||
/**
|
||||
*Transformation from Cartesian image to cortical (log-polar) image.
|
||||
*\param source the Cartesian image
|
||||
*\return the transformed image (cortical image)
|
||||
*/
|
||||
const Mat to_cortical(const Mat &source);
|
||||
/**
|
||||
*Transformation from cortical image to retinal (inverse log-polar) image.
|
||||
*\param source the cortical image
|
||||
*\return the transformed image (retinal image)
|
||||
*/
|
||||
const Mat to_cartesian(const Mat &source);
|
||||
/**
|
||||
*Destructor
|
||||
*/
|
||||
~LogPolar_Overlapping();
|
||||
|
||||
protected:
|
||||
|
||||
Mat Rsri;
|
||||
Mat Csri;
|
||||
vector<int> Rsr;
|
||||
vector<int> Csr;
|
||||
vector<double> Wsr;
|
||||
|
||||
int S, R, M, N, ind1;
|
||||
int top, bottom,left,right;
|
||||
double ro0, romax, a, q;
|
||||
|
||||
struct kernel
|
||||
{
|
||||
kernel() { w = 0; }
|
||||
vector<double> weights;
|
||||
int w;
|
||||
};
|
||||
|
||||
Mat ETAyx;
|
||||
Mat CSIyx;
|
||||
vector<kernel> w_ker_2D;
|
||||
|
||||
void create_map(int M, int N, int R, int S, double ro0);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adjacent receptive fields technique
|
||||
*
|
||||
*All the Cartesian pixels, whose coordinates in the cortical domain share the same integer part, are assigned to the same RF.
|
||||
*The precision of the boundaries of the RF can be improved by breaking each pixel into subpixels and assigning each of them to the correct RF.
|
||||
*This technique is implemented from: Traver, V., Pla, F.: Log-polar mapping template design: From task-level requirements
|
||||
*to geometry parameters. Image Vision Comput. 26(10) (2008) 1354-1370
|
||||
*
|
||||
*More details can be found in http://dx.doi.org/10.1007/978-3-642-23968-7_5
|
||||
*/
|
||||
class CV_EXPORTS LogPolar_Adjacent
|
||||
{
|
||||
public:
|
||||
LogPolar_Adjacent() {}
|
||||
|
||||
/**
|
||||
*Constructor
|
||||
*\param w the width of the input image
|
||||
*\param h the height of the input image
|
||||
*\param center the transformation center: where the output precision is maximal
|
||||
*\param R the number of rings of the cortical image (default value 70 pixel)
|
||||
*\param ro0 the radius of the blind spot (default value 3 pixel)
|
||||
*\param smin the size of the subpixel (default value 0.25 pixel)
|
||||
*\param full \a 1 (default value) means that the retinal image (the inverse transform) is computed within the circumscribing circle.
|
||||
* \a 0 means that the retinal image is computed within the inscribed circle.
|
||||
*\param S the number of sectors of the cortical image (default value 70 pixel).
|
||||
* Its value is usually internally computed to obtain a pixel aspect ratio equals to 1.
|
||||
*\param sp \a 1 (default value) means that the parameter \a S is internally computed.
|
||||
* \a 0 means that the parameter \a S is provided by the user.
|
||||
*/
|
||||
LogPolar_Adjacent(int w, int h, Point2i center, int R=70, double ro0=3.0, double smin=0.25, int full=1, int S=117, int sp=1);
|
||||
/**
|
||||
*Transformation from Cartesian image to cortical (log-polar) image.
|
||||
*\param source the Cartesian image
|
||||
*\return the transformed image (cortical image)
|
||||
*/
|
||||
const Mat to_cortical(const Mat &source);
|
||||
/**
|
||||
*Transformation from cortical image to retinal (inverse log-polar) image.
|
||||
*\param source the cortical image
|
||||
*\return the transformed image (retinal image)
|
||||
*/
|
||||
const Mat to_cartesian(const Mat &source);
|
||||
/**
|
||||
*Destructor
|
||||
*/
|
||||
~LogPolar_Adjacent();
|
||||
|
||||
protected:
|
||||
struct pixel
|
||||
{
|
||||
pixel() { u = v = 0; a = 0.; }
|
||||
int u;
|
||||
int v;
|
||||
double a;
|
||||
};
|
||||
int S, R, M, N;
|
||||
int top, bottom,left,right;
|
||||
double ro0, romax, a, q;
|
||||
vector<vector<pixel> > L;
|
||||
vector<double> A;
|
||||
|
||||
void subdivide_recursively(double x, double y, int i, int j, double length, double smin);
|
||||
bool get_uv(double x, double y, int&u, int&v);
|
||||
void create_map(int M, int N, int R, int S, double ro0, double smin);
|
||||
};
|
||||
|
||||
CV_EXPORTS Mat subspaceProject(InputArray W, InputArray mean, InputArray src);
|
||||
CV_EXPORTS Mat subspaceReconstruct(InputArray W, InputArray mean, InputArray src);
|
||||
|
||||
class CV_EXPORTS LDA
|
||||
{
|
||||
public:
|
||||
// Initializes a LDA with num_components (default 0) and specifies how
|
||||
// samples are aligned (default dataAsRow=true).
|
||||
LDA(int num_components = 0) :
|
||||
_num_components(num_components) {};
|
||||
|
||||
// Initializes and performs a Discriminant Analysis with Fisher's
|
||||
// Optimization Criterion on given data in src and corresponding labels
|
||||
// in labels. If 0 (or less) number of components are given, they are
|
||||
// automatically determined for given data in computation.
|
||||
LDA(const Mat& src, vector<int> labels,
|
||||
int num_components = 0) :
|
||||
_num_components(num_components)
|
||||
{
|
||||
this->compute(src, labels); //! compute eigenvectors and eigenvalues
|
||||
}
|
||||
|
||||
// Initializes and performs a Discriminant Analysis with Fisher's
|
||||
// Optimization Criterion on given data in src and corresponding labels
|
||||
// in labels. If 0 (or less) number of components are given, they are
|
||||
// automatically determined for given data in computation.
|
||||
LDA(InputArrayOfArrays src, InputArray labels,
|
||||
int num_components = 0) :
|
||||
_num_components(num_components)
|
||||
{
|
||||
this->compute(src, labels); //! compute eigenvectors and eigenvalues
|
||||
}
|
||||
|
||||
// Serializes this object to a given filename.
|
||||
void save(const string& filename) const;
|
||||
|
||||
// Deserializes this object from a given filename.
|
||||
void load(const string& filename);
|
||||
|
||||
// Serializes this object to a given cv::FileStorage.
|
||||
void save(FileStorage& fs) const;
|
||||
|
||||
// Deserializes this object from a given cv::FileStorage.
|
||||
void load(const FileStorage& node);
|
||||
|
||||
// Destructor.
|
||||
~LDA() {}
|
||||
|
||||
//! Compute the discriminants for data in src and labels.
|
||||
void compute(InputArrayOfArrays src, InputArray labels);
|
||||
|
||||
// Projects samples into the LDA subspace.
|
||||
Mat project(InputArray src);
|
||||
|
||||
// Reconstructs projections from the LDA subspace.
|
||||
Mat reconstruct(InputArray src);
|
||||
|
||||
// Returns the eigenvectors of this LDA.
|
||||
Mat eigenvectors() const { return _eigenvectors; };
|
||||
|
||||
// Returns the eigenvalues of this LDA.
|
||||
Mat eigenvalues() const { return _eigenvalues; }
|
||||
|
||||
protected:
|
||||
bool _dataAsRow;
|
||||
int _num_components;
|
||||
Mat _eigenvectors;
|
||||
Mat _eigenvalues;
|
||||
|
||||
void lda(InputArrayOfArrays src, InputArray labels);
|
||||
};
|
||||
|
||||
class CV_EXPORTS_W FaceRecognizer : public Algorithm
|
||||
{
|
||||
public:
|
||||
//! virtual destructor
|
||||
virtual ~FaceRecognizer() {}
|
||||
|
||||
// Trains a FaceRecognizer.
|
||||
CV_WRAP virtual void train(InputArrayOfArrays src, InputArray labels) = 0;
|
||||
|
||||
// Updates a FaceRecognizer.
|
||||
CV_WRAP void update(InputArrayOfArrays src, InputArray labels);
|
||||
|
||||
// Gets a prediction from a FaceRecognizer.
|
||||
virtual int predict(InputArray src) const = 0;
|
||||
|
||||
// Predicts the label and confidence for a given sample.
|
||||
CV_WRAP virtual void predict(InputArray src, CV_OUT int &label, CV_OUT double &confidence) const = 0;
|
||||
|
||||
// Serializes this object to a given filename.
|
||||
CV_WRAP virtual void save(const string& filename) const;
|
||||
|
||||
// Deserializes this object from a given filename.
|
||||
CV_WRAP virtual void load(const string& filename);
|
||||
|
||||
// Serializes this object to a given cv::FileStorage.
|
||||
virtual void save(FileStorage& fs) const = 0;
|
||||
|
||||
// Deserializes this object from a given cv::FileStorage.
|
||||
virtual void load(const FileStorage& fs) = 0;
|
||||
|
||||
};
|
||||
|
||||
CV_EXPORTS_W Ptr<FaceRecognizer> createEigenFaceRecognizer(int num_components = 0, double threshold = DBL_MAX);
|
||||
CV_EXPORTS_W Ptr<FaceRecognizer> createFisherFaceRecognizer(int num_components = 0, double threshold = DBL_MAX);
|
||||
CV_EXPORTS_W Ptr<FaceRecognizer> createLBPHFaceRecognizer(int radius=1, int neighbors=8,
|
||||
int grid_x=8, int grid_y=8, double threshold = DBL_MAX);
|
||||
|
||||
enum
|
||||
{
|
||||
COLORMAP_AUTUMN = 0,
|
||||
COLORMAP_BONE = 1,
|
||||
COLORMAP_JET = 2,
|
||||
COLORMAP_WINTER = 3,
|
||||
COLORMAP_RAINBOW = 4,
|
||||
COLORMAP_OCEAN = 5,
|
||||
COLORMAP_SUMMER = 6,
|
||||
COLORMAP_SPRING = 7,
|
||||
COLORMAP_COOL = 8,
|
||||
COLORMAP_HSV = 9,
|
||||
COLORMAP_PINK = 10,
|
||||
COLORMAP_HOT = 11
|
||||
};
|
||||
|
||||
CV_EXPORTS_W void applyColorMap(InputArray src, OutputArray dst, int colormap);
|
||||
|
||||
CV_EXPORTS bool initModule_contrib();
|
||||
}
|
||||
|
||||
#include "opencv2/contrib/retina.hpp"
|
||||
|
||||
#include "opencv2/contrib/openfabmap.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,106 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(__linux__) || defined(LINUX) || defined(__APPLE__) || defined(ANDROID)
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/objdetect/objdetect.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
class DetectionBasedTracker
|
||||
{
|
||||
public:
|
||||
struct Parameters
|
||||
{
|
||||
int minObjectSize;
|
||||
int maxObjectSize;
|
||||
double scaleFactor;
|
||||
int maxTrackLifetime;
|
||||
int minNeighbors;
|
||||
int minDetectionPeriod; //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0
|
||||
|
||||
Parameters();
|
||||
};
|
||||
|
||||
DetectionBasedTracker(const std::string& cascadeFilename, const Parameters& params);
|
||||
virtual ~DetectionBasedTracker();
|
||||
|
||||
virtual bool run();
|
||||
virtual void stop();
|
||||
virtual void resetTracking();
|
||||
|
||||
virtual void process(const cv::Mat& imageGray);
|
||||
|
||||
bool setParameters(const Parameters& params);
|
||||
const Parameters& getParameters();
|
||||
|
||||
|
||||
typedef std::pair<cv::Rect, int> Object;
|
||||
virtual void getObjects(std::vector<cv::Rect>& result) const;
|
||||
virtual void getObjects(std::vector<Object>& result) const;
|
||||
|
||||
protected:
|
||||
class SeparateDetectionWork;
|
||||
cv::Ptr<SeparateDetectionWork> separateDetectionWork;
|
||||
friend void* workcycleObjectDetectorFunction(void* p);
|
||||
|
||||
|
||||
struct InnerParameters
|
||||
{
|
||||
int numLastPositionsToTrack;
|
||||
int numStepsToWaitBeforeFirstShow;
|
||||
int numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown;
|
||||
int numStepsToShowWithoutDetecting;
|
||||
|
||||
float coeffTrackingWindowSize;
|
||||
float coeffObjectSizeToTrack;
|
||||
float coeffObjectSpeedUsingInPrediction;
|
||||
|
||||
InnerParameters();
|
||||
};
|
||||
Parameters parameters;
|
||||
InnerParameters innerParameters;
|
||||
|
||||
struct TrackedObject
|
||||
{
|
||||
typedef std::vector<cv::Rect> PositionsVector;
|
||||
|
||||
PositionsVector lastPositions;
|
||||
|
||||
int numDetectedFrames;
|
||||
int numFramesNotDetected;
|
||||
int id;
|
||||
|
||||
TrackedObject(const cv::Rect& rect):numDetectedFrames(1), numFramesNotDetected(0)
|
||||
{
|
||||
lastPositions.push_back(rect);
|
||||
id=getNextId();
|
||||
};
|
||||
|
||||
static int getNextId()
|
||||
{
|
||||
static int _id=0;
|
||||
return _id++;
|
||||
}
|
||||
};
|
||||
|
||||
int numTrackedSteps;
|
||||
std::vector<TrackedObject> trackedObjects;
|
||||
|
||||
std::vector<float> weightsPositionsSmoothing;
|
||||
std::vector<float> weightsSizesSmoothing;
|
||||
|
||||
cv::CascadeClassifier cascadeForTracking;
|
||||
|
||||
|
||||
void updateTrackedObjects(const std::vector<cv::Rect>& detectedObjects);
|
||||
cv::Rect calcTrackedObjectPositionToShow(int i) const;
|
||||
void detectInRegion(const cv::Mat& img, const cv::Rect& r, std::vector<cv::Rect>& detectedObjectsInRegions);
|
||||
};
|
||||
|
||||
namespace cv
|
||||
{
|
||||
using ::DetectionBasedTracker;
|
||||
} //end of cv namespace
|
||||
|
||||
#endif
|
||||
@@ -1,220 +0,0 @@
|
||||
//*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of Intel Corporation may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_HYBRIDTRACKER_H_
|
||||
#define __OPENCV_HYBRIDTRACKER_H_
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/operations.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/video/tracking.hpp"
|
||||
#include "opencv2/ml/ml.hpp"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
// Motion model for tracking algorithm. Currently supports objects that do not move much.
|
||||
// To add Kalman filter
|
||||
struct CV_EXPORTS CvMotionModel
|
||||
{
|
||||
enum {LOW_PASS_FILTER = 0, KALMAN_FILTER = 1, EM = 2};
|
||||
|
||||
CvMotionModel()
|
||||
{
|
||||
}
|
||||
|
||||
float low_pass_gain; // low pass gain
|
||||
};
|
||||
|
||||
// Mean Shift Tracker parameters for specifying use of HSV channel and CamShift parameters.
|
||||
struct CV_EXPORTS CvMeanShiftTrackerParams
|
||||
{
|
||||
enum { H = 0, HS = 1, HSV = 2 };
|
||||
CvMeanShiftTrackerParams(int tracking_type = CvMeanShiftTrackerParams::HS,
|
||||
CvTermCriteria term_crit = CvTermCriteria());
|
||||
|
||||
int tracking_type;
|
||||
vector<float> h_range;
|
||||
vector<float> s_range;
|
||||
vector<float> v_range;
|
||||
CvTermCriteria term_crit;
|
||||
};
|
||||
|
||||
// Feature tracking parameters
|
||||
struct CV_EXPORTS CvFeatureTrackerParams
|
||||
{
|
||||
enum { SIFT = 0, SURF = 1, OPTICAL_FLOW = 2 };
|
||||
CvFeatureTrackerParams(int featureType = 0, int windowSize = 0)
|
||||
{
|
||||
feature_type = featureType;
|
||||
window_size = windowSize;
|
||||
}
|
||||
|
||||
int feature_type; // Feature type to use
|
||||
int window_size; // Window size in pixels around which to search for new window
|
||||
};
|
||||
|
||||
// Hybrid Tracking parameters for specifying weights of individual trackers and motion model.
|
||||
struct CV_EXPORTS CvHybridTrackerParams
|
||||
{
|
||||
CvHybridTrackerParams(float ft_tracker_weight = 0.5, float ms_tracker_weight = 0.5,
|
||||
CvFeatureTrackerParams ft_params = CvFeatureTrackerParams(),
|
||||
CvMeanShiftTrackerParams ms_params = CvMeanShiftTrackerParams(),
|
||||
CvMotionModel model = CvMotionModel());
|
||||
|
||||
float ft_tracker_weight;
|
||||
float ms_tracker_weight;
|
||||
CvFeatureTrackerParams ft_params;
|
||||
CvMeanShiftTrackerParams ms_params;
|
||||
int motion_model;
|
||||
float low_pass_gain;
|
||||
};
|
||||
|
||||
// Performs Camshift using parameters from MeanShiftTrackerParams
|
||||
class CV_EXPORTS CvMeanShiftTracker
|
||||
{
|
||||
private:
|
||||
Mat hsv, hue;
|
||||
Mat backproj;
|
||||
Mat mask, maskroi;
|
||||
MatND hist;
|
||||
Rect prev_trackwindow;
|
||||
RotatedRect prev_trackbox;
|
||||
Point2f prev_center;
|
||||
|
||||
public:
|
||||
CvMeanShiftTrackerParams params;
|
||||
|
||||
CvMeanShiftTracker();
|
||||
explicit CvMeanShiftTracker(CvMeanShiftTrackerParams _params);
|
||||
~CvMeanShiftTracker();
|
||||
void newTrackingWindow(Mat image, Rect selection);
|
||||
RotatedRect updateTrackingWindow(Mat image);
|
||||
Mat getHistogramProjection(int type);
|
||||
void setTrackingWindow(Rect _window);
|
||||
Rect getTrackingWindow();
|
||||
RotatedRect getTrackingEllipse();
|
||||
Point2f getTrackingCenter();
|
||||
};
|
||||
|
||||
// Performs SIFT/SURF feature tracking using parameters from FeatureTrackerParams
|
||||
class CV_EXPORTS CvFeatureTracker
|
||||
{
|
||||
private:
|
||||
Ptr<Feature2D> dd;
|
||||
Ptr<DescriptorMatcher> matcher;
|
||||
vector<DMatch> matches;
|
||||
|
||||
Mat prev_image;
|
||||
Mat prev_image_bw;
|
||||
Rect prev_trackwindow;
|
||||
Point2d prev_center;
|
||||
|
||||
int ittr;
|
||||
vector<Point2f> features[2];
|
||||
|
||||
public:
|
||||
Mat disp_matches;
|
||||
CvFeatureTrackerParams params;
|
||||
|
||||
CvFeatureTracker();
|
||||
explicit CvFeatureTracker(CvFeatureTrackerParams params);
|
||||
~CvFeatureTracker();
|
||||
void newTrackingWindow(Mat image, Rect selection);
|
||||
Rect updateTrackingWindow(Mat image);
|
||||
Rect updateTrackingWindowWithSIFT(Mat image);
|
||||
Rect updateTrackingWindowWithFlow(Mat image);
|
||||
void setTrackingWindow(Rect _window);
|
||||
Rect getTrackingWindow();
|
||||
Point2f getTrackingCenter();
|
||||
};
|
||||
|
||||
// Performs Hybrid Tracking and combines individual trackers using EM or filters
|
||||
class CV_EXPORTS CvHybridTracker
|
||||
{
|
||||
private:
|
||||
CvMeanShiftTracker* mstracker;
|
||||
CvFeatureTracker* fttracker;
|
||||
|
||||
CvMat* samples;
|
||||
CvMat* labels;
|
||||
|
||||
Rect prev_window;
|
||||
Point2f prev_center;
|
||||
Mat prev_proj;
|
||||
RotatedRect trackbox;
|
||||
|
||||
int ittr;
|
||||
Point2f curr_center;
|
||||
|
||||
inline float getL2Norm(Point2f p1, Point2f p2);
|
||||
Mat getDistanceProjection(Mat image, Point2f center);
|
||||
Mat getGaussianProjection(Mat image, int ksize, double sigma, Point2f center);
|
||||
void updateTrackerWithEM(Mat image);
|
||||
void updateTrackerWithLowPassFilter(Mat image);
|
||||
|
||||
public:
|
||||
CvHybridTrackerParams params;
|
||||
CvHybridTracker();
|
||||
explicit CvHybridTracker(CvHybridTrackerParams params);
|
||||
~CvHybridTracker();
|
||||
|
||||
void newTracker(Mat image, Rect selection);
|
||||
void updateTracker(Mat image);
|
||||
Rect getTrackingWindow();
|
||||
};
|
||||
|
||||
typedef CvMotionModel MotionModel;
|
||||
typedef CvMeanShiftTrackerParams MeanShiftTrackerParams;
|
||||
typedef CvFeatureTrackerParams FeatureTrackerParams;
|
||||
typedef CvHybridTrackerParams HybridTrackerParams;
|
||||
typedef CvMeanShiftTracker MeanShiftTracker;
|
||||
typedef CvFeatureTracker FeatureTracker;
|
||||
typedef CvHybridTracker HybridTracker;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,405 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
// This file originates from the openFABMAP project:
|
||||
// [http://code.google.com/p/openfabmap/]
|
||||
//
|
||||
// For published work which uses all or part of OpenFABMAP, please cite:
|
||||
// [http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=6224843]
|
||||
//
|
||||
// Original Algorithm by Mark Cummins and Paul Newman:
|
||||
// [http://ijr.sagepub.com/content/27/6/647.short]
|
||||
// [http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=5613942]
|
||||
// [http://ijr.sagepub.com/content/30/9/1100.abstract]
|
||||
//
|
||||
// License Agreement
|
||||
//
|
||||
// Copyright (C) 2012 Arren Glover [aj.glover@qut.edu.au] and
|
||||
// Will Maddern [w.maddern@qut.edu.au], all rights reserved.
|
||||
//
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_OPENFABMAP_H_
|
||||
#define __OPENCV_OPENFABMAP_H_
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <valarray>
|
||||
|
||||
namespace cv {
|
||||
|
||||
namespace of2 {
|
||||
|
||||
using std::list;
|
||||
using std::map;
|
||||
using std::multiset;
|
||||
|
||||
/*
|
||||
Return data format of a FABMAP compare call
|
||||
*/
|
||||
struct CV_EXPORTS IMatch {
|
||||
|
||||
IMatch() :
|
||||
queryIdx(-1), imgIdx(-1), likelihood(-DBL_MAX), match(-DBL_MAX) {
|
||||
}
|
||||
IMatch(int _queryIdx, int _imgIdx, double _likelihood, double _match) :
|
||||
queryIdx(_queryIdx), imgIdx(_imgIdx), likelihood(_likelihood), match(
|
||||
_match) {
|
||||
}
|
||||
|
||||
int queryIdx; //query index
|
||||
int imgIdx; //test index
|
||||
|
||||
double likelihood; //raw loglikelihood
|
||||
double match; //normalised probability
|
||||
|
||||
bool operator<(const IMatch& m) const {
|
||||
return match < m.match;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
Base FabMap class. Each FabMap method inherits from this class.
|
||||
*/
|
||||
class CV_EXPORTS FabMap {
|
||||
public:
|
||||
|
||||
//FabMap options
|
||||
enum {
|
||||
MEAN_FIELD = 1,
|
||||
SAMPLED = 2,
|
||||
NAIVE_BAYES = 4,
|
||||
CHOW_LIU = 8,
|
||||
MOTION_MODEL = 16
|
||||
};
|
||||
|
||||
FabMap(const Mat& clTree, double PzGe, double PzGNe, int flags,
|
||||
int numSamples = 0);
|
||||
virtual ~FabMap();
|
||||
|
||||
//methods to add training data for sampling method
|
||||
virtual void addTraining(const Mat& queryImgDescriptor);
|
||||
virtual void addTraining(const vector<Mat>& queryImgDescriptors);
|
||||
|
||||
//methods to add to the test data
|
||||
virtual void add(const Mat& queryImgDescriptor);
|
||||
virtual void add(const vector<Mat>& queryImgDescriptors);
|
||||
|
||||
//accessors
|
||||
const vector<Mat>& getTrainingImgDescriptors() const;
|
||||
const vector<Mat>& getTestImgDescriptors() const;
|
||||
|
||||
//Main FabMap image comparison
|
||||
void compare(const Mat& queryImgDescriptor,
|
||||
vector<IMatch>& matches, bool addQuery = false,
|
||||
const Mat& mask = Mat());
|
||||
void compare(const Mat& queryImgDescriptor,
|
||||
const Mat& testImgDescriptors, vector<IMatch>& matches,
|
||||
const Mat& mask = Mat());
|
||||
void compare(const Mat& queryImgDescriptor,
|
||||
const vector<Mat>& testImgDescriptors,
|
||||
vector<IMatch>& matches, const Mat& mask = Mat());
|
||||
void compare(const vector<Mat>& queryImgDescriptors, vector<
|
||||
IMatch>& matches, bool addQuery = false, const Mat& mask =
|
||||
Mat());
|
||||
void compare(const vector<Mat>& queryImgDescriptors,
|
||||
const vector<Mat>& testImgDescriptors,
|
||||
vector<IMatch>& matches, const Mat& mask = Mat());
|
||||
|
||||
protected:
|
||||
|
||||
void compareImgDescriptor(const Mat& queryImgDescriptor,
|
||||
int queryIndex, const vector<Mat>& testImgDescriptors,
|
||||
vector<IMatch>& matches);
|
||||
|
||||
void addImgDescriptor(const Mat& queryImgDescriptor);
|
||||
|
||||
//the getLikelihoods method is overwritten for each different FabMap
|
||||
//method.
|
||||
virtual void getLikelihoods(const Mat& queryImgDescriptor,
|
||||
const vector<Mat>& testImgDescriptors,
|
||||
vector<IMatch>& matches);
|
||||
virtual double getNewPlaceLikelihood(const Mat& queryImgDescriptor);
|
||||
|
||||
//turn likelihoods into probabilities (also add in motion model if used)
|
||||
void normaliseDistribution(vector<IMatch>& matches);
|
||||
|
||||
//Chow-Liu Tree
|
||||
int pq(int q);
|
||||
double Pzq(int q, bool zq);
|
||||
double PzqGzpq(int q, bool zq, bool zpq);
|
||||
|
||||
//FAB-MAP Core
|
||||
double PzqGeq(bool zq, bool eq);
|
||||
double PeqGL(int q, bool Lzq, bool eq);
|
||||
double PzqGL(int q, bool zq, bool zpq, bool Lzq);
|
||||
double PzqGzpqL(int q, bool zq, bool zpq, bool Lzq);
|
||||
double (FabMap::*PzGL)(int q, bool zq, bool zpq, bool Lzq);
|
||||
|
||||
//data
|
||||
Mat clTree;
|
||||
vector<Mat> trainingImgDescriptors;
|
||||
vector<Mat> testImgDescriptors;
|
||||
vector<IMatch> priorMatches;
|
||||
|
||||
//parameters
|
||||
double PzGe;
|
||||
double PzGNe;
|
||||
double Pnew;
|
||||
|
||||
double mBias;
|
||||
double sFactor;
|
||||
|
||||
int flags;
|
||||
int numSamples;
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
The original FAB-MAP algorithm, developed based on:
|
||||
http://ijr.sagepub.com/content/27/6/647.short
|
||||
*/
|
||||
class CV_EXPORTS FabMap1: public FabMap {
|
||||
public:
|
||||
FabMap1(const Mat& clTree, double PzGe, double PzGNe, int flags,
|
||||
int numSamples = 0);
|
||||
virtual ~FabMap1();
|
||||
protected:
|
||||
|
||||
//FabMap1 implementation of likelihood comparison
|
||||
void getLikelihoods(const Mat& queryImgDescriptor, const vector<
|
||||
Mat>& testImgDescriptors, vector<IMatch>& matches);
|
||||
};
|
||||
|
||||
/*
|
||||
A computationally faster version of the original FAB-MAP algorithm. A look-
|
||||
up-table is used to precompute many of the reoccuring calculations
|
||||
*/
|
||||
class CV_EXPORTS FabMapLUT: public FabMap {
|
||||
public:
|
||||
FabMapLUT(const Mat& clTree, double PzGe, double PzGNe,
|
||||
int flags, int numSamples = 0, int precision = 6);
|
||||
virtual ~FabMapLUT();
|
||||
protected:
|
||||
|
||||
//FabMap look-up-table implementation of the likelihood comparison
|
||||
void getLikelihoods(const Mat& queryImgDescriptor, const vector<
|
||||
Mat>& testImgDescriptors, vector<IMatch>& matches);
|
||||
|
||||
//precomputed data
|
||||
int (*table)[8];
|
||||
|
||||
//data precision
|
||||
int precision;
|
||||
};
|
||||
|
||||
/*
|
||||
The Accelerated FAB-MAP algorithm, developed based on:
|
||||
http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=5613942
|
||||
*/
|
||||
class CV_EXPORTS FabMapFBO: public FabMap {
|
||||
public:
|
||||
FabMapFBO(const Mat& clTree, double PzGe, double PzGNe, int flags,
|
||||
int numSamples = 0, double rejectionThreshold = 1e-8, double PsGd =
|
||||
1e-8, int bisectionStart = 512, int bisectionIts = 9);
|
||||
virtual ~FabMapFBO();
|
||||
|
||||
protected:
|
||||
|
||||
//FabMap Fast Bail-out implementation of the likelihood comparison
|
||||
void getLikelihoods(const Mat& queryImgDescriptor, const vector<
|
||||
Mat>& testImgDescriptors, vector<IMatch>& matches);
|
||||
|
||||
//stucture used to determine word comparison order
|
||||
struct WordStats {
|
||||
WordStats() :
|
||||
q(0), info(0), V(0), M(0) {
|
||||
}
|
||||
|
||||
WordStats(int _q, double _info) :
|
||||
q(_q), info(_info), V(0), M(0) {
|
||||
}
|
||||
|
||||
int q;
|
||||
double info;
|
||||
mutable double V;
|
||||
mutable double M;
|
||||
|
||||
bool operator<(const WordStats& w) const {
|
||||
return info < w.info;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//private fast bail-out necessary functions
|
||||
void setWordStatistics(const Mat& queryImgDescriptor, multiset<WordStats>& wordData);
|
||||
double limitbisection(double v, double m);
|
||||
double bennettInequality(double v, double m, double delta);
|
||||
static bool compInfo(const WordStats& first, const WordStats& second);
|
||||
|
||||
//parameters
|
||||
double PsGd;
|
||||
double rejectionThreshold;
|
||||
int bisectionStart;
|
||||
int bisectionIts;
|
||||
};
|
||||
|
||||
/*
|
||||
The FAB-MAP2.0 algorithm, developed based on:
|
||||
http://ijr.sagepub.com/content/30/9/1100.abstract
|
||||
*/
|
||||
class CV_EXPORTS FabMap2: public FabMap {
|
||||
public:
|
||||
|
||||
FabMap2(const Mat& clTree, double PzGe, double PzGNe, int flags);
|
||||
virtual ~FabMap2();
|
||||
|
||||
//FabMap2 builds the inverted index and requires an additional training/test
|
||||
//add function
|
||||
void addTraining(const Mat& queryImgDescriptors) {
|
||||
FabMap::addTraining(queryImgDescriptors);
|
||||
}
|
||||
void addTraining(const vector<Mat>& queryImgDescriptors);
|
||||
|
||||
void add(const Mat& queryImgDescriptors) {
|
||||
FabMap::add(queryImgDescriptors);
|
||||
}
|
||||
void add(const vector<Mat>& queryImgDescriptors);
|
||||
|
||||
protected:
|
||||
|
||||
//FabMap2 implementation of the likelihood comparison
|
||||
void getLikelihoods(const Mat& queryImgDescriptor, const vector<
|
||||
Mat>& testImgDescriptors, vector<IMatch>& matches);
|
||||
double getNewPlaceLikelihood(const Mat& queryImgDescriptor);
|
||||
|
||||
//the likelihood function using the inverted index
|
||||
void getIndexLikelihoods(const Mat& queryImgDescriptor, vector<
|
||||
double>& defaults, map<int, vector<int> >& invertedMap,
|
||||
vector<IMatch>& matches);
|
||||
void addToIndex(const Mat& queryImgDescriptor,
|
||||
vector<double>& defaults,
|
||||
map<int, vector<int> >& invertedMap);
|
||||
|
||||
//data
|
||||
vector<double> d1, d2, d3, d4;
|
||||
vector<vector<int> > children;
|
||||
|
||||
// TODO: inverted map a vector?
|
||||
|
||||
vector<double> trainingDefaults;
|
||||
map<int, vector<int> > trainingInvertedMap;
|
||||
|
||||
vector<double> testDefaults;
|
||||
map<int, vector<int> > testInvertedMap;
|
||||
|
||||
};
|
||||
/*
|
||||
A Chow-Liu tree is required by FAB-MAP. The Chow-Liu tree provides an
|
||||
estimate of the full distribution of visual words using a minimum spanning
|
||||
tree. The tree is generated through training data.
|
||||
*/
|
||||
class CV_EXPORTS ChowLiuTree {
|
||||
public:
|
||||
ChowLiuTree();
|
||||
virtual ~ChowLiuTree();
|
||||
|
||||
//add data to the chow-liu tree before calling make
|
||||
void add(const Mat& imgDescriptor);
|
||||
void add(const vector<Mat>& imgDescriptors);
|
||||
|
||||
const vector<Mat>& getImgDescriptors() const;
|
||||
|
||||
Mat make(double infoThreshold = 0.0);
|
||||
|
||||
private:
|
||||
vector<Mat> imgDescriptors;
|
||||
Mat mergedImgDescriptors;
|
||||
|
||||
typedef struct info {
|
||||
float score;
|
||||
short word1;
|
||||
short word2;
|
||||
} info;
|
||||
|
||||
//probabilities extracted from mergedImgDescriptors
|
||||
double P(int a, bool za);
|
||||
double JP(int a, bool za, int b, bool zb); //a & b
|
||||
double CP(int a, bool za, int b, bool zb); // a | b
|
||||
|
||||
//calculating mutual information of all edges
|
||||
void createBaseEdges(list<info>& edges, double infoThreshold);
|
||||
double calcMutInfo(int word1, int word2);
|
||||
static bool sortInfoScores(const info& first, const info& second);
|
||||
|
||||
//selecting minimum spanning egdges with maximum information
|
||||
bool reduceEdgesToMinSpan(list<info>& edges);
|
||||
|
||||
//building the tree sctructure
|
||||
Mat buildTree(int root_word, list<info> &edges);
|
||||
void recAddToTree(Mat &cltree, int q, int pq,
|
||||
list<info> &remaining_edges);
|
||||
vector<int> extractChildren(list<info> &remaining_edges, int q);
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
A custom vocabulary training method based on:
|
||||
http://www.springerlink.com/content/d1h6j8x552532003/
|
||||
*/
|
||||
class CV_EXPORTS BOWMSCTrainer: public BOWTrainer {
|
||||
public:
|
||||
BOWMSCTrainer(double clusterSize = 0.4);
|
||||
virtual ~BOWMSCTrainer();
|
||||
|
||||
// Returns trained vocabulary (i.e. cluster centers).
|
||||
virtual Mat cluster() const;
|
||||
virtual Mat cluster(const Mat& descriptors) const;
|
||||
|
||||
protected:
|
||||
|
||||
double clusterSize;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif /* OPENFABMAP_H_ */
|
||||
@@ -1,355 +0,0 @@
|
||||
/*#******************************************************************************
|
||||
** IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
**
|
||||
** By downloading, copying, installing or using the software you agree to this license.
|
||||
** If you do not agree to this license, do not download, install,
|
||||
** copy or use the software.
|
||||
**
|
||||
**
|
||||
** HVStools : interfaces allowing OpenCV users to integrate Human Vision System models. Presented models originate from Jeanny Herault's original research and have been reused and adapted by the author&collaborators for computed vision applications since his thesis with Alice Caplier at Gipsa-Lab.
|
||||
** Use: extract still images & image sequences features, from contours details to motion spatio-temporal features, etc. for high level visual scene analysis. Also contribute to image enhancement/compression such as tone mapping.
|
||||
**
|
||||
** Maintainers : Listic lab (code author current affiliation & applications) and Gipsa Lab (original research origins & applications)
|
||||
**
|
||||
** Creation - enhancement process 2007-2011
|
||||
** Author: Alexandre Benoit (benoit.alexandre.vision@gmail.com), LISTIC lab, Annecy le vieux, France
|
||||
**
|
||||
** Theses algorithm have been developped by Alexandre BENOIT since his thesis with Alice Caplier at Gipsa-Lab (www.gipsa-lab.inpg.fr) and the research he pursues at LISTIC Lab (www.listic.univ-savoie.fr).
|
||||
** Refer to the following research paper for more information:
|
||||
** Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
** This work have been carried out thanks to Jeanny Herault who's research and great discussions are the basis of all this work, please take a look at his book:
|
||||
** Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
**
|
||||
** The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
** _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper:
|
||||
** ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
** _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions.
|
||||
** ====> more informations in the above cited Jeanny Heraults's book.
|
||||
**
|
||||
** License Agreement
|
||||
** For Open Source Computer Vision Library
|
||||
**
|
||||
** Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
** Copyright (C) 2008-2011, Willow Garage Inc., all rights reserved.
|
||||
**
|
||||
** For Human Visual System tools (hvstools)
|
||||
** Copyright (C) 2007-2011, LISTIC Lab, Annecy le Vieux and GIPSA Lab, Grenoble, France, all rights reserved.
|
||||
**
|
||||
** Third party copyrights are property of their respective owners.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without modification,
|
||||
** are permitted provided that the following conditions are met:
|
||||
**
|
||||
** * Redistributions of source code must retain the above copyright notice,
|
||||
** this list of conditions and the following disclaimer.
|
||||
**
|
||||
** * Redistributions in binary form must reproduce the above copyright notice,
|
||||
** this list of conditions and the following disclaimer in the documentation
|
||||
** and/or other materials provided with the distribution.
|
||||
**
|
||||
** * The name of the copyright holders may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** This software is provided by the copyright holders and contributors "as is" and
|
||||
** any express or implied warranties, including, but not limited to, the implied
|
||||
** warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
** In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
** indirect, incidental, special, exemplary, or consequential damages
|
||||
** (including, but not limited to, procurement of substitute goods or services;
|
||||
** loss of use, data, or profits; or business interruption) however caused
|
||||
** and on any theory of liability, whether in contract, strict liability,
|
||||
** or tort (including negligence or otherwise) arising in any way out of
|
||||
** the use of this software, even if advised of the possibility of such damage.
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __OPENCV_CONTRIB_RETINA_HPP__
|
||||
#define __OPENCV_CONTRIB_RETINA_HPP__
|
||||
|
||||
/*
|
||||
* Retina.hpp
|
||||
*
|
||||
* Created on: Jul 19, 2011
|
||||
* Author: Alexandre Benoit
|
||||
*/
|
||||
|
||||
#include "opencv2/core/core.hpp" // for all OpenCV core functionalities access, including cv::Exception support
|
||||
#include <valarray>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
enum RETINA_COLORSAMPLINGMETHOD
|
||||
{
|
||||
RETINA_COLOR_RANDOM, //!< each pixel position is either R, G or B in a random choice
|
||||
RETINA_COLOR_DIAGONAL,//!< color sampling is RGBRGBRGB..., line 2 BRGBRGBRG..., line 3, GBRGBRGBR...
|
||||
RETINA_COLOR_BAYER//!< standard bayer sampling
|
||||
};
|
||||
|
||||
class RetinaFilter;
|
||||
|
||||
/**
|
||||
* @class Retina a wrapper class which allows the Gipsa/Listic Labs model to be used.
|
||||
* This retina model allows spatio-temporal image processing (applied on still images, video sequences).
|
||||
* As a summary, these are the retina model properties:
|
||||
* => It applies a spectral whithening (mid-frequency details enhancement)
|
||||
* => high frequency spatio-temporal noise reduction
|
||||
* => low frequency luminance to be reduced (luminance range compression)
|
||||
* => local logarithmic luminance compression allows details to be enhanced in low light conditions
|
||||
*
|
||||
* USE : this model can be used basically for spatio-temporal video effects but also for :
|
||||
* _using the getParvo method output matrix : texture analysiswith enhanced signal to noise ratio and enhanced details robust against input images luminance ranges
|
||||
* _using the getMagno method output matrix : motion analysis also with the previously cited properties
|
||||
*
|
||||
* for more information, reer to the following papers :
|
||||
* Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
* Vision: Images, Signals and Neural Networks: Models of Neural Processing in Visual Perception (Progress in Neural Processing),By: Jeanny Herault, ISBN: 9814273686. WAPI (Tower ID): 113266891.
|
||||
*
|
||||
* The retina filter includes the research contributions of phd/research collegues from which code has been redrawn by the author :
|
||||
* _take a look at the retinacolor.hpp module to discover Brice Chaix de Lavarene color mosaicing/demosaicing and the reference paper:
|
||||
* ====> B. Chaix de Lavarene, D. Alleysson, B. Durette, J. Herault (2007). "Efficient demosaicing through recursive filtering", IEEE International Conference on Image Processing ICIP 2007
|
||||
* _take a look at imagelogpolprojection.hpp to discover retina spatial log sampling which originates from Barthelemy Durette phd with Jeanny Herault. A Retina / V1 cortex projection is also proposed and originates from Jeanny's discussions.
|
||||
* ====> more informations in the above cited Jeanny Heraults's book.
|
||||
*/
|
||||
class CV_EXPORTS Retina {
|
||||
|
||||
public:
|
||||
|
||||
// parameters structure for better clarity, check explenations on the comments of methods : setupOPLandIPLParvoChannel and setupIPLMagnoChannel
|
||||
struct RetinaParameters{
|
||||
struct OPLandIplParvoParameters{ // Outer Plexiform Layer (OPL) and Inner Plexiform Layer Parvocellular (IplParvo) parameters
|
||||
OPLandIplParvoParameters():colorMode(true),
|
||||
normaliseOutput(true),
|
||||
photoreceptorsLocalAdaptationSensitivity(0.7f),
|
||||
photoreceptorsTemporalConstant(0.5f),
|
||||
photoreceptorsSpatialConstant(0.53f),
|
||||
horizontalCellsGain(0.0f),
|
||||
hcellsTemporalConstant(1.f),
|
||||
hcellsSpatialConstant(7.f),
|
||||
ganglionCellsSensitivity(0.7f){};// default setup
|
||||
bool colorMode, normaliseOutput;
|
||||
float photoreceptorsLocalAdaptationSensitivity, photoreceptorsTemporalConstant, photoreceptorsSpatialConstant, horizontalCellsGain, hcellsTemporalConstant, hcellsSpatialConstant, ganglionCellsSensitivity;
|
||||
};
|
||||
struct IplMagnoParameters{ // Inner Plexiform Layer Magnocellular channel (IplMagno)
|
||||
IplMagnoParameters():
|
||||
normaliseOutput(true),
|
||||
parasolCells_beta(0.f),
|
||||
parasolCells_tau(0.f),
|
||||
parasolCells_k(7.f),
|
||||
amacrinCellsTemporalCutFrequency(1.2f),
|
||||
V0CompressionParameter(0.95f),
|
||||
localAdaptintegration_tau(0.f),
|
||||
localAdaptintegration_k(7.f){};// default setup
|
||||
bool normaliseOutput;
|
||||
float parasolCells_beta, parasolCells_tau, parasolCells_k, amacrinCellsTemporalCutFrequency, V0CompressionParameter, localAdaptintegration_tau, localAdaptintegration_k;
|
||||
};
|
||||
struct OPLandIplParvoParameters OPLandIplParvo;
|
||||
struct IplMagnoParameters IplMagno;
|
||||
};
|
||||
|
||||
/**
|
||||
* Main constructor with most commun use setup : create an instance of color ready retina model
|
||||
* @param inputSize : the input frame size
|
||||
*/
|
||||
Retina(Size inputSize);
|
||||
|
||||
/**
|
||||
* Complete Retina filter constructor which allows all basic structural parameters definition
|
||||
* @param inputSize : the input frame size
|
||||
* @param colorMode : the chosen processing mode : with or without color processing
|
||||
* @param colorSamplingMethod: specifies which kind of color sampling will be used
|
||||
* @param useRetinaLogSampling: activate retina log sampling, if true, the 2 following parameters can be used
|
||||
* @param reductionFactor: only usefull if param useRetinaLogSampling=true, specifies the reduction factor of the output frame (as the center (fovea) is high resolution and corners can be underscaled, then a reduction of the output is allowed without precision leak
|
||||
* @param samplingStrenght: only usefull if param useRetinaLogSampling=true, specifies the strenght of the log scale that is applied
|
||||
*/
|
||||
Retina(Size inputSize, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod=RETINA_COLOR_BAYER, const bool useRetinaLogSampling=false, const double reductionFactor=1.0, const double samplingStrenght=10.0);
|
||||
|
||||
virtual ~Retina();
|
||||
|
||||
/**
|
||||
* retreive retina input buffer size
|
||||
*/
|
||||
Size inputSize();
|
||||
|
||||
/**
|
||||
* retreive retina output buffer size
|
||||
*/
|
||||
Size outputSize();
|
||||
|
||||
/**
|
||||
* try to open an XML retina parameters file to adjust current retina instance setup
|
||||
* => if the xml file does not exist, then default setup is applied
|
||||
* => warning, Exceptions are thrown if read XML file is not valid
|
||||
* @param retinaParameterFile : the parameters filename
|
||||
* @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
|
||||
*/
|
||||
void setup(std::string retinaParameterFile="", const bool applyDefaultSetupOnFailure=true);
|
||||
|
||||
|
||||
/**
|
||||
* try to open an XML retina parameters file to adjust current retina instance setup
|
||||
* => if the xml file does not exist, then default setup is applied
|
||||
* => warning, Exceptions are thrown if read XML file is not valid
|
||||
* @param fs : the open Filestorage which contains retina parameters
|
||||
* @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
|
||||
*/
|
||||
void setup(cv::FileStorage &fs, const bool applyDefaultSetupOnFailure=true);
|
||||
|
||||
/**
|
||||
* try to open an XML retina parameters file to adjust current retina instance setup
|
||||
* => if the xml file does not exist, then default setup is applied
|
||||
* => warning, Exceptions are thrown if read XML file is not valid
|
||||
* @param newParameters : a parameters structures updated with the new target configuration
|
||||
* @param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
|
||||
*/
|
||||
void setup(RetinaParameters newParameters);
|
||||
|
||||
/**
|
||||
* @return the current parameters setup
|
||||
*/
|
||||
Retina::RetinaParameters getParameters();
|
||||
|
||||
/**
|
||||
* parameters setup display method
|
||||
* @return a string which contains formatted parameters information
|
||||
*/
|
||||
const std::string printSetup();
|
||||
|
||||
/**
|
||||
* write xml/yml formated parameters information
|
||||
* @rparam fs : the filename of the xml file that will be open and writen with formatted parameters information
|
||||
*/
|
||||
virtual void write( std::string fs ) const;
|
||||
|
||||
|
||||
/**
|
||||
* write xml/yml formated parameters information
|
||||
* @param fs : a cv::Filestorage object ready to be filled
|
||||
*/
|
||||
virtual void write( FileStorage& fs ) const;
|
||||
|
||||
/**
|
||||
* setup the OPL and IPL parvo channels (see biologocal model)
|
||||
* OPL is referred as Outer Plexiform Layer of the retina, it allows the spatio-temporal filtering which withens the spectrum and reduces spatio-temporal noise while attenuating global luminance (low frequency energy)
|
||||
* IPL parvo is the OPL next processing stage, it refers to Inner Plexiform layer of the retina, it allows high contours sensitivity in foveal vision.
|
||||
* for more informations, please have a look at the paper Benoit A., Caplier A., Durette B., Herault, J., "USING HUMAN VISUAL SYSTEM MODELING FOR BIO-INSPIRED LOW LEVEL IMAGE PROCESSING", Elsevier, Computer Vision and Image Understanding 114 (2010), pp. 758-773, DOI: http://dx.doi.org/10.1016/j.cviu.2010.01.011
|
||||
* @param colorMode : specifies if (true) color is processed of not (false) to then processing gray level image
|
||||
* @param normaliseOutput : specifies if (true) output is rescaled between 0 and 255 of not (false)
|
||||
* @param photoreceptorsLocalAdaptationSensitivity: the photoreceptors sensitivity renage is 0-1 (more log compression effect when value increases)
|
||||
* @param photoreceptorsTemporalConstant: the time constant of the first order low pass filter of the photoreceptors, use it to cut high temporal frequencies (noise or fast motion), unit is frames, typical value is 1 frame
|
||||
* @param photoreceptorsSpatialConstant: the spatial constant of the first order low pass filter of the photoreceptors, use it to cut high spatial frequencies (noise or thick contours), unit is pixels, typical value is 1 pixel
|
||||
* @param horizontalCellsGain: gain of the horizontal cells network, if 0, then the mean value of the output is zero, if the parameter is near 1, then, the luminance is not filtered and is still reachable at the output, typicall value is 0
|
||||
* @param HcellsTemporalConstant: the time constant of the first order low pass filter of the horizontal cells, use it to cut low temporal frequencies (local luminance variations), unit is frames, typical value is 1 frame, as the photoreceptors
|
||||
* @param HcellsSpatialConstant: the spatial constant of the first order low pass filter of the horizontal cells, use it to cut low spatial frequencies (local luminance), unit is pixels, typical value is 5 pixel, this value is also used for local contrast computing when computing the local contrast adaptation at the ganglion cells level (Inner Plexiform Layer parvocellular channel model)
|
||||
* @param ganglionCellsSensitivity: the compression strengh of the ganglion cells local adaptation output, set a value between 160 and 250 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 230
|
||||
*/
|
||||
void setupOPLandIPLParvoChannel(const bool colorMode=true, const bool normaliseOutput = true, const float photoreceptorsLocalAdaptationSensitivity=0.7, const float photoreceptorsTemporalConstant=0.5, const float photoreceptorsSpatialConstant=0.53, const float horizontalCellsGain=0, const float HcellsTemporalConstant=1, const float HcellsSpatialConstant=7, const float ganglionCellsSensitivity=0.7);
|
||||
|
||||
/**
|
||||
* set parameters values for the Inner Plexiform Layer (IPL) magnocellular channel
|
||||
* this channel processes signals outpint from OPL processing stage in peripheral vision, it allows motion information enhancement. It is decorrelated from the details channel. See reference paper for more details.
|
||||
* @param normaliseOutput : specifies if (true) output is rescaled between 0 and 255 of not (false)
|
||||
* @param parasolCells_beta: the low pass filter gain used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), typical value is 0
|
||||
* @param parasolCells_tau: the low pass filter time constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is frame, typical value is 0 (immediate response)
|
||||
* @param parasolCells_k: the low pass filter spatial constant used for local contrast adaptation at the IPL level of the retina (for ganglion cells local adaptation), unit is pixels, typical value is 5
|
||||
* @param amacrinCellsTemporalCutFrequency: the time constant of the first order high pass fiter of the magnocellular way (motion information channel), unit is frames, tipicall value is 5
|
||||
* @param V0CompressionParameter: the compression strengh of the ganglion cells local adaptation output, set a value between 160 and 250 for best results, a high value increases more the low value sensitivity... and the output saturates faster, recommended value: 200
|
||||
* @param localAdaptintegration_tau: specifies the temporal constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
|
||||
* @param localAdaptintegration_k: specifies the spatial constant of the low pas filter involved in the computation of the local "motion mean" for the local adaptation computation
|
||||
*/
|
||||
void setupIPLMagnoChannel(const bool normaliseOutput = true, const float parasolCells_beta=0, const float parasolCells_tau=0, const float parasolCells_k=7, const float amacrinCellsTemporalCutFrequency=1.2, const float V0CompressionParameter=0.95, const float localAdaptintegration_tau=0, const float localAdaptintegration_k=7);
|
||||
|
||||
/**
|
||||
* method which allows retina to be applied on an input image, after run, encapsulated retina module is ready to deliver its outputs using dedicated acccessors, see getParvo and getMagno methods
|
||||
* @param inputImage : the input cv::Mat image to be processed, can be gray level or BGR coded in any format (from 8bit to 16bits)
|
||||
*/
|
||||
void run(const Mat &inputImage);
|
||||
|
||||
/**
|
||||
* accessor of the details channel of the retina (models foveal vision)
|
||||
* @param retinaOutput_parvo : the output buffer (reallocated if necessary), this output is rescaled for standard 8bits image processing use in OpenCV
|
||||
*/
|
||||
void getParvo(Mat &retinaOutput_parvo);
|
||||
|
||||
/**
|
||||
* accessor of the details channel of the retina (models foveal vision)
|
||||
* @param retinaOutput_parvo : the output buffer (reallocated if necessary), this output is the original retina filter model output, without any quantification or rescaling
|
||||
*/
|
||||
void getParvo(std::valarray<float> &retinaOutput_parvo);
|
||||
|
||||
/**
|
||||
* accessor of the motion channel of the retina (models peripheral vision)
|
||||
* @param retinaOutput_magno : the output buffer (reallocated if necessary), this output is rescaled for standard 8bits image processing use in OpenCV
|
||||
*/
|
||||
void getMagno(Mat &retinaOutput_magno);
|
||||
|
||||
/**
|
||||
* accessor of the motion channel of the retina (models peripheral vision)
|
||||
* @param retinaOutput_magno : the output buffer (reallocated if necessary), this output is the original retina filter model output, without any quantification or rescaling
|
||||
*/
|
||||
void getMagno(std::valarray<float> &retinaOutput_magno);
|
||||
|
||||
// original API level data accessors : get buffers addresses...
|
||||
const std::valarray<float> & getMagno() const;
|
||||
const std::valarray<float> & getParvo() const;
|
||||
|
||||
/**
|
||||
* activate color saturation as the final step of the color demultiplexing process
|
||||
* -> this saturation is a sigmoide function applied to each channel of the demultiplexed image.
|
||||
* @param saturateColors: boolean that activates color saturation (if true) or desactivate (if false)
|
||||
* @param colorSaturationValue: the saturation factor
|
||||
*/
|
||||
void setColorSaturation(const bool saturateColors=true, const float colorSaturationValue=4.0);
|
||||
|
||||
/**
|
||||
* clear all retina buffers (equivalent to opening the eyes after a long period of eye close ;o)
|
||||
*/
|
||||
void clearBuffers();
|
||||
|
||||
/**
|
||||
* Activate/desactivate the Magnocellular pathway processing (motion information extraction), by default, it is activated
|
||||
* @param activate: true if Magnocellular output should be activated, false if not
|
||||
*/
|
||||
void activateMovingContoursProcessing(const bool activate);
|
||||
|
||||
/**
|
||||
* Activate/desactivate the Parvocellular pathway processing (contours information extraction), by default, it is activated
|
||||
* @param activate: true if Parvocellular (contours information extraction) output should be activated, false if not
|
||||
*/
|
||||
void activateContoursProcessing(const bool activate);
|
||||
|
||||
protected:
|
||||
// Parameteres setup members
|
||||
RetinaParameters _retinaParameters; // structure of parameters
|
||||
|
||||
// Retina model related modules
|
||||
std::valarray<float> _inputBuffer; //!< buffer used to convert input cv::Mat to internal retina buffers format (valarrays)
|
||||
|
||||
// pointer to retina model
|
||||
RetinaFilter* _retinaFilter; //!< the pointer to the retina module, allocated with instance construction
|
||||
|
||||
/**
|
||||
* exports a valarray buffer outing from HVStools objects to a cv::Mat in CV_8UC1 (gray level picture) or CV_8UC3 (color) format
|
||||
* @param grayMatrixToConvert the valarray to export to OpenCV
|
||||
* @param nbRows : the number of rows of the valarray flatten matrix
|
||||
* @param nbColumns : the number of rows of the valarray flatten matrix
|
||||
* @param colorMode : a flag which mentions if matrix is color (true) or graylevel (false)
|
||||
* @param outBuffer : the output matrix which is reallocated to satisfy Retina output buffer dimensions
|
||||
*/
|
||||
void _convertValarrayBuffer2cvMat(const std::valarray<float> &grayMatrixToConvert, const unsigned int nbRows, const unsigned int nbColumns, const bool colorMode, Mat &outBuffer);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param inputMatToConvert : the OpenCV cv::Mat that has to be converted to gray or RGB valarray buffer that will be processed by the retina model
|
||||
* @param outputValarrayMatrix : the output valarray
|
||||
* @return the input image color mode (color=true, gray levels=false)
|
||||
*/
|
||||
bool _convertCvMat2ValarrayBuffer(const cv::Mat inputMatToConvert, std::valarray<float> &outputValarrayMatrix);
|
||||
|
||||
//! private method called by constructors, gathers their parameters and use them in a unified way
|
||||
void _init(const Size inputSize, const bool colorMode, RETINA_COLORSAMPLINGMETHOD colorSamplingMethod=RETINA_COLOR_BAYER, const bool useRetinaLogSampling=false, const double reductionFactor=1.0, const double samplingStrenght=10.0);
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
#endif /* __OPENCV_CONTRIB_RETINA_HPP__ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,517 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_AFFINE3_HPP
|
||||
#define OPENCV_CORE_AFFINE3_HPP
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
//! @addtogroup core
|
||||
//! @{
|
||||
|
||||
/** @brief Affine transform
|
||||
@todo document
|
||||
*/
|
||||
template<typename T>
|
||||
class Affine3
|
||||
{
|
||||
public:
|
||||
typedef T float_type;
|
||||
typedef Matx<float_type, 3, 3> Mat3;
|
||||
typedef Matx<float_type, 4, 4> Mat4;
|
||||
typedef Vec<float_type, 3> Vec3;
|
||||
|
||||
Affine3();
|
||||
|
||||
//! Augmented affine matrix
|
||||
Affine3(const Mat4& affine);
|
||||
|
||||
//! Rotation matrix
|
||||
Affine3(const Mat3& R, const Vec3& t = Vec3::all(0));
|
||||
|
||||
//! Rodrigues vector
|
||||
Affine3(const Vec3& rvec, const Vec3& t = Vec3::all(0));
|
||||
|
||||
//! Combines all contructors above. Supports 4x4, 4x3, 3x3, 1x3, 3x1 sizes of data matrix
|
||||
explicit Affine3(const Mat& data, const Vec3& t = Vec3::all(0));
|
||||
|
||||
//! From 16th element array
|
||||
explicit Affine3(const float_type* vals);
|
||||
|
||||
//! Create identity transform
|
||||
static Affine3 Identity();
|
||||
|
||||
//! Rotation matrix
|
||||
void rotation(const Mat3& R);
|
||||
|
||||
//! Rodrigues vector
|
||||
void rotation(const Vec3& rvec);
|
||||
|
||||
//! Combines rotation methods above. Suports 3x3, 1x3, 3x1 sizes of data matrix;
|
||||
void rotation(const Mat& data);
|
||||
|
||||
void linear(const Mat3& L);
|
||||
void translation(const Vec3& t);
|
||||
|
||||
Mat3 rotation() const;
|
||||
Mat3 linear() const;
|
||||
Vec3 translation() const;
|
||||
|
||||
//! Rodrigues vector
|
||||
Vec3 rvec() const;
|
||||
|
||||
Affine3 inv(int method = cv::DECOMP_SVD) const;
|
||||
|
||||
//! a.rotate(R) is equivalent to Affine(R, 0) * a;
|
||||
Affine3 rotate(const Mat3& R) const;
|
||||
|
||||
//! a.rotate(rvec) is equivalent to Affine(rvec, 0) * a;
|
||||
Affine3 rotate(const Vec3& rvec) const;
|
||||
|
||||
//! a.translate(t) is equivalent to Affine(E, t) * a;
|
||||
Affine3 translate(const Vec3& t) const;
|
||||
|
||||
//! a.concatenate(affine) is equivalent to affine * a;
|
||||
Affine3 concatenate(const Affine3& affine) const;
|
||||
|
||||
template <typename Y> operator Affine3<Y>() const;
|
||||
|
||||
template <typename Y> Affine3<Y> cast() const;
|
||||
|
||||
Mat4 matrix;
|
||||
|
||||
#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H
|
||||
Affine3(const Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine);
|
||||
Affine3(const Eigen::Transform<T, 3, Eigen::Affine>& affine);
|
||||
operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>() const;
|
||||
operator Eigen::Transform<T, 3, Eigen::Affine>() const;
|
||||
#endif
|
||||
};
|
||||
|
||||
template<typename T> static
|
||||
Affine3<T> operator*(const Affine3<T>& affine1, const Affine3<T>& affine2);
|
||||
|
||||
template<typename T, typename V> static
|
||||
V operator*(const Affine3<T>& affine, const V& vector);
|
||||
|
||||
typedef Affine3<float> Affine3f;
|
||||
typedef Affine3<double> Affine3d;
|
||||
|
||||
static Vec3f operator*(const Affine3f& affine, const Vec3f& vector);
|
||||
static Vec3d operator*(const Affine3d& affine, const Vec3d& vector);
|
||||
|
||||
template<typename _Tp> class DataType< Affine3<_Tp> >
|
||||
{
|
||||
public:
|
||||
typedef Affine3<_Tp> value_type;
|
||||
typedef Affine3<typename DataType<_Tp>::work_type> work_type;
|
||||
typedef _Tp channel_type;
|
||||
|
||||
enum { generic_type = 0,
|
||||
depth = DataType<channel_type>::depth,
|
||||
channels = 16,
|
||||
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
|
||||
typedef Vec<channel_type, channels> vec_type;
|
||||
};
|
||||
|
||||
//! @} core
|
||||
|
||||
}
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementaiton
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T>::Affine3()
|
||||
: matrix(Mat4::eye())
|
||||
{}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T>::Affine3(const Mat4& affine)
|
||||
: matrix(affine)
|
||||
{}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T>::Affine3(const Mat3& R, const Vec3& t)
|
||||
{
|
||||
rotation(R);
|
||||
translation(t);
|
||||
matrix.val[12] = matrix.val[13] = matrix.val[14] = 0;
|
||||
matrix.val[15] = 1;
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T>::Affine3(const Vec3& _rvec, const Vec3& t)
|
||||
{
|
||||
rotation(_rvec);
|
||||
translation(t);
|
||||
matrix.val[12] = matrix.val[13] = matrix.val[14] = 0;
|
||||
matrix.val[15] = 1;
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T>::Affine3(const cv::Mat& data, const Vec3& t)
|
||||
{
|
||||
CV_Assert(data.type() == cv::DataType<T>::type);
|
||||
|
||||
if (data.cols == 4 && data.rows == 4)
|
||||
{
|
||||
data.copyTo(matrix);
|
||||
return;
|
||||
}
|
||||
else if (data.cols == 4 && data.rows == 3)
|
||||
{
|
||||
rotation(data(Rect(0, 0, 3, 3)));
|
||||
translation(data(Rect(3, 0, 1, 3)));
|
||||
return;
|
||||
}
|
||||
|
||||
rotation(data);
|
||||
translation(t);
|
||||
matrix.val[12] = matrix.val[13] = matrix.val[14] = 0;
|
||||
matrix.val[15] = 1;
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T>::Affine3(const float_type* vals) : matrix(vals)
|
||||
{}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T> cv::Affine3<T>::Identity()
|
||||
{
|
||||
return Affine3<T>(cv::Affine3<T>::Mat4::eye());
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
void cv::Affine3<T>::rotation(const Mat3& R)
|
||||
{
|
||||
linear(R);
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
void cv::Affine3<T>::rotation(const Vec3& _rvec)
|
||||
{
|
||||
double theta = norm(_rvec);
|
||||
|
||||
if (theta < DBL_EPSILON)
|
||||
rotation(Mat3::eye());
|
||||
else
|
||||
{
|
||||
double c = std::cos(theta);
|
||||
double s = std::sin(theta);
|
||||
double c1 = 1. - c;
|
||||
double itheta = (theta != 0) ? 1./theta : 0.;
|
||||
|
||||
Point3_<T> r = _rvec*itheta;
|
||||
|
||||
Mat3 rrt( r.x*r.x, r.x*r.y, r.x*r.z, r.x*r.y, r.y*r.y, r.y*r.z, r.x*r.z, r.y*r.z, r.z*r.z );
|
||||
Mat3 r_x( 0, -r.z, r.y, r.z, 0, -r.x, -r.y, r.x, 0 );
|
||||
|
||||
// R = cos(theta)*I + (1 - cos(theta))*r*rT + sin(theta)*[r_x]
|
||||
// where [r_x] is [0 -rz ry; rz 0 -rx; -ry rx 0]
|
||||
Mat3 R = c*Mat3::eye() + c1*rrt + s*r_x;
|
||||
|
||||
rotation(R);
|
||||
}
|
||||
}
|
||||
|
||||
//Combines rotation methods above. Suports 3x3, 1x3, 3x1 sizes of data matrix;
|
||||
template<typename T> inline
|
||||
void cv::Affine3<T>::rotation(const cv::Mat& data)
|
||||
{
|
||||
CV_Assert(data.type() == cv::DataType<T>::type);
|
||||
|
||||
if (data.cols == 3 && data.rows == 3)
|
||||
{
|
||||
Mat3 R;
|
||||
data.copyTo(R);
|
||||
rotation(R);
|
||||
}
|
||||
else if ((data.cols == 3 && data.rows == 1) || (data.cols == 1 && data.rows == 3))
|
||||
{
|
||||
Vec3 _rvec;
|
||||
data.reshape(1, 3).copyTo(_rvec);
|
||||
rotation(_rvec);
|
||||
}
|
||||
else
|
||||
CV_Assert(!"Input marix can be 3x3, 1x3 or 3x1");
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
void cv::Affine3<T>::linear(const Mat3& L)
|
||||
{
|
||||
matrix.val[0] = L.val[0]; matrix.val[1] = L.val[1]; matrix.val[ 2] = L.val[2];
|
||||
matrix.val[4] = L.val[3]; matrix.val[5] = L.val[4]; matrix.val[ 6] = L.val[5];
|
||||
matrix.val[8] = L.val[6]; matrix.val[9] = L.val[7]; matrix.val[10] = L.val[8];
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
void cv::Affine3<T>::translation(const Vec3& t)
|
||||
{
|
||||
matrix.val[3] = t[0]; matrix.val[7] = t[1]; matrix.val[11] = t[2];
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
typename cv::Affine3<T>::Mat3 cv::Affine3<T>::rotation() const
|
||||
{
|
||||
return linear();
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
typename cv::Affine3<T>::Mat3 cv::Affine3<T>::linear() const
|
||||
{
|
||||
typename cv::Affine3<T>::Mat3 R;
|
||||
R.val[0] = matrix.val[0]; R.val[1] = matrix.val[1]; R.val[2] = matrix.val[ 2];
|
||||
R.val[3] = matrix.val[4]; R.val[4] = matrix.val[5]; R.val[5] = matrix.val[ 6];
|
||||
R.val[6] = matrix.val[8]; R.val[7] = matrix.val[9]; R.val[8] = matrix.val[10];
|
||||
return R;
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
typename cv::Affine3<T>::Vec3 cv::Affine3<T>::translation() const
|
||||
{
|
||||
return Vec3(matrix.val[3], matrix.val[7], matrix.val[11]);
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
typename cv::Affine3<T>::Vec3 cv::Affine3<T>::rvec() const
|
||||
{
|
||||
cv::Vec3d w;
|
||||
cv::Matx33d u, vt, R = rotation();
|
||||
cv::SVD::compute(R, w, u, vt, cv::SVD::FULL_UV + cv::SVD::MODIFY_A);
|
||||
R = u * vt;
|
||||
|
||||
double rx = R.val[7] - R.val[5];
|
||||
double ry = R.val[2] - R.val[6];
|
||||
double rz = R.val[3] - R.val[1];
|
||||
|
||||
double s = std::sqrt((rx*rx + ry*ry + rz*rz)*0.25);
|
||||
double c = (R.val[0] + R.val[4] + R.val[8] - 1) * 0.5;
|
||||
c = c > 1.0 ? 1.0 : c < -1.0 ? -1.0 : c;
|
||||
double theta = acos(c);
|
||||
|
||||
if( s < 1e-5 )
|
||||
{
|
||||
if( c > 0 )
|
||||
rx = ry = rz = 0;
|
||||
else
|
||||
{
|
||||
double t;
|
||||
t = (R.val[0] + 1) * 0.5;
|
||||
rx = std::sqrt(std::max(t, 0.0));
|
||||
t = (R.val[4] + 1) * 0.5;
|
||||
ry = std::sqrt(std::max(t, 0.0)) * (R.val[1] < 0 ? -1.0 : 1.0);
|
||||
t = (R.val[8] + 1) * 0.5;
|
||||
rz = std::sqrt(std::max(t, 0.0)) * (R.val[2] < 0 ? -1.0 : 1.0);
|
||||
|
||||
if( fabs(rx) < fabs(ry) && fabs(rx) < fabs(rz) && (R.val[5] > 0) != (ry*rz > 0) )
|
||||
rz = -rz;
|
||||
theta /= std::sqrt(rx*rx + ry*ry + rz*rz);
|
||||
rx *= theta;
|
||||
ry *= theta;
|
||||
rz *= theta;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
double vth = 1/(2*s);
|
||||
vth *= theta;
|
||||
rx *= vth; ry *= vth; rz *= vth;
|
||||
}
|
||||
|
||||
return cv::Vec3d(rx, ry, rz);
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T> cv::Affine3<T>::inv(int method) const
|
||||
{
|
||||
return matrix.inv(method);
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T> cv::Affine3<T>::rotate(const Mat3& R) const
|
||||
{
|
||||
Mat3 Lc = linear();
|
||||
Vec3 tc = translation();
|
||||
Mat4 result;
|
||||
result.val[12] = result.val[13] = result.val[14] = 0;
|
||||
result.val[15] = 1;
|
||||
|
||||
for(int j = 0; j < 3; ++j)
|
||||
{
|
||||
for(int i = 0; i < 3; ++i)
|
||||
{
|
||||
float_type value = 0;
|
||||
for(int k = 0; k < 3; ++k)
|
||||
value += R(j, k) * Lc(k, i);
|
||||
result(j, i) = value;
|
||||
}
|
||||
|
||||
result(j, 3) = R.row(j).dot(tc.t());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T> cv::Affine3<T>::rotate(const Vec3& _rvec) const
|
||||
{
|
||||
return rotate(Affine3f(_rvec).rotation());
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T> cv::Affine3<T>::translate(const Vec3& t) const
|
||||
{
|
||||
Mat4 m = matrix;
|
||||
m.val[ 3] += t[0];
|
||||
m.val[ 7] += t[1];
|
||||
m.val[11] += t[2];
|
||||
return m;
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T> cv::Affine3<T>::concatenate(const Affine3<T>& affine) const
|
||||
{
|
||||
return (*this).rotate(affine.rotation()).translate(affine.translation());
|
||||
}
|
||||
|
||||
template<typename T> template <typename Y> inline
|
||||
cv::Affine3<T>::operator Affine3<Y>() const
|
||||
{
|
||||
return Affine3<Y>(matrix);
|
||||
}
|
||||
|
||||
template<typename T> template <typename Y> inline
|
||||
cv::Affine3<Y> cv::Affine3<T>::cast() const
|
||||
{
|
||||
return Affine3<Y>(matrix);
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T> cv::operator*(const cv::Affine3<T>& affine1, const cv::Affine3<T>& affine2)
|
||||
{
|
||||
return affine2.concatenate(affine1);
|
||||
}
|
||||
|
||||
template<typename T, typename V> inline
|
||||
V cv::operator*(const cv::Affine3<T>& affine, const V& v)
|
||||
{
|
||||
const typename Affine3<T>::Mat4& m = affine.matrix;
|
||||
|
||||
V r;
|
||||
r.x = m.val[0] * v.x + m.val[1] * v.y + m.val[ 2] * v.z + m.val[ 3];
|
||||
r.y = m.val[4] * v.x + m.val[5] * v.y + m.val[ 6] * v.z + m.val[ 7];
|
||||
r.z = m.val[8] * v.x + m.val[9] * v.y + m.val[10] * v.z + m.val[11];
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline
|
||||
cv::Vec3f cv::operator*(const cv::Affine3f& affine, const cv::Vec3f& v)
|
||||
{
|
||||
const cv::Matx44f& m = affine.matrix;
|
||||
cv::Vec3f r;
|
||||
r.val[0] = m.val[0] * v[0] + m.val[1] * v[1] + m.val[ 2] * v[2] + m.val[ 3];
|
||||
r.val[1] = m.val[4] * v[0] + m.val[5] * v[1] + m.val[ 6] * v[2] + m.val[ 7];
|
||||
r.val[2] = m.val[8] * v[0] + m.val[9] * v[1] + m.val[10] * v[2] + m.val[11];
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline
|
||||
cv::Vec3d cv::operator*(const cv::Affine3d& affine, const cv::Vec3d& v)
|
||||
{
|
||||
const cv::Matx44d& m = affine.matrix;
|
||||
cv::Vec3d r;
|
||||
r.val[0] = m.val[0] * v[0] + m.val[1] * v[1] + m.val[ 2] * v[2] + m.val[ 3];
|
||||
r.val[1] = m.val[4] * v[0] + m.val[5] * v[1] + m.val[ 6] * v[2] + m.val[ 7];
|
||||
r.val[2] = m.val[8] * v[0] + m.val[9] * v[1] + m.val[10] * v[2] + m.val[11];
|
||||
return r;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T>::Affine3(const Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>& affine)
|
||||
{
|
||||
cv::Mat(4, 4, cv::DataType<T>::type, affine.matrix().data()).copyTo(matrix);
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T>::Affine3(const Eigen::Transform<T, 3, Eigen::Affine>& affine)
|
||||
{
|
||||
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)> a = affine;
|
||||
cv::Mat(4, 4, cv::DataType<T>::type, a.matrix().data()).copyTo(matrix);
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T>::operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>() const
|
||||
{
|
||||
Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)> r;
|
||||
cv::Mat hdr(4, 4, cv::DataType<T>::type, r.matrix().data());
|
||||
cv::Mat(matrix, false).copyTo(hdr);
|
||||
return r;
|
||||
}
|
||||
|
||||
template<typename T> inline
|
||||
cv::Affine3<T>::operator Eigen::Transform<T, 3, Eigen::Affine>() const
|
||||
{
|
||||
return this->operator Eigen::Transform<T, 3, Eigen::Affine, (Eigen::RowMajor)>();
|
||||
}
|
||||
|
||||
#endif /* defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H */
|
||||
|
||||
//! @endcond
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* OPENCV_CORE_AFFINE3_HPP */
|
||||
@@ -0,0 +1,691 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Copyright (C) 2014, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_BASE_HPP
|
||||
#define OPENCV_CORE_BASE_HPP
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error base.hpp header must be compiled as C++
|
||||
#endif
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#include <climits>
|
||||
#include <algorithm>
|
||||
|
||||
#include "opencv2/core/cvdef.h"
|
||||
#include "opencv2/core/cvstd.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
//! @addtogroup core_utils
|
||||
//! @{
|
||||
|
||||
namespace Error {
|
||||
//! error codes
|
||||
enum Code {
|
||||
StsOk= 0, //!< everithing is ok
|
||||
StsBackTrace= -1, //!< pseudo error for back trace
|
||||
StsError= -2, //!< unknown /unspecified error
|
||||
StsInternal= -3, //!< internal error (bad state)
|
||||
StsNoMem= -4, //!< insufficient memory
|
||||
StsBadArg= -5, //!< function arg/param is bad
|
||||
StsBadFunc= -6, //!< unsupported function
|
||||
StsNoConv= -7, //!< iter. didn't converge
|
||||
StsAutoTrace= -8, //!< tracing
|
||||
HeaderIsNull= -9, //!< image header is NULL
|
||||
BadImageSize= -10, //!< image size is invalid
|
||||
BadOffset= -11, //!< offset is invalid
|
||||
BadDataPtr= -12, //!<
|
||||
BadStep= -13, //!<
|
||||
BadModelOrChSeq= -14, //!<
|
||||
BadNumChannels= -15, //!<
|
||||
BadNumChannel1U= -16, //!<
|
||||
BadDepth= -17, //!<
|
||||
BadAlphaChannel= -18, //!<
|
||||
BadOrder= -19, //!<
|
||||
BadOrigin= -20, //!<
|
||||
BadAlign= -21, //!<
|
||||
BadCallBack= -22, //!<
|
||||
BadTileSize= -23, //!<
|
||||
BadCOI= -24, //!<
|
||||
BadROISize= -25, //!<
|
||||
MaskIsTiled= -26, //!<
|
||||
StsNullPtr= -27, //!< null pointer
|
||||
StsVecLengthErr= -28, //!< incorrect vector length
|
||||
StsFilterStructContentErr= -29, //!< incorr. filter structure content
|
||||
StsKernelStructContentErr= -30, //!< incorr. transform kernel content
|
||||
StsFilterOffsetErr= -31, //!< incorrect filter ofset value
|
||||
StsBadSize= -201, //!< the input/output structure size is incorrect
|
||||
StsDivByZero= -202, //!< division by zero
|
||||
StsInplaceNotSupported= -203, //!< in-place operation is not supported
|
||||
StsObjectNotFound= -204, //!< request can't be completed
|
||||
StsUnmatchedFormats= -205, //!< formats of input/output arrays differ
|
||||
StsBadFlag= -206, //!< flag is wrong or not supported
|
||||
StsBadPoint= -207, //!< bad CvPoint
|
||||
StsBadMask= -208, //!< bad format of mask (neither 8uC1 nor 8sC1)
|
||||
StsUnmatchedSizes= -209, //!< sizes of input/output structures do not match
|
||||
StsUnsupportedFormat= -210, //!< the data format/type is not supported by the function
|
||||
StsOutOfRange= -211, //!< some of parameters are out of range
|
||||
StsParseError= -212, //!< invalid syntax/structure of the parsed file
|
||||
StsNotImplemented= -213, //!< the requested function/feature is not implemented
|
||||
StsBadMemBlock= -214, //!< an allocated block has been corrupted
|
||||
StsAssert= -215, //!< assertion failed
|
||||
GpuNotSupported= -216,
|
||||
GpuApiCallError= -217,
|
||||
OpenGlNotSupported= -218,
|
||||
OpenGlApiCallError= -219,
|
||||
OpenCLApiCallError= -220,
|
||||
OpenCLDoubleNotSupported= -221,
|
||||
OpenCLInitError= -222,
|
||||
OpenCLNoAMDBlasFft= -223
|
||||
};
|
||||
} //Error
|
||||
|
||||
//! @} core_utils
|
||||
|
||||
//! @addtogroup core_array
|
||||
//! @{
|
||||
|
||||
//! matrix decomposition types
|
||||
enum DecompTypes {
|
||||
/** Gaussian elimination with the optimal pivot element chosen. */
|
||||
DECOMP_LU = 0,
|
||||
/** singular value decomposition (SVD) method; the system can be over-defined and/or the matrix
|
||||
src1 can be singular */
|
||||
DECOMP_SVD = 1,
|
||||
/** eigenvalue decomposition; the matrix src1 must be symmetrical */
|
||||
DECOMP_EIG = 2,
|
||||
/** Cholesky \f$LL^T\f$ factorization; the matrix src1 must be symmetrical and positively
|
||||
defined */
|
||||
DECOMP_CHOLESKY = 3,
|
||||
/** QR factorization; the system can be over-defined and/or the matrix src1 can be singular */
|
||||
DECOMP_QR = 4,
|
||||
/** while all the previous flags are mutually exclusive, this flag can be used together with
|
||||
any of the previous; it means that the normal equations
|
||||
\f$\texttt{src1}^T\cdot\texttt{src1}\cdot\texttt{dst}=\texttt{src1}^T\texttt{src2}\f$ are
|
||||
solved instead of the original system
|
||||
\f$\texttt{src1}\cdot\texttt{dst}=\texttt{src2}\f$ */
|
||||
DECOMP_NORMAL = 16
|
||||
};
|
||||
|
||||
/** norm types
|
||||
- For one array:
|
||||
\f[norm = \forkthree{\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
|
||||
{ \| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) }
|
||||
{ \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\f]
|
||||
|
||||
- Absolute norm for two arrays
|
||||
\f[norm = \forkthree{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} = \max _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
|
||||
{ \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) }
|
||||
{ \| \texttt{src1} - \texttt{src2} \| _{L_2} = \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\f]
|
||||
|
||||
- Relative norm for two arrays
|
||||
\f[norm = \forkthree{\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE_INF}\) }
|
||||
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE_L1}\) }
|
||||
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE_L2}\) }\f]
|
||||
|
||||
As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$.
|
||||
The \f$ L_{1}, L_{2} \f$ and \f$ L_{\infty} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$
|
||||
is calculated as follows
|
||||
\f{align*}
|
||||
\| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\
|
||||
\| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\
|
||||
\| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2
|
||||
\f}
|
||||
and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is
|
||||
\f{align*}
|
||||
\| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\
|
||||
\| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\
|
||||
\| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5.
|
||||
\f}
|
||||
The following graphic shows all values for the three norm functions \f$\| r(x) \|_{L_1}, \| r(x) \|_{L_2}\f$ and \f$\| r(x) \|_{L_\infty}\f$.
|
||||
It is notable that the \f$ L_{1} \f$ norm forms the upper and the \f$ L_{\infty} \f$ norm forms the lower border for the example function \f$ r(x) \f$.
|
||||

|
||||
*/
|
||||
enum NormTypes { NORM_INF = 1,
|
||||
NORM_L1 = 2,
|
||||
NORM_L2 = 4,
|
||||
NORM_L2SQR = 5,
|
||||
NORM_HAMMING = 6,
|
||||
NORM_HAMMING2 = 7,
|
||||
NORM_TYPE_MASK = 7,
|
||||
NORM_RELATIVE = 8, //!< flag
|
||||
NORM_MINMAX = 32 //!< flag
|
||||
};
|
||||
|
||||
//! comparison types
|
||||
enum CmpTypes { CMP_EQ = 0, //!< src1 is equal to src2.
|
||||
CMP_GT = 1, //!< src1 is greater than src2.
|
||||
CMP_GE = 2, //!< src1 is greater than or equal to src2.
|
||||
CMP_LT = 3, //!< src1 is less than src2.
|
||||
CMP_LE = 4, //!< src1 is less than or equal to src2.
|
||||
CMP_NE = 5 //!< src1 is unequal to src2.
|
||||
};
|
||||
|
||||
//! generalized matrix multiplication flags
|
||||
enum GemmFlags { GEMM_1_T = 1, //!< transposes src1
|
||||
GEMM_2_T = 2, //!< transposes src2
|
||||
GEMM_3_T = 4 //!< transposes src3
|
||||
};
|
||||
|
||||
enum DftFlags {
|
||||
/** performs an inverse 1D or 2D transform instead of the default forward
|
||||
transform. */
|
||||
DFT_INVERSE = 1,
|
||||
/** scales the result: divide it by the number of array elements. Normally, it is
|
||||
combined with DFT_INVERSE. */
|
||||
DFT_SCALE = 2,
|
||||
/** performs a forward or inverse transform of every individual row of the input
|
||||
matrix; this flag enables you to transform multiple vectors simultaneously and can be used to
|
||||
decrease the overhead (which is sometimes several times larger than the processing itself) to
|
||||
perform 3D and higher-dimensional transformations and so forth.*/
|
||||
DFT_ROWS = 4,
|
||||
/** performs a forward transformation of 1D or 2D real array; the result,
|
||||
though being a complex array, has complex-conjugate symmetry (*CCS*, see the function
|
||||
description below for details), and such an array can be packed into a real array of the same
|
||||
size as input, which is the fastest option and which is what the function does by default;
|
||||
however, you may wish to get a full complex array (for simpler spectrum analysis, and so on) -
|
||||
pass the flag to enable the function to produce a full-size complex output array. */
|
||||
DFT_COMPLEX_OUTPUT = 16,
|
||||
/** performs an inverse transformation of a 1D or 2D complex array; the
|
||||
result is normally a complex array of the same size, however, if the input array has
|
||||
conjugate-complex symmetry (for example, it is a result of forward transformation with
|
||||
DFT_COMPLEX_OUTPUT flag), the output is a real array; while the function itself does not
|
||||
check whether the input is symmetrical or not, you can pass the flag and then the function
|
||||
will assume the symmetry and produce the real output array (note that when the input is packed
|
||||
into a real array and inverse transformation is executed, the function treats the input as a
|
||||
packed complex-conjugate symmetrical array, and the output will also be a real array). */
|
||||
DFT_REAL_OUTPUT = 32,
|
||||
/** performs an inverse 1D or 2D transform instead of the default forward transform. */
|
||||
DCT_INVERSE = DFT_INVERSE,
|
||||
/** performs a forward or inverse transform of every individual row of the input
|
||||
matrix. This flag enables you to transform multiple vectors simultaneously and can be used to
|
||||
decrease the overhead (which is sometimes several times larger than the processing itself) to
|
||||
perform 3D and higher-dimensional transforms and so forth.*/
|
||||
DCT_ROWS = DFT_ROWS
|
||||
};
|
||||
|
||||
//! Various border types, image boundaries are denoted with `|`
|
||||
//! @see borderInterpolate, copyMakeBorder
|
||||
enum BorderTypes {
|
||||
BORDER_CONSTANT = 0, //!< `iiiiii|abcdefgh|iiiiiii` with some specified `i`
|
||||
BORDER_REPLICATE = 1, //!< `aaaaaa|abcdefgh|hhhhhhh`
|
||||
BORDER_REFLECT = 2, //!< `fedcba|abcdefgh|hgfedcb`
|
||||
BORDER_WRAP = 3, //!< `cdefgh|abcdefgh|abcdefg`
|
||||
BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba`
|
||||
BORDER_TRANSPARENT = 5, //!< `uvwxyz|absdefgh|ijklmno`
|
||||
|
||||
BORDER_REFLECT101 = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
|
||||
BORDER_DEFAULT = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
|
||||
BORDER_ISOLATED = 16 //!< do not look outside of ROI
|
||||
};
|
||||
|
||||
//! @} core_array
|
||||
|
||||
//! @addtogroup core_utils
|
||||
//! @{
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
//////////////// static assert /////////////////
|
||||
#define CVAUX_CONCAT_EXP(a, b) a##b
|
||||
#define CVAUX_CONCAT(a, b) CVAUX_CONCAT_EXP(a,b)
|
||||
|
||||
#if defined(__clang__)
|
||||
# ifndef __has_extension
|
||||
# define __has_extension __has_feature /* compatibility, for older versions of clang */
|
||||
# endif
|
||||
# if __has_extension(cxx_static_assert)
|
||||
# define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition)
|
||||
# elif __has_extension(c_static_assert)
|
||||
# define CV_StaticAssert(condition, reason) _Static_assert((condition), reason " " #condition)
|
||||
# endif
|
||||
#elif defined(__GNUC__)
|
||||
# if (defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L)
|
||||
# define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition)
|
||||
# endif
|
||||
#elif defined(_MSC_VER)
|
||||
# if _MSC_VER >= 1600 /* MSVC 10 */
|
||||
# define CV_StaticAssert(condition, reason) static_assert((condition), reason " " #condition)
|
||||
# endif
|
||||
#endif
|
||||
#ifndef CV_StaticAssert
|
||||
# if !defined(__clang__) && defined(__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 302)
|
||||
# define CV_StaticAssert(condition, reason) ({ extern int __attribute__((error("CV_StaticAssert: " reason " " #condition))) CV_StaticAssert(); ((condition) ? 0 : CV_StaticAssert()); })
|
||||
# else
|
||||
template <bool x> struct CV_StaticAssert_failed;
|
||||
template <> struct CV_StaticAssert_failed<true> { enum { val = 1 }; };
|
||||
template<int x> struct CV_StaticAssert_test {};
|
||||
# define CV_StaticAssert(condition, reason)\
|
||||
typedef cv::CV_StaticAssert_test< sizeof(cv::CV_StaticAssert_failed< static_cast<bool>(condition) >) > CVAUX_CONCAT(CV_StaticAssert_failed_at_, __LINE__)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// Suppress warning "-Wdeprecated-declarations" / C4996
|
||||
#if defined(_MSC_VER)
|
||||
#define CV_DO_PRAGMA(x) __pragma(x)
|
||||
#elif defined(__GNUC__)
|
||||
#define CV_DO_PRAGMA(x) _Pragma (#x)
|
||||
#else
|
||||
#define CV_DO_PRAGMA(x)
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define CV_SUPPRESS_DEPRECATED_START \
|
||||
CV_DO_PRAGMA(warning(push)) \
|
||||
CV_DO_PRAGMA(warning(disable: 4996))
|
||||
#define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(warning(pop))
|
||||
#elif defined (__clang__) || ((__GNUC__) && (__GNUC__*100 + __GNUC_MINOR__ > 405))
|
||||
#define CV_SUPPRESS_DEPRECATED_START \
|
||||
CV_DO_PRAGMA(GCC diagnostic push) \
|
||||
CV_DO_PRAGMA(GCC diagnostic ignored "-Wdeprecated-declarations")
|
||||
#define CV_SUPPRESS_DEPRECATED_END CV_DO_PRAGMA(GCC diagnostic pop)
|
||||
#else
|
||||
#define CV_SUPPRESS_DEPRECATED_START
|
||||
#define CV_SUPPRESS_DEPRECATED_END
|
||||
#endif
|
||||
#define CV_UNUSED(name) (void)name
|
||||
//! @endcond
|
||||
|
||||
/*! @brief Signals an error and raises the exception.
|
||||
|
||||
By default the function prints information about the error to stderr,
|
||||
then it either stops if setBreakOnError() had been called before or raises the exception.
|
||||
It is possible to alternate error processing by using redirectError().
|
||||
@param _code - error code (Error::Code)
|
||||
@param _err - error description
|
||||
@param _func - function name. Available only when the compiler supports getting it
|
||||
@param _file - source file name where the error has occured
|
||||
@param _line - line number in the source file where the error has occured
|
||||
@see CV_Error, CV_Error_, CV_ErrorNoReturn, CV_ErrorNoReturn_, CV_Assert, CV_DbgAssert
|
||||
*/
|
||||
CV_EXPORTS void error(int _code, const String& _err, const char* _func, const char* _file, int _line);
|
||||
|
||||
#ifdef __GNUC__
|
||||
# if defined __clang__ || defined __APPLE__
|
||||
# pragma GCC diagnostic push
|
||||
# pragma GCC diagnostic ignored "-Winvalid-noreturn"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/** same as cv::error, but does not return */
|
||||
CV_INLINE CV_NORETURN void errorNoReturn(int _code, const String& _err, const char* _func, const char* _file, int _line)
|
||||
{
|
||||
error(_code, _err, _func, _file, _line);
|
||||
#ifdef __GNUC__
|
||||
# if !defined __clang__ && !defined __APPLE__
|
||||
// this suppresses this warning: "noreturn" function does return [enabled by default]
|
||||
__builtin_trap();
|
||||
// or use infinite loop: for (;;) {}
|
||||
# endif
|
||||
#endif
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
# if defined __clang__ || defined __APPLE__
|
||||
# pragma GCC diagnostic pop
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined __GNUC__
|
||||
#define CV_Func __func__
|
||||
#elif defined _MSC_VER
|
||||
#define CV_Func __FUNCTION__
|
||||
#else
|
||||
#define CV_Func ""
|
||||
#endif
|
||||
|
||||
/** @brief Call the error handler.
|
||||
|
||||
Currently, the error handler prints the error code and the error message to the standard
|
||||
error stream `stderr`. In the Debug configuration, it then provokes memory access violation, so that
|
||||
the execution stack and all the parameters can be analyzed by the debugger. In the Release
|
||||
configuration, the exception is thrown.
|
||||
|
||||
@param code one of Error::Code
|
||||
@param msg error message
|
||||
*/
|
||||
#define CV_Error( code, msg ) cv::error( code, msg, CV_Func, __FILE__, __LINE__ )
|
||||
|
||||
/** @brief Call the error handler.
|
||||
|
||||
This macro can be used to construct an error message on-fly to include some dynamic information,
|
||||
for example:
|
||||
@code
|
||||
// note the extra parentheses around the formatted text message
|
||||
CV_Error_( CV_StsOutOfRange,
|
||||
("the value at (%d, %d)=%g is out of range", badPt.x, badPt.y, badValue));
|
||||
@endcode
|
||||
@param code one of Error::Code
|
||||
@param args printf-like formatted error message in parentheses
|
||||
*/
|
||||
#define CV_Error_( code, args ) cv::error( code, cv::format args, CV_Func, __FILE__, __LINE__ )
|
||||
|
||||
/** @brief Checks a condition at runtime and throws exception if it fails
|
||||
|
||||
The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. If it is 0, the macros
|
||||
raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release
|
||||
configurations while CV_DbgAssert is only retained in the Debug configuration.
|
||||
*/
|
||||
#define CV_Assert( expr ) if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ )
|
||||
|
||||
/** same as CV_Error(code,msg), but does not return */
|
||||
#define CV_ErrorNoReturn( code, msg ) cv::errorNoReturn( code, msg, CV_Func, __FILE__, __LINE__ )
|
||||
|
||||
/** same as CV_Error_(code,args), but does not return */
|
||||
#define CV_ErrorNoReturn_( code, args ) cv::errorNoReturn( code, cv::format args, CV_Func, __FILE__, __LINE__ )
|
||||
|
||||
/** replaced with CV_Assert(expr) in Debug configuration */
|
||||
#ifdef _DEBUG
|
||||
# define CV_DbgAssert(expr) CV_Assert(expr)
|
||||
#else
|
||||
# define CV_DbgAssert(expr)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor
|
||||
* bit count of A exclusive XOR'ed with B
|
||||
*/
|
||||
struct CV_EXPORTS Hamming
|
||||
{
|
||||
enum { normType = NORM_HAMMING };
|
||||
typedef unsigned char ValueType;
|
||||
typedef int ResultType;
|
||||
|
||||
/** this will count the bits in a ^ b
|
||||
*/
|
||||
ResultType operator()( const unsigned char* a, const unsigned char* b, int size ) const;
|
||||
};
|
||||
|
||||
typedef Hamming HammingLUT;
|
||||
|
||||
/////////////////////////////////// inline norms ////////////////////////////////////
|
||||
|
||||
template<typename _Tp> inline _Tp cv_abs(_Tp x) { return std::abs(x); }
|
||||
inline int cv_abs(uchar x) { return x; }
|
||||
inline int cv_abs(schar x) { return std::abs(x); }
|
||||
inline int cv_abs(ushort x) { return x; }
|
||||
inline int cv_abs(short x) { return std::abs(x); }
|
||||
|
||||
template<typename _Tp, typename _AccTp> static inline
|
||||
_AccTp normL2Sqr(const _Tp* a, int n)
|
||||
{
|
||||
_AccTp s = 0;
|
||||
int i=0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for( ; i <= n - 4; i += 4 )
|
||||
{
|
||||
_AccTp v0 = a[i], v1 = a[i+1], v2 = a[i+2], v3 = a[i+3];
|
||||
s += v0*v0 + v1*v1 + v2*v2 + v3*v3;
|
||||
}
|
||||
#endif
|
||||
for( ; i < n; i++ )
|
||||
{
|
||||
_AccTp v = a[i];
|
||||
s += v*v;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename _Tp, typename _AccTp> static inline
|
||||
_AccTp normL1(const _Tp* a, int n)
|
||||
{
|
||||
_AccTp s = 0;
|
||||
int i = 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; i <= n - 4; i += 4 )
|
||||
{
|
||||
s += (_AccTp)cv_abs(a[i]) + (_AccTp)cv_abs(a[i+1]) +
|
||||
(_AccTp)cv_abs(a[i+2]) + (_AccTp)cv_abs(a[i+3]);
|
||||
}
|
||||
#endif
|
||||
for( ; i < n; i++ )
|
||||
s += cv_abs(a[i]);
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename _Tp, typename _AccTp> static inline
|
||||
_AccTp normInf(const _Tp* a, int n)
|
||||
{
|
||||
_AccTp s = 0;
|
||||
for( int i = 0; i < n; i++ )
|
||||
s = std::max(s, (_AccTp)cv_abs(a[i]));
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename _Tp, typename _AccTp> static inline
|
||||
_AccTp normL2Sqr(const _Tp* a, const _Tp* b, int n)
|
||||
{
|
||||
_AccTp s = 0;
|
||||
int i= 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; i <= n - 4; i += 4 )
|
||||
{
|
||||
_AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]);
|
||||
s += v0*v0 + v1*v1 + v2*v2 + v3*v3;
|
||||
}
|
||||
#endif
|
||||
for( ; i < n; i++ )
|
||||
{
|
||||
_AccTp v = _AccTp(a[i] - b[i]);
|
||||
s += v*v;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static inline float normL2Sqr(const float* a, const float* b, int n)
|
||||
{
|
||||
float s = 0.f;
|
||||
for( int i = 0; i < n; i++ )
|
||||
{
|
||||
float v = a[i] - b[i];
|
||||
s += v*v;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename _Tp, typename _AccTp> static inline
|
||||
_AccTp normL1(const _Tp* a, const _Tp* b, int n)
|
||||
{
|
||||
_AccTp s = 0;
|
||||
int i= 0;
|
||||
#if CV_ENABLE_UNROLLED
|
||||
for(; i <= n - 4; i += 4 )
|
||||
{
|
||||
_AccTp v0 = _AccTp(a[i] - b[i]), v1 = _AccTp(a[i+1] - b[i+1]), v2 = _AccTp(a[i+2] - b[i+2]), v3 = _AccTp(a[i+3] - b[i+3]);
|
||||
s += std::abs(v0) + std::abs(v1) + std::abs(v2) + std::abs(v3);
|
||||
}
|
||||
#endif
|
||||
for( ; i < n; i++ )
|
||||
{
|
||||
_AccTp v = _AccTp(a[i] - b[i]);
|
||||
s += std::abs(v);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
inline float normL1(const float* a, const float* b, int n)
|
||||
{
|
||||
float s = 0.f;
|
||||
for( int i = 0; i < n; i++ )
|
||||
{
|
||||
s += std::abs(a[i] - b[i]);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
inline int normL1(const uchar* a, const uchar* b, int n)
|
||||
{
|
||||
int s = 0;
|
||||
for( int i = 0; i < n; i++ )
|
||||
{
|
||||
s += std::abs(a[i] - b[i]);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
template<typename _Tp, typename _AccTp> static inline
|
||||
_AccTp normInf(const _Tp* a, const _Tp* b, int n)
|
||||
{
|
||||
_AccTp s = 0;
|
||||
for( int i = 0; i < n; i++ )
|
||||
{
|
||||
_AccTp v0 = a[i] - b[i];
|
||||
s = std::max(s, std::abs(v0));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/** @brief Computes the cube root of an argument.
|
||||
|
||||
The function cubeRoot computes \f$\sqrt[3]{\texttt{val}}\f$. Negative arguments are handled correctly.
|
||||
NaN and Inf are not handled. The accuracy approaches the maximum possible accuracy for
|
||||
single-precision data.
|
||||
@param val A function argument.
|
||||
*/
|
||||
CV_EXPORTS_W float cubeRoot(float val);
|
||||
|
||||
/** @brief Calculates the angle of a 2D vector in degrees.
|
||||
|
||||
The function fastAtan2 calculates the full-range angle of an input 2D vector. The angle is measured
|
||||
in degrees and varies from 0 to 360 degrees. The accuracy is about 0.3 degrees.
|
||||
@param x x-coordinate of the vector.
|
||||
@param y y-coordinate of the vector.
|
||||
*/
|
||||
CV_EXPORTS_W float fastAtan2(float y, float x);
|
||||
|
||||
/** proxy for hal::LU */
|
||||
CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n);
|
||||
/** proxy for hal::LU */
|
||||
CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n);
|
||||
/** proxy for hal::Cholesky */
|
||||
CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n);
|
||||
/** proxy for hal::Cholesky */
|
||||
CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n);
|
||||
|
||||
////////////////// forward declarations for important OpenCV types //////////////////
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
template<typename _Tp, int cn> class Vec;
|
||||
template<typename _Tp, int m, int n> class Matx;
|
||||
|
||||
template<typename _Tp> class Complex;
|
||||
template<typename _Tp> class Point_;
|
||||
template<typename _Tp> class Point3_;
|
||||
template<typename _Tp> class Size_;
|
||||
template<typename _Tp> class Rect_;
|
||||
template<typename _Tp> class Scalar_;
|
||||
|
||||
class CV_EXPORTS RotatedRect;
|
||||
class CV_EXPORTS Range;
|
||||
class CV_EXPORTS TermCriteria;
|
||||
class CV_EXPORTS KeyPoint;
|
||||
class CV_EXPORTS DMatch;
|
||||
class CV_EXPORTS RNG;
|
||||
|
||||
class CV_EXPORTS Mat;
|
||||
class CV_EXPORTS MatExpr;
|
||||
|
||||
class CV_EXPORTS UMat;
|
||||
|
||||
class CV_EXPORTS SparseMat;
|
||||
typedef Mat MatND;
|
||||
|
||||
template<typename _Tp> class Mat_;
|
||||
template<typename _Tp> class SparseMat_;
|
||||
|
||||
class CV_EXPORTS MatConstIterator;
|
||||
class CV_EXPORTS SparseMatIterator;
|
||||
class CV_EXPORTS SparseMatConstIterator;
|
||||
template<typename _Tp> class MatIterator_;
|
||||
template<typename _Tp> class MatConstIterator_;
|
||||
template<typename _Tp> class SparseMatIterator_;
|
||||
template<typename _Tp> class SparseMatConstIterator_;
|
||||
|
||||
namespace ogl
|
||||
{
|
||||
class CV_EXPORTS Buffer;
|
||||
class CV_EXPORTS Texture2D;
|
||||
class CV_EXPORTS Arrays;
|
||||
}
|
||||
|
||||
namespace cuda
|
||||
{
|
||||
class CV_EXPORTS GpuMat;
|
||||
class CV_EXPORTS HostMem;
|
||||
class CV_EXPORTS Stream;
|
||||
class CV_EXPORTS Event;
|
||||
}
|
||||
|
||||
namespace cudev
|
||||
{
|
||||
template <typename _Tp> class GpuMat_;
|
||||
}
|
||||
|
||||
namespace ipp
|
||||
{
|
||||
CV_EXPORTS int getIppFeatures();
|
||||
CV_EXPORTS void setIppStatus(int status, const char * const funcname = NULL, const char * const filename = NULL,
|
||||
int line = 0);
|
||||
CV_EXPORTS int getIppStatus();
|
||||
CV_EXPORTS String getIppErrorLocation();
|
||||
CV_EXPORTS bool useIPP();
|
||||
CV_EXPORTS void setUseIPP(bool flag);
|
||||
|
||||
} // ipp
|
||||
|
||||
//! @endcond
|
||||
|
||||
//! @} core_utils
|
||||
|
||||
|
||||
|
||||
|
||||
} // cv
|
||||
|
||||
#include "opencv2/core/neon_utils.hpp"
|
||||
|
||||
#endif //OPENCV_CORE_BASE_HPP
|
||||
@@ -0,0 +1,31 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
//
|
||||
// Copyright (C) 2014, Advanced Micro Devices, Inc., all rights reserved.
|
||||
|
||||
#ifndef OPENCV_CORE_BUFFER_POOL_HPP
|
||||
#define OPENCV_CORE_BUFFER_POOL_HPP
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
//! @addtogroup core
|
||||
//! @{
|
||||
|
||||
class BufferPoolController
|
||||
{
|
||||
protected:
|
||||
~BufferPoolController() { }
|
||||
public:
|
||||
virtual size_t getReservedSize() const = 0;
|
||||
virtual size_t getMaxReservedSize() const = 0;
|
||||
virtual void setMaxReservedSize(size_t size) = 0;
|
||||
virtual void freeAllReservedBuffers() = 0;
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
||||
}
|
||||
|
||||
#endif // OPENCV_CORE_BUFFER_POOL_HPP
|
||||
+6
-4815
File diff suppressed because it is too large
Load Diff
+1856
-557
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,874 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_CUDA_HPP
|
||||
#define OPENCV_CORE_CUDA_HPP
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error cuda.hpp header must be compiled as C++
|
||||
#endif
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/core/cuda_types.hpp"
|
||||
|
||||
/**
|
||||
@defgroup cuda CUDA-accelerated Computer Vision
|
||||
@{
|
||||
@defgroup cudacore Core part
|
||||
@{
|
||||
@defgroup cudacore_init Initalization and Information
|
||||
@defgroup cudacore_struct Data Structures
|
||||
@}
|
||||
@}
|
||||
*/
|
||||
|
||||
namespace cv { namespace cuda {
|
||||
|
||||
//! @addtogroup cudacore_struct
|
||||
//! @{
|
||||
|
||||
//===================================================================================
|
||||
// GpuMat
|
||||
//===================================================================================
|
||||
|
||||
/** @brief Base storage class for GPU memory with reference counting.
|
||||
|
||||
Its interface matches the Mat interface with the following limitations:
|
||||
|
||||
- no arbitrary dimensions support (only 2D)
|
||||
- no functions that return references to their data (because references on GPU are not valid for
|
||||
CPU)
|
||||
- no expression templates technique support
|
||||
|
||||
Beware that the latter limitation may lead to overloaded matrix operators that cause memory
|
||||
allocations. The GpuMat class is convertible to cuda::PtrStepSz and cuda::PtrStep so it can be
|
||||
passed directly to the kernel.
|
||||
|
||||
@note In contrast with Mat, in most cases GpuMat::isContinuous() == false . This means that rows are
|
||||
aligned to a size depending on the hardware. Single-row GpuMat is always a continuous matrix.
|
||||
|
||||
@note You are not recommended to leave static or global GpuMat variables allocated, that is, to rely
|
||||
on its destructor. The destruction order of such variables and CUDA context is undefined. GPU memory
|
||||
release function returns error if the CUDA context has been destroyed before.
|
||||
|
||||
@sa Mat
|
||||
*/
|
||||
class CV_EXPORTS GpuMat
|
||||
{
|
||||
public:
|
||||
class CV_EXPORTS Allocator
|
||||
{
|
||||
public:
|
||||
virtual ~Allocator() {}
|
||||
|
||||
// allocator must fill data, step and refcount fields
|
||||
virtual bool allocate(GpuMat* mat, int rows, int cols, size_t elemSize) = 0;
|
||||
virtual void free(GpuMat* mat) = 0;
|
||||
};
|
||||
|
||||
//! default allocator
|
||||
static Allocator* defaultAllocator();
|
||||
static void setDefaultAllocator(Allocator* allocator);
|
||||
|
||||
//! default constructor
|
||||
explicit GpuMat(Allocator* allocator = defaultAllocator());
|
||||
|
||||
//! constructs GpuMat of the specified size and type
|
||||
GpuMat(int rows, int cols, int type, Allocator* allocator = defaultAllocator());
|
||||
GpuMat(Size size, int type, Allocator* allocator = defaultAllocator());
|
||||
|
||||
//! constucts GpuMat and fills it with the specified value _s
|
||||
GpuMat(int rows, int cols, int type, Scalar s, Allocator* allocator = defaultAllocator());
|
||||
GpuMat(Size size, int type, Scalar s, Allocator* allocator = defaultAllocator());
|
||||
|
||||
//! copy constructor
|
||||
GpuMat(const GpuMat& m);
|
||||
|
||||
//! constructor for GpuMat headers pointing to user-allocated data
|
||||
GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP);
|
||||
GpuMat(Size size, int type, void* data, size_t step = Mat::AUTO_STEP);
|
||||
|
||||
//! creates a GpuMat header for a part of the bigger matrix
|
||||
GpuMat(const GpuMat& m, Range rowRange, Range colRange);
|
||||
GpuMat(const GpuMat& m, Rect roi);
|
||||
|
||||
//! builds GpuMat from host memory (Blocking call)
|
||||
explicit GpuMat(InputArray arr, Allocator* allocator = defaultAllocator());
|
||||
|
||||
//! destructor - calls release()
|
||||
~GpuMat();
|
||||
|
||||
//! assignment operators
|
||||
GpuMat& operator =(const GpuMat& m);
|
||||
|
||||
//! allocates new GpuMat data unless the GpuMat already has specified size and type
|
||||
void create(int rows, int cols, int type);
|
||||
void create(Size size, int type);
|
||||
|
||||
//! decreases reference counter, deallocate the data when reference counter reaches 0
|
||||
void release();
|
||||
|
||||
//! swaps with other smart pointer
|
||||
void swap(GpuMat& mat);
|
||||
|
||||
//! pefroms upload data to GpuMat (Blocking call)
|
||||
void upload(InputArray arr);
|
||||
|
||||
//! pefroms upload data to GpuMat (Non-Blocking call)
|
||||
void upload(InputArray arr, Stream& stream);
|
||||
|
||||
//! pefroms download data from device to host memory (Blocking call)
|
||||
void download(OutputArray dst) const;
|
||||
|
||||
//! pefroms download data from device to host memory (Non-Blocking call)
|
||||
void download(OutputArray dst, Stream& stream) const;
|
||||
|
||||
//! returns deep copy of the GpuMat, i.e. the data is copied
|
||||
GpuMat clone() const;
|
||||
|
||||
//! copies the GpuMat content to device memory (Blocking call)
|
||||
void copyTo(OutputArray dst) const;
|
||||
|
||||
//! copies the GpuMat content to device memory (Non-Blocking call)
|
||||
void copyTo(OutputArray dst, Stream& stream) const;
|
||||
|
||||
//! copies those GpuMat elements to "m" that are marked with non-zero mask elements (Blocking call)
|
||||
void copyTo(OutputArray dst, InputArray mask) const;
|
||||
|
||||
//! copies those GpuMat elements to "m" that are marked with non-zero mask elements (Non-Blocking call)
|
||||
void copyTo(OutputArray dst, InputArray mask, Stream& stream) const;
|
||||
|
||||
//! sets some of the GpuMat elements to s (Blocking call)
|
||||
GpuMat& setTo(Scalar s);
|
||||
|
||||
//! sets some of the GpuMat elements to s (Non-Blocking call)
|
||||
GpuMat& setTo(Scalar s, Stream& stream);
|
||||
|
||||
//! sets some of the GpuMat elements to s, according to the mask (Blocking call)
|
||||
GpuMat& setTo(Scalar s, InputArray mask);
|
||||
|
||||
//! sets some of the GpuMat elements to s, according to the mask (Non-Blocking call)
|
||||
GpuMat& setTo(Scalar s, InputArray mask, Stream& stream);
|
||||
|
||||
//! converts GpuMat to another datatype (Blocking call)
|
||||
void convertTo(OutputArray dst, int rtype) const;
|
||||
|
||||
//! converts GpuMat to another datatype (Non-Blocking call)
|
||||
void convertTo(OutputArray dst, int rtype, Stream& stream) const;
|
||||
|
||||
//! converts GpuMat to another datatype with scaling (Blocking call)
|
||||
void convertTo(OutputArray dst, int rtype, double alpha, double beta = 0.0) const;
|
||||
|
||||
//! converts GpuMat to another datatype with scaling (Non-Blocking call)
|
||||
void convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const;
|
||||
|
||||
//! converts GpuMat to another datatype with scaling (Non-Blocking call)
|
||||
void convertTo(OutputArray dst, int rtype, double alpha, double beta, Stream& stream) const;
|
||||
|
||||
void assignTo(GpuMat& m, int type=-1) const;
|
||||
|
||||
//! returns pointer to y-th row
|
||||
uchar* ptr(int y = 0);
|
||||
const uchar* ptr(int y = 0) const;
|
||||
|
||||
//! template version of the above method
|
||||
template<typename _Tp> _Tp* ptr(int y = 0);
|
||||
template<typename _Tp> const _Tp* ptr(int y = 0) const;
|
||||
|
||||
template <typename _Tp> operator PtrStepSz<_Tp>() const;
|
||||
template <typename _Tp> operator PtrStep<_Tp>() const;
|
||||
|
||||
//! returns a new GpuMat header for the specified row
|
||||
GpuMat row(int y) const;
|
||||
|
||||
//! returns a new GpuMat header for the specified column
|
||||
GpuMat col(int x) const;
|
||||
|
||||
//! ... for the specified row span
|
||||
GpuMat rowRange(int startrow, int endrow) const;
|
||||
GpuMat rowRange(Range r) const;
|
||||
|
||||
//! ... for the specified column span
|
||||
GpuMat colRange(int startcol, int endcol) const;
|
||||
GpuMat colRange(Range r) const;
|
||||
|
||||
//! extracts a rectangular sub-GpuMat (this is a generalized form of row, rowRange etc.)
|
||||
GpuMat operator ()(Range rowRange, Range colRange) const;
|
||||
GpuMat operator ()(Rect roi) const;
|
||||
|
||||
//! creates alternative GpuMat header for the same data, with different
|
||||
//! number of channels and/or different number of rows
|
||||
GpuMat reshape(int cn, int rows = 0) const;
|
||||
|
||||
//! locates GpuMat header within a parent GpuMat
|
||||
void locateROI(Size& wholeSize, Point& ofs) const;
|
||||
|
||||
//! moves/resizes the current GpuMat ROI inside the parent GpuMat
|
||||
GpuMat& adjustROI(int dtop, int dbottom, int dleft, int dright);
|
||||
|
||||
//! returns true iff the GpuMat data is continuous
|
||||
//! (i.e. when there are no gaps between successive rows)
|
||||
bool isContinuous() const;
|
||||
|
||||
//! returns element size in bytes
|
||||
size_t elemSize() const;
|
||||
|
||||
//! returns the size of element channel in bytes
|
||||
size_t elemSize1() const;
|
||||
|
||||
//! returns element type
|
||||
int type() const;
|
||||
|
||||
//! returns element type
|
||||
int depth() const;
|
||||
|
||||
//! returns number of channels
|
||||
int channels() const;
|
||||
|
||||
//! returns step/elemSize1()
|
||||
size_t step1() const;
|
||||
|
||||
//! returns GpuMat size : width == number of columns, height == number of rows
|
||||
Size size() const;
|
||||
|
||||
//! returns true if GpuMat data is NULL
|
||||
bool empty() const;
|
||||
|
||||
/*! includes several bit-fields:
|
||||
- the magic signature
|
||||
- continuity flag
|
||||
- depth
|
||||
- number of channels
|
||||
*/
|
||||
int flags;
|
||||
|
||||
//! the number of rows and columns
|
||||
int rows, cols;
|
||||
|
||||
//! a distance between successive rows in bytes; includes the gap if any
|
||||
size_t step;
|
||||
|
||||
//! pointer to the data
|
||||
uchar* data;
|
||||
|
||||
//! pointer to the reference counter;
|
||||
//! when GpuMat points to user-allocated data, the pointer is NULL
|
||||
int* refcount;
|
||||
|
||||
//! helper fields used in locateROI and adjustROI
|
||||
uchar* datastart;
|
||||
const uchar* dataend;
|
||||
|
||||
//! allocator
|
||||
Allocator* allocator;
|
||||
};
|
||||
|
||||
/** @brief Creates a continuous matrix.
|
||||
|
||||
@param rows Row count.
|
||||
@param cols Column count.
|
||||
@param type Type of the matrix.
|
||||
@param arr Destination matrix. This parameter changes only if it has a proper type and area (
|
||||
\f$\texttt{rows} \times \texttt{cols}\f$ ).
|
||||
|
||||
Matrix is called continuous if its elements are stored continuously, that is, without gaps at the
|
||||
end of each row.
|
||||
*/
|
||||
CV_EXPORTS void createContinuous(int rows, int cols, int type, OutputArray arr);
|
||||
|
||||
/** @brief Ensures that the size of a matrix is big enough and the matrix has a proper type.
|
||||
|
||||
@param rows Minimum desired number of rows.
|
||||
@param cols Minimum desired number of columns.
|
||||
@param type Desired matrix type.
|
||||
@param arr Destination matrix.
|
||||
|
||||
The function does not reallocate memory if the matrix has proper attributes already.
|
||||
*/
|
||||
CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, OutputArray arr);
|
||||
|
||||
//! BufferPool management (must be called before Stream creation)
|
||||
CV_EXPORTS void setBufferPoolUsage(bool on);
|
||||
CV_EXPORTS void setBufferPoolConfig(int deviceId, size_t stackSize, int stackCount);
|
||||
|
||||
//===================================================================================
|
||||
// HostMem
|
||||
//===================================================================================
|
||||
|
||||
/** @brief Class with reference counting wrapping special memory type allocation functions from CUDA.
|
||||
|
||||
Its interface is also Mat-like but with additional memory type parameters.
|
||||
|
||||
- **PAGE_LOCKED** sets a page locked memory type used commonly for fast and asynchronous
|
||||
uploading/downloading data from/to GPU.
|
||||
- **SHARED** specifies a zero copy memory allocation that enables mapping the host memory to GPU
|
||||
address space, if supported.
|
||||
- **WRITE_COMBINED** sets the write combined buffer that is not cached by CPU. Such buffers are
|
||||
used to supply GPU with data when GPU only reads it. The advantage is a better CPU cache
|
||||
utilization.
|
||||
|
||||
@note Allocation size of such memory types is usually limited. For more details, see *CUDA 2.2
|
||||
Pinned Memory APIs* document or *CUDA C Programming Guide*.
|
||||
*/
|
||||
class CV_EXPORTS HostMem
|
||||
{
|
||||
public:
|
||||
enum AllocType { PAGE_LOCKED = 1, SHARED = 2, WRITE_COMBINED = 4 };
|
||||
|
||||
static MatAllocator* getAllocator(AllocType alloc_type = PAGE_LOCKED);
|
||||
|
||||
explicit HostMem(AllocType alloc_type = PAGE_LOCKED);
|
||||
|
||||
HostMem(const HostMem& m);
|
||||
|
||||
HostMem(int rows, int cols, int type, AllocType alloc_type = PAGE_LOCKED);
|
||||
HostMem(Size size, int type, AllocType alloc_type = PAGE_LOCKED);
|
||||
|
||||
//! creates from host memory with coping data
|
||||
explicit HostMem(InputArray arr, AllocType alloc_type = PAGE_LOCKED);
|
||||
|
||||
~HostMem();
|
||||
|
||||
HostMem& operator =(const HostMem& m);
|
||||
|
||||
//! swaps with other smart pointer
|
||||
void swap(HostMem& b);
|
||||
|
||||
//! returns deep copy of the matrix, i.e. the data is copied
|
||||
HostMem clone() const;
|
||||
|
||||
//! allocates new matrix data unless the matrix already has specified size and type.
|
||||
void create(int rows, int cols, int type);
|
||||
void create(Size size, int type);
|
||||
|
||||
//! creates alternative HostMem header for the same data, with different
|
||||
//! number of channels and/or different number of rows
|
||||
HostMem reshape(int cn, int rows = 0) const;
|
||||
|
||||
//! decrements reference counter and released memory if needed.
|
||||
void release();
|
||||
|
||||
//! returns matrix header with disabled reference counting for HostMem data.
|
||||
Mat createMatHeader() const;
|
||||
|
||||
/** @brief Maps CPU memory to GPU address space and creates the cuda::GpuMat header without reference counting
|
||||
for it.
|
||||
|
||||
This can be done only if memory was allocated with the SHARED flag and if it is supported by the
|
||||
hardware. Laptops often share video and CPU memory, so address spaces can be mapped, which
|
||||
eliminates an extra copy.
|
||||
*/
|
||||
GpuMat createGpuMatHeader() const;
|
||||
|
||||
// Please see cv::Mat for descriptions
|
||||
bool isContinuous() const;
|
||||
size_t elemSize() const;
|
||||
size_t elemSize1() const;
|
||||
int type() const;
|
||||
int depth() const;
|
||||
int channels() const;
|
||||
size_t step1() const;
|
||||
Size size() const;
|
||||
bool empty() const;
|
||||
|
||||
// Please see cv::Mat for descriptions
|
||||
int flags;
|
||||
int rows, cols;
|
||||
size_t step;
|
||||
|
||||
uchar* data;
|
||||
int* refcount;
|
||||
|
||||
uchar* datastart;
|
||||
const uchar* dataend;
|
||||
|
||||
AllocType alloc_type;
|
||||
};
|
||||
|
||||
/** @brief Page-locks the memory of matrix and maps it for the device(s).
|
||||
|
||||
@param m Input matrix.
|
||||
*/
|
||||
CV_EXPORTS void registerPageLocked(Mat& m);
|
||||
|
||||
/** @brief Unmaps the memory of matrix and makes it pageable again.
|
||||
|
||||
@param m Input matrix.
|
||||
*/
|
||||
CV_EXPORTS void unregisterPageLocked(Mat& m);
|
||||
|
||||
//===================================================================================
|
||||
// Stream
|
||||
//===================================================================================
|
||||
|
||||
/** @brief This class encapsulates a queue of asynchronous calls.
|
||||
|
||||
@note Currently, you may face problems if an operation is enqueued twice with different data. Some
|
||||
functions use the constant GPU memory, and next call may update the memory before the previous one
|
||||
has been finished. But calling different operations asynchronously is safe because each operation
|
||||
has its own constant buffer. Memory copy/upload/download/set operations to the buffers you hold are
|
||||
also safe.
|
||||
|
||||
@note The Stream class is not thread-safe. Please use different Stream objects for different CPU threads.
|
||||
|
||||
@code
|
||||
void thread1()
|
||||
{
|
||||
cv::cuda::Stream stream1;
|
||||
cv::cuda::func1(..., stream1);
|
||||
}
|
||||
|
||||
void thread2()
|
||||
{
|
||||
cv::cuda::Stream stream2;
|
||||
cv::cuda::func2(..., stream2);
|
||||
}
|
||||
@endcode
|
||||
|
||||
@note By default all CUDA routines are launched in Stream::Null() object, if the stream is not specified by user.
|
||||
In multi-threading environment the stream objects must be passed explicitly (see previous note).
|
||||
*/
|
||||
class CV_EXPORTS Stream
|
||||
{
|
||||
typedef void (Stream::*bool_type)() const;
|
||||
void this_type_does_not_support_comparisons() const {}
|
||||
|
||||
public:
|
||||
typedef void (*StreamCallback)(int status, void* userData);
|
||||
|
||||
//! creates a new asynchronous stream
|
||||
Stream();
|
||||
|
||||
/** @brief Returns true if the current stream queue is finished. Otherwise, it returns false.
|
||||
*/
|
||||
bool queryIfComplete() const;
|
||||
|
||||
/** @brief Blocks the current CPU thread until all operations in the stream are complete.
|
||||
*/
|
||||
void waitForCompletion();
|
||||
|
||||
/** @brief Makes a compute stream wait on an event.
|
||||
*/
|
||||
void waitEvent(const Event& event);
|
||||
|
||||
/** @brief Adds a callback to be called on the host after all currently enqueued items in the stream have
|
||||
completed.
|
||||
|
||||
@note Callbacks must not make any CUDA API calls. Callbacks must not perform any synchronization
|
||||
that may depend on outstanding device work or other callbacks that are not mandated to run earlier.
|
||||
Callbacks without a mandated order (in independent streams) execute in undefined order and may be
|
||||
serialized.
|
||||
*/
|
||||
void enqueueHostCallback(StreamCallback callback, void* userData);
|
||||
|
||||
//! return Stream object for default CUDA stream
|
||||
static Stream& Null();
|
||||
|
||||
//! returns true if stream object is not default (!= 0)
|
||||
operator bool_type() const;
|
||||
|
||||
class Impl;
|
||||
|
||||
private:
|
||||
Ptr<Impl> impl_;
|
||||
Stream(const Ptr<Impl>& impl);
|
||||
|
||||
friend struct StreamAccessor;
|
||||
friend class BufferPool;
|
||||
friend class DefaultDeviceInitializer;
|
||||
};
|
||||
|
||||
class CV_EXPORTS Event
|
||||
{
|
||||
public:
|
||||
enum CreateFlags
|
||||
{
|
||||
DEFAULT = 0x00, /**< Default event flag */
|
||||
BLOCKING_SYNC = 0x01, /**< Event uses blocking synchronization */
|
||||
DISABLE_TIMING = 0x02, /**< Event will not record timing data */
|
||||
INTERPROCESS = 0x04 /**< Event is suitable for interprocess use. DisableTiming must be set */
|
||||
};
|
||||
|
||||
explicit Event(CreateFlags flags = DEFAULT);
|
||||
|
||||
//! records an event
|
||||
void record(Stream& stream = Stream::Null());
|
||||
|
||||
//! queries an event's status
|
||||
bool queryIfComplete() const;
|
||||
|
||||
//! waits for an event to complete
|
||||
void waitForCompletion();
|
||||
|
||||
//! computes the elapsed time between events
|
||||
static float elapsedTime(const Event& start, const Event& end);
|
||||
|
||||
class Impl;
|
||||
|
||||
private:
|
||||
Ptr<Impl> impl_;
|
||||
Event(const Ptr<Impl>& impl);
|
||||
|
||||
friend struct EventAccessor;
|
||||
};
|
||||
|
||||
//! @} cudacore_struct
|
||||
|
||||
//===================================================================================
|
||||
// Initialization & Info
|
||||
//===================================================================================
|
||||
|
||||
//! @addtogroup cudacore_init
|
||||
//! @{
|
||||
|
||||
/** @brief Returns the number of installed CUDA-enabled devices.
|
||||
|
||||
Use this function before any other CUDA functions calls. If OpenCV is compiled without CUDA support,
|
||||
this function returns 0.
|
||||
*/
|
||||
CV_EXPORTS int getCudaEnabledDeviceCount();
|
||||
|
||||
/** @brief Sets a device and initializes it for the current thread.
|
||||
|
||||
@param device System index of a CUDA device starting with 0.
|
||||
|
||||
If the call of this function is omitted, a default device is initialized at the fist CUDA usage.
|
||||
*/
|
||||
CV_EXPORTS void setDevice(int device);
|
||||
|
||||
/** @brief Returns the current device index set by cuda::setDevice or initialized by default.
|
||||
*/
|
||||
CV_EXPORTS int getDevice();
|
||||
|
||||
/** @brief Explicitly destroys and cleans up all resources associated with the current device in the current
|
||||
process.
|
||||
|
||||
Any subsequent API call to this device will reinitialize the device.
|
||||
*/
|
||||
CV_EXPORTS void resetDevice();
|
||||
|
||||
/** @brief Enumeration providing CUDA computing features.
|
||||
*/
|
||||
enum FeatureSet
|
||||
{
|
||||
FEATURE_SET_COMPUTE_10 = 10,
|
||||
FEATURE_SET_COMPUTE_11 = 11,
|
||||
FEATURE_SET_COMPUTE_12 = 12,
|
||||
FEATURE_SET_COMPUTE_13 = 13,
|
||||
FEATURE_SET_COMPUTE_20 = 20,
|
||||
FEATURE_SET_COMPUTE_21 = 21,
|
||||
FEATURE_SET_COMPUTE_30 = 30,
|
||||
FEATURE_SET_COMPUTE_32 = 32,
|
||||
FEATURE_SET_COMPUTE_35 = 35,
|
||||
FEATURE_SET_COMPUTE_50 = 50,
|
||||
|
||||
GLOBAL_ATOMICS = FEATURE_SET_COMPUTE_11,
|
||||
SHARED_ATOMICS = FEATURE_SET_COMPUTE_12,
|
||||
NATIVE_DOUBLE = FEATURE_SET_COMPUTE_13,
|
||||
WARP_SHUFFLE_FUNCTIONS = FEATURE_SET_COMPUTE_30,
|
||||
DYNAMIC_PARALLELISM = FEATURE_SET_COMPUTE_35
|
||||
};
|
||||
|
||||
//! checks whether current device supports the given feature
|
||||
CV_EXPORTS bool deviceSupports(FeatureSet feature_set);
|
||||
|
||||
/** @brief Class providing a set of static methods to check what NVIDIA\* card architecture the CUDA module was
|
||||
built for.
|
||||
|
||||
According to the CUDA C Programming Guide Version 3.2: "PTX code produced for some specific compute
|
||||
capability can always be compiled to binary code of greater or equal compute capability".
|
||||
*/
|
||||
class CV_EXPORTS TargetArchs
|
||||
{
|
||||
public:
|
||||
/** @brief The following method checks whether the module was built with the support of the given feature:
|
||||
|
||||
@param feature_set Features to be checked. See :ocvcuda::FeatureSet.
|
||||
*/
|
||||
static bool builtWith(FeatureSet feature_set);
|
||||
|
||||
/** @brief There is a set of methods to check whether the module contains intermediate (PTX) or binary CUDA
|
||||
code for the given architecture(s):
|
||||
|
||||
@param major Major compute capability version.
|
||||
@param minor Minor compute capability version.
|
||||
*/
|
||||
static bool has(int major, int minor);
|
||||
static bool hasPtx(int major, int minor);
|
||||
static bool hasBin(int major, int minor);
|
||||
|
||||
static bool hasEqualOrLessPtx(int major, int minor);
|
||||
static bool hasEqualOrGreater(int major, int minor);
|
||||
static bool hasEqualOrGreaterPtx(int major, int minor);
|
||||
static bool hasEqualOrGreaterBin(int major, int minor);
|
||||
};
|
||||
|
||||
/** @brief Class providing functionality for querying the specified GPU properties.
|
||||
*/
|
||||
class CV_EXPORTS DeviceInfo
|
||||
{
|
||||
public:
|
||||
//! creates DeviceInfo object for the current GPU
|
||||
DeviceInfo();
|
||||
|
||||
/** @brief The constructors.
|
||||
|
||||
@param device_id System index of the CUDA device starting with 0.
|
||||
|
||||
Constructs the DeviceInfo object for the specified device. If device_id parameter is missed, it
|
||||
constructs an object for the current device.
|
||||
*/
|
||||
DeviceInfo(int device_id);
|
||||
|
||||
/** @brief Returns system index of the CUDA device starting with 0.
|
||||
*/
|
||||
int deviceID() const;
|
||||
|
||||
//! ASCII string identifying device
|
||||
const char* name() const;
|
||||
|
||||
//! global memory available on device in bytes
|
||||
size_t totalGlobalMem() const;
|
||||
|
||||
//! shared memory available per block in bytes
|
||||
size_t sharedMemPerBlock() const;
|
||||
|
||||
//! 32-bit registers available per block
|
||||
int regsPerBlock() const;
|
||||
|
||||
//! warp size in threads
|
||||
int warpSize() const;
|
||||
|
||||
//! maximum pitch in bytes allowed by memory copies
|
||||
size_t memPitch() const;
|
||||
|
||||
//! maximum number of threads per block
|
||||
int maxThreadsPerBlock() const;
|
||||
|
||||
//! maximum size of each dimension of a block
|
||||
Vec3i maxThreadsDim() const;
|
||||
|
||||
//! maximum size of each dimension of a grid
|
||||
Vec3i maxGridSize() const;
|
||||
|
||||
//! clock frequency in kilohertz
|
||||
int clockRate() const;
|
||||
|
||||
//! constant memory available on device in bytes
|
||||
size_t totalConstMem() const;
|
||||
|
||||
//! major compute capability
|
||||
int majorVersion() const;
|
||||
|
||||
//! minor compute capability
|
||||
int minorVersion() const;
|
||||
|
||||
//! alignment requirement for textures
|
||||
size_t textureAlignment() const;
|
||||
|
||||
//! pitch alignment requirement for texture references bound to pitched memory
|
||||
size_t texturePitchAlignment() const;
|
||||
|
||||
//! number of multiprocessors on device
|
||||
int multiProcessorCount() const;
|
||||
|
||||
//! specified whether there is a run time limit on kernels
|
||||
bool kernelExecTimeoutEnabled() const;
|
||||
|
||||
//! device is integrated as opposed to discrete
|
||||
bool integrated() const;
|
||||
|
||||
//! device can map host memory with cudaHostAlloc/cudaHostGetDevicePointer
|
||||
bool canMapHostMemory() const;
|
||||
|
||||
enum ComputeMode
|
||||
{
|
||||
ComputeModeDefault, /**< default compute mode (Multiple threads can use cudaSetDevice with this device) */
|
||||
ComputeModeExclusive, /**< compute-exclusive-thread mode (Only one thread in one process will be able to use cudaSetDevice with this device) */
|
||||
ComputeModeProhibited, /**< compute-prohibited mode (No threads can use cudaSetDevice with this device) */
|
||||
ComputeModeExclusiveProcess /**< compute-exclusive-process mode (Many threads in one process will be able to use cudaSetDevice with this device) */
|
||||
};
|
||||
|
||||
//! compute mode
|
||||
ComputeMode computeMode() const;
|
||||
|
||||
//! maximum 1D texture size
|
||||
int maxTexture1D() const;
|
||||
|
||||
//! maximum 1D mipmapped texture size
|
||||
int maxTexture1DMipmap() const;
|
||||
|
||||
//! maximum size for 1D textures bound to linear memory
|
||||
int maxTexture1DLinear() const;
|
||||
|
||||
//! maximum 2D texture dimensions
|
||||
Vec2i maxTexture2D() const;
|
||||
|
||||
//! maximum 2D mipmapped texture dimensions
|
||||
Vec2i maxTexture2DMipmap() const;
|
||||
|
||||
//! maximum dimensions (width, height, pitch) for 2D textures bound to pitched memory
|
||||
Vec3i maxTexture2DLinear() const;
|
||||
|
||||
//! maximum 2D texture dimensions if texture gather operations have to be performed
|
||||
Vec2i maxTexture2DGather() const;
|
||||
|
||||
//! maximum 3D texture dimensions
|
||||
Vec3i maxTexture3D() const;
|
||||
|
||||
//! maximum Cubemap texture dimensions
|
||||
int maxTextureCubemap() const;
|
||||
|
||||
//! maximum 1D layered texture dimensions
|
||||
Vec2i maxTexture1DLayered() const;
|
||||
|
||||
//! maximum 2D layered texture dimensions
|
||||
Vec3i maxTexture2DLayered() const;
|
||||
|
||||
//! maximum Cubemap layered texture dimensions
|
||||
Vec2i maxTextureCubemapLayered() const;
|
||||
|
||||
//! maximum 1D surface size
|
||||
int maxSurface1D() const;
|
||||
|
||||
//! maximum 2D surface dimensions
|
||||
Vec2i maxSurface2D() const;
|
||||
|
||||
//! maximum 3D surface dimensions
|
||||
Vec3i maxSurface3D() const;
|
||||
|
||||
//! maximum 1D layered surface dimensions
|
||||
Vec2i maxSurface1DLayered() const;
|
||||
|
||||
//! maximum 2D layered surface dimensions
|
||||
Vec3i maxSurface2DLayered() const;
|
||||
|
||||
//! maximum Cubemap surface dimensions
|
||||
int maxSurfaceCubemap() const;
|
||||
|
||||
//! maximum Cubemap layered surface dimensions
|
||||
Vec2i maxSurfaceCubemapLayered() const;
|
||||
|
||||
//! alignment requirements for surfaces
|
||||
size_t surfaceAlignment() const;
|
||||
|
||||
//! device can possibly execute multiple kernels concurrently
|
||||
bool concurrentKernels() const;
|
||||
|
||||
//! device has ECC support enabled
|
||||
bool ECCEnabled() const;
|
||||
|
||||
//! PCI bus ID of the device
|
||||
int pciBusID() const;
|
||||
|
||||
//! PCI device ID of the device
|
||||
int pciDeviceID() const;
|
||||
|
||||
//! PCI domain ID of the device
|
||||
int pciDomainID() const;
|
||||
|
||||
//! true if device is a Tesla device using TCC driver, false otherwise
|
||||
bool tccDriver() const;
|
||||
|
||||
//! number of asynchronous engines
|
||||
int asyncEngineCount() const;
|
||||
|
||||
//! device shares a unified address space with the host
|
||||
bool unifiedAddressing() const;
|
||||
|
||||
//! peak memory clock frequency in kilohertz
|
||||
int memoryClockRate() const;
|
||||
|
||||
//! global memory bus width in bits
|
||||
int memoryBusWidth() const;
|
||||
|
||||
//! size of L2 cache in bytes
|
||||
int l2CacheSize() const;
|
||||
|
||||
//! maximum resident threads per multiprocessor
|
||||
int maxThreadsPerMultiProcessor() const;
|
||||
|
||||
//! gets free and total device memory
|
||||
void queryMemory(size_t& totalMemory, size_t& freeMemory) const;
|
||||
size_t freeMemory() const;
|
||||
size_t totalMemory() const;
|
||||
|
||||
/** @brief Provides information on CUDA feature support.
|
||||
|
||||
@param feature_set Features to be checked. See cuda::FeatureSet.
|
||||
|
||||
This function returns true if the device has the specified CUDA feature. Otherwise, it returns false
|
||||
*/
|
||||
bool supports(FeatureSet feature_set) const;
|
||||
|
||||
/** @brief Checks the CUDA module and device compatibility.
|
||||
|
||||
This function returns true if the CUDA module can be run on the specified device. Otherwise, it
|
||||
returns false .
|
||||
*/
|
||||
bool isCompatible() const;
|
||||
|
||||
private:
|
||||
int device_id_;
|
||||
};
|
||||
|
||||
CV_EXPORTS void printCudaDeviceInfo(int device);
|
||||
CV_EXPORTS void printShortCudaDeviceInfo(int device);
|
||||
|
||||
/** @brief Converts an array to half precision floating number.
|
||||
|
||||
@param _src input array.
|
||||
@param _dst output array.
|
||||
@param stream Stream for the asynchronous version.
|
||||
@sa convertFp16
|
||||
*/
|
||||
CV_EXPORTS void convertFp16(InputArray _src, OutputArray _dst, Stream& stream = Stream::Null());
|
||||
|
||||
//! @} cudacore_init
|
||||
|
||||
}} // namespace cv { namespace cuda {
|
||||
|
||||
|
||||
#include "opencv2/core/cuda.inl.hpp"
|
||||
|
||||
#endif /* OPENCV_CORE_CUDA_HPP */
|
||||
@@ -0,0 +1,631 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_CUDAINL_HPP
|
||||
#define OPENCV_CORE_CUDAINL_HPP
|
||||
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
namespace cv { namespace cuda {
|
||||
|
||||
//===================================================================================
|
||||
// GpuMat
|
||||
//===================================================================================
|
||||
|
||||
inline
|
||||
GpuMat::GpuMat(Allocator* allocator_)
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
|
||||
{}
|
||||
|
||||
inline
|
||||
GpuMat::GpuMat(int rows_, int cols_, int type_, Allocator* allocator_)
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
|
||||
{
|
||||
if (rows_ > 0 && cols_ > 0)
|
||||
create(rows_, cols_, type_);
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat::GpuMat(Size size_, int type_, Allocator* allocator_)
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
|
||||
{
|
||||
if (size_.height > 0 && size_.width > 0)
|
||||
create(size_.height, size_.width, type_);
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat::GpuMat(int rows_, int cols_, int type_, Scalar s_, Allocator* allocator_)
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
|
||||
{
|
||||
if (rows_ > 0 && cols_ > 0)
|
||||
{
|
||||
create(rows_, cols_, type_);
|
||||
setTo(s_);
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat::GpuMat(Size size_, int type_, Scalar s_, Allocator* allocator_)
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
|
||||
{
|
||||
if (size_.height > 0 && size_.width > 0)
|
||||
{
|
||||
create(size_.height, size_.width, type_);
|
||||
setTo(s_);
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat::GpuMat(const GpuMat& m)
|
||||
: flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data), refcount(m.refcount), datastart(m.datastart), dataend(m.dataend), allocator(m.allocator)
|
||||
{
|
||||
if (refcount)
|
||||
CV_XADD(refcount, 1);
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat::GpuMat(InputArray arr, Allocator* allocator_) :
|
||||
flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), allocator(allocator_)
|
||||
{
|
||||
upload(arr);
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat::~GpuMat()
|
||||
{
|
||||
release();
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat& GpuMat::operator =(const GpuMat& m)
|
||||
{
|
||||
if (this != &m)
|
||||
{
|
||||
GpuMat temp(m);
|
||||
swap(temp);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
void GpuMat::create(Size size_, int type_)
|
||||
{
|
||||
create(size_.height, size_.width, type_);
|
||||
}
|
||||
|
||||
inline
|
||||
void GpuMat::swap(GpuMat& b)
|
||||
{
|
||||
std::swap(flags, b.flags);
|
||||
std::swap(rows, b.rows);
|
||||
std::swap(cols, b.cols);
|
||||
std::swap(step, b.step);
|
||||
std::swap(data, b.data);
|
||||
std::swap(datastart, b.datastart);
|
||||
std::swap(dataend, b.dataend);
|
||||
std::swap(refcount, b.refcount);
|
||||
std::swap(allocator, b.allocator);
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat GpuMat::clone() const
|
||||
{
|
||||
GpuMat m;
|
||||
copyTo(m);
|
||||
return m;
|
||||
}
|
||||
|
||||
inline
|
||||
void GpuMat::copyTo(OutputArray dst, InputArray mask) const
|
||||
{
|
||||
copyTo(dst, mask, Stream::Null());
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat& GpuMat::setTo(Scalar s)
|
||||
{
|
||||
return setTo(s, Stream::Null());
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat& GpuMat::setTo(Scalar s, InputArray mask)
|
||||
{
|
||||
return setTo(s, mask, Stream::Null());
|
||||
}
|
||||
|
||||
inline
|
||||
void GpuMat::convertTo(OutputArray dst, int rtype) const
|
||||
{
|
||||
convertTo(dst, rtype, Stream::Null());
|
||||
}
|
||||
|
||||
inline
|
||||
void GpuMat::convertTo(OutputArray dst, int rtype, double alpha, double beta) const
|
||||
{
|
||||
convertTo(dst, rtype, alpha, beta, Stream::Null());
|
||||
}
|
||||
|
||||
inline
|
||||
void GpuMat::convertTo(OutputArray dst, int rtype, double alpha, Stream& stream) const
|
||||
{
|
||||
convertTo(dst, rtype, alpha, 0.0, stream);
|
||||
}
|
||||
|
||||
inline
|
||||
void GpuMat::assignTo(GpuMat& m, int _type) const
|
||||
{
|
||||
if (_type < 0)
|
||||
m = *this;
|
||||
else
|
||||
convertTo(m, _type);
|
||||
}
|
||||
|
||||
inline
|
||||
uchar* GpuMat::ptr(int y)
|
||||
{
|
||||
CV_DbgAssert( (unsigned)y < (unsigned)rows );
|
||||
return data + step * y;
|
||||
}
|
||||
|
||||
inline
|
||||
const uchar* GpuMat::ptr(int y) const
|
||||
{
|
||||
CV_DbgAssert( (unsigned)y < (unsigned)rows );
|
||||
return data + step * y;
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
_Tp* GpuMat::ptr(int y)
|
||||
{
|
||||
return (_Tp*)ptr(y);
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
const _Tp* GpuMat::ptr(int y) const
|
||||
{
|
||||
return (const _Tp*)ptr(y);
|
||||
}
|
||||
|
||||
template <class T> inline
|
||||
GpuMat::operator PtrStepSz<T>() const
|
||||
{
|
||||
return PtrStepSz<T>(rows, cols, (T*)data, step);
|
||||
}
|
||||
|
||||
template <class T> inline
|
||||
GpuMat::operator PtrStep<T>() const
|
||||
{
|
||||
return PtrStep<T>((T*)data, step);
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat GpuMat::row(int y) const
|
||||
{
|
||||
return GpuMat(*this, Range(y, y+1), Range::all());
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat GpuMat::col(int x) const
|
||||
{
|
||||
return GpuMat(*this, Range::all(), Range(x, x+1));
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat GpuMat::rowRange(int startrow, int endrow) const
|
||||
{
|
||||
return GpuMat(*this, Range(startrow, endrow), Range::all());
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat GpuMat::rowRange(Range r) const
|
||||
{
|
||||
return GpuMat(*this, r, Range::all());
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat GpuMat::colRange(int startcol, int endcol) const
|
||||
{
|
||||
return GpuMat(*this, Range::all(), Range(startcol, endcol));
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat GpuMat::colRange(Range r) const
|
||||
{
|
||||
return GpuMat(*this, Range::all(), r);
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat GpuMat::operator ()(Range rowRange_, Range colRange_) const
|
||||
{
|
||||
return GpuMat(*this, rowRange_, colRange_);
|
||||
}
|
||||
|
||||
inline
|
||||
GpuMat GpuMat::operator ()(Rect roi) const
|
||||
{
|
||||
return GpuMat(*this, roi);
|
||||
}
|
||||
|
||||
inline
|
||||
bool GpuMat::isContinuous() const
|
||||
{
|
||||
return (flags & Mat::CONTINUOUS_FLAG) != 0;
|
||||
}
|
||||
|
||||
inline
|
||||
size_t GpuMat::elemSize() const
|
||||
{
|
||||
return CV_ELEM_SIZE(flags);
|
||||
}
|
||||
|
||||
inline
|
||||
size_t GpuMat::elemSize1() const
|
||||
{
|
||||
return CV_ELEM_SIZE1(flags);
|
||||
}
|
||||
|
||||
inline
|
||||
int GpuMat::type() const
|
||||
{
|
||||
return CV_MAT_TYPE(flags);
|
||||
}
|
||||
|
||||
inline
|
||||
int GpuMat::depth() const
|
||||
{
|
||||
return CV_MAT_DEPTH(flags);
|
||||
}
|
||||
|
||||
inline
|
||||
int GpuMat::channels() const
|
||||
{
|
||||
return CV_MAT_CN(flags);
|
||||
}
|
||||
|
||||
inline
|
||||
size_t GpuMat::step1() const
|
||||
{
|
||||
return step / elemSize1();
|
||||
}
|
||||
|
||||
inline
|
||||
Size GpuMat::size() const
|
||||
{
|
||||
return Size(cols, rows);
|
||||
}
|
||||
|
||||
inline
|
||||
bool GpuMat::empty() const
|
||||
{
|
||||
return data == 0;
|
||||
}
|
||||
|
||||
static inline
|
||||
GpuMat createContinuous(int rows, int cols, int type)
|
||||
{
|
||||
GpuMat m;
|
||||
createContinuous(rows, cols, type, m);
|
||||
return m;
|
||||
}
|
||||
|
||||
static inline
|
||||
void createContinuous(Size size, int type, OutputArray arr)
|
||||
{
|
||||
createContinuous(size.height, size.width, type, arr);
|
||||
}
|
||||
|
||||
static inline
|
||||
GpuMat createContinuous(Size size, int type)
|
||||
{
|
||||
GpuMat m;
|
||||
createContinuous(size, type, m);
|
||||
return m;
|
||||
}
|
||||
|
||||
static inline
|
||||
void ensureSizeIsEnough(Size size, int type, OutputArray arr)
|
||||
{
|
||||
ensureSizeIsEnough(size.height, size.width, type, arr);
|
||||
}
|
||||
|
||||
static inline
|
||||
void swap(GpuMat& a, GpuMat& b)
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
//===================================================================================
|
||||
// HostMem
|
||||
//===================================================================================
|
||||
|
||||
inline
|
||||
HostMem::HostMem(AllocType alloc_type_)
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
HostMem::HostMem(const HostMem& m)
|
||||
: flags(m.flags), rows(m.rows), cols(m.cols), step(m.step), data(m.data), refcount(m.refcount), datastart(m.datastart), dataend(m.dataend), alloc_type(m.alloc_type)
|
||||
{
|
||||
if( refcount )
|
||||
CV_XADD(refcount, 1);
|
||||
}
|
||||
|
||||
inline
|
||||
HostMem::HostMem(int rows_, int cols_, int type_, AllocType alloc_type_)
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_)
|
||||
{
|
||||
if (rows_ > 0 && cols_ > 0)
|
||||
create(rows_, cols_, type_);
|
||||
}
|
||||
|
||||
inline
|
||||
HostMem::HostMem(Size size_, int type_, AllocType alloc_type_)
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_)
|
||||
{
|
||||
if (size_.height > 0 && size_.width > 0)
|
||||
create(size_.height, size_.width, type_);
|
||||
}
|
||||
|
||||
inline
|
||||
HostMem::HostMem(InputArray arr, AllocType alloc_type_)
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0), alloc_type(alloc_type_)
|
||||
{
|
||||
arr.getMat().copyTo(*this);
|
||||
}
|
||||
|
||||
inline
|
||||
HostMem::~HostMem()
|
||||
{
|
||||
release();
|
||||
}
|
||||
|
||||
inline
|
||||
HostMem& HostMem::operator =(const HostMem& m)
|
||||
{
|
||||
if (this != &m)
|
||||
{
|
||||
HostMem temp(m);
|
||||
swap(temp);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
void HostMem::swap(HostMem& b)
|
||||
{
|
||||
std::swap(flags, b.flags);
|
||||
std::swap(rows, b.rows);
|
||||
std::swap(cols, b.cols);
|
||||
std::swap(step, b.step);
|
||||
std::swap(data, b.data);
|
||||
std::swap(datastart, b.datastart);
|
||||
std::swap(dataend, b.dataend);
|
||||
std::swap(refcount, b.refcount);
|
||||
std::swap(alloc_type, b.alloc_type);
|
||||
}
|
||||
|
||||
inline
|
||||
HostMem HostMem::clone() const
|
||||
{
|
||||
HostMem m(size(), type(), alloc_type);
|
||||
createMatHeader().copyTo(m);
|
||||
return m;
|
||||
}
|
||||
|
||||
inline
|
||||
void HostMem::create(Size size_, int type_)
|
||||
{
|
||||
create(size_.height, size_.width, type_);
|
||||
}
|
||||
|
||||
inline
|
||||
Mat HostMem::createMatHeader() const
|
||||
{
|
||||
return Mat(size(), type(), data, step);
|
||||
}
|
||||
|
||||
inline
|
||||
bool HostMem::isContinuous() const
|
||||
{
|
||||
return (flags & Mat::CONTINUOUS_FLAG) != 0;
|
||||
}
|
||||
|
||||
inline
|
||||
size_t HostMem::elemSize() const
|
||||
{
|
||||
return CV_ELEM_SIZE(flags);
|
||||
}
|
||||
|
||||
inline
|
||||
size_t HostMem::elemSize1() const
|
||||
{
|
||||
return CV_ELEM_SIZE1(flags);
|
||||
}
|
||||
|
||||
inline
|
||||
int HostMem::type() const
|
||||
{
|
||||
return CV_MAT_TYPE(flags);
|
||||
}
|
||||
|
||||
inline
|
||||
int HostMem::depth() const
|
||||
{
|
||||
return CV_MAT_DEPTH(flags);
|
||||
}
|
||||
|
||||
inline
|
||||
int HostMem::channels() const
|
||||
{
|
||||
return CV_MAT_CN(flags);
|
||||
}
|
||||
|
||||
inline
|
||||
size_t HostMem::step1() const
|
||||
{
|
||||
return step / elemSize1();
|
||||
}
|
||||
|
||||
inline
|
||||
Size HostMem::size() const
|
||||
{
|
||||
return Size(cols, rows);
|
||||
}
|
||||
|
||||
inline
|
||||
bool HostMem::empty() const
|
||||
{
|
||||
return data == 0;
|
||||
}
|
||||
|
||||
static inline
|
||||
void swap(HostMem& a, HostMem& b)
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
//===================================================================================
|
||||
// Stream
|
||||
//===================================================================================
|
||||
|
||||
inline
|
||||
Stream::Stream(const Ptr<Impl>& impl)
|
||||
: impl_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
//===================================================================================
|
||||
// Event
|
||||
//===================================================================================
|
||||
|
||||
inline
|
||||
Event::Event(const Ptr<Impl>& impl)
|
||||
: impl_(impl)
|
||||
{
|
||||
}
|
||||
|
||||
//===================================================================================
|
||||
// Initialization & Info
|
||||
//===================================================================================
|
||||
|
||||
inline
|
||||
bool TargetArchs::has(int major, int minor)
|
||||
{
|
||||
return hasPtx(major, minor) || hasBin(major, minor);
|
||||
}
|
||||
|
||||
inline
|
||||
bool TargetArchs::hasEqualOrGreater(int major, int minor)
|
||||
{
|
||||
return hasEqualOrGreaterPtx(major, minor) || hasEqualOrGreaterBin(major, minor);
|
||||
}
|
||||
|
||||
inline
|
||||
DeviceInfo::DeviceInfo()
|
||||
{
|
||||
device_id_ = getDevice();
|
||||
}
|
||||
|
||||
inline
|
||||
DeviceInfo::DeviceInfo(int device_id)
|
||||
{
|
||||
CV_Assert( device_id >= 0 && device_id < getCudaEnabledDeviceCount() );
|
||||
device_id_ = device_id;
|
||||
}
|
||||
|
||||
inline
|
||||
int DeviceInfo::deviceID() const
|
||||
{
|
||||
return device_id_;
|
||||
}
|
||||
|
||||
inline
|
||||
size_t DeviceInfo::freeMemory() const
|
||||
{
|
||||
size_t _totalMemory = 0, _freeMemory = 0;
|
||||
queryMemory(_totalMemory, _freeMemory);
|
||||
return _freeMemory;
|
||||
}
|
||||
|
||||
inline
|
||||
size_t DeviceInfo::totalMemory() const
|
||||
{
|
||||
size_t _totalMemory = 0, _freeMemory = 0;
|
||||
queryMemory(_totalMemory, _freeMemory);
|
||||
return _totalMemory;
|
||||
}
|
||||
|
||||
inline
|
||||
bool DeviceInfo::supports(FeatureSet feature_set) const
|
||||
{
|
||||
int version = majorVersion() * 10 + minorVersion();
|
||||
return version >= feature_set;
|
||||
}
|
||||
|
||||
|
||||
}} // namespace cv { namespace cuda {
|
||||
|
||||
//===================================================================================
|
||||
// Mat
|
||||
//===================================================================================
|
||||
|
||||
namespace cv {
|
||||
|
||||
inline
|
||||
Mat::Mat(const cuda::GpuMat& m)
|
||||
: flags(0), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows)
|
||||
{
|
||||
m.download(*this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//! @endcond
|
||||
|
||||
#endif // OPENCV_CORE_CUDAINL_HPP
|
||||
@@ -1,199 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_CORE_DEVPTRS_HPP__
|
||||
#define __OPENCV_CORE_DEVPTRS_HPP__
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#ifdef __CUDACC__
|
||||
#define __CV_GPU_HOST_DEVICE__ __host__ __device__ __forceinline__
|
||||
#else
|
||||
#define __CV_GPU_HOST_DEVICE__
|
||||
#endif
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace gpu
|
||||
{
|
||||
// Simple lightweight structures that encapsulates information about an image on device.
|
||||
// It is intended to pass to nvcc-compiled code. GpuMat depends on headers that nvcc can't compile
|
||||
|
||||
template <bool expr> struct StaticAssert;
|
||||
template <> struct StaticAssert<true> {static __CV_GPU_HOST_DEVICE__ void check(){}};
|
||||
|
||||
template<typename T> struct DevPtr
|
||||
{
|
||||
typedef T elem_type;
|
||||
typedef int index_type;
|
||||
|
||||
enum { elem_size = sizeof(elem_type) };
|
||||
|
||||
T* data;
|
||||
|
||||
__CV_GPU_HOST_DEVICE__ DevPtr() : data(0) {}
|
||||
__CV_GPU_HOST_DEVICE__ DevPtr(T* data_) : data(data_) {}
|
||||
|
||||
__CV_GPU_HOST_DEVICE__ size_t elemSize() const { return elem_size; }
|
||||
__CV_GPU_HOST_DEVICE__ operator T*() { return data; }
|
||||
__CV_GPU_HOST_DEVICE__ operator const T*() const { return data; }
|
||||
};
|
||||
|
||||
template<typename T> struct PtrSz : public DevPtr<T>
|
||||
{
|
||||
__CV_GPU_HOST_DEVICE__ PtrSz() : size(0) {}
|
||||
__CV_GPU_HOST_DEVICE__ PtrSz(T* data_, size_t size_) : DevPtr<T>(data_), size(size_) {}
|
||||
|
||||
size_t size;
|
||||
};
|
||||
|
||||
template<typename T> struct PtrStep : public DevPtr<T>
|
||||
{
|
||||
__CV_GPU_HOST_DEVICE__ PtrStep() : step(0) {}
|
||||
__CV_GPU_HOST_DEVICE__ PtrStep(T* data_, size_t step_) : DevPtr<T>(data_), step(step_) {}
|
||||
|
||||
/** \brief stride between two consecutive rows in bytes. Step is stored always and everywhere in bytes!!! */
|
||||
size_t step;
|
||||
|
||||
__CV_GPU_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)DevPtr<T>::data + y * step); }
|
||||
__CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)DevPtr<T>::data + y * step); }
|
||||
|
||||
__CV_GPU_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; }
|
||||
__CV_GPU_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; }
|
||||
};
|
||||
|
||||
template <typename T> struct PtrStepSz : public PtrStep<T>
|
||||
{
|
||||
__CV_GPU_HOST_DEVICE__ PtrStepSz() : cols(0), rows(0) {}
|
||||
__CV_GPU_HOST_DEVICE__ PtrStepSz(int rows_, int cols_, T* data_, size_t step_)
|
||||
: PtrStep<T>(data_, step_), cols(cols_), rows(rows_) {}
|
||||
|
||||
template <typename U>
|
||||
explicit PtrStepSz(const PtrStepSz<U>& d) : PtrStep<T>((T*)d.data, d.step), cols(d.cols), rows(d.rows){}
|
||||
|
||||
int cols;
|
||||
int rows;
|
||||
};
|
||||
|
||||
typedef PtrStepSz<unsigned char> PtrStepSzb;
|
||||
typedef PtrStepSz<float> PtrStepSzf;
|
||||
typedef PtrStepSz<int> PtrStepSzi;
|
||||
|
||||
typedef PtrStep<unsigned char> PtrStepb;
|
||||
typedef PtrStep<float> PtrStepf;
|
||||
typedef PtrStep<int> PtrStepi;
|
||||
|
||||
|
||||
#if defined __GNUC__
|
||||
#define __CV_GPU_DEPR_BEFORE__
|
||||
#define __CV_GPU_DEPR_AFTER__ __attribute__ ((deprecated))
|
||||
#elif defined(__MSVC__) //|| defined(__CUDACC__)
|
||||
#pragma deprecated(DevMem2D_)
|
||||
#define __CV_GPU_DEPR_BEFORE__ __declspec(deprecated)
|
||||
#define __CV_GPU_DEPR_AFTER__
|
||||
#else
|
||||
#define __CV_GPU_DEPR_BEFORE__
|
||||
#define __CV_GPU_DEPR_AFTER__
|
||||
#endif
|
||||
|
||||
template <typename T> struct __CV_GPU_DEPR_BEFORE__ DevMem2D_ : public PtrStepSz<T>
|
||||
{
|
||||
DevMem2D_() {}
|
||||
DevMem2D_(int rows_, int cols_, T* data_, size_t step_) : PtrStepSz<T>(rows_, cols_, data_, step_) {}
|
||||
|
||||
template <typename U>
|
||||
explicit __CV_GPU_DEPR_BEFORE__ DevMem2D_(const DevMem2D_<U>& d) : PtrStepSz<T>(d.rows, d.cols, (T*)d.data, d.step) {}
|
||||
} __CV_GPU_DEPR_AFTER__ ;
|
||||
|
||||
typedef DevMem2D_<unsigned char> DevMem2Db;
|
||||
typedef DevMem2Db DevMem2D;
|
||||
typedef DevMem2D_<float> DevMem2Df;
|
||||
typedef DevMem2D_<int> DevMem2Di;
|
||||
|
||||
template<typename T> struct PtrElemStep_ : public PtrStep<T>
|
||||
{
|
||||
PtrElemStep_(const DevMem2D_<T>& mem) : PtrStep<T>(mem.data, mem.step)
|
||||
{
|
||||
StaticAssert<256 % sizeof(T) == 0>::check();
|
||||
|
||||
PtrStep<T>::step /= PtrStep<T>::elem_size;
|
||||
}
|
||||
__CV_GPU_HOST_DEVICE__ T* ptr(int y = 0) { return PtrStep<T>::data + y * PtrStep<T>::step; }
|
||||
__CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const { return PtrStep<T>::data + y * PtrStep<T>::step; }
|
||||
|
||||
__CV_GPU_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; }
|
||||
__CV_GPU_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; }
|
||||
};
|
||||
|
||||
template<typename T> struct PtrStep_ : public PtrStep<T>
|
||||
{
|
||||
PtrStep_() {}
|
||||
PtrStep_(const DevMem2D_<T>& mem) : PtrStep<T>(mem.data, mem.step) {}
|
||||
};
|
||||
|
||||
typedef PtrElemStep_<unsigned char> PtrElemStep;
|
||||
typedef PtrElemStep_<float> PtrElemStepf;
|
||||
typedef PtrElemStep_<int> PtrElemStepi;
|
||||
|
||||
//#undef __CV_GPU_DEPR_BEFORE__
|
||||
//#undef __CV_GPU_DEPR_AFTER__
|
||||
|
||||
namespace device
|
||||
{
|
||||
using cv::gpu::PtrSz;
|
||||
using cv::gpu::PtrStep;
|
||||
using cv::gpu::PtrStepSz;
|
||||
|
||||
using cv::gpu::PtrStepSzb;
|
||||
using cv::gpu::PtrStepSzf;
|
||||
using cv::gpu::PtrStepSzi;
|
||||
|
||||
using cv::gpu::PtrStepb;
|
||||
using cv::gpu::PtrStepf;
|
||||
using cv::gpu::PtrStepi;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif /* __OPENCV_CORE_DEVPTRS_HPP__ */
|
||||
+32
-10
@@ -40,25 +40,47 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_GPU_STREAM_ACCESSOR_HPP__
|
||||
#define __OPENCV_GPU_STREAM_ACCESSOR_HPP__
|
||||
#ifndef OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP
|
||||
#define OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP
|
||||
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
#include "cuda_runtime_api.h"
|
||||
#ifndef __cplusplus
|
||||
# error cuda_stream_accessor.hpp header must be compiled as C++
|
||||
#endif
|
||||
|
||||
/** @file cuda_stream_accessor.hpp
|
||||
* This is only header file that depends on CUDA Runtime API. All other headers are independent.
|
||||
*/
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace gpu
|
||||
namespace cuda
|
||||
{
|
||||
// This is only header file that depends on Cuda. All other headers are independent.
|
||||
// So if you use OpenCV binaries you do noot need to install Cuda Toolkit.
|
||||
// But of you wanna use GPU by yourself, may get cuda stream instance using the class below.
|
||||
// In this case you have to install Cuda Toolkit.
|
||||
|
||||
//! @addtogroup cudacore_struct
|
||||
//! @{
|
||||
|
||||
/** @brief Class that enables getting cudaStream_t from cuda::Stream
|
||||
*/
|
||||
struct StreamAccessor
|
||||
{
|
||||
CV_EXPORTS static cudaStream_t getStream(const Stream& stream);
|
||||
CV_EXPORTS static Stream wrapStream(cudaStream_t stream);
|
||||
};
|
||||
|
||||
/** @brief Class that enables getting cudaEvent_t from cuda::Event
|
||||
*/
|
||||
struct EventAccessor
|
||||
{
|
||||
CV_EXPORTS static cudaEvent_t getEvent(const Event& event);
|
||||
CV_EXPORTS static Event wrapEvent(cudaEvent_t event);
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* __OPENCV_GPU_STREAM_ACCESSOR_HPP__ */
|
||||
#endif /* OPENCV_CORE_CUDA_STREAM_ACCESSOR_HPP */
|
||||
@@ -0,0 +1,135 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_CUDA_TYPES_HPP
|
||||
#define OPENCV_CORE_CUDA_TYPES_HPP
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error cuda_types.hpp header must be compiled as C++
|
||||
#endif
|
||||
|
||||
/** @file
|
||||
* @deprecated Use @ref cudev instead.
|
||||
*/
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
#ifdef __CUDACC__
|
||||
#define __CV_CUDA_HOST_DEVICE__ __host__ __device__ __forceinline__
|
||||
#else
|
||||
#define __CV_CUDA_HOST_DEVICE__
|
||||
#endif
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace cuda
|
||||
{
|
||||
|
||||
// Simple lightweight structures that encapsulates information about an image on device.
|
||||
// It is intended to pass to nvcc-compiled code. GpuMat depends on headers that nvcc can't compile
|
||||
|
||||
template <typename T> struct DevPtr
|
||||
{
|
||||
typedef T elem_type;
|
||||
typedef int index_type;
|
||||
|
||||
enum { elem_size = sizeof(elem_type) };
|
||||
|
||||
T* data;
|
||||
|
||||
__CV_CUDA_HOST_DEVICE__ DevPtr() : data(0) {}
|
||||
__CV_CUDA_HOST_DEVICE__ DevPtr(T* data_) : data(data_) {}
|
||||
|
||||
__CV_CUDA_HOST_DEVICE__ size_t elemSize() const { return elem_size; }
|
||||
__CV_CUDA_HOST_DEVICE__ operator T*() { return data; }
|
||||
__CV_CUDA_HOST_DEVICE__ operator const T*() const { return data; }
|
||||
};
|
||||
|
||||
template <typename T> struct PtrSz : public DevPtr<T>
|
||||
{
|
||||
__CV_CUDA_HOST_DEVICE__ PtrSz() : size(0) {}
|
||||
__CV_CUDA_HOST_DEVICE__ PtrSz(T* data_, size_t size_) : DevPtr<T>(data_), size(size_) {}
|
||||
|
||||
size_t size;
|
||||
};
|
||||
|
||||
template <typename T> struct PtrStep : public DevPtr<T>
|
||||
{
|
||||
__CV_CUDA_HOST_DEVICE__ PtrStep() : step(0) {}
|
||||
__CV_CUDA_HOST_DEVICE__ PtrStep(T* data_, size_t step_) : DevPtr<T>(data_), step(step_) {}
|
||||
|
||||
size_t step;
|
||||
|
||||
__CV_CUDA_HOST_DEVICE__ T* ptr(int y = 0) { return ( T*)( ( char*)DevPtr<T>::data + y * step); }
|
||||
__CV_CUDA_HOST_DEVICE__ const T* ptr(int y = 0) const { return (const T*)( (const char*)DevPtr<T>::data + y * step); }
|
||||
|
||||
__CV_CUDA_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; }
|
||||
__CV_CUDA_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; }
|
||||
};
|
||||
|
||||
template <typename T> struct PtrStepSz : public PtrStep<T>
|
||||
{
|
||||
__CV_CUDA_HOST_DEVICE__ PtrStepSz() : cols(0), rows(0) {}
|
||||
__CV_CUDA_HOST_DEVICE__ PtrStepSz(int rows_, int cols_, T* data_, size_t step_)
|
||||
: PtrStep<T>(data_, step_), cols(cols_), rows(rows_) {}
|
||||
|
||||
template <typename U>
|
||||
explicit PtrStepSz(const PtrStepSz<U>& d) : PtrStep<T>((T*)d.data, d.step), cols(d.cols), rows(d.rows){}
|
||||
|
||||
int cols;
|
||||
int rows;
|
||||
};
|
||||
|
||||
typedef PtrStepSz<unsigned char> PtrStepSzb;
|
||||
typedef PtrStepSz<float> PtrStepSzf;
|
||||
typedef PtrStepSz<int> PtrStepSzi;
|
||||
|
||||
typedef PtrStep<unsigned char> PtrStepb;
|
||||
typedef PtrStep<float> PtrStepf;
|
||||
typedef PtrStep<int> PtrStepi;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//! @endcond
|
||||
|
||||
#endif /* OPENCV_CORE_CUDA_TYPES_HPP */
|
||||
@@ -0,0 +1,481 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Copyright (C) 2015, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_CVDEF_H
|
||||
#define OPENCV_CORE_CVDEF_H
|
||||
|
||||
//! @addtogroup core_utils
|
||||
//! @{
|
||||
|
||||
#if !defined _CRT_SECURE_NO_DEPRECATE && defined _MSC_VER && _MSC_VER > 1300
|
||||
# define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio warnings */
|
||||
#endif
|
||||
|
||||
// undef problematic defines sometimes defined by system headers (windows.h in particular)
|
||||
#undef small
|
||||
#undef min
|
||||
#undef max
|
||||
#undef abs
|
||||
#undef Complex
|
||||
|
||||
#if !defined _CRT_SECURE_NO_DEPRECATE && defined _MSC_VER && _MSC_VER > 1300
|
||||
# define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio warnings */
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
#include "opencv2/core/hal/interface.h"
|
||||
|
||||
#if defined __ICL
|
||||
# define CV_ICC __ICL
|
||||
#elif defined __ICC
|
||||
# define CV_ICC __ICC
|
||||
#elif defined __ECL
|
||||
# define CV_ICC __ECL
|
||||
#elif defined __ECC
|
||||
# define CV_ICC __ECC
|
||||
#elif defined __INTEL_COMPILER
|
||||
# define CV_ICC __INTEL_COMPILER
|
||||
#endif
|
||||
|
||||
#ifndef CV_INLINE
|
||||
# if defined __cplusplus
|
||||
# define CV_INLINE static inline
|
||||
# elif defined _MSC_VER
|
||||
# define CV_INLINE __inline
|
||||
# else
|
||||
# define CV_INLINE static
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined CV_ICC && !defined CV_ENABLE_UNROLLED
|
||||
# define CV_ENABLE_UNROLLED 0
|
||||
#else
|
||||
# define CV_ENABLE_UNROLLED 1
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
|
||||
#elif defined _MSC_VER
|
||||
# define CV_DECL_ALIGNED(x) __declspec(align(x))
|
||||
#else
|
||||
# define CV_DECL_ALIGNED(x)
|
||||
#endif
|
||||
|
||||
/* CPU features and intrinsics support */
|
||||
#define CV_CPU_NONE 0
|
||||
#define CV_CPU_MMX 1
|
||||
#define CV_CPU_SSE 2
|
||||
#define CV_CPU_SSE2 3
|
||||
#define CV_CPU_SSE3 4
|
||||
#define CV_CPU_SSSE3 5
|
||||
#define CV_CPU_SSE4_1 6
|
||||
#define CV_CPU_SSE4_2 7
|
||||
#define CV_CPU_POPCNT 8
|
||||
#define CV_CPU_FP16 9
|
||||
#define CV_CPU_AVX 10
|
||||
#define CV_CPU_AVX2 11
|
||||
#define CV_CPU_FMA3 12
|
||||
|
||||
#define CV_CPU_AVX_512F 13
|
||||
#define CV_CPU_AVX_512BW 14
|
||||
#define CV_CPU_AVX_512CD 15
|
||||
#define CV_CPU_AVX_512DQ 16
|
||||
#define CV_CPU_AVX_512ER 17
|
||||
#define CV_CPU_AVX_512IFMA512 18
|
||||
#define CV_CPU_AVX_512PF 19
|
||||
#define CV_CPU_AVX_512VBMI 20
|
||||
#define CV_CPU_AVX_512VL 21
|
||||
|
||||
#define CV_CPU_NEON 100
|
||||
|
||||
// when adding to this list remember to update the following enum
|
||||
#define CV_HARDWARE_MAX_FEATURE 255
|
||||
|
||||
/** @brief Available CPU features.
|
||||
*/
|
||||
enum CpuFeatures {
|
||||
CPU_MMX = 1,
|
||||
CPU_SSE = 2,
|
||||
CPU_SSE2 = 3,
|
||||
CPU_SSE3 = 4,
|
||||
CPU_SSSE3 = 5,
|
||||
CPU_SSE4_1 = 6,
|
||||
CPU_SSE4_2 = 7,
|
||||
CPU_POPCNT = 8,
|
||||
CPU_FP16 = 9,
|
||||
CPU_AVX = 10,
|
||||
CPU_AVX2 = 11,
|
||||
CPU_FMA3 = 12,
|
||||
|
||||
CPU_AVX_512F = 13,
|
||||
CPU_AVX_512BW = 14,
|
||||
CPU_AVX_512CD = 15,
|
||||
CPU_AVX_512DQ = 16,
|
||||
CPU_AVX_512ER = 17,
|
||||
CPU_AVX_512IFMA512 = 18,
|
||||
CPU_AVX_512PF = 19,
|
||||
CPU_AVX_512VBMI = 20,
|
||||
CPU_AVX_512VL = 21,
|
||||
|
||||
CPU_NEON = 100
|
||||
};
|
||||
|
||||
// do not include SSE/AVX/NEON headers for NVCC compiler
|
||||
#ifndef __CUDACC__
|
||||
|
||||
#if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2)
|
||||
# include <emmintrin.h>
|
||||
# define CV_MMX 1
|
||||
# define CV_SSE 1
|
||||
# define CV_SSE2 1
|
||||
# if defined __SSE3__ || (defined _MSC_VER && _MSC_VER >= 1500)
|
||||
# include <pmmintrin.h>
|
||||
# define CV_SSE3 1
|
||||
# endif
|
||||
# if defined __SSSE3__ || (defined _MSC_VER && _MSC_VER >= 1500)
|
||||
# include <tmmintrin.h>
|
||||
# define CV_SSSE3 1
|
||||
# endif
|
||||
# if defined __SSE4_1__ || (defined _MSC_VER && _MSC_VER >= 1500)
|
||||
# include <smmintrin.h>
|
||||
# define CV_SSE4_1 1
|
||||
# endif
|
||||
# if defined __SSE4_2__ || (defined _MSC_VER && _MSC_VER >= 1500)
|
||||
# include <nmmintrin.h>
|
||||
# define CV_SSE4_2 1
|
||||
# endif
|
||||
# if defined __POPCNT__ || (defined _MSC_VER && _MSC_VER >= 1500)
|
||||
# ifdef _MSC_VER
|
||||
# include <nmmintrin.h>
|
||||
# else
|
||||
# include <popcntintrin.h>
|
||||
# endif
|
||||
# define CV_POPCNT 1
|
||||
# endif
|
||||
# if defined __AVX__ || (defined _MSC_VER && _MSC_VER >= 1600 && 0)
|
||||
// MS Visual Studio 2010 (2012?) has no macro pre-defined to identify the use of /arch:AVX
|
||||
// See: http://connect.microsoft.com/VisualStudio/feedback/details/605858/arch-avx-should-define-a-predefined-macro-in-x64-and-set-a-unique-value-for-m-ix86-fp-in-win32
|
||||
# include <immintrin.h>
|
||||
# define CV_AVX 1
|
||||
# if defined(_XCR_XFEATURE_ENABLED_MASK)
|
||||
# define __xgetbv() _xgetbv(_XCR_XFEATURE_ENABLED_MASK)
|
||||
# else
|
||||
# define __xgetbv() 0
|
||||
# endif
|
||||
# endif
|
||||
# if defined __AVX2__ || (defined _MSC_VER && _MSC_VER >= 1800 && 0)
|
||||
# include <immintrin.h>
|
||||
# define CV_AVX2 1
|
||||
# if defined __FMA__
|
||||
# define CV_FMA3 1
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if (defined WIN32 || defined _WIN32) && defined(_M_ARM)
|
||||
# include <Intrin.h>
|
||||
# include <arm_neon.h>
|
||||
# define CV_NEON 1
|
||||
# define CPU_HAS_NEON_FEATURE (true)
|
||||
#elif defined(__ARM_NEON__) || (defined (__ARM_NEON) && defined(__aarch64__))
|
||||
# include <arm_neon.h>
|
||||
# define CV_NEON 1
|
||||
#endif
|
||||
|
||||
#if defined __GNUC__ && defined __arm__ && (defined __ARM_PCS_VFP || defined __ARM_VFPV3__ || defined __ARM_NEON__) && !defined __SOFTFP__
|
||||
# define CV_VFP 1
|
||||
#endif
|
||||
|
||||
#endif // __CUDACC__
|
||||
|
||||
#ifndef CV_POPCNT
|
||||
#define CV_POPCNT 0
|
||||
#endif
|
||||
#ifndef CV_MMX
|
||||
# define CV_MMX 0
|
||||
#endif
|
||||
#ifndef CV_SSE
|
||||
# define CV_SSE 0
|
||||
#endif
|
||||
#ifndef CV_SSE2
|
||||
# define CV_SSE2 0
|
||||
#endif
|
||||
#ifndef CV_SSE3
|
||||
# define CV_SSE3 0
|
||||
#endif
|
||||
#ifndef CV_SSSE3
|
||||
# define CV_SSSE3 0
|
||||
#endif
|
||||
#ifndef CV_SSE4_1
|
||||
# define CV_SSE4_1 0
|
||||
#endif
|
||||
#ifndef CV_SSE4_2
|
||||
# define CV_SSE4_2 0
|
||||
#endif
|
||||
#ifndef CV_AVX
|
||||
# define CV_AVX 0
|
||||
#endif
|
||||
#ifndef CV_AVX2
|
||||
# define CV_AVX2 0
|
||||
#endif
|
||||
#ifndef CV_FMA3
|
||||
# define CV_FMA3 0
|
||||
#endif
|
||||
#ifndef CV_AVX_512F
|
||||
# define CV_AVX_512F 0
|
||||
#endif
|
||||
#ifndef CV_AVX_512BW
|
||||
# define CV_AVX_512BW 0
|
||||
#endif
|
||||
#ifndef CV_AVX_512CD
|
||||
# define CV_AVX_512CD 0
|
||||
#endif
|
||||
#ifndef CV_AVX_512DQ
|
||||
# define CV_AVX_512DQ 0
|
||||
#endif
|
||||
#ifndef CV_AVX_512ER
|
||||
# define CV_AVX_512ER 0
|
||||
#endif
|
||||
#ifndef CV_AVX_512IFMA512
|
||||
# define CV_AVX_512IFMA512 0
|
||||
#endif
|
||||
#ifndef CV_AVX_512PF
|
||||
# define CV_AVX_512PF 0
|
||||
#endif
|
||||
#ifndef CV_AVX_512VBMI
|
||||
# define CV_AVX_512VBMI 0
|
||||
#endif
|
||||
#ifndef CV_AVX_512VL
|
||||
# define CV_AVX_512VL 0
|
||||
#endif
|
||||
|
||||
#ifndef CV_NEON
|
||||
# define CV_NEON 0
|
||||
#endif
|
||||
|
||||
#ifndef CV_VFP
|
||||
# define CV_VFP 0
|
||||
#endif
|
||||
|
||||
/* fundamental constants */
|
||||
#define CV_PI 3.1415926535897932384626433832795
|
||||
#define CV_2PI 6.283185307179586476925286766559
|
||||
#define CV_LOG2 0.69314718055994530941723212145818
|
||||
|
||||
#if defined __ARM_FP16_FORMAT_IEEE \
|
||||
&& !defined __CUDACC__
|
||||
# define CV_FP16_TYPE 1
|
||||
#else
|
||||
# define CV_FP16_TYPE 0
|
||||
#endif
|
||||
|
||||
typedef union Cv16suf
|
||||
{
|
||||
short i;
|
||||
#if CV_FP16_TYPE
|
||||
__fp16 h;
|
||||
#endif
|
||||
struct _fp16Format
|
||||
{
|
||||
unsigned int significand : 10;
|
||||
unsigned int exponent : 5;
|
||||
unsigned int sign : 1;
|
||||
} fmt;
|
||||
}
|
||||
Cv16suf;
|
||||
|
||||
typedef union Cv32suf
|
||||
{
|
||||
int i;
|
||||
unsigned u;
|
||||
float f;
|
||||
struct _fp32Format
|
||||
{
|
||||
unsigned int significand : 23;
|
||||
unsigned int exponent : 8;
|
||||
unsigned int sign : 1;
|
||||
} fmt;
|
||||
}
|
||||
Cv32suf;
|
||||
|
||||
typedef union Cv64suf
|
||||
{
|
||||
int64 i;
|
||||
uint64 u;
|
||||
double f;
|
||||
}
|
||||
Cv64suf;
|
||||
|
||||
#define OPENCV_ABI_COMPATIBILITY 300
|
||||
|
||||
#ifdef __OPENCV_BUILD
|
||||
# define DISABLE_OPENCV_24_COMPATIBILITY
|
||||
#endif
|
||||
|
||||
#if (defined WIN32 || defined _WIN32 || defined WINCE || defined __CYGWIN__) && defined CVAPI_EXPORTS
|
||||
# define CV_EXPORTS __declspec(dllexport)
|
||||
#elif defined __GNUC__ && __GNUC__ >= 4
|
||||
# define CV_EXPORTS __attribute__ ((visibility ("default")))
|
||||
#else
|
||||
# define CV_EXPORTS
|
||||
#endif
|
||||
|
||||
#ifndef CV_EXTERN_C
|
||||
# ifdef __cplusplus
|
||||
# define CV_EXTERN_C extern "C"
|
||||
# else
|
||||
# define CV_EXTERN_C
|
||||
# endif
|
||||
#endif
|
||||
|
||||
/* special informative macros for wrapper generators */
|
||||
#define CV_EXPORTS_W CV_EXPORTS
|
||||
#define CV_EXPORTS_W_SIMPLE CV_EXPORTS
|
||||
#define CV_EXPORTS_AS(synonym) CV_EXPORTS
|
||||
#define CV_EXPORTS_W_MAP CV_EXPORTS
|
||||
#define CV_IN_OUT
|
||||
#define CV_OUT
|
||||
#define CV_PROP
|
||||
#define CV_PROP_RW
|
||||
#define CV_WRAP
|
||||
#define CV_WRAP_AS(synonym)
|
||||
|
||||
/****************************************************************************************\
|
||||
* Matrix type (Mat) *
|
||||
\****************************************************************************************/
|
||||
|
||||
#define CV_MAT_CN_MASK ((CV_CN_MAX - 1) << CV_CN_SHIFT)
|
||||
#define CV_MAT_CN(flags) ((((flags) & CV_MAT_CN_MASK) >> CV_CN_SHIFT) + 1)
|
||||
#define CV_MAT_TYPE_MASK (CV_DEPTH_MAX*CV_CN_MAX - 1)
|
||||
#define CV_MAT_TYPE(flags) ((flags) & CV_MAT_TYPE_MASK)
|
||||
#define CV_MAT_CONT_FLAG_SHIFT 14
|
||||
#define CV_MAT_CONT_FLAG (1 << CV_MAT_CONT_FLAG_SHIFT)
|
||||
#define CV_IS_MAT_CONT(flags) ((flags) & CV_MAT_CONT_FLAG)
|
||||
#define CV_IS_CONT_MAT CV_IS_MAT_CONT
|
||||
#define CV_SUBMAT_FLAG_SHIFT 15
|
||||
#define CV_SUBMAT_FLAG (1 << CV_SUBMAT_FLAG_SHIFT)
|
||||
#define CV_IS_SUBMAT(flags) ((flags) & CV_MAT_SUBMAT_FLAG)
|
||||
|
||||
/** Size of each channel item,
|
||||
0x124489 = 1000 0100 0100 0010 0010 0001 0001 ~ array of sizeof(arr_type_elem) */
|
||||
#define CV_ELEM_SIZE1(type) \
|
||||
((((sizeof(size_t)<<28)|0x8442211) >> CV_MAT_DEPTH(type)*4) & 15)
|
||||
|
||||
/** 0x3a50 = 11 10 10 01 01 00 00 ~ array of log2(sizeof(arr_type_elem)) */
|
||||
#define CV_ELEM_SIZE(type) \
|
||||
(CV_MAT_CN(type) << ((((sizeof(size_t)/4+1)*16384|0x3a50) >> CV_MAT_DEPTH(type)*2) & 3))
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) ((a) > (b) ? (b) : (a))
|
||||
#endif
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) ((a) < (b) ? (b) : (a))
|
||||
#endif
|
||||
|
||||
/****************************************************************************************\
|
||||
* exchange-add operation for atomic operations on reference counters *
|
||||
\****************************************************************************************/
|
||||
|
||||
#ifdef CV_XADD
|
||||
// allow to use user-defined macro
|
||||
#elif defined __GNUC__
|
||||
# if defined __clang__ && __clang_major__ >= 3 && !defined __ANDROID__ && !defined __EMSCRIPTEN__ && !defined(__CUDACC__)
|
||||
# ifdef __ATOMIC_ACQ_REL
|
||||
# define CV_XADD(addr, delta) __c11_atomic_fetch_add((_Atomic(int)*)(addr), delta, __ATOMIC_ACQ_REL)
|
||||
# else
|
||||
# define CV_XADD(addr, delta) __atomic_fetch_add((_Atomic(int)*)(addr), delta, 4)
|
||||
# endif
|
||||
# else
|
||||
# if defined __ATOMIC_ACQ_REL && !defined __clang__
|
||||
// version for gcc >= 4.7
|
||||
# define CV_XADD(addr, delta) (int)__atomic_fetch_add((unsigned*)(addr), (unsigned)(delta), __ATOMIC_ACQ_REL)
|
||||
# else
|
||||
# define CV_XADD(addr, delta) (int)__sync_fetch_and_add((unsigned*)(addr), (unsigned)(delta))
|
||||
# endif
|
||||
# endif
|
||||
#elif defined _MSC_VER && !defined RC_INVOKED
|
||||
# include <intrin.h>
|
||||
# define CV_XADD(addr, delta) (int)_InterlockedExchangeAdd((long volatile*)addr, delta)
|
||||
#else
|
||||
CV_INLINE CV_XADD(int* addr, int delta) { int tmp = *addr; *addr += delta; return tmp; }
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************************\
|
||||
* CV_NORETURN attribute *
|
||||
\****************************************************************************************/
|
||||
|
||||
#ifndef CV_NORETURN
|
||||
# if defined(__GNUC__)
|
||||
# define CV_NORETURN __attribute__((__noreturn__))
|
||||
# elif defined(_MSC_VER) && (_MSC_VER >= 1300)
|
||||
# define CV_NORETURN __declspec(noreturn)
|
||||
# else
|
||||
# define CV_NORETURN /* nothing by default */
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
/****************************************************************************************\
|
||||
* C++ Move semantics *
|
||||
\****************************************************************************************/
|
||||
|
||||
#ifndef CV_CXX_MOVE_SEMANTICS
|
||||
# if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || defined(_MSC_VER) && _MSC_VER >= 1600
|
||||
# define CV_CXX_MOVE_SEMANTICS 1
|
||||
# elif defined(__clang)
|
||||
# if __has_feature(cxx_rvalue_references)
|
||||
# define CV_CXX_MOVE_SEMANTICS 1
|
||||
# endif
|
||||
# endif
|
||||
#else
|
||||
# if CV_CXX_MOVE_SEMANTICS == 0
|
||||
# undef CV_CXX_MOVE_SEMANTICS
|
||||
# endif
|
||||
#endif
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // OPENCV_CORE_CVDEF_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,267 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_CVSTDINL_HPP
|
||||
#define OPENCV_CORE_CVSTDINL_HPP
|
||||
|
||||
#ifndef OPENCV_NOSTL
|
||||
# include <complex>
|
||||
# include <ostream>
|
||||
#endif
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
namespace cv
|
||||
{
|
||||
#ifndef OPENCV_NOSTL
|
||||
|
||||
template<typename _Tp> class DataType< std::complex<_Tp> >
|
||||
{
|
||||
public:
|
||||
typedef std::complex<_Tp> value_type;
|
||||
typedef value_type work_type;
|
||||
typedef _Tp channel_type;
|
||||
|
||||
enum { generic_type = 0,
|
||||
depth = DataType<channel_type>::depth,
|
||||
channels = 2,
|
||||
fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
|
||||
type = CV_MAKETYPE(depth, channels) };
|
||||
|
||||
typedef Vec<channel_type, channels> vec_type;
|
||||
};
|
||||
|
||||
inline
|
||||
String::String(const std::string& str)
|
||||
: cstr_(0), len_(0)
|
||||
{
|
||||
if (!str.empty())
|
||||
{
|
||||
size_t len = str.size();
|
||||
memcpy(allocate(len), str.c_str(), len);
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
String::String(const std::string& str, size_t pos, size_t len)
|
||||
: cstr_(0), len_(0)
|
||||
{
|
||||
size_t strlen = str.size();
|
||||
pos = min(pos, strlen);
|
||||
len = min(strlen - pos, len);
|
||||
if (!len) return;
|
||||
memcpy(allocate(len), str.c_str() + pos, len);
|
||||
}
|
||||
|
||||
inline
|
||||
String& String::operator = (const std::string& str)
|
||||
{
|
||||
deallocate();
|
||||
if (!str.empty())
|
||||
{
|
||||
size_t len = str.size();
|
||||
memcpy(allocate(len), str.c_str(), len);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
String& String::operator += (const std::string& str)
|
||||
{
|
||||
*this = *this + str;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline
|
||||
String::operator std::string() const
|
||||
{
|
||||
return std::string(cstr_, len_);
|
||||
}
|
||||
|
||||
inline
|
||||
String operator + (const String& lhs, const std::string& rhs)
|
||||
{
|
||||
String s;
|
||||
size_t rhslen = rhs.size();
|
||||
s.allocate(lhs.len_ + rhslen);
|
||||
memcpy(s.cstr_, lhs.cstr_, lhs.len_);
|
||||
memcpy(s.cstr_ + lhs.len_, rhs.c_str(), rhslen);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline
|
||||
String operator + (const std::string& lhs, const String& rhs)
|
||||
{
|
||||
String s;
|
||||
size_t lhslen = lhs.size();
|
||||
s.allocate(lhslen + rhs.len_);
|
||||
memcpy(s.cstr_, lhs.c_str(), lhslen);
|
||||
memcpy(s.cstr_ + lhslen, rhs.cstr_, rhs.len_);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline
|
||||
FileNode::operator std::string() const
|
||||
{
|
||||
String value;
|
||||
read(*this, value, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
template<> inline
|
||||
void operator >> (const FileNode& n, std::string& value)
|
||||
{
|
||||
String val;
|
||||
read(n, val, val);
|
||||
value = val;
|
||||
}
|
||||
|
||||
template<> inline
|
||||
FileStorage& operator << (FileStorage& fs, const std::string& value)
|
||||
{
|
||||
return fs << cv::String(value);
|
||||
}
|
||||
|
||||
static inline
|
||||
std::ostream& operator << (std::ostream& os, const String& str)
|
||||
{
|
||||
return os << str.c_str();
|
||||
}
|
||||
|
||||
static inline
|
||||
std::ostream& operator << (std::ostream& out, Ptr<Formatted> fmtd)
|
||||
{
|
||||
fmtd->reset();
|
||||
for(const char* str = fmtd->next(); str; str = fmtd->next())
|
||||
out << str;
|
||||
return out;
|
||||
}
|
||||
|
||||
static inline
|
||||
std::ostream& operator << (std::ostream& out, const Mat& mtx)
|
||||
{
|
||||
return out << Formatter::get()->format(mtx);
|
||||
}
|
||||
|
||||
template<typename _Tp> static inline
|
||||
std::ostream& operator << (std::ostream& out, const std::vector<Point_<_Tp> >& vec)
|
||||
{
|
||||
return out << Formatter::get()->format(Mat(vec));
|
||||
}
|
||||
|
||||
|
||||
template<typename _Tp> static inline
|
||||
std::ostream& operator << (std::ostream& out, const std::vector<Point3_<_Tp> >& vec)
|
||||
{
|
||||
return out << Formatter::get()->format(Mat(vec));
|
||||
}
|
||||
|
||||
|
||||
template<typename _Tp, int m, int n> static inline
|
||||
std::ostream& operator << (std::ostream& out, const Matx<_Tp, m, n>& matx)
|
||||
{
|
||||
return out << Formatter::get()->format(Mat(matx));
|
||||
}
|
||||
|
||||
template<typename _Tp> static inline
|
||||
std::ostream& operator << (std::ostream& out, const Point_<_Tp>& p)
|
||||
{
|
||||
out << "[" << p.x << ", " << p.y << "]";
|
||||
return out;
|
||||
}
|
||||
|
||||
template<typename _Tp> static inline
|
||||
std::ostream& operator << (std::ostream& out, const Point3_<_Tp>& p)
|
||||
{
|
||||
out << "[" << p.x << ", " << p.y << ", " << p.z << "]";
|
||||
return out;
|
||||
}
|
||||
|
||||
template<typename _Tp, int n> static inline
|
||||
std::ostream& operator << (std::ostream& out, const Vec<_Tp, n>& vec)
|
||||
{
|
||||
out << "[";
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable: 4127 )
|
||||
#endif
|
||||
if(Vec<_Tp, n>::depth < CV_32F)
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
{
|
||||
for (int i = 0; i < n - 1; ++i) {
|
||||
out << (int)vec[i] << ", ";
|
||||
}
|
||||
out << (int)vec[n-1] << "]";
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < n - 1; ++i) {
|
||||
out << vec[i] << ", ";
|
||||
}
|
||||
out << vec[n-1] << "]";
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
template<typename _Tp> static inline
|
||||
std::ostream& operator << (std::ostream& out, const Size_<_Tp>& size)
|
||||
{
|
||||
return out << "[" << size.width << " x " << size.height << "]";
|
||||
}
|
||||
|
||||
template<typename _Tp> static inline
|
||||
std::ostream& operator << (std::ostream& out, const Rect_<_Tp>& rect)
|
||||
{
|
||||
return out << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]";
|
||||
}
|
||||
|
||||
|
||||
#endif // OPENCV_NOSTL
|
||||
} // cv
|
||||
|
||||
//! @endcond
|
||||
|
||||
#endif // OPENCV_CORE_CVSTDINL_HPP
|
||||
@@ -0,0 +1,184 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2010-2013, Advanced Micro Devices, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors as is and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the copyright holders or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_DIRECTX_HPP
|
||||
#define OPENCV_CORE_DIRECTX_HPP
|
||||
|
||||
#include "mat.hpp"
|
||||
#include "ocl.hpp"
|
||||
|
||||
#if !defined(__d3d11_h__)
|
||||
struct ID3D11Device;
|
||||
struct ID3D11Texture2D;
|
||||
#endif
|
||||
|
||||
#if !defined(__d3d10_h__)
|
||||
struct ID3D10Device;
|
||||
struct ID3D10Texture2D;
|
||||
#endif
|
||||
|
||||
#if !defined(_D3D9_H_)
|
||||
struct IDirect3DDevice9;
|
||||
struct IDirect3DDevice9Ex;
|
||||
struct IDirect3DSurface9;
|
||||
#endif
|
||||
|
||||
|
||||
namespace cv { namespace directx {
|
||||
|
||||
namespace ocl {
|
||||
using namespace cv::ocl;
|
||||
|
||||
//! @addtogroup core_directx
|
||||
// This section describes OpenCL and DirectX interoperability.
|
||||
//
|
||||
// To enable DirectX support, configure OpenCV using CMake with WITH_DIRECTX=ON . Note, DirectX is
|
||||
// supported only on Windows.
|
||||
//
|
||||
// To use OpenCL functionality you should first initialize OpenCL context from DirectX resource.
|
||||
//
|
||||
//! @{
|
||||
|
||||
// TODO static functions in the Context class
|
||||
//! @brief Creates OpenCL context from D3D11 device
|
||||
//
|
||||
//! @param pD3D11Device - pointer to D3D11 device
|
||||
//! @return Returns reference to OpenCL Context
|
||||
CV_EXPORTS Context& initializeContextFromD3D11Device(ID3D11Device* pD3D11Device);
|
||||
|
||||
//! @brief Creates OpenCL context from D3D10 device
|
||||
//
|
||||
//! @param pD3D10Device - pointer to D3D10 device
|
||||
//! @return Returns reference to OpenCL Context
|
||||
CV_EXPORTS Context& initializeContextFromD3D10Device(ID3D10Device* pD3D10Device);
|
||||
|
||||
//! @brief Creates OpenCL context from Direct3DDevice9Ex device
|
||||
//
|
||||
//! @param pDirect3DDevice9Ex - pointer to Direct3DDevice9Ex device
|
||||
//! @return Returns reference to OpenCL Context
|
||||
CV_EXPORTS Context& initializeContextFromDirect3DDevice9Ex(IDirect3DDevice9Ex* pDirect3DDevice9Ex);
|
||||
|
||||
//! @brief Creates OpenCL context from Direct3DDevice9 device
|
||||
//
|
||||
//! @param pDirect3DDevice9 - pointer to Direct3Device9 device
|
||||
//! @return Returns reference to OpenCL Context
|
||||
CV_EXPORTS Context& initializeContextFromDirect3DDevice9(IDirect3DDevice9* pDirect3DDevice9);
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace cv::directx::ocl
|
||||
|
||||
//! @addtogroup core_directx
|
||||
//! @{
|
||||
|
||||
//! @brief Converts InputArray to ID3D11Texture2D. If destination texture format is DXGI_FORMAT_NV12 then
|
||||
//! input UMat expected to be in BGR format and data will be downsampled and color-converted to NV12.
|
||||
//
|
||||
//! @note Note: Destination texture must be allocated by application. Function does memory copy from src to
|
||||
//! pD3D11Texture2D
|
||||
//
|
||||
//! @param src - source InputArray
|
||||
//! @param pD3D11Texture2D - destination D3D11 texture
|
||||
CV_EXPORTS void convertToD3D11Texture2D(InputArray src, ID3D11Texture2D* pD3D11Texture2D);
|
||||
|
||||
//! @brief Converts ID3D11Texture2D to OutputArray. If input texture format is DXGI_FORMAT_NV12 then
|
||||
//! data will be upsampled and color-converted to BGR format.
|
||||
//
|
||||
//! @note Note: Destination matrix will be re-allocated if it has not enough memory to match texture size.
|
||||
//! function does memory copy from pD3D11Texture2D to dst
|
||||
//
|
||||
//! @param pD3D11Texture2D - source D3D11 texture
|
||||
//! @param dst - destination OutputArray
|
||||
CV_EXPORTS void convertFromD3D11Texture2D(ID3D11Texture2D* pD3D11Texture2D, OutputArray dst);
|
||||
|
||||
//! @brief Converts InputArray to ID3D10Texture2D
|
||||
//
|
||||
//! @note Note: function does memory copy from src to
|
||||
//! pD3D10Texture2D
|
||||
//
|
||||
//! @param src - source InputArray
|
||||
//! @param pD3D10Texture2D - destination D3D10 texture
|
||||
CV_EXPORTS void convertToD3D10Texture2D(InputArray src, ID3D10Texture2D* pD3D10Texture2D);
|
||||
|
||||
//! @brief Converts ID3D10Texture2D to OutputArray
|
||||
//
|
||||
//! @note Note: function does memory copy from pD3D10Texture2D
|
||||
//! to dst
|
||||
//
|
||||
//! @param pD3D10Texture2D - source D3D10 texture
|
||||
//! @param dst - destination OutputArray
|
||||
CV_EXPORTS void convertFromD3D10Texture2D(ID3D10Texture2D* pD3D10Texture2D, OutputArray dst);
|
||||
|
||||
//! @brief Converts InputArray to IDirect3DSurface9
|
||||
//
|
||||
//! @note Note: function does memory copy from src to
|
||||
//! pDirect3DSurface9
|
||||
//
|
||||
//! @param src - source InputArray
|
||||
//! @param pDirect3DSurface9 - destination D3D10 texture
|
||||
//! @param surfaceSharedHandle - shared handle
|
||||
CV_EXPORTS void convertToDirect3DSurface9(InputArray src, IDirect3DSurface9* pDirect3DSurface9, void* surfaceSharedHandle = NULL);
|
||||
|
||||
//! @brief Converts IDirect3DSurface9 to OutputArray
|
||||
//
|
||||
//! @note Note: function does memory copy from pDirect3DSurface9
|
||||
//! to dst
|
||||
//
|
||||
//! @param pDirect3DSurface9 - source D3D10 texture
|
||||
//! @param dst - destination OutputArray
|
||||
//! @param surfaceSharedHandle - shared handle
|
||||
CV_EXPORTS void convertFromDirect3DSurface9(IDirect3DSurface9* pDirect3DSurface9, OutputArray dst, void* surfaceSharedHandle = NULL);
|
||||
|
||||
//! @brief Get OpenCV type from DirectX type
|
||||
//! @param iDXGI_FORMAT - enum DXGI_FORMAT for D3D10/D3D11
|
||||
//! @return OpenCV type or -1 if there is no equivalent
|
||||
CV_EXPORTS int getTypeFromDXGI_FORMAT(const int iDXGI_FORMAT); // enum DXGI_FORMAT for D3D10/D3D11
|
||||
|
||||
//! @brief Get OpenCV type from DirectX type
|
||||
//! @param iD3DFORMAT - enum D3DTYPE for D3D9
|
||||
//! @return OpenCV type or -1 if there is no equivalent
|
||||
CV_EXPORTS int getTypeFromD3DFORMAT(const int iD3DFORMAT); // enum D3DTYPE for D3D9
|
||||
|
||||
//! @}
|
||||
|
||||
} } // namespace cv::directx
|
||||
|
||||
#endif // OPENCV_CORE_DIRECTX_HPP
|
||||
@@ -12,6 +12,7 @@
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -40,13 +41,11 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_CORE_EIGEN_HPP__
|
||||
#define __OPENCV_CORE_EIGEN_HPP__
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifndef OPENCV_CORE_EIGEN_HPP
|
||||
#define OPENCV_CORE_EIGEN_HPP
|
||||
|
||||
#include "opencv2/core/core_c.h"
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
#if defined _MSC_VER && _MSC_VER >= 1200
|
||||
#pragma warning( disable: 4714 ) //__forceinline is not inlined
|
||||
@@ -57,7 +56,10 @@
|
||||
namespace cv
|
||||
{
|
||||
|
||||
template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols>
|
||||
//! @addtogroup core_eigen
|
||||
//! @{
|
||||
|
||||
template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols> static inline
|
||||
void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, Mat& dst )
|
||||
{
|
||||
if( !(src.Flags & Eigen::RowMajorBit) )
|
||||
@@ -74,14 +76,29 @@ void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCo
|
||||
}
|
||||
}
|
||||
|
||||
template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols>
|
||||
// Matx case
|
||||
template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols> static inline
|
||||
void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src,
|
||||
Matx<_Tp, _rows, _cols>& dst )
|
||||
{
|
||||
if( !(src.Flags & Eigen::RowMajorBit) )
|
||||
{
|
||||
dst = Matx<_Tp, _cols, _rows>(static_cast<const _Tp*>(src.data())).t();
|
||||
}
|
||||
else
|
||||
{
|
||||
dst = Matx<_Tp, _rows, _cols>(static_cast<const _Tp*>(src.data()));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols> static inline
|
||||
void cv2eigen( const Mat& src,
|
||||
Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
|
||||
{
|
||||
CV_DbgAssert(src.rows == _rows && src.cols == _cols);
|
||||
if( !(dst.Flags & Eigen::RowMajorBit) )
|
||||
{
|
||||
Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
|
||||
const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
if( src.type() == _dst.type() )
|
||||
transpose(src, _dst);
|
||||
@@ -92,46 +109,42 @@ void cv2eigen( const Mat& src,
|
||||
}
|
||||
else
|
||||
Mat(src.t()).convertTo(_dst, _dst.type());
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
|
||||
const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
src.convertTo(_dst, _dst.type());
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
}
|
||||
|
||||
// Matx case
|
||||
template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols>
|
||||
template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols> static inline
|
||||
void cv2eigen( const Matx<_Tp, _rows, _cols>& src,
|
||||
Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
|
||||
{
|
||||
if( !(dst.Flags & Eigen::RowMajorBit) )
|
||||
{
|
||||
Mat _dst(_cols, _rows, DataType<_Tp>::type,
|
||||
const Mat _dst(_cols, _rows, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
transpose(src, _dst);
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat _dst(_rows, _cols, DataType<_Tp>::type,
|
||||
const Mat _dst(_rows, _cols, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
Mat(src).copyTo(_dst);
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
}
|
||||
|
||||
template<typename _Tp>
|
||||
template<typename _Tp> static inline
|
||||
void cv2eigen( const Mat& src,
|
||||
Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
|
||||
{
|
||||
dst.resize(src.rows, src.cols);
|
||||
if( !(dst.Flags & Eigen::RowMajorBit) )
|
||||
{
|
||||
Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
|
||||
const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
if( src.type() == _dst.type() )
|
||||
transpose(src, _dst);
|
||||
@@ -142,40 +155,36 @@ void cv2eigen( const Mat& src,
|
||||
}
|
||||
else
|
||||
Mat(src.t()).convertTo(_dst, _dst.type());
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
|
||||
const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
src.convertTo(_dst, _dst.type());
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
}
|
||||
|
||||
// Matx case
|
||||
template<typename _Tp, int _rows, int _cols>
|
||||
template<typename _Tp, int _rows, int _cols> static inline
|
||||
void cv2eigen( const Matx<_Tp, _rows, _cols>& src,
|
||||
Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
|
||||
{
|
||||
dst.resize(_rows, _cols);
|
||||
if( !(dst.Flags & Eigen::RowMajorBit) )
|
||||
{
|
||||
Mat _dst(_cols, _rows, DataType<_Tp>::type,
|
||||
const Mat _dst(_cols, _rows, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
transpose(src, _dst);
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat _dst(_rows, _cols, DataType<_Tp>::type,
|
||||
const Mat _dst(_rows, _cols, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
Mat(src).copyTo(_dst);
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
}
|
||||
|
||||
template<typename _Tp>
|
||||
template<typename _Tp> static inline
|
||||
void cv2eigen( const Mat& src,
|
||||
Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
|
||||
{
|
||||
@@ -184,25 +193,23 @@ void cv2eigen( const Mat& src,
|
||||
|
||||
if( !(dst.Flags & Eigen::RowMajorBit) )
|
||||
{
|
||||
Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
|
||||
const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
if( src.type() == _dst.type() )
|
||||
transpose(src, _dst);
|
||||
else
|
||||
Mat(src.t()).convertTo(_dst, _dst.type());
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
|
||||
const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
src.convertTo(_dst, _dst.type());
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
}
|
||||
|
||||
// Matx case
|
||||
template<typename _Tp, int _rows>
|
||||
template<typename _Tp, int _rows> static inline
|
||||
void cv2eigen( const Matx<_Tp, _rows, 1>& src,
|
||||
Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
|
||||
{
|
||||
@@ -210,22 +217,20 @@ void cv2eigen( const Matx<_Tp, _rows, 1>& src,
|
||||
|
||||
if( !(dst.Flags & Eigen::RowMajorBit) )
|
||||
{
|
||||
Mat _dst(1, _rows, DataType<_Tp>::type,
|
||||
const Mat _dst(1, _rows, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
transpose(src, _dst);
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat _dst(_rows, 1, DataType<_Tp>::type,
|
||||
const Mat _dst(_rows, 1, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
src.copyTo(_dst);
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename _Tp>
|
||||
template<typename _Tp> static inline
|
||||
void cv2eigen( const Mat& src,
|
||||
Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
|
||||
{
|
||||
@@ -233,48 +238,43 @@ void cv2eigen( const Mat& src,
|
||||
dst.resize(src.cols);
|
||||
if( !(dst.Flags & Eigen::RowMajorBit) )
|
||||
{
|
||||
Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
|
||||
const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
if( src.type() == _dst.type() )
|
||||
transpose(src, _dst);
|
||||
else
|
||||
Mat(src.t()).convertTo(_dst, _dst.type());
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
|
||||
const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
src.convertTo(_dst, _dst.type());
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
}
|
||||
|
||||
//Matx
|
||||
template<typename _Tp, int _cols>
|
||||
template<typename _Tp, int _cols> static inline
|
||||
void cv2eigen( const Matx<_Tp, 1, _cols>& src,
|
||||
Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
|
||||
{
|
||||
dst.resize(_cols);
|
||||
if( !(dst.Flags & Eigen::RowMajorBit) )
|
||||
{
|
||||
Mat _dst(_cols, 1, DataType<_Tp>::type,
|
||||
const Mat _dst(_cols, 1, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
transpose(src, _dst);
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
else
|
||||
{
|
||||
Mat _dst(1, _cols, DataType<_Tp>::type,
|
||||
const Mat _dst(1, _cols, DataType<_Tp>::type,
|
||||
dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
|
||||
Mat(src).copyTo(_dst);
|
||||
CV_DbgAssert(_dst.data == (uchar*)dst.data());
|
||||
}
|
||||
}
|
||||
|
||||
//! @}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
} // cv
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Copyright (C) 2015, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_FAST_MATH_HPP
|
||||
#define OPENCV_CORE_FAST_MATH_HPP
|
||||
|
||||
#include "opencv2/core/cvdef.h"
|
||||
|
||||
//! @addtogroup core_utils
|
||||
//! @{
|
||||
|
||||
/****************************************************************************************\
|
||||
* fast math *
|
||||
\****************************************************************************************/
|
||||
|
||||
#if defined __BORLANDC__
|
||||
# include <fastmath.h>
|
||||
#elif defined __cplusplus
|
||||
# include <cmath>
|
||||
#else
|
||||
# include <math.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
# include "tegra_round.hpp"
|
||||
#endif
|
||||
|
||||
#if CV_VFP
|
||||
// 1. general scheme
|
||||
#define ARM_ROUND(_value, _asm_string) \
|
||||
int res; \
|
||||
float temp; \
|
||||
(void)temp; \
|
||||
asm(_asm_string : [res] "=r" (res), [temp] "=w" (temp) : [value] "w" (_value)); \
|
||||
return res
|
||||
// 2. version for double
|
||||
#ifdef __clang__
|
||||
#define ARM_ROUND_DBL(value) ARM_ROUND(value, "vcvtr.s32.f64 %[temp], %[value] \n vmov %[res], %[temp]")
|
||||
#else
|
||||
#define ARM_ROUND_DBL(value) ARM_ROUND(value, "vcvtr.s32.f64 %[temp], %P[value] \n vmov %[res], %[temp]")
|
||||
#endif
|
||||
// 3. version for float
|
||||
#define ARM_ROUND_FLT(value) ARM_ROUND(value, "vcvtr.s32.f32 %[temp], %[value]\n vmov %[res], %[temp]")
|
||||
#endif // CV_VFP
|
||||
|
||||
/** @brief Rounds floating-point number to the nearest integer
|
||||
|
||||
@param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the
|
||||
result is not defined.
|
||||
*/
|
||||
CV_INLINE int
|
||||
cvRound( double value )
|
||||
{
|
||||
#if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \
|
||||
&& defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__)
|
||||
__m128d t = _mm_set_sd( value );
|
||||
return _mm_cvtsd_si32(t);
|
||||
#elif defined _MSC_VER && defined _M_IX86
|
||||
int t;
|
||||
__asm
|
||||
{
|
||||
fld value;
|
||||
fistp t;
|
||||
}
|
||||
return t;
|
||||
#elif ((defined _MSC_VER && defined _M_ARM) || defined CV_ICC || \
|
||||
defined __GNUC__) && defined HAVE_TEGRA_OPTIMIZATION
|
||||
TEGRA_ROUND_DBL(value);
|
||||
#elif defined CV_ICC || defined __GNUC__
|
||||
# if CV_VFP
|
||||
ARM_ROUND_DBL(value);
|
||||
# else
|
||||
return (int)lrint(value);
|
||||
# endif
|
||||
#else
|
||||
/* it's ok if round does not comply with IEEE754 standard;
|
||||
the tests should allow +/-1 difference when the tested functions use round */
|
||||
return (int)(value + (value >= 0 ? 0.5 : -0.5));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/** @brief Rounds floating-point number to the nearest integer not larger than the original.
|
||||
|
||||
The function computes an integer i such that:
|
||||
\f[i \le \texttt{value} < i+1\f]
|
||||
@param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the
|
||||
result is not defined.
|
||||
*/
|
||||
CV_INLINE int cvFloor( double value )
|
||||
{
|
||||
#if (defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__)
|
||||
__m128d t = _mm_set_sd( value );
|
||||
int i = _mm_cvtsd_si32(t);
|
||||
return i - _mm_movemask_pd(_mm_cmplt_sd(t, _mm_cvtsi32_sd(t,i)));
|
||||
#elif defined __GNUC__
|
||||
int i = (int)value;
|
||||
return i - (i > value);
|
||||
#else
|
||||
int i = cvRound(value);
|
||||
float diff = (float)(value - i);
|
||||
return i - (diff < 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** @brief Rounds floating-point number to the nearest integer not smaller than the original.
|
||||
|
||||
The function computes an integer i such that:
|
||||
\f[i \le \texttt{value} < i+1\f]
|
||||
@param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the
|
||||
result is not defined.
|
||||
*/
|
||||
CV_INLINE int cvCeil( double value )
|
||||
{
|
||||
#if (defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__&& !defined __APPLE__)) && !defined(__CUDACC__)
|
||||
__m128d t = _mm_set_sd( value );
|
||||
int i = _mm_cvtsd_si32(t);
|
||||
return i + _mm_movemask_pd(_mm_cmplt_sd(_mm_cvtsi32_sd(t,i), t));
|
||||
#elif defined __GNUC__
|
||||
int i = (int)value;
|
||||
return i + (i < value);
|
||||
#else
|
||||
int i = cvRound(value);
|
||||
float diff = (float)(i - value);
|
||||
return i + (diff < 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** @brief Determines if the argument is Not A Number.
|
||||
|
||||
@param value The input floating-point value
|
||||
|
||||
The function returns 1 if the argument is Not A Number (as defined by IEEE754 standard), 0
|
||||
otherwise. */
|
||||
CV_INLINE int cvIsNaN( double value )
|
||||
{
|
||||
Cv64suf ieee754;
|
||||
ieee754.f = value;
|
||||
return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) +
|
||||
((unsigned)ieee754.u != 0) > 0x7ff00000;
|
||||
}
|
||||
|
||||
/** @brief Determines if the argument is Infinity.
|
||||
|
||||
@param value The input floating-point value
|
||||
|
||||
The function returns 1 if the argument is a plus or minus infinity (as defined by IEEE754 standard)
|
||||
and 0 otherwise. */
|
||||
CV_INLINE int cvIsInf( double value )
|
||||
{
|
||||
Cv64suf ieee754;
|
||||
ieee754.f = value;
|
||||
return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 &&
|
||||
(unsigned)ieee754.u == 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
/** @overload */
|
||||
CV_INLINE int cvRound(float value)
|
||||
{
|
||||
#if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ && \
|
||||
defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__)
|
||||
__m128 t = _mm_set_ss( value );
|
||||
return _mm_cvtss_si32(t);
|
||||
#elif defined _MSC_VER && defined _M_IX86
|
||||
int t;
|
||||
__asm
|
||||
{
|
||||
fld value;
|
||||
fistp t;
|
||||
}
|
||||
return t;
|
||||
#elif ((defined _MSC_VER && defined _M_ARM) || defined CV_ICC || \
|
||||
defined __GNUC__) && defined HAVE_TEGRA_OPTIMIZATION
|
||||
TEGRA_ROUND_FLT(value);
|
||||
#elif defined CV_ICC || defined __GNUC__
|
||||
# if CV_VFP
|
||||
ARM_ROUND_FLT(value);
|
||||
# else
|
||||
return (int)lrintf(value);
|
||||
# endif
|
||||
#else
|
||||
/* it's ok if round does not comply with IEEE754 standard;
|
||||
the tests should allow +/-1 difference when the tested functions use round */
|
||||
return (int)(value + (value >= 0 ? 0.5f : -0.5f));
|
||||
#endif
|
||||
}
|
||||
|
||||
/** @overload */
|
||||
CV_INLINE int cvRound( int value )
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/** @overload */
|
||||
CV_INLINE int cvFloor( float value )
|
||||
{
|
||||
#if (defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__)
|
||||
__m128 t = _mm_set_ss( value );
|
||||
int i = _mm_cvtss_si32(t);
|
||||
return i - _mm_movemask_ps(_mm_cmplt_ss(t, _mm_cvtsi32_ss(t,i)));
|
||||
#elif defined __GNUC__
|
||||
int i = (int)value;
|
||||
return i - (i > value);
|
||||
#else
|
||||
int i = cvRound(value);
|
||||
float diff = (float)(value - i);
|
||||
return i - (diff < 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** @overload */
|
||||
CV_INLINE int cvFloor( int value )
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/** @overload */
|
||||
CV_INLINE int cvCeil( float value )
|
||||
{
|
||||
#if (defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__&& !defined __APPLE__)) && !defined(__CUDACC__)
|
||||
__m128 t = _mm_set_ss( value );
|
||||
int i = _mm_cvtss_si32(t);
|
||||
return i + _mm_movemask_ps(_mm_cmplt_ss(_mm_cvtsi32_ss(t,i), t));
|
||||
#elif defined __GNUC__
|
||||
int i = (int)value;
|
||||
return i + (i < value);
|
||||
#else
|
||||
int i = cvRound(value);
|
||||
float diff = (float)(i - value);
|
||||
return i + (diff < 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/** @overload */
|
||||
CV_INLINE int cvCeil( int value )
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/** @overload */
|
||||
CV_INLINE int cvIsNaN( float value )
|
||||
{
|
||||
Cv32suf ieee754;
|
||||
ieee754.f = value;
|
||||
return (ieee754.u & 0x7fffffff) > 0x7f800000;
|
||||
}
|
||||
|
||||
/** @overload */
|
||||
CV_INLINE int cvIsInf( float value )
|
||||
{
|
||||
Cv32suf ieee754;
|
||||
ieee754.f = value;
|
||||
return (ieee754.u & 0x7fffffff) == 0x7f800000;
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
//! @} core_utils
|
||||
|
||||
#endif
|
||||
@@ -1,562 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_GPUMAT_HPP__
|
||||
#define __OPENCV_GPUMAT_HPP__
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/cuda_devptrs.hpp"
|
||||
|
||||
namespace cv { namespace gpu
|
||||
{
|
||||
//////////////////////////////// Initialization & Info ////////////////////////
|
||||
|
||||
//! This is the only function that do not throw exceptions if the library is compiled without Cuda.
|
||||
CV_EXPORTS int getCudaEnabledDeviceCount();
|
||||
|
||||
//! Functions below throw cv::Expception if the library is compiled without Cuda.
|
||||
|
||||
CV_EXPORTS void setDevice(int device);
|
||||
CV_EXPORTS int getDevice();
|
||||
|
||||
//! Explicitly destroys and cleans up all resources associated with the current device in the current process.
|
||||
//! Any subsequent API call to this device will reinitialize the device.
|
||||
CV_EXPORTS void resetDevice();
|
||||
|
||||
enum FeatureSet
|
||||
{
|
||||
FEATURE_SET_COMPUTE_10 = 10,
|
||||
FEATURE_SET_COMPUTE_11 = 11,
|
||||
FEATURE_SET_COMPUTE_12 = 12,
|
||||
FEATURE_SET_COMPUTE_13 = 13,
|
||||
FEATURE_SET_COMPUTE_20 = 20,
|
||||
FEATURE_SET_COMPUTE_21 = 21,
|
||||
FEATURE_SET_COMPUTE_30 = 30,
|
||||
FEATURE_SET_COMPUTE_35 = 35,
|
||||
|
||||
GLOBAL_ATOMICS = FEATURE_SET_COMPUTE_11,
|
||||
SHARED_ATOMICS = FEATURE_SET_COMPUTE_12,
|
||||
NATIVE_DOUBLE = FEATURE_SET_COMPUTE_13,
|
||||
WARP_SHUFFLE_FUNCTIONS = FEATURE_SET_COMPUTE_30,
|
||||
DYNAMIC_PARALLELISM = FEATURE_SET_COMPUTE_35
|
||||
};
|
||||
|
||||
// Checks whether current device supports the given feature
|
||||
CV_EXPORTS bool deviceSupports(FeatureSet feature_set);
|
||||
|
||||
// Gives information about what GPU archs this OpenCV GPU module was
|
||||
// compiled for
|
||||
class CV_EXPORTS TargetArchs
|
||||
{
|
||||
public:
|
||||
static bool builtWith(FeatureSet feature_set);
|
||||
static bool has(int major, int minor);
|
||||
static bool hasPtx(int major, int minor);
|
||||
static bool hasBin(int major, int minor);
|
||||
static bool hasEqualOrLessPtx(int major, int minor);
|
||||
static bool hasEqualOrGreater(int major, int minor);
|
||||
static bool hasEqualOrGreaterPtx(int major, int minor);
|
||||
static bool hasEqualOrGreaterBin(int major, int minor);
|
||||
private:
|
||||
TargetArchs();
|
||||
};
|
||||
|
||||
// Gives information about the given GPU
|
||||
class CV_EXPORTS DeviceInfo
|
||||
{
|
||||
public:
|
||||
// Creates DeviceInfo object for the current GPU
|
||||
DeviceInfo() : device_id_(getDevice()) { query(); }
|
||||
|
||||
// Creates DeviceInfo object for the given GPU
|
||||
DeviceInfo(int device_id) : device_id_(device_id) { query(); }
|
||||
|
||||
std::string name() const { return name_; }
|
||||
|
||||
// Return compute capability versions
|
||||
int majorVersion() const { return majorVersion_; }
|
||||
int minorVersion() const { return minorVersion_; }
|
||||
|
||||
int multiProcessorCount() const { return multi_processor_count_; }
|
||||
|
||||
size_t sharedMemPerBlock() const;
|
||||
|
||||
void queryMemory(size_t& totalMemory, size_t& freeMemory) const;
|
||||
size_t freeMemory() const;
|
||||
size_t totalMemory() const;
|
||||
|
||||
// Checks whether device supports the given feature
|
||||
bool supports(FeatureSet feature_set) const;
|
||||
|
||||
// Checks whether the GPU module can be run on the given device
|
||||
bool isCompatible() const;
|
||||
|
||||
int deviceID() const { return device_id_; }
|
||||
|
||||
private:
|
||||
void query();
|
||||
|
||||
int device_id_;
|
||||
|
||||
std::string name_;
|
||||
int multi_processor_count_;
|
||||
int majorVersion_;
|
||||
int minorVersion_;
|
||||
};
|
||||
|
||||
CV_EXPORTS void printCudaDeviceInfo(int device);
|
||||
CV_EXPORTS void printShortCudaDeviceInfo(int device);
|
||||
|
||||
//////////////////////////////// GpuMat ///////////////////////////////
|
||||
|
||||
//! Smart pointer for GPU memory with reference counting. Its interface is mostly similar with cv::Mat.
|
||||
class CV_EXPORTS GpuMat
|
||||
{
|
||||
public:
|
||||
//! default constructor
|
||||
GpuMat();
|
||||
|
||||
//! constructs GpuMatrix of the specified size and type (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
|
||||
GpuMat(int rows, int cols, int type);
|
||||
GpuMat(Size size, int type);
|
||||
|
||||
//! constucts GpuMatrix and fills it with the specified value _s.
|
||||
GpuMat(int rows, int cols, int type, Scalar s);
|
||||
GpuMat(Size size, int type, Scalar s);
|
||||
|
||||
//! copy constructor
|
||||
GpuMat(const GpuMat& m);
|
||||
|
||||
//! constructor for GpuMatrix headers pointing to user-allocated data
|
||||
GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP);
|
||||
GpuMat(Size size, int type, void* data, size_t step = Mat::AUTO_STEP);
|
||||
|
||||
//! creates a matrix header for a part of the bigger matrix
|
||||
GpuMat(const GpuMat& m, Range rowRange, Range colRange);
|
||||
GpuMat(const GpuMat& m, Rect roi);
|
||||
|
||||
//! builds GpuMat from Mat. Perfom blocking upload to device.
|
||||
explicit GpuMat(const Mat& m);
|
||||
|
||||
//! destructor - calls release()
|
||||
~GpuMat();
|
||||
|
||||
//! assignment operators
|
||||
GpuMat& operator = (const GpuMat& m);
|
||||
|
||||
//! pefroms blocking upload data to GpuMat.
|
||||
void upload(const Mat& m);
|
||||
|
||||
//! downloads data from device to host memory. Blocking calls.
|
||||
void download(Mat& m) const;
|
||||
|
||||
//! returns a new GpuMatrix header for the specified row
|
||||
GpuMat row(int y) const;
|
||||
//! returns a new GpuMatrix header for the specified column
|
||||
GpuMat col(int x) const;
|
||||
//! ... for the specified row span
|
||||
GpuMat rowRange(int startrow, int endrow) const;
|
||||
GpuMat rowRange(Range r) const;
|
||||
//! ... for the specified column span
|
||||
GpuMat colRange(int startcol, int endcol) const;
|
||||
GpuMat colRange(Range r) const;
|
||||
|
||||
//! returns deep copy of the GpuMatrix, i.e. the data is copied
|
||||
GpuMat clone() const;
|
||||
//! copies the GpuMatrix content to "m".
|
||||
// It calls m.create(this->size(), this->type()).
|
||||
void copyTo(GpuMat& m) const;
|
||||
//! copies those GpuMatrix elements to "m" that are marked with non-zero mask elements.
|
||||
void copyTo(GpuMat& m, const GpuMat& mask) const;
|
||||
//! converts GpuMatrix to another datatype with optional scalng. See cvConvertScale.
|
||||
void convertTo(GpuMat& m, int rtype, double alpha = 1, double beta = 0) const;
|
||||
|
||||
void assignTo(GpuMat& m, int type=-1) const;
|
||||
|
||||
//! sets every GpuMatrix element to s
|
||||
GpuMat& operator = (Scalar s);
|
||||
//! sets some of the GpuMatrix elements to s, according to the mask
|
||||
GpuMat& setTo(Scalar s, const GpuMat& mask = GpuMat());
|
||||
//! creates alternative GpuMatrix header for the same data, with different
|
||||
// number of channels and/or different number of rows. see cvReshape.
|
||||
GpuMat reshape(int cn, int rows = 0) const;
|
||||
|
||||
//! allocates new GpuMatrix data unless the GpuMatrix already has specified size and type.
|
||||
// previous data is unreferenced if needed.
|
||||
void create(int rows, int cols, int type);
|
||||
void create(Size size, int type);
|
||||
//! decreases reference counter;
|
||||
// deallocate the data when reference counter reaches 0.
|
||||
void release();
|
||||
|
||||
//! swaps with other smart pointer
|
||||
void swap(GpuMat& mat);
|
||||
|
||||
//! locates GpuMatrix header within a parent GpuMatrix. See below
|
||||
void locateROI(Size& wholeSize, Point& ofs) const;
|
||||
//! moves/resizes the current GpuMatrix ROI inside the parent GpuMatrix.
|
||||
GpuMat& adjustROI(int dtop, int dbottom, int dleft, int dright);
|
||||
//! extracts a rectangular sub-GpuMatrix
|
||||
// (this is a generalized form of row, rowRange etc.)
|
||||
GpuMat operator()(Range rowRange, Range colRange) const;
|
||||
GpuMat operator()(Rect roi) const;
|
||||
|
||||
//! returns true iff the GpuMatrix data is continuous
|
||||
// (i.e. when there are no gaps between successive rows).
|
||||
// similar to CV_IS_GpuMat_CONT(cvGpuMat->type)
|
||||
bool isContinuous() const;
|
||||
//! returns element size in bytes,
|
||||
// similar to CV_ELEM_SIZE(cvMat->type)
|
||||
size_t elemSize() const;
|
||||
//! returns the size of element channel in bytes.
|
||||
size_t elemSize1() const;
|
||||
//! returns element type, similar to CV_MAT_TYPE(cvMat->type)
|
||||
int type() const;
|
||||
//! returns element type, similar to CV_MAT_DEPTH(cvMat->type)
|
||||
int depth() const;
|
||||
//! returns element type, similar to CV_MAT_CN(cvMat->type)
|
||||
int channels() const;
|
||||
//! returns step/elemSize1()
|
||||
size_t step1() const;
|
||||
//! returns GpuMatrix size:
|
||||
// width == number of columns, height == number of rows
|
||||
Size size() const;
|
||||
//! returns true if GpuMatrix data is NULL
|
||||
bool empty() const;
|
||||
|
||||
//! returns pointer to y-th row
|
||||
uchar* ptr(int y = 0);
|
||||
const uchar* ptr(int y = 0) const;
|
||||
|
||||
//! template version of the above method
|
||||
template<typename _Tp> _Tp* ptr(int y = 0);
|
||||
template<typename _Tp> const _Tp* ptr(int y = 0) const;
|
||||
|
||||
template <typename _Tp> operator PtrStepSz<_Tp>() const;
|
||||
template <typename _Tp> operator PtrStep<_Tp>() const;
|
||||
|
||||
// Deprecated function
|
||||
__CV_GPU_DEPR_BEFORE__ template <typename _Tp> operator DevMem2D_<_Tp>() const __CV_GPU_DEPR_AFTER__;
|
||||
__CV_GPU_DEPR_BEFORE__ template <typename _Tp> operator PtrStep_<_Tp>() const __CV_GPU_DEPR_AFTER__;
|
||||
#undef __CV_GPU_DEPR_BEFORE__
|
||||
#undef __CV_GPU_DEPR_AFTER__
|
||||
|
||||
/*! includes several bit-fields:
|
||||
- the magic signature
|
||||
- continuity flag
|
||||
- depth
|
||||
- number of channels
|
||||
*/
|
||||
int flags;
|
||||
|
||||
//! the number of rows and columns
|
||||
int rows, cols;
|
||||
|
||||
//! a distance between successive rows in bytes; includes the gap if any
|
||||
size_t step;
|
||||
|
||||
//! pointer to the data
|
||||
uchar* data;
|
||||
|
||||
//! pointer to the reference counter;
|
||||
// when GpuMatrix points to user-allocated data, the pointer is NULL
|
||||
int* refcount;
|
||||
|
||||
//! helper fields used in locateROI and adjustROI
|
||||
uchar* datastart;
|
||||
uchar* dataend;
|
||||
};
|
||||
|
||||
//! Creates continuous GPU matrix
|
||||
CV_EXPORTS void createContinuous(int rows, int cols, int type, GpuMat& m);
|
||||
CV_EXPORTS GpuMat createContinuous(int rows, int cols, int type);
|
||||
CV_EXPORTS void createContinuous(Size size, int type, GpuMat& m);
|
||||
CV_EXPORTS GpuMat createContinuous(Size size, int type);
|
||||
|
||||
//! Ensures that size of the given matrix is not less than (rows, cols) size
|
||||
//! and matrix type is match specified one too
|
||||
CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, GpuMat& m);
|
||||
CV_EXPORTS void ensureSizeIsEnough(Size size, int type, GpuMat& m);
|
||||
|
||||
CV_EXPORTS GpuMat allocMatFromBuf(int rows, int cols, int type, GpuMat &mat);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Error handling
|
||||
|
||||
CV_EXPORTS void error(const char* error_string, const char* file, const int line, const char* func = "");
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline GpuMat::GpuMat()
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline GpuMat::GpuMat(int rows_, int cols_, int type_)
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0)
|
||||
{
|
||||
if (rows_ > 0 && cols_ > 0)
|
||||
create(rows_, cols_, type_);
|
||||
}
|
||||
|
||||
inline GpuMat::GpuMat(Size size_, int type_)
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0)
|
||||
{
|
||||
if (size_.height > 0 && size_.width > 0)
|
||||
create(size_.height, size_.width, type_);
|
||||
}
|
||||
|
||||
inline GpuMat::GpuMat(int rows_, int cols_, int type_, Scalar s_)
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0)
|
||||
{
|
||||
if (rows_ > 0 && cols_ > 0)
|
||||
{
|
||||
create(rows_, cols_, type_);
|
||||
setTo(s_);
|
||||
}
|
||||
}
|
||||
|
||||
inline GpuMat::GpuMat(Size size_, int type_, Scalar s_)
|
||||
: flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0)
|
||||
{
|
||||
if (size_.height > 0 && size_.width > 0)
|
||||
{
|
||||
create(size_.height, size_.width, type_);
|
||||
setTo(s_);
|
||||
}
|
||||
}
|
||||
|
||||
inline GpuMat::~GpuMat()
|
||||
{
|
||||
release();
|
||||
}
|
||||
|
||||
inline GpuMat GpuMat::clone() const
|
||||
{
|
||||
GpuMat m;
|
||||
copyTo(m);
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void GpuMat::assignTo(GpuMat& m, int _type) const
|
||||
{
|
||||
if (_type < 0)
|
||||
m = *this;
|
||||
else
|
||||
convertTo(m, _type);
|
||||
}
|
||||
|
||||
inline size_t GpuMat::step1() const
|
||||
{
|
||||
return step / elemSize1();
|
||||
}
|
||||
|
||||
inline bool GpuMat::empty() const
|
||||
{
|
||||
return data == 0;
|
||||
}
|
||||
|
||||
template<typename _Tp> inline _Tp* GpuMat::ptr(int y)
|
||||
{
|
||||
return (_Tp*)ptr(y);
|
||||
}
|
||||
|
||||
template<typename _Tp> inline const _Tp* GpuMat::ptr(int y) const
|
||||
{
|
||||
return (const _Tp*)ptr(y);
|
||||
}
|
||||
|
||||
inline void swap(GpuMat& a, GpuMat& b)
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
inline GpuMat GpuMat::row(int y) const
|
||||
{
|
||||
return GpuMat(*this, Range(y, y+1), Range::all());
|
||||
}
|
||||
|
||||
inline GpuMat GpuMat::col(int x) const
|
||||
{
|
||||
return GpuMat(*this, Range::all(), Range(x, x+1));
|
||||
}
|
||||
|
||||
inline GpuMat GpuMat::rowRange(int startrow, int endrow) const
|
||||
{
|
||||
return GpuMat(*this, Range(startrow, endrow), Range::all());
|
||||
}
|
||||
|
||||
inline GpuMat GpuMat::rowRange(Range r) const
|
||||
{
|
||||
return GpuMat(*this, r, Range::all());
|
||||
}
|
||||
|
||||
inline GpuMat GpuMat::colRange(int startcol, int endcol) const
|
||||
{
|
||||
return GpuMat(*this, Range::all(), Range(startcol, endcol));
|
||||
}
|
||||
|
||||
inline GpuMat GpuMat::colRange(Range r) const
|
||||
{
|
||||
return GpuMat(*this, Range::all(), r);
|
||||
}
|
||||
|
||||
inline void GpuMat::create(Size size_, int type_)
|
||||
{
|
||||
create(size_.height, size_.width, type_);
|
||||
}
|
||||
|
||||
inline GpuMat GpuMat::operator()(Range _rowRange, Range _colRange) const
|
||||
{
|
||||
return GpuMat(*this, _rowRange, _colRange);
|
||||
}
|
||||
|
||||
inline GpuMat GpuMat::operator()(Rect roi) const
|
||||
{
|
||||
return GpuMat(*this, roi);
|
||||
}
|
||||
|
||||
inline bool GpuMat::isContinuous() const
|
||||
{
|
||||
return (flags & Mat::CONTINUOUS_FLAG) != 0;
|
||||
}
|
||||
|
||||
inline size_t GpuMat::elemSize() const
|
||||
{
|
||||
return CV_ELEM_SIZE(flags);
|
||||
}
|
||||
|
||||
inline size_t GpuMat::elemSize1() const
|
||||
{
|
||||
return CV_ELEM_SIZE1(flags);
|
||||
}
|
||||
|
||||
inline int GpuMat::type() const
|
||||
{
|
||||
return CV_MAT_TYPE(flags);
|
||||
}
|
||||
|
||||
inline int GpuMat::depth() const
|
||||
{
|
||||
return CV_MAT_DEPTH(flags);
|
||||
}
|
||||
|
||||
inline int GpuMat::channels() const
|
||||
{
|
||||
return CV_MAT_CN(flags);
|
||||
}
|
||||
|
||||
inline Size GpuMat::size() const
|
||||
{
|
||||
return Size(cols, rows);
|
||||
}
|
||||
|
||||
inline uchar* GpuMat::ptr(int y)
|
||||
{
|
||||
CV_DbgAssert((unsigned)y < (unsigned)rows);
|
||||
return data + step * y;
|
||||
}
|
||||
|
||||
inline const uchar* GpuMat::ptr(int y) const
|
||||
{
|
||||
CV_DbgAssert((unsigned)y < (unsigned)rows);
|
||||
return data + step * y;
|
||||
}
|
||||
|
||||
inline GpuMat& GpuMat::operator = (Scalar s)
|
||||
{
|
||||
setTo(s);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <class T> inline GpuMat::operator PtrStepSz<T>() const
|
||||
{
|
||||
return PtrStepSz<T>(rows, cols, (T*)data, step);
|
||||
}
|
||||
|
||||
template <class T> inline GpuMat::operator PtrStep<T>() const
|
||||
{
|
||||
return PtrStep<T>((T*)data, step);
|
||||
}
|
||||
|
||||
template <class T> inline GpuMat::operator DevMem2D_<T>() const
|
||||
{
|
||||
return DevMem2D_<T>(rows, cols, (T*)data, step);
|
||||
}
|
||||
|
||||
template <class T> inline GpuMat::operator PtrStep_<T>() const
|
||||
{
|
||||
return PtrStep_<T>(static_cast< DevMem2D_<T> >(*this));
|
||||
}
|
||||
|
||||
inline GpuMat createContinuous(int rows, int cols, int type)
|
||||
{
|
||||
GpuMat m;
|
||||
createContinuous(rows, cols, type, m);
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void createContinuous(Size size, int type, GpuMat& m)
|
||||
{
|
||||
createContinuous(size.height, size.width, type, m);
|
||||
}
|
||||
|
||||
inline GpuMat createContinuous(Size size, int type)
|
||||
{
|
||||
GpuMat m;
|
||||
createContinuous(size, type, m);
|
||||
return m;
|
||||
}
|
||||
|
||||
inline void ensureSizeIsEnough(Size size, int type, GpuMat& m)
|
||||
{
|
||||
ensureSizeIsEnough(size.height, size.width, type, m);
|
||||
}
|
||||
}}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __OPENCV_GPUMAT_HPP__
|
||||
@@ -0,0 +1,250 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Copyright (C) 2015, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_HAL_HPP
|
||||
#define OPENCV_HAL_HPP
|
||||
|
||||
#include "opencv2/core/cvdef.h"
|
||||
#include "opencv2/core/cvstd.hpp"
|
||||
#include "opencv2/core/hal/interface.h"
|
||||
|
||||
namespace cv { namespace hal {
|
||||
|
||||
//! @addtogroup core_hal_functions
|
||||
//! @{
|
||||
|
||||
CV_EXPORTS int normHamming(const uchar* a, int n);
|
||||
CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n);
|
||||
|
||||
CV_EXPORTS int normHamming(const uchar* a, int n, int cellSize);
|
||||
CV_EXPORTS int normHamming(const uchar* a, const uchar* b, int n, int cellSize);
|
||||
|
||||
CV_EXPORTS int LU32f(float* A, size_t astep, int m, float* b, size_t bstep, int n);
|
||||
CV_EXPORTS int LU64f(double* A, size_t astep, int m, double* b, size_t bstep, int n);
|
||||
CV_EXPORTS bool Cholesky32f(float* A, size_t astep, int m, float* b, size_t bstep, int n);
|
||||
CV_EXPORTS bool Cholesky64f(double* A, size_t astep, int m, double* b, size_t bstep, int n);
|
||||
CV_EXPORTS void SVD32f(float* At, size_t astep, float* W, float* U, size_t ustep, float* Vt, size_t vstep, int m, int n, int flags);
|
||||
CV_EXPORTS void SVD64f(double* At, size_t astep, double* W, double* U, size_t ustep, double* Vt, size_t vstep, int m, int n, int flags);
|
||||
CV_EXPORTS int QR32f(float* A, size_t astep, int m, int n, int k, float* b, size_t bstep, float* hFactors);
|
||||
CV_EXPORTS int QR64f(double* A, size_t astep, int m, int n, int k, double* b, size_t bstep, double* hFactors);
|
||||
|
||||
CV_EXPORTS void gemm32f(const float* src1, size_t src1_step, const float* src2, size_t src2_step,
|
||||
float alpha, const float* src3, size_t src3_step, float beta, float* dst, size_t dst_step,
|
||||
int m_a, int n_a, int n_d, int flags);
|
||||
CV_EXPORTS void gemm64f(const double* src1, size_t src1_step, const double* src2, size_t src2_step,
|
||||
double alpha, const double* src3, size_t src3_step, double beta, double* dst, size_t dst_step,
|
||||
int m_a, int n_a, int n_d, int flags);
|
||||
CV_EXPORTS void gemm32fc(const float* src1, size_t src1_step, const float* src2, size_t src2_step,
|
||||
float alpha, const float* src3, size_t src3_step, float beta, float* dst, size_t dst_step,
|
||||
int m_a, int n_a, int n_d, int flags);
|
||||
CV_EXPORTS void gemm64fc(const double* src1, size_t src1_step, const double* src2, size_t src2_step,
|
||||
double alpha, const double* src3, size_t src3_step, double beta, double* dst, size_t dst_step,
|
||||
int m_a, int n_a, int n_d, int flags);
|
||||
|
||||
CV_EXPORTS int normL1_(const uchar* a, const uchar* b, int n);
|
||||
CV_EXPORTS float normL1_(const float* a, const float* b, int n);
|
||||
CV_EXPORTS float normL2Sqr_(const float* a, const float* b, int n);
|
||||
|
||||
CV_EXPORTS void exp32f(const float* src, float* dst, int n);
|
||||
CV_EXPORTS void exp64f(const double* src, double* dst, int n);
|
||||
CV_EXPORTS void log32f(const float* src, float* dst, int n);
|
||||
CV_EXPORTS void log64f(const double* src, double* dst, int n);
|
||||
|
||||
CV_EXPORTS void fastAtan32f(const float* y, const float* x, float* dst, int n, bool angleInDegrees);
|
||||
CV_EXPORTS void fastAtan64f(const double* y, const double* x, double* dst, int n, bool angleInDegrees);
|
||||
CV_EXPORTS void magnitude32f(const float* x, const float* y, float* dst, int n);
|
||||
CV_EXPORTS void magnitude64f(const double* x, const double* y, double* dst, int n);
|
||||
CV_EXPORTS void sqrt32f(const float* src, float* dst, int len);
|
||||
CV_EXPORTS void sqrt64f(const double* src, double* dst, int len);
|
||||
CV_EXPORTS void invSqrt32f(const float* src, float* dst, int len);
|
||||
CV_EXPORTS void invSqrt64f(const double* src, double* dst, int len);
|
||||
|
||||
CV_EXPORTS void split8u(const uchar* src, uchar** dst, int len, int cn );
|
||||
CV_EXPORTS void split16u(const ushort* src, ushort** dst, int len, int cn );
|
||||
CV_EXPORTS void split32s(const int* src, int** dst, int len, int cn );
|
||||
CV_EXPORTS void split64s(const int64* src, int64** dst, int len, int cn );
|
||||
|
||||
CV_EXPORTS void merge8u(const uchar** src, uchar* dst, int len, int cn );
|
||||
CV_EXPORTS void merge16u(const ushort** src, ushort* dst, int len, int cn );
|
||||
CV_EXPORTS void merge32s(const int** src, int* dst, int len, int cn );
|
||||
CV_EXPORTS void merge64s(const int64** src, int64* dst, int len, int cn );
|
||||
|
||||
CV_EXPORTS void add8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void add8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void add16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void add16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void add32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void add32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void add64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* );
|
||||
|
||||
CV_EXPORTS void sub8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void sub8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void sub16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void sub16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void sub32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void sub32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void sub64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* );
|
||||
|
||||
CV_EXPORTS void max8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void max8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void max16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void max16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void max32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void max32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void max64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* );
|
||||
|
||||
CV_EXPORTS void min8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void min8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void min16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void min16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void min32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void min32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void min64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* );
|
||||
|
||||
CV_EXPORTS void absdiff8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void absdiff8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void absdiff16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void absdiff16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void absdiff32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void absdiff32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void absdiff64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* );
|
||||
|
||||
CV_EXPORTS void and8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void or8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void xor8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* );
|
||||
CV_EXPORTS void not8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* );
|
||||
|
||||
CV_EXPORTS void cmp8u(const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop);
|
||||
CV_EXPORTS void cmp8s(const schar* src1, size_t step1, const schar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop);
|
||||
CV_EXPORTS void cmp16u(const ushort* src1, size_t step1, const ushort* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop);
|
||||
CV_EXPORTS void cmp16s(const short* src1, size_t step1, const short* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop);
|
||||
CV_EXPORTS void cmp32s(const int* src1, size_t step1, const int* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop);
|
||||
CV_EXPORTS void cmp32f(const float* src1, size_t step1, const float* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop);
|
||||
CV_EXPORTS void cmp64f(const double* src1, size_t step1, const double* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _cmpop);
|
||||
|
||||
CV_EXPORTS void mul8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void mul8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void mul16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void mul16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void mul32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void mul32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void mul64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scale);
|
||||
|
||||
CV_EXPORTS void div8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void div8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void div16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void div16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void div32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void div32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void div64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scale);
|
||||
|
||||
CV_EXPORTS void recip8u( const uchar *, size_t, const uchar * src2, size_t step2, uchar* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void recip8s( const schar *, size_t, const schar * src2, size_t step2, schar* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void recip16u( const ushort *, size_t, const ushort * src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void recip16s( const short *, size_t, const short * src2, size_t step2, short* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void recip32s( const int *, size_t, const int * src2, size_t step2, int* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void recip32f( const float *, size_t, const float * src2, size_t step2, float* dst, size_t step, int width, int height, void* scale);
|
||||
CV_EXPORTS void recip64f( const double *, size_t, const double * src2, size_t step2, double* dst, size_t step, int width, int height, void* scale);
|
||||
|
||||
CV_EXPORTS void addWeighted8u( const uchar* src1, size_t step1, const uchar* src2, size_t step2, uchar* dst, size_t step, int width, int height, void* _scalars );
|
||||
CV_EXPORTS void addWeighted8s( const schar* src1, size_t step1, const schar* src2, size_t step2, schar* dst, size_t step, int width, int height, void* scalars );
|
||||
CV_EXPORTS void addWeighted16u( const ushort* src1, size_t step1, const ushort* src2, size_t step2, ushort* dst, size_t step, int width, int height, void* scalars );
|
||||
CV_EXPORTS void addWeighted16s( const short* src1, size_t step1, const short* src2, size_t step2, short* dst, size_t step, int width, int height, void* scalars );
|
||||
CV_EXPORTS void addWeighted32s( const int* src1, size_t step1, const int* src2, size_t step2, int* dst, size_t step, int width, int height, void* scalars );
|
||||
CV_EXPORTS void addWeighted32f( const float* src1, size_t step1, const float* src2, size_t step2, float* dst, size_t step, int width, int height, void* scalars );
|
||||
CV_EXPORTS void addWeighted64f( const double* src1, size_t step1, const double* src2, size_t step2, double* dst, size_t step, int width, int height, void* scalars );
|
||||
|
||||
struct CV_EXPORTS DFT1D
|
||||
{
|
||||
static Ptr<DFT1D> create(int len, int count, int depth, int flags, bool * useBuffer = 0);
|
||||
virtual void apply(const uchar *src, uchar *dst) = 0;
|
||||
virtual ~DFT1D() {}
|
||||
};
|
||||
|
||||
struct CV_EXPORTS DFT2D
|
||||
{
|
||||
static Ptr<DFT2D> create(int width, int height, int depth,
|
||||
int src_channels, int dst_channels,
|
||||
int flags, int nonzero_rows = 0);
|
||||
virtual void apply(const uchar *src_data, size_t src_step, uchar *dst_data, size_t dst_step) = 0;
|
||||
virtual ~DFT2D() {}
|
||||
};
|
||||
|
||||
struct CV_EXPORTS DCT2D
|
||||
{
|
||||
static Ptr<DCT2D> create(int width, int height, int depth, int flags);
|
||||
virtual void apply(const uchar *src_data, size_t src_step, uchar *dst_data, size_t dst_step) = 0;
|
||||
virtual ~DCT2D() {}
|
||||
};
|
||||
|
||||
//! @} core_hal
|
||||
|
||||
//=============================================================================
|
||||
// for binary compatibility with 3.0
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
CV_EXPORTS int LU(float* A, size_t astep, int m, float* b, size_t bstep, int n);
|
||||
CV_EXPORTS int LU(double* A, size_t astep, int m, double* b, size_t bstep, int n);
|
||||
CV_EXPORTS bool Cholesky(float* A, size_t astep, int m, float* b, size_t bstep, int n);
|
||||
CV_EXPORTS bool Cholesky(double* A, size_t astep, int m, double* b, size_t bstep, int n);
|
||||
|
||||
CV_EXPORTS void exp(const float* src, float* dst, int n);
|
||||
CV_EXPORTS void exp(const double* src, double* dst, int n);
|
||||
CV_EXPORTS void log(const float* src, float* dst, int n);
|
||||
CV_EXPORTS void log(const double* src, double* dst, int n);
|
||||
|
||||
CV_EXPORTS void fastAtan2(const float* y, const float* x, float* dst, int n, bool angleInDegrees);
|
||||
CV_EXPORTS void magnitude(const float* x, const float* y, float* dst, int n);
|
||||
CV_EXPORTS void magnitude(const double* x, const double* y, double* dst, int n);
|
||||
CV_EXPORTS void sqrt(const float* src, float* dst, int len);
|
||||
CV_EXPORTS void sqrt(const double* src, double* dst, int len);
|
||||
CV_EXPORTS void invSqrt(const float* src, float* dst, int len);
|
||||
CV_EXPORTS void invSqrt(const double* src, double* dst, int len);
|
||||
|
||||
//! @endcond
|
||||
|
||||
}} //cv::hal
|
||||
|
||||
#endif //OPENCV_HAL_HPP
|
||||
@@ -0,0 +1,178 @@
|
||||
#ifndef OPENCV_CORE_HAL_INTERFACE_H
|
||||
#define OPENCV_CORE_HAL_INTERFACE_H
|
||||
|
||||
//! @addtogroup core_hal_interface
|
||||
//! @{
|
||||
|
||||
//! @name Return codes
|
||||
//! @{
|
||||
#define CV_HAL_ERROR_OK 0
|
||||
#define CV_HAL_ERROR_NOT_IMPLEMENTED 1
|
||||
#define CV_HAL_ERROR_UNKNOWN -1
|
||||
//! @}
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <cstddef>
|
||||
#else
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
//! @name Data types
|
||||
//! primitive types
|
||||
//! - schar - signed 1 byte integer
|
||||
//! - uchar - unsigned 1 byte integer
|
||||
//! - short - signed 2 byte integer
|
||||
//! - ushort - unsigned 2 byte integer
|
||||
//! - int - signed 4 byte integer
|
||||
//! - uint - unsigned 4 byte integer
|
||||
//! - int64 - signed 8 byte integer
|
||||
//! - uint64 - unsigned 8 byte integer
|
||||
//! @{
|
||||
#if !defined _MSC_VER && !defined __BORLANDC__
|
||||
# if defined __cplusplus && __cplusplus >= 201103L && !defined __APPLE__
|
||||
# include <cstdint>
|
||||
typedef std::uint32_t uint;
|
||||
# else
|
||||
# include <stdint.h>
|
||||
typedef uint32_t uint;
|
||||
# endif
|
||||
#else
|
||||
typedef unsigned uint;
|
||||
#endif
|
||||
|
||||
typedef signed char schar;
|
||||
|
||||
#ifndef __IPL_H__
|
||||
typedef unsigned char uchar;
|
||||
typedef unsigned short ushort;
|
||||
#endif
|
||||
|
||||
#if defined _MSC_VER || defined __BORLANDC__
|
||||
typedef __int64 int64;
|
||||
typedef unsigned __int64 uint64;
|
||||
# define CV_BIG_INT(n) n##I64
|
||||
# define CV_BIG_UINT(n) n##UI64
|
||||
#else
|
||||
typedef int64_t int64;
|
||||
typedef uint64_t uint64;
|
||||
# define CV_BIG_INT(n) n##LL
|
||||
# define CV_BIG_UINT(n) n##ULL
|
||||
#endif
|
||||
|
||||
#define CV_CN_MAX 512
|
||||
#define CV_CN_SHIFT 3
|
||||
#define CV_DEPTH_MAX (1 << CV_CN_SHIFT)
|
||||
|
||||
#define CV_8U 0
|
||||
#define CV_8S 1
|
||||
#define CV_16U 2
|
||||
#define CV_16S 3
|
||||
#define CV_32S 4
|
||||
#define CV_32F 5
|
||||
#define CV_64F 6
|
||||
#define CV_USRTYPE1 7
|
||||
|
||||
#define CV_MAT_DEPTH_MASK (CV_DEPTH_MAX - 1)
|
||||
#define CV_MAT_DEPTH(flags) ((flags) & CV_MAT_DEPTH_MASK)
|
||||
|
||||
#define CV_MAKETYPE(depth,cn) (CV_MAT_DEPTH(depth) + (((cn)-1) << CV_CN_SHIFT))
|
||||
#define CV_MAKE_TYPE CV_MAKETYPE
|
||||
|
||||
#define CV_8UC1 CV_MAKETYPE(CV_8U,1)
|
||||
#define CV_8UC2 CV_MAKETYPE(CV_8U,2)
|
||||
#define CV_8UC3 CV_MAKETYPE(CV_8U,3)
|
||||
#define CV_8UC4 CV_MAKETYPE(CV_8U,4)
|
||||
#define CV_8UC(n) CV_MAKETYPE(CV_8U,(n))
|
||||
|
||||
#define CV_8SC1 CV_MAKETYPE(CV_8S,1)
|
||||
#define CV_8SC2 CV_MAKETYPE(CV_8S,2)
|
||||
#define CV_8SC3 CV_MAKETYPE(CV_8S,3)
|
||||
#define CV_8SC4 CV_MAKETYPE(CV_8S,4)
|
||||
#define CV_8SC(n) CV_MAKETYPE(CV_8S,(n))
|
||||
|
||||
#define CV_16UC1 CV_MAKETYPE(CV_16U,1)
|
||||
#define CV_16UC2 CV_MAKETYPE(CV_16U,2)
|
||||
#define CV_16UC3 CV_MAKETYPE(CV_16U,3)
|
||||
#define CV_16UC4 CV_MAKETYPE(CV_16U,4)
|
||||
#define CV_16UC(n) CV_MAKETYPE(CV_16U,(n))
|
||||
|
||||
#define CV_16SC1 CV_MAKETYPE(CV_16S,1)
|
||||
#define CV_16SC2 CV_MAKETYPE(CV_16S,2)
|
||||
#define CV_16SC3 CV_MAKETYPE(CV_16S,3)
|
||||
#define CV_16SC4 CV_MAKETYPE(CV_16S,4)
|
||||
#define CV_16SC(n) CV_MAKETYPE(CV_16S,(n))
|
||||
|
||||
#define CV_32SC1 CV_MAKETYPE(CV_32S,1)
|
||||
#define CV_32SC2 CV_MAKETYPE(CV_32S,2)
|
||||
#define CV_32SC3 CV_MAKETYPE(CV_32S,3)
|
||||
#define CV_32SC4 CV_MAKETYPE(CV_32S,4)
|
||||
#define CV_32SC(n) CV_MAKETYPE(CV_32S,(n))
|
||||
|
||||
#define CV_32FC1 CV_MAKETYPE(CV_32F,1)
|
||||
#define CV_32FC2 CV_MAKETYPE(CV_32F,2)
|
||||
#define CV_32FC3 CV_MAKETYPE(CV_32F,3)
|
||||
#define CV_32FC4 CV_MAKETYPE(CV_32F,4)
|
||||
#define CV_32FC(n) CV_MAKETYPE(CV_32F,(n))
|
||||
|
||||
#define CV_64FC1 CV_MAKETYPE(CV_64F,1)
|
||||
#define CV_64FC2 CV_MAKETYPE(CV_64F,2)
|
||||
#define CV_64FC3 CV_MAKETYPE(CV_64F,3)
|
||||
#define CV_64FC4 CV_MAKETYPE(CV_64F,4)
|
||||
#define CV_64FC(n) CV_MAKETYPE(CV_64F,(n))
|
||||
//! @}
|
||||
|
||||
//! @name Comparison operation
|
||||
//! @sa cv::CmpTypes
|
||||
//! @{
|
||||
#define CV_HAL_CMP_EQ 0
|
||||
#define CV_HAL_CMP_GT 1
|
||||
#define CV_HAL_CMP_GE 2
|
||||
#define CV_HAL_CMP_LT 3
|
||||
#define CV_HAL_CMP_LE 4
|
||||
#define CV_HAL_CMP_NE 5
|
||||
//! @}
|
||||
|
||||
//! @name Border processing modes
|
||||
//! @sa cv::BorderTypes
|
||||
//! @{
|
||||
#define CV_HAL_BORDER_CONSTANT 0
|
||||
#define CV_HAL_BORDER_REPLICATE 1
|
||||
#define CV_HAL_BORDER_REFLECT 2
|
||||
#define CV_HAL_BORDER_WRAP 3
|
||||
#define CV_HAL_BORDER_REFLECT_101 4
|
||||
#define CV_HAL_BORDER_TRANSPARENT 5
|
||||
#define CV_HAL_BORDER_ISOLATED 16
|
||||
//! @}
|
||||
|
||||
//! @name DFT flags
|
||||
//! @{
|
||||
#define CV_HAL_DFT_INVERSE 1
|
||||
#define CV_HAL_DFT_SCALE 2
|
||||
#define CV_HAL_DFT_ROWS 4
|
||||
#define CV_HAL_DFT_COMPLEX_OUTPUT 16
|
||||
#define CV_HAL_DFT_REAL_OUTPUT 32
|
||||
#define CV_HAL_DFT_TWO_STAGE 64
|
||||
#define CV_HAL_DFT_STAGE_COLS 128
|
||||
#define CV_HAL_DFT_IS_CONTINUOUS 512
|
||||
#define CV_HAL_DFT_IS_INPLACE 1024
|
||||
//! @}
|
||||
|
||||
//! @name SVD flags
|
||||
//! @{
|
||||
#define CV_HAL_SVD_NO_UV 1
|
||||
#define CV_HAL_SVD_SHORT_UV 2
|
||||
#define CV_HAL_SVD_MODIFY_A 4
|
||||
#define CV_HAL_SVD_FULL_UV 8
|
||||
//! @}
|
||||
|
||||
//! @name Gemm flags
|
||||
//! @{
|
||||
#define CV_HAL_GEMM_1_T 1
|
||||
#define CV_HAL_GEMM_2_T 2
|
||||
#define CV_HAL_GEMM_3_T 4
|
||||
//! @}
|
||||
|
||||
//! @}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,414 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Copyright (C) 2015, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_HAL_INTRIN_HPP
|
||||
#define OPENCV_HAL_INTRIN_HPP
|
||||
|
||||
#include <cmath>
|
||||
#include <float.h>
|
||||
#include <stdlib.h>
|
||||
#include "opencv2/core/cvdef.h"
|
||||
|
||||
#define OPENCV_HAL_ADD(a, b) ((a) + (b))
|
||||
#define OPENCV_HAL_AND(a, b) ((a) & (b))
|
||||
#define OPENCV_HAL_NOP(a) (a)
|
||||
#define OPENCV_HAL_1ST(a, b) (a)
|
||||
|
||||
// unlike HAL API, which is in cv::hal,
|
||||
// we put intrinsics into cv namespace to make its
|
||||
// access from within opencv code more accessible
|
||||
namespace cv {
|
||||
|
||||
//! @addtogroup core_hal_intrin
|
||||
//! @{
|
||||
|
||||
//! @cond IGNORED
|
||||
template<typename _Tp> struct V_TypeTraits
|
||||
{
|
||||
typedef _Tp int_type;
|
||||
typedef _Tp uint_type;
|
||||
typedef _Tp abs_type;
|
||||
typedef _Tp sum_type;
|
||||
|
||||
enum { delta = 0, shift = 0 };
|
||||
|
||||
static int_type reinterpret_int(_Tp x) { return x; }
|
||||
static uint_type reinterpet_uint(_Tp x) { return x; }
|
||||
static _Tp reinterpret_from_int(int_type x) { return (_Tp)x; }
|
||||
};
|
||||
|
||||
template<> struct V_TypeTraits<uchar>
|
||||
{
|
||||
typedef uchar value_type;
|
||||
typedef schar int_type;
|
||||
typedef uchar uint_type;
|
||||
typedef uchar abs_type;
|
||||
typedef int sum_type;
|
||||
|
||||
typedef ushort w_type;
|
||||
typedef unsigned q_type;
|
||||
|
||||
enum { delta = 128, shift = 8 };
|
||||
|
||||
static int_type reinterpret_int(value_type x) { return (int_type)x; }
|
||||
static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
|
||||
static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
|
||||
};
|
||||
|
||||
template<> struct V_TypeTraits<schar>
|
||||
{
|
||||
typedef schar value_type;
|
||||
typedef schar int_type;
|
||||
typedef uchar uint_type;
|
||||
typedef uchar abs_type;
|
||||
typedef int sum_type;
|
||||
|
||||
typedef short w_type;
|
||||
typedef int q_type;
|
||||
|
||||
enum { delta = 128, shift = 8 };
|
||||
|
||||
static int_type reinterpret_int(value_type x) { return (int_type)x; }
|
||||
static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
|
||||
static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
|
||||
};
|
||||
|
||||
template<> struct V_TypeTraits<ushort>
|
||||
{
|
||||
typedef ushort value_type;
|
||||
typedef short int_type;
|
||||
typedef ushort uint_type;
|
||||
typedef ushort abs_type;
|
||||
typedef int sum_type;
|
||||
|
||||
typedef unsigned w_type;
|
||||
typedef uchar nu_type;
|
||||
|
||||
enum { delta = 32768, shift = 16 };
|
||||
|
||||
static int_type reinterpret_int(value_type x) { return (int_type)x; }
|
||||
static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
|
||||
static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
|
||||
};
|
||||
|
||||
template<> struct V_TypeTraits<short>
|
||||
{
|
||||
typedef short value_type;
|
||||
typedef short int_type;
|
||||
typedef ushort uint_type;
|
||||
typedef ushort abs_type;
|
||||
typedef int sum_type;
|
||||
|
||||
typedef int w_type;
|
||||
typedef uchar nu_type;
|
||||
typedef schar n_type;
|
||||
|
||||
enum { delta = 128, shift = 8 };
|
||||
|
||||
static int_type reinterpret_int(value_type x) { return (int_type)x; }
|
||||
static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
|
||||
static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
|
||||
};
|
||||
|
||||
template<> struct V_TypeTraits<unsigned>
|
||||
{
|
||||
typedef unsigned value_type;
|
||||
typedef int int_type;
|
||||
typedef unsigned uint_type;
|
||||
typedef unsigned abs_type;
|
||||
typedef unsigned sum_type;
|
||||
|
||||
typedef uint64 w_type;
|
||||
typedef ushort nu_type;
|
||||
|
||||
static int_type reinterpret_int(value_type x) { return (int_type)x; }
|
||||
static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
|
||||
static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
|
||||
};
|
||||
|
||||
template<> struct V_TypeTraits<int>
|
||||
{
|
||||
typedef int value_type;
|
||||
typedef int int_type;
|
||||
typedef unsigned uint_type;
|
||||
typedef unsigned abs_type;
|
||||
typedef int sum_type;
|
||||
|
||||
typedef int64 w_type;
|
||||
typedef short n_type;
|
||||
typedef ushort nu_type;
|
||||
|
||||
static int_type reinterpret_int(value_type x) { return (int_type)x; }
|
||||
static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
|
||||
static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
|
||||
};
|
||||
|
||||
template<> struct V_TypeTraits<uint64>
|
||||
{
|
||||
typedef uint64 value_type;
|
||||
typedef int64 int_type;
|
||||
typedef uint64 uint_type;
|
||||
typedef uint64 abs_type;
|
||||
typedef uint64 sum_type;
|
||||
|
||||
typedef unsigned nu_type;
|
||||
|
||||
static int_type reinterpret_int(value_type x) { return (int_type)x; }
|
||||
static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
|
||||
static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
|
||||
};
|
||||
|
||||
template<> struct V_TypeTraits<int64>
|
||||
{
|
||||
typedef int64 value_type;
|
||||
typedef int64 int_type;
|
||||
typedef uint64 uint_type;
|
||||
typedef uint64 abs_type;
|
||||
typedef int64 sum_type;
|
||||
|
||||
typedef int nu_type;
|
||||
|
||||
static int_type reinterpret_int(value_type x) { return (int_type)x; }
|
||||
static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
|
||||
static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
|
||||
};
|
||||
|
||||
|
||||
template<> struct V_TypeTraits<float>
|
||||
{
|
||||
typedef float value_type;
|
||||
typedef int int_type;
|
||||
typedef unsigned uint_type;
|
||||
typedef float abs_type;
|
||||
typedef float sum_type;
|
||||
|
||||
typedef double w_type;
|
||||
|
||||
static int_type reinterpret_int(value_type x)
|
||||
{
|
||||
Cv32suf u;
|
||||
u.f = x;
|
||||
return u.i;
|
||||
}
|
||||
static uint_type reinterpet_uint(value_type x)
|
||||
{
|
||||
Cv32suf u;
|
||||
u.f = x;
|
||||
return u.u;
|
||||
}
|
||||
static value_type reinterpret_from_int(int_type x)
|
||||
{
|
||||
Cv32suf u;
|
||||
u.i = x;
|
||||
return u.f;
|
||||
}
|
||||
};
|
||||
|
||||
template<> struct V_TypeTraits<double>
|
||||
{
|
||||
typedef double value_type;
|
||||
typedef int64 int_type;
|
||||
typedef uint64 uint_type;
|
||||
typedef double abs_type;
|
||||
typedef double sum_type;
|
||||
static int_type reinterpret_int(value_type x)
|
||||
{
|
||||
Cv64suf u;
|
||||
u.f = x;
|
||||
return u.i;
|
||||
}
|
||||
static uint_type reinterpet_uint(value_type x)
|
||||
{
|
||||
Cv64suf u;
|
||||
u.f = x;
|
||||
return u.u;
|
||||
}
|
||||
static value_type reinterpret_from_int(int_type x)
|
||||
{
|
||||
Cv64suf u;
|
||||
u.i = x;
|
||||
return u.f;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T> struct V_SIMD128Traits
|
||||
{
|
||||
enum { nlanes = 16 / sizeof(T) };
|
||||
};
|
||||
|
||||
//! @endcond
|
||||
|
||||
//! @}
|
||||
|
||||
}
|
||||
|
||||
#ifdef CV_DOXYGEN
|
||||
# undef CV_SSE2
|
||||
# undef CV_NEON
|
||||
#endif
|
||||
|
||||
#if CV_SSE2
|
||||
|
||||
#include "opencv2/core/hal/intrin_sse.hpp"
|
||||
|
||||
#elif CV_NEON
|
||||
|
||||
#include "opencv2/core/hal/intrin_neon.hpp"
|
||||
|
||||
#else
|
||||
|
||||
#include "opencv2/core/hal/intrin_cpp.hpp"
|
||||
|
||||
#endif
|
||||
|
||||
//! @addtogroup core_hal_intrin
|
||||
//! @{
|
||||
|
||||
#ifndef CV_SIMD128
|
||||
//! Set to 1 if current compiler supports vector extensions (NEON or SSE is enabled)
|
||||
#define CV_SIMD128 0
|
||||
#endif
|
||||
|
||||
#ifndef CV_SIMD128_64F
|
||||
//! Set to 1 if current intrinsics implementation supports 64-bit float vectors
|
||||
#define CV_SIMD128_64F 0
|
||||
#endif
|
||||
|
||||
//! @}
|
||||
|
||||
//==================================================================================================
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
namespace cv {
|
||||
|
||||
template <typename R> struct V_RegTrait128;
|
||||
|
||||
template <> struct V_RegTrait128<uchar> {
|
||||
typedef v_uint8x16 reg;
|
||||
typedef v_uint16x8 w_reg;
|
||||
typedef v_uint32x4 q_reg;
|
||||
typedef v_uint8x16 u_reg;
|
||||
static v_uint8x16 zero() { return v_setzero_u8(); }
|
||||
static v_uint8x16 all(uchar val) { return v_setall_u8(val); }
|
||||
};
|
||||
|
||||
template <> struct V_RegTrait128<schar> {
|
||||
typedef v_int8x16 reg;
|
||||
typedef v_int16x8 w_reg;
|
||||
typedef v_int32x4 q_reg;
|
||||
typedef v_uint8x16 u_reg;
|
||||
static v_int8x16 zero() { return v_setzero_s8(); }
|
||||
static v_int8x16 all(schar val) { return v_setall_s8(val); }
|
||||
};
|
||||
|
||||
template <> struct V_RegTrait128<ushort> {
|
||||
typedef v_uint16x8 reg;
|
||||
typedef v_uint32x4 w_reg;
|
||||
typedef v_int16x8 int_reg;
|
||||
typedef v_uint16x8 u_reg;
|
||||
static v_uint16x8 zero() { return v_setzero_u16(); }
|
||||
static v_uint16x8 all(ushort val) { return v_setall_u16(val); }
|
||||
};
|
||||
|
||||
template <> struct V_RegTrait128<short> {
|
||||
typedef v_int16x8 reg;
|
||||
typedef v_int32x4 w_reg;
|
||||
typedef v_uint16x8 u_reg;
|
||||
static v_int16x8 zero() { return v_setzero_s16(); }
|
||||
static v_int16x8 all(short val) { return v_setall_s16(val); }
|
||||
};
|
||||
|
||||
template <> struct V_RegTrait128<unsigned> {
|
||||
typedef v_uint32x4 reg;
|
||||
typedef v_uint64x2 w_reg;
|
||||
typedef v_int32x4 int_reg;
|
||||
typedef v_uint32x4 u_reg;
|
||||
static v_uint32x4 zero() { return v_setzero_u32(); }
|
||||
static v_uint32x4 all(unsigned val) { return v_setall_u32(val); }
|
||||
};
|
||||
|
||||
template <> struct V_RegTrait128<int> {
|
||||
typedef v_int32x4 reg;
|
||||
typedef v_int64x2 w_reg;
|
||||
typedef v_uint32x4 u_reg;
|
||||
static v_int32x4 zero() { return v_setzero_s32(); }
|
||||
static v_int32x4 all(int val) { return v_setall_s32(val); }
|
||||
};
|
||||
|
||||
template <> struct V_RegTrait128<uint64> {
|
||||
typedef v_uint64x2 reg;
|
||||
static v_uint64x2 zero() { return v_setzero_u64(); }
|
||||
static v_uint64x2 all(uint64 val) { return v_setall_u64(val); }
|
||||
};
|
||||
|
||||
template <> struct V_RegTrait128<int64> {
|
||||
typedef v_int64x2 reg;
|
||||
static v_int64x2 zero() { return v_setzero_s64(); }
|
||||
static v_int64x2 all(int64 val) { return v_setall_s64(val); }
|
||||
};
|
||||
|
||||
template <> struct V_RegTrait128<float> {
|
||||
typedef v_float32x4 reg;
|
||||
typedef v_int32x4 int_reg;
|
||||
typedef v_float32x4 u_reg;
|
||||
static v_float32x4 zero() { return v_setzero_f32(); }
|
||||
static v_float32x4 all(float val) { return v_setall_f32(val); }
|
||||
};
|
||||
|
||||
#if CV_SIMD128_64F
|
||||
template <> struct V_RegTrait128<double> {
|
||||
typedef v_float64x2 reg;
|
||||
typedef v_int32x4 int_reg;
|
||||
typedef v_float64x2 u_reg;
|
||||
static v_float64x2 zero() { return v_setzero_f64(); }
|
||||
static v_float64x2 all(double val) { return v_setall_f64(val); }
|
||||
};
|
||||
#endif
|
||||
|
||||
} // cv::
|
||||
|
||||
//! @endcond
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,781 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
/* The header is for internal use and it is likely to change.
|
||||
It contains some macro definitions that are used in cxcore, cv, cvaux
|
||||
and, probably, other libraries. If you need some of this functionality,
|
||||
the safe way is to copy it into your code and rename the macros.
|
||||
*/
|
||||
#ifndef __OPENCV_CORE_INTERNAL_HPP__
|
||||
#define __OPENCV_CORE_INTERNAL_HPP__
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/types_c.h"
|
||||
|
||||
#if defined WIN32 || defined _WIN32
|
||||
# ifndef WIN32
|
||||
# define WIN32
|
||||
# endif
|
||||
# ifndef _WIN32
|
||||
# define _WIN32
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined WIN32 && !defined WINCE
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# ifndef WIN32
|
||||
# define WIN32
|
||||
# endif
|
||||
# ifndef _WIN32
|
||||
# define _WIN32
|
||||
# endif
|
||||
# define CV_DLL
|
||||
# undef _CV_ALWAYS_PROFILE_
|
||||
# define _CV_ALWAYS_NO_PROFILE_
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
# define FALSE 0
|
||||
#endif
|
||||
#ifndef TRUE
|
||||
# define TRUE 1
|
||||
#endif
|
||||
|
||||
#define __BEGIN__ __CV_BEGIN__
|
||||
#define __END__ __CV_END__
|
||||
#define EXIT __CV_EXIT__
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
# include "ipp.h"
|
||||
|
||||
CV_INLINE IppiSize ippiSize(int width, int height)
|
||||
{
|
||||
IppiSize size = { width, height };
|
||||
return size;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef IPPI_CALL
|
||||
# define IPPI_CALL(func) CV_Assert((func) >= 0)
|
||||
#endif
|
||||
|
||||
#if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2)
|
||||
# include "emmintrin.h"
|
||||
# define CV_SSE 1
|
||||
# define CV_SSE2 1
|
||||
# if defined __SSE3__ || (defined _MSC_VER && _MSC_VER >= 1500)
|
||||
# include "pmmintrin.h"
|
||||
# define CV_SSE3 1
|
||||
# endif
|
||||
# if defined __SSSE3__ || (defined _MSC_VER && _MSC_VER >= 1500)
|
||||
# include "tmmintrin.h"
|
||||
# define CV_SSSE3 1
|
||||
# endif
|
||||
# if defined __SSE4_1__ || (defined _MSC_VER && _MSC_VER >= 1500)
|
||||
# include <smmintrin.h>
|
||||
# define CV_SSE4_1 1
|
||||
# endif
|
||||
# if defined __SSE4_2__ || (defined _MSC_VER && _MSC_VER >= 1500)
|
||||
# include <nmmintrin.h>
|
||||
# define CV_SSE4_2 1
|
||||
# endif
|
||||
# if defined __AVX__ || (defined _MSC_FULL_VER && _MSC_FULL_VER >= 160040219)
|
||||
// MS Visual Studio 2010 (2012?) has no macro pre-defined to identify the use of /arch:AVX
|
||||
// See: http://connect.microsoft.com/VisualStudio/feedback/details/605858/arch-avx-should-define-a-predefined-macro-in-x64-and-set-a-unique-value-for-m-ix86-fp-in-win32
|
||||
# include <immintrin.h>
|
||||
# define CV_AVX 1
|
||||
# if defined(_XCR_XFEATURE_ENABLED_MASK)
|
||||
# define __xgetbv() _xgetbv(_XCR_XFEATURE_ENABLED_MASK)
|
||||
# else
|
||||
# define __xgetbv() 0
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
#if (defined WIN32 || defined _WIN32) && defined(_M_ARM)
|
||||
# include <Intrin.h>
|
||||
# include "arm_neon.h"
|
||||
# define CV_NEON 1
|
||||
# define CPU_HAS_NEON_FEATURE (true)
|
||||
#elif defined(__ARM_NEON__)
|
||||
# include <arm_neon.h>
|
||||
# define CV_NEON 1
|
||||
# define CPU_HAS_NEON_FEATURE (true)
|
||||
#endif
|
||||
|
||||
#ifndef CV_SSE
|
||||
# define CV_SSE 0
|
||||
#endif
|
||||
#ifndef CV_SSE2
|
||||
# define CV_SSE2 0
|
||||
#endif
|
||||
#ifndef CV_SSE3
|
||||
# define CV_SSE3 0
|
||||
#endif
|
||||
#ifndef CV_SSSE3
|
||||
# define CV_SSSE3 0
|
||||
#endif
|
||||
#ifndef CV_SSE4_1
|
||||
# define CV_SSE4_1 0
|
||||
#endif
|
||||
#ifndef CV_SSE4_2
|
||||
# define CV_SSE4_2 0
|
||||
#endif
|
||||
#ifndef CV_AVX
|
||||
# define CV_AVX 0
|
||||
#endif
|
||||
#ifndef CV_NEON
|
||||
# define CV_NEON 0
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
# include "tbb/tbb_stddef.h"
|
||||
# if TBB_VERSION_MAJOR*100 + TBB_VERSION_MINOR >= 202
|
||||
# include "tbb/tbb.h"
|
||||
# include "tbb/task.h"
|
||||
# undef min
|
||||
# undef max
|
||||
# else
|
||||
# undef HAVE_TBB
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_EIGEN
|
||||
# if defined __GNUC__ && defined __APPLE__
|
||||
# pragma GCC diagnostic ignored "-Wshadow"
|
||||
# endif
|
||||
# include <Eigen/Core>
|
||||
# include "opencv2/core/eigen.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace cv
|
||||
{
|
||||
#ifdef HAVE_TBB
|
||||
|
||||
typedef tbb::blocked_range<int> BlockedRange;
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_for( const BlockedRange& range, const Body& body )
|
||||
{
|
||||
tbb::parallel_for(range, body);
|
||||
}
|
||||
|
||||
template<typename Iterator, typename Body> static inline
|
||||
void parallel_do( Iterator first, Iterator last, const Body& body )
|
||||
{
|
||||
tbb::parallel_do(first, last, body);
|
||||
}
|
||||
|
||||
typedef tbb::split Split;
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_reduce( const BlockedRange& range, Body& body )
|
||||
{
|
||||
tbb::parallel_reduce(range, body);
|
||||
}
|
||||
|
||||
typedef tbb::concurrent_vector<Rect> ConcurrentRectVector;
|
||||
typedef tbb::concurrent_vector<double> ConcurrentDoubleVector;
|
||||
#else
|
||||
class BlockedRange
|
||||
{
|
||||
public:
|
||||
BlockedRange() : _begin(0), _end(0), _grainsize(0) {}
|
||||
BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {}
|
||||
int begin() const { return _begin; }
|
||||
int end() const { return _end; }
|
||||
int grainsize() const { return _grainsize; }
|
||||
|
||||
protected:
|
||||
int _begin, _end, _grainsize;
|
||||
};
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_for( const BlockedRange& range, const Body& body )
|
||||
{
|
||||
body(range);
|
||||
}
|
||||
typedef std::vector<Rect> ConcurrentRectVector;
|
||||
typedef std::vector<double> ConcurrentDoubleVector;
|
||||
|
||||
template<typename Iterator, typename Body> static inline
|
||||
void parallel_do( Iterator first, Iterator last, const Body& body )
|
||||
{
|
||||
for( ; first != last; ++first )
|
||||
body(*first);
|
||||
}
|
||||
|
||||
class Split {};
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_reduce( const BlockedRange& range, Body& body )
|
||||
{
|
||||
body(range);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Returns a static string if there is a parallel framework,
|
||||
// NULL otherwise.
|
||||
CV_EXPORTS const char* currentParallelFramework();
|
||||
} //namespace cv
|
||||
|
||||
#define CV_INIT_ALGORITHM(classname, algname, memberinit) \
|
||||
static ::cv::Algorithm* create##classname() \
|
||||
{ \
|
||||
return new classname; \
|
||||
} \
|
||||
\
|
||||
static ::cv::AlgorithmInfo& classname##_info() \
|
||||
{ \
|
||||
static ::cv::AlgorithmInfo classname##_info_var(algname, create##classname); \
|
||||
return classname##_info_var; \
|
||||
} \
|
||||
\
|
||||
static ::cv::AlgorithmInfo& classname##_info_auto = classname##_info(); \
|
||||
\
|
||||
::cv::AlgorithmInfo* classname::info() const \
|
||||
{ \
|
||||
static volatile bool initialized = false; \
|
||||
\
|
||||
if( !initialized ) \
|
||||
{ \
|
||||
initialized = true; \
|
||||
classname obj; \
|
||||
memberinit; \
|
||||
} \
|
||||
return &classname##_info(); \
|
||||
}
|
||||
|
||||
#endif //__cplusplus
|
||||
|
||||
/* maximal size of vector to run matrix operations on it inline (i.e. w/o ipp calls) */
|
||||
#define CV_MAX_INLINE_MAT_OP_SIZE 10
|
||||
|
||||
/* maximal linear size of matrix to allocate it on stack. */
|
||||
#define CV_MAX_LOCAL_MAT_SIZE 32
|
||||
|
||||
/* maximal size of local memory storage */
|
||||
#define CV_MAX_LOCAL_SIZE \
|
||||
(CV_MAX_LOCAL_MAT_SIZE*CV_MAX_LOCAL_MAT_SIZE*(int)sizeof(double))
|
||||
|
||||
/* default image row align (in bytes) */
|
||||
#define CV_DEFAULT_IMAGE_ROW_ALIGN 4
|
||||
|
||||
/* matrices are continuous by default */
|
||||
#define CV_DEFAULT_MAT_ROW_ALIGN 1
|
||||
|
||||
/* maximum size of dynamic memory buffer.
|
||||
cvAlloc reports an error if a larger block is requested. */
|
||||
#define CV_MAX_ALLOC_SIZE (((size_t)1 << (sizeof(size_t)*8-2)))
|
||||
|
||||
/* the alignment of all the allocated buffers */
|
||||
#define CV_MALLOC_ALIGN 16
|
||||
|
||||
/* default alignment for dynamic data strucutures, resided in storages. */
|
||||
#define CV_STRUCT_ALIGN ((int)sizeof(double))
|
||||
|
||||
/* default storage block size */
|
||||
#define CV_STORAGE_BLOCK_SIZE ((1<<16) - 128)
|
||||
|
||||
/* default memory block for sparse array elements */
|
||||
#define CV_SPARSE_MAT_BLOCK (1<<12)
|
||||
|
||||
/* initial hash table size */
|
||||
#define CV_SPARSE_HASH_SIZE0 (1<<10)
|
||||
|
||||
/* maximal average node_count/hash_size ratio beyond which hash table is resized */
|
||||
#define CV_SPARSE_HASH_RATIO 3
|
||||
|
||||
/* max length of strings */
|
||||
#define CV_MAX_STRLEN 1024
|
||||
|
||||
#if 0 /*def CV_CHECK_FOR_NANS*/
|
||||
# define CV_CHECK_NANS( arr ) cvCheckArray((arr))
|
||||
#else
|
||||
# define CV_CHECK_NANS( arr )
|
||||
#endif
|
||||
|
||||
/****************************************************************************************\
|
||||
* Common declarations *
|
||||
\****************************************************************************************/
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define CV_DECL_ALIGNED(x) __attribute__ ((aligned (x)))
|
||||
#elif defined _MSC_VER
|
||||
# define CV_DECL_ALIGNED(x) __declspec(align(x))
|
||||
#else
|
||||
# define CV_DECL_ALIGNED(x)
|
||||
#endif
|
||||
|
||||
#ifndef CV_IMPL
|
||||
# define CV_IMPL CV_EXTERN_C
|
||||
#endif
|
||||
|
||||
#define CV_DBG_BREAK() { volatile int* crashMe = 0; *crashMe = 0; }
|
||||
|
||||
/* default step, set in case of continuous data
|
||||
to work around checks for valid step in some ipp functions */
|
||||
#define CV_STUB_STEP (1 << 30)
|
||||
|
||||
#define CV_SIZEOF_FLOAT ((int)sizeof(float))
|
||||
#define CV_SIZEOF_SHORT ((int)sizeof(short))
|
||||
|
||||
#define CV_ORIGIN_TL 0
|
||||
#define CV_ORIGIN_BL 1
|
||||
|
||||
/* IEEE754 constants and macros */
|
||||
#define CV_POS_INF 0x7f800000
|
||||
#define CV_NEG_INF 0x807fffff /* CV_TOGGLE_FLT(0xff800000) */
|
||||
#define CV_1F 0x3f800000
|
||||
#define CV_TOGGLE_FLT(x) ((x)^((int)(x) < 0 ? 0x7fffffff : 0))
|
||||
#define CV_TOGGLE_DBL(x) \
|
||||
((x)^((int64)(x) < 0 ? CV_BIG_INT(0x7fffffffffffffff) : 0))
|
||||
|
||||
#define CV_NOP(a) (a)
|
||||
#define CV_ADD(a, b) ((a) + (b))
|
||||
#define CV_SUB(a, b) ((a) - (b))
|
||||
#define CV_MUL(a, b) ((a) * (b))
|
||||
#define CV_AND(a, b) ((a) & (b))
|
||||
#define CV_OR(a, b) ((a) | (b))
|
||||
#define CV_XOR(a, b) ((a) ^ (b))
|
||||
#define CV_ANDN(a, b) (~(a) & (b))
|
||||
#define CV_ORN(a, b) (~(a) | (b))
|
||||
#define CV_SQR(a) ((a) * (a))
|
||||
|
||||
#define CV_LT(a, b) ((a) < (b))
|
||||
#define CV_LE(a, b) ((a) <= (b))
|
||||
#define CV_EQ(a, b) ((a) == (b))
|
||||
#define CV_NE(a, b) ((a) != (b))
|
||||
#define CV_GT(a, b) ((a) > (b))
|
||||
#define CV_GE(a, b) ((a) >= (b))
|
||||
|
||||
#define CV_NONZERO(a) ((a) != 0)
|
||||
#define CV_NONZERO_FLT(a) (((a)+(a)) != 0)
|
||||
|
||||
/* general-purpose saturation macros */
|
||||
#define CV_CAST_8U(t) (uchar)(!((t) & ~255) ? (t) : (t) > 0 ? 255 : 0)
|
||||
#define CV_CAST_8S(t) (schar)(!(((t)+128) & ~255) ? (t) : (t) > 0 ? 127 : -128)
|
||||
#define CV_CAST_16U(t) (ushort)(!((t) & ~65535) ? (t) : (t) > 0 ? 65535 : 0)
|
||||
#define CV_CAST_16S(t) (short)(!(((t)+32768) & ~65535) ? (t) : (t) > 0 ? 32767 : -32768)
|
||||
#define CV_CAST_32S(t) (int)(t)
|
||||
#define CV_CAST_64S(t) (int64)(t)
|
||||
#define CV_CAST_32F(t) (float)(t)
|
||||
#define CV_CAST_64F(t) (double)(t)
|
||||
|
||||
#define CV_PASTE2(a,b) a##b
|
||||
#define CV_PASTE(a,b) CV_PASTE2(a,b)
|
||||
|
||||
#define CV_EMPTY
|
||||
#define CV_MAKE_STR(a) #a
|
||||
|
||||
#define CV_ZERO_OBJ(x) memset((x), 0, sizeof(*(x)))
|
||||
|
||||
#define CV_DIM(static_array) ((int)(sizeof(static_array)/sizeof((static_array)[0])))
|
||||
|
||||
#define cvUnsupportedFormat "Unsupported format"
|
||||
|
||||
CV_INLINE void* cvAlignPtr( const void* ptr, int align CV_DEFAULT(32) )
|
||||
{
|
||||
assert( (align & (align-1)) == 0 );
|
||||
return (void*)( ((size_t)ptr + align - 1) & ~(size_t)(align-1) );
|
||||
}
|
||||
|
||||
CV_INLINE int cvAlign( int size, int align )
|
||||
{
|
||||
assert( (align & (align-1)) == 0 && size < INT_MAX );
|
||||
return (size + align - 1) & -align;
|
||||
}
|
||||
|
||||
CV_INLINE CvSize cvGetMatSize( const CvMat* mat )
|
||||
{
|
||||
CvSize size;
|
||||
size.width = mat->cols;
|
||||
size.height = mat->rows;
|
||||
return size;
|
||||
}
|
||||
|
||||
#define CV_DESCALE(x,n) (((x) + (1 << ((n)-1))) >> (n))
|
||||
#define CV_FLT_TO_FIX(x,n) cvRound((x)*(1<<(n)))
|
||||
|
||||
/****************************************************************************************\
|
||||
|
||||
Generic implementation of QuickSort algorithm.
|
||||
----------------------------------------------
|
||||
Using this macro user can declare customized sort function that can be much faster
|
||||
than built-in qsort function because of lower overhead on elements
|
||||
comparison and exchange. The macro takes less_than (or LT) argument - a macro or function
|
||||
that takes 2 arguments returns non-zero if the first argument should be before the second
|
||||
one in the sorted sequence and zero otherwise.
|
||||
|
||||
Example:
|
||||
|
||||
Suppose that the task is to sort points by ascending of y coordinates and if
|
||||
y's are equal x's should ascend.
|
||||
|
||||
The code is:
|
||||
------------------------------------------------------------------------------
|
||||
#define cmp_pts( pt1, pt2 ) \
|
||||
((pt1).y < (pt2).y || ((pt1).y < (pt2).y && (pt1).x < (pt2).x))
|
||||
|
||||
[static] CV_IMPLEMENT_QSORT( icvSortPoints, CvPoint, cmp_pts )
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
After that the function "void icvSortPoints( CvPoint* array, size_t total, int aux );"
|
||||
is available to user.
|
||||
|
||||
aux is an additional parameter, which can be used when comparing elements.
|
||||
The current implementation was derived from *BSD system qsort():
|
||||
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
|
||||
\****************************************************************************************/
|
||||
|
||||
#define CV_IMPLEMENT_QSORT_EX( func_name, T, LT, user_data_type ) \
|
||||
void func_name( T *array, size_t total, user_data_type aux ) \
|
||||
{ \
|
||||
int isort_thresh = 7; \
|
||||
T t; \
|
||||
int sp = 0; \
|
||||
\
|
||||
struct \
|
||||
{ \
|
||||
T *lb; \
|
||||
T *ub; \
|
||||
} \
|
||||
stack[48]; \
|
||||
\
|
||||
aux = aux; \
|
||||
\
|
||||
if( total <= 1 ) \
|
||||
return; \
|
||||
\
|
||||
stack[0].lb = array; \
|
||||
stack[0].ub = array + (total - 1); \
|
||||
\
|
||||
while( sp >= 0 ) \
|
||||
{ \
|
||||
T* left = stack[sp].lb; \
|
||||
T* right = stack[sp--].ub; \
|
||||
\
|
||||
for(;;) \
|
||||
{ \
|
||||
int i, n = (int)(right - left) + 1, m; \
|
||||
T* ptr; \
|
||||
T* ptr2; \
|
||||
\
|
||||
if( n <= isort_thresh ) \
|
||||
{ \
|
||||
insert_sort: \
|
||||
for( ptr = left + 1; ptr <= right; ptr++ ) \
|
||||
{ \
|
||||
for( ptr2 = ptr; ptr2 > left && LT(ptr2[0],ptr2[-1]); ptr2--) \
|
||||
CV_SWAP( ptr2[0], ptr2[-1], t ); \
|
||||
} \
|
||||
break; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
T* left0; \
|
||||
T* left1; \
|
||||
T* right0; \
|
||||
T* right1; \
|
||||
T* pivot; \
|
||||
T* a; \
|
||||
T* b; \
|
||||
T* c; \
|
||||
int swap_cnt = 0; \
|
||||
\
|
||||
left0 = left; \
|
||||
right0 = right; \
|
||||
pivot = left + (n/2); \
|
||||
\
|
||||
if( n > 40 ) \
|
||||
{ \
|
||||
int d = n / 8; \
|
||||
a = left, b = left + d, c = left + 2*d; \
|
||||
left = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
|
||||
: (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
|
||||
\
|
||||
a = pivot - d, b = pivot, c = pivot + d; \
|
||||
pivot = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
|
||||
: (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
|
||||
\
|
||||
a = right - 2*d, b = right - d, c = right; \
|
||||
right = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
|
||||
: (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
|
||||
} \
|
||||
\
|
||||
a = left, b = pivot, c = right; \
|
||||
pivot = LT(*a, *b) ? (LT(*b, *c) ? b : (LT(*a, *c) ? c : a)) \
|
||||
: (LT(*c, *b) ? b : (LT(*a, *c) ? a : c)); \
|
||||
if( pivot != left0 ) \
|
||||
{ \
|
||||
CV_SWAP( *pivot, *left0, t ); \
|
||||
pivot = left0; \
|
||||
} \
|
||||
left = left1 = left0 + 1; \
|
||||
right = right1 = right0; \
|
||||
\
|
||||
for(;;) \
|
||||
{ \
|
||||
while( left <= right && !LT(*pivot, *left) ) \
|
||||
{ \
|
||||
if( !LT(*left, *pivot) ) \
|
||||
{ \
|
||||
if( left > left1 ) \
|
||||
CV_SWAP( *left1, *left, t ); \
|
||||
swap_cnt = 1; \
|
||||
left1++; \
|
||||
} \
|
||||
left++; \
|
||||
} \
|
||||
\
|
||||
while( left <= right && !LT(*right, *pivot) ) \
|
||||
{ \
|
||||
if( !LT(*pivot, *right) ) \
|
||||
{ \
|
||||
if( right < right1 ) \
|
||||
CV_SWAP( *right1, *right, t ); \
|
||||
swap_cnt = 1; \
|
||||
right1--; \
|
||||
} \
|
||||
right--; \
|
||||
} \
|
||||
\
|
||||
if( left > right ) \
|
||||
break; \
|
||||
CV_SWAP( *left, *right, t ); \
|
||||
swap_cnt = 1; \
|
||||
left++; \
|
||||
right--; \
|
||||
} \
|
||||
\
|
||||
if( swap_cnt == 0 ) \
|
||||
{ \
|
||||
left = left0, right = right0; \
|
||||
goto insert_sort; \
|
||||
} \
|
||||
\
|
||||
n = MIN( (int)(left1 - left0), (int)(left - left1) ); \
|
||||
for( i = 0; i < n; i++ ) \
|
||||
CV_SWAP( left0[i], left[i-n], t ); \
|
||||
\
|
||||
n = MIN( (int)(right0 - right1), (int)(right1 - right) ); \
|
||||
for( i = 0; i < n; i++ ) \
|
||||
CV_SWAP( left[i], right0[i-n+1], t ); \
|
||||
n = (int)(left - left1); \
|
||||
m = (int)(right1 - right); \
|
||||
if( n > 1 ) \
|
||||
{ \
|
||||
if( m > 1 ) \
|
||||
{ \
|
||||
if( n > m ) \
|
||||
{ \
|
||||
stack[++sp].lb = left0; \
|
||||
stack[sp].ub = left0 + n - 1; \
|
||||
left = right0 - m + 1, right = right0; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
stack[++sp].lb = right0 - m + 1; \
|
||||
stack[sp].ub = right0; \
|
||||
left = left0, right = left0 + n - 1; \
|
||||
} \
|
||||
} \
|
||||
else \
|
||||
left = left0, right = left0 + n - 1; \
|
||||
} \
|
||||
else if( m > 1 ) \
|
||||
left = right0 - m + 1, right = right0; \
|
||||
else \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CV_IMPLEMENT_QSORT( func_name, T, cmp ) \
|
||||
CV_IMPLEMENT_QSORT_EX( func_name, T, cmp, int )
|
||||
|
||||
/****************************************************************************************\
|
||||
* Structures and macros for integration with IPP *
|
||||
\****************************************************************************************/
|
||||
|
||||
/* IPP-compatible return codes */
|
||||
typedef enum CvStatus
|
||||
{
|
||||
CV_BADMEMBLOCK_ERR = -113,
|
||||
CV_INPLACE_NOT_SUPPORTED_ERR= -112,
|
||||
CV_UNMATCHED_ROI_ERR = -111,
|
||||
CV_NOTFOUND_ERR = -110,
|
||||
CV_BADCONVERGENCE_ERR = -109,
|
||||
|
||||
CV_BADDEPTH_ERR = -107,
|
||||
CV_BADROI_ERR = -106,
|
||||
CV_BADHEADER_ERR = -105,
|
||||
CV_UNMATCHED_FORMATS_ERR = -104,
|
||||
CV_UNSUPPORTED_COI_ERR = -103,
|
||||
CV_UNSUPPORTED_CHANNELS_ERR = -102,
|
||||
CV_UNSUPPORTED_DEPTH_ERR = -101,
|
||||
CV_UNSUPPORTED_FORMAT_ERR = -100,
|
||||
|
||||
CV_BADARG_ERR = -49, //ipp comp
|
||||
CV_NOTDEFINED_ERR = -48, //ipp comp
|
||||
|
||||
CV_BADCHANNELS_ERR = -47, //ipp comp
|
||||
CV_BADRANGE_ERR = -44, //ipp comp
|
||||
CV_BADSTEP_ERR = -29, //ipp comp
|
||||
|
||||
CV_BADFLAG_ERR = -12,
|
||||
CV_DIV_BY_ZERO_ERR = -11, //ipp comp
|
||||
CV_BADCOEF_ERR = -10,
|
||||
|
||||
CV_BADFACTOR_ERR = -7,
|
||||
CV_BADPOINT_ERR = -6,
|
||||
CV_BADSCALE_ERR = -4,
|
||||
CV_OUTOFMEM_ERR = -3,
|
||||
CV_NULLPTR_ERR = -2,
|
||||
CV_BADSIZE_ERR = -1,
|
||||
CV_NO_ERR = 0,
|
||||
CV_OK = CV_NO_ERR
|
||||
}
|
||||
CvStatus;
|
||||
|
||||
#define CV_NOTHROW throw()
|
||||
|
||||
typedef struct CvFuncTable
|
||||
{
|
||||
void* fn_2d[CV_DEPTH_MAX];
|
||||
}
|
||||
CvFuncTable;
|
||||
|
||||
typedef struct CvBigFuncTable
|
||||
{
|
||||
void* fn_2d[CV_DEPTH_MAX*4];
|
||||
} CvBigFuncTable;
|
||||
|
||||
#define CV_INIT_FUNC_TAB( tab, FUNCNAME, FLAG ) \
|
||||
(tab).fn_2d[CV_8U] = (void*)FUNCNAME##_8u##FLAG; \
|
||||
(tab).fn_2d[CV_8S] = 0; \
|
||||
(tab).fn_2d[CV_16U] = (void*)FUNCNAME##_16u##FLAG; \
|
||||
(tab).fn_2d[CV_16S] = (void*)FUNCNAME##_16s##FLAG; \
|
||||
(tab).fn_2d[CV_32S] = (void*)FUNCNAME##_32s##FLAG; \
|
||||
(tab).fn_2d[CV_32F] = (void*)FUNCNAME##_32f##FLAG; \
|
||||
(tab).fn_2d[CV_64F] = (void*)FUNCNAME##_64f##FLAG
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
// < Deprecated
|
||||
|
||||
class CV_EXPORTS CvOpenGlFuncTab
|
||||
{
|
||||
public:
|
||||
virtual ~CvOpenGlFuncTab();
|
||||
|
||||
virtual void genBuffers(int n, unsigned int* buffers) const = 0;
|
||||
virtual void deleteBuffers(int n, const unsigned int* buffers) const = 0;
|
||||
|
||||
virtual void bufferData(unsigned int target, ptrdiff_t size, const void* data, unsigned int usage) const = 0;
|
||||
virtual void bufferSubData(unsigned int target, ptrdiff_t offset, ptrdiff_t size, const void* data) const = 0;
|
||||
|
||||
virtual void bindBuffer(unsigned int target, unsigned int buffer) const = 0;
|
||||
|
||||
virtual void* mapBuffer(unsigned int target, unsigned int access) const = 0;
|
||||
virtual void unmapBuffer(unsigned int target) const = 0;
|
||||
|
||||
virtual void generateBitmapFont(const std::string& family, int height, int weight, bool italic, bool underline, int start, int count, int base) const = 0;
|
||||
|
||||
virtual bool isGlContextInitialized() const = 0;
|
||||
};
|
||||
|
||||
CV_EXPORTS void icvSetOpenGlFuncTab(const CvOpenGlFuncTab* tab);
|
||||
|
||||
CV_EXPORTS bool icvCheckGlError(const char* file, const int line, const char* func = "");
|
||||
|
||||
// >
|
||||
|
||||
namespace cv { namespace ogl {
|
||||
CV_EXPORTS bool checkError(const char* file, const int line, const char* func = "");
|
||||
}}
|
||||
|
||||
#define CV_CheckGlError() CV_DbgAssert( (cv::ogl::checkError(__FILE__, __LINE__, CV_Func)) )
|
||||
|
||||
#endif //__cplusplus
|
||||
|
||||
#endif // __OPENCV_CORE_INTERNAL_HPP__
|
||||
@@ -0,0 +1,195 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2015, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Copyright (C) 2015, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_IPPASYNC_HPP
|
||||
#define OPENCV_CORE_IPPASYNC_HPP
|
||||
|
||||
#ifdef HAVE_IPP_A
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include <ipp_async_op.h>
|
||||
#include <ipp_async_accel.h>
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
namespace hpp
|
||||
{
|
||||
|
||||
/** @addtogroup core_ipp
|
||||
This section describes conversion between OpenCV and [Intel® IPP Asynchronous
|
||||
C/C++](http://software.intel.com/en-us/intel-ipp-preview) library. [Getting Started
|
||||
Guide](http://registrationcenter.intel.com/irc_nas/3727/ipp_async_get_started.htm) help you to
|
||||
install the library, configure header and library build paths.
|
||||
*/
|
||||
//! @{
|
||||
|
||||
//! convert OpenCV data type to hppDataType
|
||||
inline int toHppType(const int cvType)
|
||||
{
|
||||
int depth = CV_MAT_DEPTH(cvType);
|
||||
int hppType = depth == CV_8U ? HPP_DATA_TYPE_8U :
|
||||
depth == CV_16U ? HPP_DATA_TYPE_16U :
|
||||
depth == CV_16S ? HPP_DATA_TYPE_16S :
|
||||
depth == CV_32S ? HPP_DATA_TYPE_32S :
|
||||
depth == CV_32F ? HPP_DATA_TYPE_32F :
|
||||
depth == CV_64F ? HPP_DATA_TYPE_64F : -1;
|
||||
CV_Assert( hppType >= 0 );
|
||||
return hppType;
|
||||
}
|
||||
|
||||
//! convert hppDataType to OpenCV data type
|
||||
inline int toCvType(const int hppType)
|
||||
{
|
||||
int cvType = hppType == HPP_DATA_TYPE_8U ? CV_8U :
|
||||
hppType == HPP_DATA_TYPE_16U ? CV_16U :
|
||||
hppType == HPP_DATA_TYPE_16S ? CV_16S :
|
||||
hppType == HPP_DATA_TYPE_32S ? CV_32S :
|
||||
hppType == HPP_DATA_TYPE_32F ? CV_32F :
|
||||
hppType == HPP_DATA_TYPE_64F ? CV_64F : -1;
|
||||
CV_Assert( cvType >= 0 );
|
||||
return cvType;
|
||||
}
|
||||
|
||||
/** @brief Convert hppiMatrix to Mat.
|
||||
|
||||
This function allocates and initializes new matrix (if needed) that has the same size and type as
|
||||
input matrix. Supports CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F.
|
||||
@param src input hppiMatrix.
|
||||
@param dst output matrix.
|
||||
@param accel accelerator instance (see hpp::getHpp for the list of acceleration framework types).
|
||||
@param cn number of channels.
|
||||
*/
|
||||
inline void copyHppToMat(hppiMatrix* src, Mat& dst, hppAccel accel, int cn)
|
||||
{
|
||||
hppDataType type;
|
||||
hpp32u width, height;
|
||||
hppStatus sts;
|
||||
|
||||
if (src == NULL)
|
||||
return dst.release();
|
||||
|
||||
sts = hppiInquireMatrix(src, &type, &width, &height);
|
||||
|
||||
CV_Assert( sts == HPP_STATUS_NO_ERROR);
|
||||
|
||||
int matType = CV_MAKETYPE(toCvType(type), cn);
|
||||
|
||||
CV_Assert(width%cn == 0);
|
||||
|
||||
width /= cn;
|
||||
|
||||
dst.create((int)height, (int)width, (int)matType);
|
||||
|
||||
size_t newSize = (size_t)(height*(hpp32u)(dst.step));
|
||||
|
||||
sts = hppiGetMatrixData(accel,src,(hpp32u)(dst.step),dst.data,&newSize);
|
||||
|
||||
CV_Assert( sts == HPP_STATUS_NO_ERROR);
|
||||
}
|
||||
|
||||
/** @brief Create Mat from hppiMatrix.
|
||||
|
||||
This function allocates and initializes the Mat that has the same size and type as input matrix.
|
||||
Supports CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F.
|
||||
@param src input hppiMatrix.
|
||||
@param accel accelerator instance (see hpp::getHpp for the list of acceleration framework types).
|
||||
@param cn number of channels.
|
||||
@sa howToUseIPPAconversion, hpp::copyHppToMat, hpp::getHpp.
|
||||
*/
|
||||
inline Mat getMat(hppiMatrix* src, hppAccel accel, int cn)
|
||||
{
|
||||
Mat dst;
|
||||
copyHppToMat(src, dst, accel, cn);
|
||||
return dst;
|
||||
}
|
||||
|
||||
/** @brief Create hppiMatrix from Mat.
|
||||
|
||||
This function allocates and initializes the hppiMatrix that has the same size and type as input
|
||||
matrix, returns the hppiMatrix*.
|
||||
|
||||
If you want to use zero-copy for GPU you should to have 4KB aligned matrix data. See details
|
||||
[hppiCreateSharedMatrix](http://software.intel.com/ru-ru/node/501697).
|
||||
|
||||
Supports CV_8U, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F.
|
||||
|
||||
@note The hppiMatrix pointer to the image buffer in system memory refers to the src.data. Control
|
||||
the lifetime of the matrix and don't change its data, if there is no special need.
|
||||
@param src input matrix.
|
||||
@param accel accelerator instance. Supports type:
|
||||
- **HPP_ACCEL_TYPE_CPU** - accelerated by optimized CPU instructions.
|
||||
- **HPP_ACCEL_TYPE_GPU** - accelerated by GPU programmable units or fixed-function
|
||||
accelerators.
|
||||
- **HPP_ACCEL_TYPE_ANY** - any acceleration or no acceleration available.
|
||||
@sa howToUseIPPAconversion, hpp::getMat
|
||||
*/
|
||||
inline hppiMatrix* getHpp(const Mat& src, hppAccel accel)
|
||||
{
|
||||
int htype = toHppType(src.type());
|
||||
int cn = src.channels();
|
||||
|
||||
CV_Assert(src.data);
|
||||
hppAccelType accelType = hppQueryAccelType(accel);
|
||||
|
||||
if (accelType!=HPP_ACCEL_TYPE_CPU)
|
||||
{
|
||||
hpp32u pitch, size;
|
||||
hppQueryMatrixAllocParams(accel, src.cols*cn, src.rows, htype, &pitch, &size);
|
||||
if (pitch!=0 && size!=0)
|
||||
if ((int)(src.data)%4096==0 && pitch==(hpp32u)(src.step))
|
||||
{
|
||||
return hppiCreateSharedMatrix(htype, src.cols*cn, src.rows, src.data, pitch, size);
|
||||
}
|
||||
}
|
||||
|
||||
return hppiCreateMatrix(htype, src.cols*cn, src.rows, src.data, (hpp32s)(src.step));;
|
||||
}
|
||||
|
||||
//! @}
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+3243
-2342
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,128 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2015, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_HAL_NEON_UTILS_HPP
|
||||
#define OPENCV_HAL_NEON_UTILS_HPP
|
||||
|
||||
#include "opencv2/core/cvdef.h"
|
||||
|
||||
//! @addtogroup core_utils_neon
|
||||
//! @{
|
||||
|
||||
#if CV_NEON
|
||||
|
||||
inline int32x2_t cv_vrnd_s32_f32(float32x2_t v)
|
||||
{
|
||||
static int32x2_t v_sign = vdup_n_s32(1 << 31),
|
||||
v_05 = vreinterpret_s32_f32(vdup_n_f32(0.5f));
|
||||
|
||||
int32x2_t v_addition = vorr_s32(v_05, vand_s32(v_sign, vreinterpret_s32_f32(v)));
|
||||
return vcvt_s32_f32(vadd_f32(v, vreinterpret_f32_s32(v_addition)));
|
||||
}
|
||||
|
||||
inline int32x4_t cv_vrndq_s32_f32(float32x4_t v)
|
||||
{
|
||||
static int32x4_t v_sign = vdupq_n_s32(1 << 31),
|
||||
v_05 = vreinterpretq_s32_f32(vdupq_n_f32(0.5f));
|
||||
|
||||
int32x4_t v_addition = vorrq_s32(v_05, vandq_s32(v_sign, vreinterpretq_s32_f32(v)));
|
||||
return vcvtq_s32_f32(vaddq_f32(v, vreinterpretq_f32_s32(v_addition)));
|
||||
}
|
||||
|
||||
inline uint32x2_t cv_vrnd_u32_f32(float32x2_t v)
|
||||
{
|
||||
static float32x2_t v_05 = vdup_n_f32(0.5f);
|
||||
return vcvt_u32_f32(vadd_f32(v, v_05));
|
||||
}
|
||||
|
||||
inline uint32x4_t cv_vrndq_u32_f32(float32x4_t v)
|
||||
{
|
||||
static float32x4_t v_05 = vdupq_n_f32(0.5f);
|
||||
return vcvtq_u32_f32(vaddq_f32(v, v_05));
|
||||
}
|
||||
|
||||
inline float32x4_t cv_vrecpq_f32(float32x4_t val)
|
||||
{
|
||||
float32x4_t reciprocal = vrecpeq_f32(val);
|
||||
reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal);
|
||||
reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal);
|
||||
return reciprocal;
|
||||
}
|
||||
|
||||
inline float32x2_t cv_vrecp_f32(float32x2_t val)
|
||||
{
|
||||
float32x2_t reciprocal = vrecpe_f32(val);
|
||||
reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal);
|
||||
reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal);
|
||||
return reciprocal;
|
||||
}
|
||||
|
||||
inline float32x4_t cv_vrsqrtq_f32(float32x4_t val)
|
||||
{
|
||||
float32x4_t e = vrsqrteq_f32(val);
|
||||
e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e);
|
||||
e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e);
|
||||
return e;
|
||||
}
|
||||
|
||||
inline float32x2_t cv_vrsqrt_f32(float32x2_t val)
|
||||
{
|
||||
float32x2_t e = vrsqrte_f32(val);
|
||||
e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e);
|
||||
e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e);
|
||||
return e;
|
||||
}
|
||||
|
||||
inline float32x4_t cv_vsqrtq_f32(float32x4_t val)
|
||||
{
|
||||
return cv_vrecpq_f32(cv_vrsqrtq_f32(val));
|
||||
}
|
||||
|
||||
inline float32x2_t cv_vsqrt_f32(float32x2_t val)
|
||||
{
|
||||
return cv_vrecp_f32(cv_vrsqrt_f32(val));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // OPENCV_HAL_NEON_UTILS_HPP
|
||||
@@ -0,0 +1,757 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the OpenCV Foundation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_OPENCL_HPP
|
||||
#define OPENCV_OPENCL_HPP
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
namespace cv { namespace ocl {
|
||||
|
||||
//! @addtogroup core_opencl
|
||||
//! @{
|
||||
|
||||
CV_EXPORTS_W bool haveOpenCL();
|
||||
CV_EXPORTS_W bool useOpenCL();
|
||||
CV_EXPORTS_W bool haveAmdBlas();
|
||||
CV_EXPORTS_W bool haveAmdFft();
|
||||
CV_EXPORTS_W void setUseOpenCL(bool flag);
|
||||
CV_EXPORTS_W void finish();
|
||||
|
||||
CV_EXPORTS bool haveSVM();
|
||||
|
||||
class CV_EXPORTS Context;
|
||||
class CV_EXPORTS Device;
|
||||
class CV_EXPORTS Kernel;
|
||||
class CV_EXPORTS Program;
|
||||
class CV_EXPORTS ProgramSource;
|
||||
class CV_EXPORTS Queue;
|
||||
class CV_EXPORTS PlatformInfo;
|
||||
class CV_EXPORTS Image2D;
|
||||
|
||||
class CV_EXPORTS Device
|
||||
{
|
||||
public:
|
||||
Device();
|
||||
explicit Device(void* d);
|
||||
Device(const Device& d);
|
||||
Device& operator = (const Device& d);
|
||||
~Device();
|
||||
|
||||
void set(void* d);
|
||||
|
||||
enum
|
||||
{
|
||||
TYPE_DEFAULT = (1 << 0),
|
||||
TYPE_CPU = (1 << 1),
|
||||
TYPE_GPU = (1 << 2),
|
||||
TYPE_ACCELERATOR = (1 << 3),
|
||||
TYPE_DGPU = TYPE_GPU + (1 << 16),
|
||||
TYPE_IGPU = TYPE_GPU + (1 << 17),
|
||||
TYPE_ALL = 0xFFFFFFFF
|
||||
};
|
||||
|
||||
String name() const;
|
||||
String extensions() const;
|
||||
String version() const;
|
||||
String vendorName() const;
|
||||
String OpenCL_C_Version() const;
|
||||
String OpenCLVersion() const;
|
||||
int deviceVersionMajor() const;
|
||||
int deviceVersionMinor() const;
|
||||
String driverVersion() const;
|
||||
void* ptr() const;
|
||||
|
||||
int type() const;
|
||||
|
||||
int addressBits() const;
|
||||
bool available() const;
|
||||
bool compilerAvailable() const;
|
||||
bool linkerAvailable() const;
|
||||
|
||||
enum
|
||||
{
|
||||
FP_DENORM=(1 << 0),
|
||||
FP_INF_NAN=(1 << 1),
|
||||
FP_ROUND_TO_NEAREST=(1 << 2),
|
||||
FP_ROUND_TO_ZERO=(1 << 3),
|
||||
FP_ROUND_TO_INF=(1 << 4),
|
||||
FP_FMA=(1 << 5),
|
||||
FP_SOFT_FLOAT=(1 << 6),
|
||||
FP_CORRECTLY_ROUNDED_DIVIDE_SQRT=(1 << 7)
|
||||
};
|
||||
int doubleFPConfig() const;
|
||||
int singleFPConfig() const;
|
||||
int halfFPConfig() const;
|
||||
|
||||
bool endianLittle() const;
|
||||
bool errorCorrectionSupport() const;
|
||||
|
||||
enum
|
||||
{
|
||||
EXEC_KERNEL=(1 << 0),
|
||||
EXEC_NATIVE_KERNEL=(1 << 1)
|
||||
};
|
||||
int executionCapabilities() const;
|
||||
|
||||
size_t globalMemCacheSize() const;
|
||||
|
||||
enum
|
||||
{
|
||||
NO_CACHE=0,
|
||||
READ_ONLY_CACHE=1,
|
||||
READ_WRITE_CACHE=2
|
||||
};
|
||||
int globalMemCacheType() const;
|
||||
int globalMemCacheLineSize() const;
|
||||
size_t globalMemSize() const;
|
||||
|
||||
size_t localMemSize() const;
|
||||
enum
|
||||
{
|
||||
NO_LOCAL_MEM=0,
|
||||
LOCAL_IS_LOCAL=1,
|
||||
LOCAL_IS_GLOBAL=2
|
||||
};
|
||||
int localMemType() const;
|
||||
bool hostUnifiedMemory() const;
|
||||
|
||||
bool imageSupport() const;
|
||||
|
||||
bool imageFromBufferSupport() const;
|
||||
uint imagePitchAlignment() const;
|
||||
uint imageBaseAddressAlignment() const;
|
||||
|
||||
size_t image2DMaxWidth() const;
|
||||
size_t image2DMaxHeight() const;
|
||||
|
||||
size_t image3DMaxWidth() const;
|
||||
size_t image3DMaxHeight() const;
|
||||
size_t image3DMaxDepth() const;
|
||||
|
||||
size_t imageMaxBufferSize() const;
|
||||
size_t imageMaxArraySize() const;
|
||||
|
||||
enum
|
||||
{
|
||||
UNKNOWN_VENDOR=0,
|
||||
VENDOR_AMD=1,
|
||||
VENDOR_INTEL=2,
|
||||
VENDOR_NVIDIA=3
|
||||
};
|
||||
int vendorID() const;
|
||||
// FIXIT
|
||||
// dev.isAMD() doesn't work for OpenCL CPU devices from AMD OpenCL platform.
|
||||
// This method should use platform name instead of vendor name.
|
||||
// After fix restore code in arithm.cpp: ocl_compare()
|
||||
inline bool isAMD() const { return vendorID() == VENDOR_AMD; }
|
||||
inline bool isIntel() const { return vendorID() == VENDOR_INTEL; }
|
||||
inline bool isNVidia() const { return vendorID() == VENDOR_NVIDIA; }
|
||||
|
||||
int maxClockFrequency() const;
|
||||
int maxComputeUnits() const;
|
||||
int maxConstantArgs() const;
|
||||
size_t maxConstantBufferSize() const;
|
||||
|
||||
size_t maxMemAllocSize() const;
|
||||
size_t maxParameterSize() const;
|
||||
|
||||
int maxReadImageArgs() const;
|
||||
int maxWriteImageArgs() const;
|
||||
int maxSamplers() const;
|
||||
|
||||
size_t maxWorkGroupSize() const;
|
||||
int maxWorkItemDims() const;
|
||||
void maxWorkItemSizes(size_t*) const;
|
||||
|
||||
int memBaseAddrAlign() const;
|
||||
|
||||
int nativeVectorWidthChar() const;
|
||||
int nativeVectorWidthShort() const;
|
||||
int nativeVectorWidthInt() const;
|
||||
int nativeVectorWidthLong() const;
|
||||
int nativeVectorWidthFloat() const;
|
||||
int nativeVectorWidthDouble() const;
|
||||
int nativeVectorWidthHalf() const;
|
||||
|
||||
int preferredVectorWidthChar() const;
|
||||
int preferredVectorWidthShort() const;
|
||||
int preferredVectorWidthInt() const;
|
||||
int preferredVectorWidthLong() const;
|
||||
int preferredVectorWidthFloat() const;
|
||||
int preferredVectorWidthDouble() const;
|
||||
int preferredVectorWidthHalf() const;
|
||||
|
||||
size_t printfBufferSize() const;
|
||||
size_t profilingTimerResolution() const;
|
||||
|
||||
static const Device& getDefault();
|
||||
|
||||
protected:
|
||||
struct Impl;
|
||||
Impl* p;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS Context
|
||||
{
|
||||
public:
|
||||
Context();
|
||||
explicit Context(int dtype);
|
||||
~Context();
|
||||
Context(const Context& c);
|
||||
Context& operator = (const Context& c);
|
||||
|
||||
bool create();
|
||||
bool create(int dtype);
|
||||
size_t ndevices() const;
|
||||
const Device& device(size_t idx) const;
|
||||
Program getProg(const ProgramSource& prog,
|
||||
const String& buildopt, String& errmsg);
|
||||
|
||||
static Context& getDefault(bool initialize = true);
|
||||
void* ptr() const;
|
||||
|
||||
friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device);
|
||||
|
||||
bool useSVM() const;
|
||||
void setUseSVM(bool enabled);
|
||||
|
||||
struct Impl;
|
||||
Impl* p;
|
||||
};
|
||||
|
||||
class CV_EXPORTS Platform
|
||||
{
|
||||
public:
|
||||
Platform();
|
||||
~Platform();
|
||||
Platform(const Platform& p);
|
||||
Platform& operator = (const Platform& p);
|
||||
|
||||
void* ptr() const;
|
||||
static Platform& getDefault();
|
||||
|
||||
friend void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device);
|
||||
protected:
|
||||
struct Impl;
|
||||
Impl* p;
|
||||
};
|
||||
|
||||
/*
|
||||
//! @brief Attaches OpenCL context to OpenCV
|
||||
//
|
||||
//! @note Note:
|
||||
// OpenCV will check if available OpenCL platform has platformName name,
|
||||
// then assign context to OpenCV and call clRetainContext function.
|
||||
// The deviceID device will be used as target device and new command queue
|
||||
// will be created.
|
||||
//
|
||||
// Params:
|
||||
//! @param platformName - name of OpenCL platform to attach,
|
||||
//! this string is used to check if platform is available
|
||||
//! to OpenCV at runtime
|
||||
//! @param platfromID - ID of platform attached context was created for
|
||||
//! @param context - OpenCL context to be attached to OpenCV
|
||||
//! @param deviceID - ID of device, must be created from attached context
|
||||
*/
|
||||
CV_EXPORTS void attachContext(const String& platformName, void* platformID, void* context, void* deviceID);
|
||||
|
||||
/*
|
||||
//! @brief Convert OpenCL buffer to UMat
|
||||
//
|
||||
//! @note Note:
|
||||
// OpenCL buffer (cl_mem_buffer) should contain 2D image data, compatible with OpenCV.
|
||||
// Memory content is not copied from clBuffer to UMat. Instead, buffer handle assigned
|
||||
// to UMat and clRetainMemObject is called.
|
||||
//
|
||||
// Params:
|
||||
//! @param cl_mem_buffer - source clBuffer handle
|
||||
//! @param step - num of bytes in single row
|
||||
//! @param rows - number of rows
|
||||
//! @param cols - number of cols
|
||||
//! @param type - OpenCV type of image
|
||||
//! @param dst - destination UMat
|
||||
*/
|
||||
CV_EXPORTS void convertFromBuffer(void* cl_mem_buffer, size_t step, int rows, int cols, int type, UMat& dst);
|
||||
|
||||
/*
|
||||
//! @brief Convert OpenCL image2d_t to UMat
|
||||
//
|
||||
//! @note Note:
|
||||
// OpenCL image2d_t (cl_mem_image), should be compatible with OpenCV
|
||||
// UMat formats.
|
||||
// Memory content is copied from image to UMat with
|
||||
// clEnqueueCopyImageToBuffer function.
|
||||
//
|
||||
// Params:
|
||||
//! @param cl_mem_image - source image2d_t handle
|
||||
//! @param dst - destination UMat
|
||||
*/
|
||||
CV_EXPORTS void convertFromImage(void* cl_mem_image, UMat& dst);
|
||||
|
||||
// TODO Move to internal header
|
||||
void initializeContextFromHandle(Context& ctx, void* platform, void* context, void* device);
|
||||
|
||||
class CV_EXPORTS Queue
|
||||
{
|
||||
public:
|
||||
Queue();
|
||||
explicit Queue(const Context& c, const Device& d=Device());
|
||||
~Queue();
|
||||
Queue(const Queue& q);
|
||||
Queue& operator = (const Queue& q);
|
||||
|
||||
bool create(const Context& c=Context(), const Device& d=Device());
|
||||
void finish();
|
||||
void* ptr() const;
|
||||
static Queue& getDefault();
|
||||
|
||||
protected:
|
||||
struct Impl;
|
||||
Impl* p;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS KernelArg
|
||||
{
|
||||
public:
|
||||
enum { LOCAL=1, READ_ONLY=2, WRITE_ONLY=4, READ_WRITE=6, CONSTANT=8, PTR_ONLY = 16, NO_SIZE=256 };
|
||||
KernelArg(int _flags, UMat* _m, int wscale=1, int iwscale=1, const void* _obj=0, size_t _sz=0);
|
||||
KernelArg();
|
||||
|
||||
static KernelArg Local() { return KernelArg(LOCAL, 0); }
|
||||
static KernelArg PtrWriteOnly(const UMat& m)
|
||||
{ return KernelArg(PTR_ONLY+WRITE_ONLY, (UMat*)&m); }
|
||||
static KernelArg PtrReadOnly(const UMat& m)
|
||||
{ return KernelArg(PTR_ONLY+READ_ONLY, (UMat*)&m); }
|
||||
static KernelArg PtrReadWrite(const UMat& m)
|
||||
{ return KernelArg(PTR_ONLY+READ_WRITE, (UMat*)&m); }
|
||||
static KernelArg ReadWrite(const UMat& m, int wscale=1, int iwscale=1)
|
||||
{ return KernelArg(READ_WRITE, (UMat*)&m, wscale, iwscale); }
|
||||
static KernelArg ReadWriteNoSize(const UMat& m, int wscale=1, int iwscale=1)
|
||||
{ return KernelArg(READ_WRITE+NO_SIZE, (UMat*)&m, wscale, iwscale); }
|
||||
static KernelArg ReadOnly(const UMat& m, int wscale=1, int iwscale=1)
|
||||
{ return KernelArg(READ_ONLY, (UMat*)&m, wscale, iwscale); }
|
||||
static KernelArg WriteOnly(const UMat& m, int wscale=1, int iwscale=1)
|
||||
{ return KernelArg(WRITE_ONLY, (UMat*)&m, wscale, iwscale); }
|
||||
static KernelArg ReadOnlyNoSize(const UMat& m, int wscale=1, int iwscale=1)
|
||||
{ return KernelArg(READ_ONLY+NO_SIZE, (UMat*)&m, wscale, iwscale); }
|
||||
static KernelArg WriteOnlyNoSize(const UMat& m, int wscale=1, int iwscale=1)
|
||||
{ return KernelArg(WRITE_ONLY+NO_SIZE, (UMat*)&m, wscale, iwscale); }
|
||||
static KernelArg Constant(const Mat& m);
|
||||
template<typename _Tp> static KernelArg Constant(const _Tp* arr, size_t n)
|
||||
{ return KernelArg(CONSTANT, 0, 1, 1, (void*)arr, n); }
|
||||
|
||||
int flags;
|
||||
UMat* m;
|
||||
const void* obj;
|
||||
size_t sz;
|
||||
int wscale, iwscale;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS Kernel
|
||||
{
|
||||
public:
|
||||
Kernel();
|
||||
Kernel(const char* kname, const Program& prog);
|
||||
Kernel(const char* kname, const ProgramSource& prog,
|
||||
const String& buildopts = String(), String* errmsg=0);
|
||||
~Kernel();
|
||||
Kernel(const Kernel& k);
|
||||
Kernel& operator = (const Kernel& k);
|
||||
|
||||
bool empty() const;
|
||||
bool create(const char* kname, const Program& prog);
|
||||
bool create(const char* kname, const ProgramSource& prog,
|
||||
const String& buildopts, String* errmsg=0);
|
||||
|
||||
int set(int i, const void* value, size_t sz);
|
||||
int set(int i, const Image2D& image2D);
|
||||
int set(int i, const UMat& m);
|
||||
int set(int i, const KernelArg& arg);
|
||||
template<typename _Tp> int set(int i, const _Tp& value)
|
||||
{ return set(i, &value, sizeof(value)); }
|
||||
|
||||
template<typename _Tp0>
|
||||
Kernel& args(const _Tp0& a0)
|
||||
{
|
||||
set(0, a0); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1)
|
||||
{
|
||||
int i = set(0, a0); set(i, a1); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); set(i, a2); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2,
|
||||
const _Tp3& a3, const _Tp4& a4)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2);
|
||||
i = set(i, a3); set(i, a4); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2,
|
||||
typename _Tp3, typename _Tp4, typename _Tp5>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2,
|
||||
const _Tp3& a3, const _Tp4& a4, const _Tp5& a5)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2);
|
||||
i = set(i, a3); i = set(i, a4); set(i, a5); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
|
||||
typename _Tp4, typename _Tp5, typename _Tp6>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3);
|
||||
i = set(i, a4); i = set(i, a5); set(i, a6); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
|
||||
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3);
|
||||
i = set(i, a4); i = set(i, a5); i = set(i, a6); set(i, a7); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4,
|
||||
typename _Tp5, typename _Tp6, typename _Tp7, typename _Tp8>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
|
||||
const _Tp8& a8)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4);
|
||||
i = set(i, a5); i = set(i, a6); i = set(i, a7); set(i, a8); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3, typename _Tp4,
|
||||
typename _Tp5, typename _Tp6, typename _Tp7, typename _Tp8, typename _Tp9>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
|
||||
const _Tp8& a8, const _Tp9& a9)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5);
|
||||
i = set(i, a6); i = set(i, a7); i = set(i, a8); set(i, a9); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
|
||||
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
|
||||
typename _Tp8, typename _Tp9, typename _Tp10>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
|
||||
const _Tp8& a8, const _Tp9& a9, const _Tp10& a10)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5);
|
||||
i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); set(i, a10); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
|
||||
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
|
||||
typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
|
||||
const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5);
|
||||
i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); set(i, a11); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
|
||||
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
|
||||
typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
|
||||
const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11,
|
||||
const _Tp12& a12)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5);
|
||||
i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11);
|
||||
set(i, a12); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
|
||||
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
|
||||
typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12,
|
||||
typename _Tp13>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
|
||||
const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11,
|
||||
const _Tp12& a12, const _Tp13& a13)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5);
|
||||
i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11);
|
||||
i = set(i, a12); set(i, a13); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
|
||||
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
|
||||
typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12,
|
||||
typename _Tp13, typename _Tp14>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
|
||||
const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11,
|
||||
const _Tp12& a12, const _Tp13& a13, const _Tp14& a14)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5);
|
||||
i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11);
|
||||
i = set(i, a12); i = set(i, a13); set(i, a14); return *this;
|
||||
}
|
||||
|
||||
template<typename _Tp0, typename _Tp1, typename _Tp2, typename _Tp3,
|
||||
typename _Tp4, typename _Tp5, typename _Tp6, typename _Tp7,
|
||||
typename _Tp8, typename _Tp9, typename _Tp10, typename _Tp11, typename _Tp12,
|
||||
typename _Tp13, typename _Tp14, typename _Tp15>
|
||||
Kernel& args(const _Tp0& a0, const _Tp1& a1, const _Tp2& a2, const _Tp3& a3,
|
||||
const _Tp4& a4, const _Tp5& a5, const _Tp6& a6, const _Tp7& a7,
|
||||
const _Tp8& a8, const _Tp9& a9, const _Tp10& a10, const _Tp11& a11,
|
||||
const _Tp12& a12, const _Tp13& a13, const _Tp14& a14, const _Tp15& a15)
|
||||
{
|
||||
int i = set(0, a0); i = set(i, a1); i = set(i, a2); i = set(i, a3); i = set(i, a4); i = set(i, a5);
|
||||
i = set(i, a6); i = set(i, a7); i = set(i, a8); i = set(i, a9); i = set(i, a10); i = set(i, a11);
|
||||
i = set(i, a12); i = set(i, a13); i = set(i, a14); set(i, a15); return *this;
|
||||
}
|
||||
/*
|
||||
Run the OpenCL kernel.
|
||||
@param dims the work problem dimensions. It is the length of globalsize and localsize. It can be either 1, 2 or 3.
|
||||
@param globalsize work items for each dimension.
|
||||
It is not the final globalsize passed to OpenCL.
|
||||
Each dimension will be adjusted to the nearest integer divisible by the corresponding value in localsize.
|
||||
If localsize is NULL, it will still be adjusted depending on dims.
|
||||
The adjusted values are greater than or equal to the original values.
|
||||
@param localsize work-group size for each dimension.
|
||||
@param sync specify whether to wait for OpenCL computation to finish before return.
|
||||
@param q command queue
|
||||
*/
|
||||
bool run(int dims, size_t globalsize[],
|
||||
size_t localsize[], bool sync, const Queue& q=Queue());
|
||||
bool runTask(bool sync, const Queue& q=Queue());
|
||||
|
||||
size_t workGroupSize() const;
|
||||
size_t preferedWorkGroupSizeMultiple() const;
|
||||
bool compileWorkGroupSize(size_t wsz[]) const;
|
||||
size_t localMemSize() const;
|
||||
|
||||
void* ptr() const;
|
||||
struct Impl;
|
||||
|
||||
protected:
|
||||
Impl* p;
|
||||
};
|
||||
|
||||
class CV_EXPORTS Program
|
||||
{
|
||||
public:
|
||||
Program();
|
||||
Program(const ProgramSource& src,
|
||||
const String& buildflags, String& errmsg);
|
||||
explicit Program(const String& buf);
|
||||
Program(const Program& prog);
|
||||
|
||||
Program& operator = (const Program& prog);
|
||||
~Program();
|
||||
|
||||
bool create(const ProgramSource& src,
|
||||
const String& buildflags, String& errmsg);
|
||||
bool read(const String& buf, const String& buildflags);
|
||||
bool write(String& buf) const;
|
||||
|
||||
const ProgramSource& source() const;
|
||||
void* ptr() const;
|
||||
|
||||
String getPrefix() const;
|
||||
static String getPrefix(const String& buildflags);
|
||||
|
||||
protected:
|
||||
struct Impl;
|
||||
Impl* p;
|
||||
};
|
||||
|
||||
|
||||
class CV_EXPORTS ProgramSource
|
||||
{
|
||||
public:
|
||||
typedef uint64 hash_t;
|
||||
|
||||
ProgramSource();
|
||||
explicit ProgramSource(const String& prog);
|
||||
explicit ProgramSource(const char* prog);
|
||||
~ProgramSource();
|
||||
ProgramSource(const ProgramSource& prog);
|
||||
ProgramSource& operator = (const ProgramSource& prog);
|
||||
|
||||
const String& source() const;
|
||||
hash_t hash() const;
|
||||
|
||||
protected:
|
||||
struct Impl;
|
||||
Impl* p;
|
||||
};
|
||||
|
||||
class CV_EXPORTS PlatformInfo
|
||||
{
|
||||
public:
|
||||
PlatformInfo();
|
||||
explicit PlatformInfo(void* id);
|
||||
~PlatformInfo();
|
||||
|
||||
PlatformInfo(const PlatformInfo& i);
|
||||
PlatformInfo& operator =(const PlatformInfo& i);
|
||||
|
||||
String name() const;
|
||||
String vendor() const;
|
||||
String version() const;
|
||||
int deviceNumber() const;
|
||||
void getDevice(Device& device, int d) const;
|
||||
|
||||
protected:
|
||||
struct Impl;
|
||||
Impl* p;
|
||||
};
|
||||
|
||||
CV_EXPORTS const char* convertTypeStr(int sdepth, int ddepth, int cn, char* buf);
|
||||
CV_EXPORTS const char* typeToStr(int t);
|
||||
CV_EXPORTS const char* memopTypeToStr(int t);
|
||||
CV_EXPORTS const char* vecopTypeToStr(int t);
|
||||
CV_EXPORTS String kernelToStr(InputArray _kernel, int ddepth = -1, const char * name = NULL);
|
||||
CV_EXPORTS void getPlatfomsInfo(std::vector<PlatformInfo>& platform_info);
|
||||
|
||||
|
||||
enum OclVectorStrategy
|
||||
{
|
||||
// all matrices have its own vector width
|
||||
OCL_VECTOR_OWN = 0,
|
||||
// all matrices have maximal vector width among all matrices
|
||||
// (useful for cases when matrices have different data types)
|
||||
OCL_VECTOR_MAX = 1,
|
||||
|
||||
// default strategy
|
||||
OCL_VECTOR_DEFAULT = OCL_VECTOR_OWN
|
||||
};
|
||||
|
||||
CV_EXPORTS int predictOptimalVectorWidth(InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(),
|
||||
InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(),
|
||||
InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray(),
|
||||
OclVectorStrategy strat = OCL_VECTOR_DEFAULT);
|
||||
|
||||
CV_EXPORTS int checkOptimalVectorWidth(const int *vectorWidths,
|
||||
InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(),
|
||||
InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(),
|
||||
InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray(),
|
||||
OclVectorStrategy strat = OCL_VECTOR_DEFAULT);
|
||||
|
||||
// with OCL_VECTOR_MAX strategy
|
||||
CV_EXPORTS int predictOptimalVectorWidthMax(InputArray src1, InputArray src2 = noArray(), InputArray src3 = noArray(),
|
||||
InputArray src4 = noArray(), InputArray src5 = noArray(), InputArray src6 = noArray(),
|
||||
InputArray src7 = noArray(), InputArray src8 = noArray(), InputArray src9 = noArray());
|
||||
|
||||
CV_EXPORTS void buildOptionsAddMatrixDescription(String& buildOptions, const String& name, InputArray _m);
|
||||
|
||||
class CV_EXPORTS Image2D
|
||||
{
|
||||
public:
|
||||
Image2D();
|
||||
|
||||
// src: The UMat from which to get image properties and data
|
||||
// norm: Flag to enable the use of normalized channel data types
|
||||
// alias: Flag indicating that the image should alias the src UMat.
|
||||
// If true, changes to the image or src will be reflected in
|
||||
// both objects.
|
||||
explicit Image2D(const UMat &src, bool norm = false, bool alias = false);
|
||||
Image2D(const Image2D & i);
|
||||
~Image2D();
|
||||
|
||||
Image2D & operator = (const Image2D & i);
|
||||
|
||||
// Indicates if creating an aliased image should succeed. Depends on the
|
||||
// underlying platform and the dimensions of the UMat.
|
||||
static bool canCreateAlias(const UMat &u);
|
||||
|
||||
// Indicates if the image format is supported.
|
||||
static bool isFormatSupported(int depth, int cn, bool norm);
|
||||
|
||||
void* ptr() const;
|
||||
protected:
|
||||
struct Impl;
|
||||
Impl* p;
|
||||
};
|
||||
|
||||
|
||||
CV_EXPORTS MatAllocator* getOpenCLAllocator();
|
||||
|
||||
|
||||
#ifdef __OPENCV_BUILD
|
||||
namespace internal {
|
||||
|
||||
CV_EXPORTS bool isOpenCLForced();
|
||||
#define OCL_FORCE_CHECK(condition) (cv::ocl::internal::isOpenCLForced() || (condition))
|
||||
|
||||
CV_EXPORTS bool isPerformanceCheckBypassed();
|
||||
#define OCL_PERFORMANCE_CHECK(condition) (cv::ocl::internal::isPerformanceCheckBypassed() || (condition))
|
||||
|
||||
CV_EXPORTS bool isCLBuffer(UMat& u);
|
||||
|
||||
} // namespace internal
|
||||
#endif
|
||||
|
||||
//! @}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,64 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the OpenCV Foundation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_OPENCL_GENBASE_HPP
|
||||
#define OPENCV_OPENCL_GENBASE_HPP
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace ocl
|
||||
{
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
struct ProgramEntry
|
||||
{
|
||||
const char* name;
|
||||
const char* programStr;
|
||||
const char* programHash;
|
||||
};
|
||||
|
||||
//! @endcond
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,729 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_OPENGL_HPP
|
||||
#define OPENCV_CORE_OPENGL_HPP
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error opengl.hpp header must be compiled as C++
|
||||
#endif
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "ocl.hpp"
|
||||
|
||||
namespace cv { namespace ogl {
|
||||
|
||||
/** @addtogroup core_opengl
|
||||
This section describes OpenGL interoperability.
|
||||
|
||||
To enable OpenGL support, configure OpenCV using CMake with WITH_OPENGL=ON . Currently OpenGL is
|
||||
supported only with WIN32, GTK and Qt backends on Windows and Linux (MacOS and Android are not
|
||||
supported). For GTK backend gtkglext-1.0 library is required.
|
||||
|
||||
To use OpenGL functionality you should first create OpenGL context (window or frame buffer). You can
|
||||
do this with namedWindow function or with other OpenGL toolkit (GLUT, for example).
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/////////////////// OpenGL Objects ///////////////////
|
||||
|
||||
/** @brief Smart pointer for OpenGL buffer object with reference counting.
|
||||
|
||||
Buffer Objects are OpenGL objects that store an array of unformatted memory allocated by the OpenGL
|
||||
context. These can be used to store vertex data, pixel data retrieved from images or the
|
||||
framebuffer, and a variety of other things.
|
||||
|
||||
ogl::Buffer has interface similar with Mat interface and represents 2D array memory.
|
||||
|
||||
ogl::Buffer supports memory transfers between host and device and also can be mapped to CUDA memory.
|
||||
*/
|
||||
class CV_EXPORTS Buffer
|
||||
{
|
||||
public:
|
||||
/** @brief The target defines how you intend to use the buffer object.
|
||||
*/
|
||||
enum Target
|
||||
{
|
||||
ARRAY_BUFFER = 0x8892, //!< The buffer will be used as a source for vertex data
|
||||
ELEMENT_ARRAY_BUFFER = 0x8893, //!< The buffer will be used for indices (in glDrawElements, for example)
|
||||
PIXEL_PACK_BUFFER = 0x88EB, //!< The buffer will be used for reading from OpenGL textures
|
||||
PIXEL_UNPACK_BUFFER = 0x88EC //!< The buffer will be used for writing to OpenGL textures
|
||||
};
|
||||
|
||||
enum Access
|
||||
{
|
||||
READ_ONLY = 0x88B8,
|
||||
WRITE_ONLY = 0x88B9,
|
||||
READ_WRITE = 0x88BA
|
||||
};
|
||||
|
||||
/** @brief The constructors.
|
||||
|
||||
Creates empty ogl::Buffer object, creates ogl::Buffer object from existed buffer ( abufId
|
||||
parameter), allocates memory for ogl::Buffer object or copies from host/device memory.
|
||||
*/
|
||||
Buffer();
|
||||
|
||||
/** @overload
|
||||
@param arows Number of rows in a 2D array.
|
||||
@param acols Number of columns in a 2D array.
|
||||
@param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details.
|
||||
@param abufId Buffer object name.
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
Buffer(int arows, int acols, int atype, unsigned int abufId, bool autoRelease = false);
|
||||
|
||||
/** @overload
|
||||
@param asize 2D array size.
|
||||
@param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details.
|
||||
@param abufId Buffer object name.
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
Buffer(Size asize, int atype, unsigned int abufId, bool autoRelease = false);
|
||||
|
||||
/** @overload
|
||||
@param arows Number of rows in a 2D array.
|
||||
@param acols Number of columns in a 2D array.
|
||||
@param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details.
|
||||
@param target Buffer usage. See cv::ogl::Buffer::Target .
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
Buffer(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
|
||||
/** @overload
|
||||
@param asize 2D array size.
|
||||
@param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details.
|
||||
@param target Buffer usage. See cv::ogl::Buffer::Target .
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
Buffer(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
|
||||
/** @overload
|
||||
@param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or std::vector ).
|
||||
@param target Buffer usage. See cv::ogl::Buffer::Target .
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
explicit Buffer(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
|
||||
/** @brief Allocates memory for ogl::Buffer object.
|
||||
|
||||
@param arows Number of rows in a 2D array.
|
||||
@param acols Number of columns in a 2D array.
|
||||
@param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details.
|
||||
@param target Buffer usage. See cv::ogl::Buffer::Target .
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
void create(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
|
||||
/** @overload
|
||||
@param asize 2D array size.
|
||||
@param atype Array type ( CV_8UC1, ..., CV_64FC4 ). See Mat for details.
|
||||
@param target Buffer usage. See cv::ogl::Buffer::Target .
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
void create(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
|
||||
/** @brief Decrements the reference counter and destroys the buffer object if needed.
|
||||
|
||||
The function will call setAutoRelease(true) .
|
||||
*/
|
||||
void release();
|
||||
|
||||
/** @brief Sets auto release mode.
|
||||
|
||||
The lifetime of the OpenGL object is tied to the lifetime of the context. If OpenGL context was
|
||||
bound to a window it could be released at any time (user can close a window). If object's destructor
|
||||
is called after destruction of the context it will cause an error. Thus ogl::Buffer doesn't destroy
|
||||
OpenGL object in destructor by default (all OpenGL resources will be released with OpenGL context).
|
||||
This function can force ogl::Buffer destructor to destroy OpenGL object.
|
||||
@param flag Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
void setAutoRelease(bool flag);
|
||||
|
||||
/** @brief Copies from host/device memory to OpenGL buffer.
|
||||
@param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or std::vector ).
|
||||
@param target Buffer usage. See cv::ogl::Buffer::Target .
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
void copyFrom(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
|
||||
/** @overload */
|
||||
void copyFrom(InputArray arr, cuda::Stream& stream, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
|
||||
/** @brief Copies from OpenGL buffer to host/device memory or another OpenGL buffer object.
|
||||
|
||||
@param arr Destination array (host or device memory, can be Mat , cuda::GpuMat , std::vector or
|
||||
ogl::Buffer ).
|
||||
*/
|
||||
void copyTo(OutputArray arr) const;
|
||||
|
||||
/** @overload */
|
||||
void copyTo(OutputArray arr, cuda::Stream& stream) const;
|
||||
|
||||
/** @brief Creates a full copy of the buffer object and the underlying data.
|
||||
|
||||
@param target Buffer usage for destination buffer.
|
||||
@param autoRelease Auto release mode for destination buffer.
|
||||
*/
|
||||
Buffer clone(Target target = ARRAY_BUFFER, bool autoRelease = false) const;
|
||||
|
||||
/** @brief Binds OpenGL buffer to the specified buffer binding point.
|
||||
|
||||
@param target Binding point. See cv::ogl::Buffer::Target .
|
||||
*/
|
||||
void bind(Target target) const;
|
||||
|
||||
/** @brief Unbind any buffers from the specified binding point.
|
||||
|
||||
@param target Binding point. See cv::ogl::Buffer::Target .
|
||||
*/
|
||||
static void unbind(Target target);
|
||||
|
||||
/** @brief Maps OpenGL buffer to host memory.
|
||||
|
||||
mapHost maps to the client's address space the entire data store of the buffer object. The data can
|
||||
then be directly read and/or written relative to the returned pointer, depending on the specified
|
||||
access policy.
|
||||
|
||||
A mapped data store must be unmapped with ogl::Buffer::unmapHost before its buffer object is used.
|
||||
|
||||
This operation can lead to memory transfers between host and device.
|
||||
|
||||
Only one buffer object can be mapped at a time.
|
||||
@param access Access policy, indicating whether it will be possible to read from, write to, or both
|
||||
read from and write to the buffer object's mapped data store. The symbolic constant must be
|
||||
ogl::Buffer::READ_ONLY , ogl::Buffer::WRITE_ONLY or ogl::Buffer::READ_WRITE .
|
||||
*/
|
||||
Mat mapHost(Access access);
|
||||
|
||||
/** @brief Unmaps OpenGL buffer.
|
||||
*/
|
||||
void unmapHost();
|
||||
|
||||
//! map to device memory (blocking)
|
||||
cuda::GpuMat mapDevice();
|
||||
void unmapDevice();
|
||||
|
||||
/** @brief Maps OpenGL buffer to CUDA device memory.
|
||||
|
||||
This operatation doesn't copy data. Several buffer objects can be mapped to CUDA memory at a time.
|
||||
|
||||
A mapped data store must be unmapped with ogl::Buffer::unmapDevice before its buffer object is used.
|
||||
*/
|
||||
cuda::GpuMat mapDevice(cuda::Stream& stream);
|
||||
|
||||
/** @brief Unmaps OpenGL buffer.
|
||||
*/
|
||||
void unmapDevice(cuda::Stream& stream);
|
||||
|
||||
int rows() const;
|
||||
int cols() const;
|
||||
Size size() const;
|
||||
bool empty() const;
|
||||
|
||||
int type() const;
|
||||
int depth() const;
|
||||
int channels() const;
|
||||
int elemSize() const;
|
||||
int elemSize1() const;
|
||||
|
||||
//! get OpenGL opject id
|
||||
unsigned int bufId() const;
|
||||
|
||||
class Impl;
|
||||
|
||||
private:
|
||||
Ptr<Impl> impl_;
|
||||
int rows_;
|
||||
int cols_;
|
||||
int type_;
|
||||
};
|
||||
|
||||
/** @brief Smart pointer for OpenGL 2D texture memory with reference counting.
|
||||
*/
|
||||
class CV_EXPORTS Texture2D
|
||||
{
|
||||
public:
|
||||
/** @brief An Image Format describes the way that the images in Textures store their data.
|
||||
*/
|
||||
enum Format
|
||||
{
|
||||
NONE = 0,
|
||||
DEPTH_COMPONENT = 0x1902, //!< Depth
|
||||
RGB = 0x1907, //!< Red, Green, Blue
|
||||
RGBA = 0x1908 //!< Red, Green, Blue, Alpha
|
||||
};
|
||||
|
||||
/** @brief The constructors.
|
||||
|
||||
Creates empty ogl::Texture2D object, allocates memory for ogl::Texture2D object or copies from
|
||||
host/device memory.
|
||||
*/
|
||||
Texture2D();
|
||||
|
||||
/** @overload */
|
||||
Texture2D(int arows, int acols, Format aformat, unsigned int atexId, bool autoRelease = false);
|
||||
|
||||
/** @overload */
|
||||
Texture2D(Size asize, Format aformat, unsigned int atexId, bool autoRelease = false);
|
||||
|
||||
/** @overload
|
||||
@param arows Number of rows.
|
||||
@param acols Number of columns.
|
||||
@param aformat Image format. See cv::ogl::Texture2D::Format .
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
Texture2D(int arows, int acols, Format aformat, bool autoRelease = false);
|
||||
|
||||
/** @overload
|
||||
@param asize 2D array size.
|
||||
@param aformat Image format. See cv::ogl::Texture2D::Format .
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
Texture2D(Size asize, Format aformat, bool autoRelease = false);
|
||||
|
||||
/** @overload
|
||||
@param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or ogl::Buffer ).
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
explicit Texture2D(InputArray arr, bool autoRelease = false);
|
||||
|
||||
/** @brief Allocates memory for ogl::Texture2D object.
|
||||
|
||||
@param arows Number of rows.
|
||||
@param acols Number of columns.
|
||||
@param aformat Image format. See cv::ogl::Texture2D::Format .
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
void create(int arows, int acols, Format aformat, bool autoRelease = false);
|
||||
/** @overload
|
||||
@param asize 2D array size.
|
||||
@param aformat Image format. See cv::ogl::Texture2D::Format .
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
void create(Size asize, Format aformat, bool autoRelease = false);
|
||||
|
||||
/** @brief Decrements the reference counter and destroys the texture object if needed.
|
||||
|
||||
The function will call setAutoRelease(true) .
|
||||
*/
|
||||
void release();
|
||||
|
||||
/** @brief Sets auto release mode.
|
||||
|
||||
@param flag Auto release mode (if true, release will be called in object's destructor).
|
||||
|
||||
The lifetime of the OpenGL object is tied to the lifetime of the context. If OpenGL context was
|
||||
bound to a window it could be released at any time (user can close a window). If object's destructor
|
||||
is called after destruction of the context it will cause an error. Thus ogl::Texture2D doesn't
|
||||
destroy OpenGL object in destructor by default (all OpenGL resources will be released with OpenGL
|
||||
context). This function can force ogl::Texture2D destructor to destroy OpenGL object.
|
||||
*/
|
||||
void setAutoRelease(bool flag);
|
||||
|
||||
/** @brief Copies from host/device memory to OpenGL texture.
|
||||
|
||||
@param arr Input array (host or device memory, it can be Mat , cuda::GpuMat or ogl::Buffer ).
|
||||
@param autoRelease Auto release mode (if true, release will be called in object's destructor).
|
||||
*/
|
||||
void copyFrom(InputArray arr, bool autoRelease = false);
|
||||
|
||||
/** @brief Copies from OpenGL texture to host/device memory or another OpenGL texture object.
|
||||
|
||||
@param arr Destination array (host or device memory, can be Mat , cuda::GpuMat , ogl::Buffer or
|
||||
ogl::Texture2D ).
|
||||
@param ddepth Destination depth.
|
||||
@param autoRelease Auto release mode for destination buffer (if arr is OpenGL buffer or texture).
|
||||
*/
|
||||
void copyTo(OutputArray arr, int ddepth = CV_32F, bool autoRelease = false) const;
|
||||
|
||||
/** @brief Binds texture to current active texture unit for GL_TEXTURE_2D target.
|
||||
*/
|
||||
void bind() const;
|
||||
|
||||
int rows() const;
|
||||
int cols() const;
|
||||
Size size() const;
|
||||
bool empty() const;
|
||||
|
||||
Format format() const;
|
||||
|
||||
//! get OpenGL opject id
|
||||
unsigned int texId() const;
|
||||
|
||||
class Impl;
|
||||
|
||||
private:
|
||||
Ptr<Impl> impl_;
|
||||
int rows_;
|
||||
int cols_;
|
||||
Format format_;
|
||||
};
|
||||
|
||||
/** @brief Wrapper for OpenGL Client-Side Vertex arrays.
|
||||
|
||||
ogl::Arrays stores vertex data in ogl::Buffer objects.
|
||||
*/
|
||||
class CV_EXPORTS Arrays
|
||||
{
|
||||
public:
|
||||
/** @brief Default constructor
|
||||
*/
|
||||
Arrays();
|
||||
|
||||
/** @brief Sets an array of vertex coordinates.
|
||||
@param vertex array with vertex coordinates, can be both host and device memory.
|
||||
*/
|
||||
void setVertexArray(InputArray vertex);
|
||||
|
||||
/** @brief Resets vertex coordinates.
|
||||
*/
|
||||
void resetVertexArray();
|
||||
|
||||
/** @brief Sets an array of vertex colors.
|
||||
@param color array with vertex colors, can be both host and device memory.
|
||||
*/
|
||||
void setColorArray(InputArray color);
|
||||
|
||||
/** @brief Resets vertex colors.
|
||||
*/
|
||||
void resetColorArray();
|
||||
|
||||
/** @brief Sets an array of vertex normals.
|
||||
@param normal array with vertex normals, can be both host and device memory.
|
||||
*/
|
||||
void setNormalArray(InputArray normal);
|
||||
|
||||
/** @brief Resets vertex normals.
|
||||
*/
|
||||
void resetNormalArray();
|
||||
|
||||
/** @brief Sets an array of vertex texture coordinates.
|
||||
@param texCoord array with vertex texture coordinates, can be both host and device memory.
|
||||
*/
|
||||
void setTexCoordArray(InputArray texCoord);
|
||||
|
||||
/** @brief Resets vertex texture coordinates.
|
||||
*/
|
||||
void resetTexCoordArray();
|
||||
|
||||
/** @brief Releases all inner buffers.
|
||||
*/
|
||||
void release();
|
||||
|
||||
/** @brief Sets auto release mode all inner buffers.
|
||||
@param flag Auto release mode.
|
||||
*/
|
||||
void setAutoRelease(bool flag);
|
||||
|
||||
/** @brief Binds all vertex arrays.
|
||||
*/
|
||||
void bind() const;
|
||||
|
||||
/** @brief Returns the vertex count.
|
||||
*/
|
||||
int size() const;
|
||||
bool empty() const;
|
||||
|
||||
private:
|
||||
int size_;
|
||||
Buffer vertex_;
|
||||
Buffer color_;
|
||||
Buffer normal_;
|
||||
Buffer texCoord_;
|
||||
};
|
||||
|
||||
/////////////////// Render Functions ///////////////////
|
||||
|
||||
//! render mode
|
||||
enum RenderModes {
|
||||
POINTS = 0x0000,
|
||||
LINES = 0x0001,
|
||||
LINE_LOOP = 0x0002,
|
||||
LINE_STRIP = 0x0003,
|
||||
TRIANGLES = 0x0004,
|
||||
TRIANGLE_STRIP = 0x0005,
|
||||
TRIANGLE_FAN = 0x0006,
|
||||
QUADS = 0x0007,
|
||||
QUAD_STRIP = 0x0008,
|
||||
POLYGON = 0x0009
|
||||
};
|
||||
|
||||
/** @brief Render OpenGL texture or primitives.
|
||||
@param tex Texture to draw.
|
||||
@param wndRect Region of window, where to draw a texture (normalized coordinates).
|
||||
@param texRect Region of texture to draw (normalized coordinates).
|
||||
*/
|
||||
CV_EXPORTS void render(const Texture2D& tex,
|
||||
Rect_<double> wndRect = Rect_<double>(0.0, 0.0, 1.0, 1.0),
|
||||
Rect_<double> texRect = Rect_<double>(0.0, 0.0, 1.0, 1.0));
|
||||
|
||||
/** @overload
|
||||
@param arr Array of privitives vertices.
|
||||
@param mode Render mode. One of cv::ogl::RenderModes
|
||||
@param color Color for all vertices. Will be used if arr doesn't contain color array.
|
||||
*/
|
||||
CV_EXPORTS void render(const Arrays& arr, int mode = POINTS, Scalar color = Scalar::all(255));
|
||||
|
||||
/** @overload
|
||||
@param arr Array of privitives vertices.
|
||||
@param indices Array of vertices indices (host or device memory).
|
||||
@param mode Render mode. One of cv::ogl::RenderModes
|
||||
@param color Color for all vertices. Will be used if arr doesn't contain color array.
|
||||
*/
|
||||
CV_EXPORTS void render(const Arrays& arr, InputArray indices, int mode = POINTS, Scalar color = Scalar::all(255));
|
||||
|
||||
/////////////////// CL-GL Interoperability Functions ///////////////////
|
||||
|
||||
namespace ocl {
|
||||
using namespace cv::ocl;
|
||||
|
||||
// TODO static functions in the Context class
|
||||
/** @brief Creates OpenCL context from GL.
|
||||
@return Returns reference to OpenCL Context
|
||||
*/
|
||||
CV_EXPORTS Context& initializeContextFromGL();
|
||||
|
||||
} // namespace cv::ogl::ocl
|
||||
|
||||
/** @brief Converts InputArray to Texture2D object.
|
||||
@param src - source InputArray.
|
||||
@param texture - destination Texture2D object.
|
||||
*/
|
||||
CV_EXPORTS void convertToGLTexture2D(InputArray src, Texture2D& texture);
|
||||
|
||||
/** @brief Converts Texture2D object to OutputArray.
|
||||
@param texture - source Texture2D object.
|
||||
@param dst - destination OutputArray.
|
||||
*/
|
||||
CV_EXPORTS void convertFromGLTexture2D(const Texture2D& texture, OutputArray dst);
|
||||
|
||||
/** @brief Maps Buffer object to process on CL side (convert to UMat).
|
||||
|
||||
Function creates CL buffer from GL one, and then constructs UMat that can be used
|
||||
to process buffer data with OpenCV functions. Note that in current implementation
|
||||
UMat constructed this way doesn't own corresponding GL buffer object, so it is
|
||||
the user responsibility to close down CL/GL buffers relationships by explicitly
|
||||
calling unmapGLBuffer() function.
|
||||
@param buffer - source Buffer object.
|
||||
@param accessFlags - data access flags (ACCESS_READ|ACCESS_WRITE).
|
||||
@return Returns UMat object
|
||||
*/
|
||||
CV_EXPORTS UMat mapGLBuffer(const Buffer& buffer, int accessFlags = ACCESS_READ|ACCESS_WRITE);
|
||||
|
||||
/** @brief Unmaps Buffer object (releases UMat, previously mapped from Buffer).
|
||||
|
||||
Function must be called explicitly by the user for each UMat previously constructed
|
||||
by the call to mapGLBuffer() function.
|
||||
@param u - source UMat, created by mapGLBuffer().
|
||||
*/
|
||||
CV_EXPORTS void unmapGLBuffer(UMat& u);
|
||||
|
||||
}} // namespace cv::ogl
|
||||
|
||||
namespace cv { namespace cuda {
|
||||
|
||||
//! @addtogroup cuda
|
||||
//! @{
|
||||
|
||||
/** @brief Sets a CUDA device and initializes it for the current thread with OpenGL interoperability.
|
||||
|
||||
This function should be explicitly called after OpenGL context creation and before any CUDA calls.
|
||||
@param device System index of a CUDA device starting with 0.
|
||||
@ingroup core_opengl
|
||||
*/
|
||||
CV_EXPORTS void setGlDevice(int device = 0);
|
||||
|
||||
//! @}
|
||||
|
||||
}}
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline
|
||||
cv::ogl::Buffer::Buffer(int arows, int acols, int atype, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0)
|
||||
{
|
||||
create(arows, acols, atype, target, autoRelease);
|
||||
}
|
||||
|
||||
inline
|
||||
cv::ogl::Buffer::Buffer(Size asize, int atype, Target target, bool autoRelease) : rows_(0), cols_(0), type_(0)
|
||||
{
|
||||
create(asize, atype, target, autoRelease);
|
||||
}
|
||||
|
||||
inline
|
||||
void cv::ogl::Buffer::create(Size asize, int atype, Target target, bool autoRelease)
|
||||
{
|
||||
create(asize.height, asize.width, atype, target, autoRelease);
|
||||
}
|
||||
|
||||
inline
|
||||
int cv::ogl::Buffer::rows() const
|
||||
{
|
||||
return rows_;
|
||||
}
|
||||
|
||||
inline
|
||||
int cv::ogl::Buffer::cols() const
|
||||
{
|
||||
return cols_;
|
||||
}
|
||||
|
||||
inline
|
||||
cv::Size cv::ogl::Buffer::size() const
|
||||
{
|
||||
return Size(cols_, rows_);
|
||||
}
|
||||
|
||||
inline
|
||||
bool cv::ogl::Buffer::empty() const
|
||||
{
|
||||
return rows_ == 0 || cols_ == 0;
|
||||
}
|
||||
|
||||
inline
|
||||
int cv::ogl::Buffer::type() const
|
||||
{
|
||||
return type_;
|
||||
}
|
||||
|
||||
inline
|
||||
int cv::ogl::Buffer::depth() const
|
||||
{
|
||||
return CV_MAT_DEPTH(type_);
|
||||
}
|
||||
|
||||
inline
|
||||
int cv::ogl::Buffer::channels() const
|
||||
{
|
||||
return CV_MAT_CN(type_);
|
||||
}
|
||||
|
||||
inline
|
||||
int cv::ogl::Buffer::elemSize() const
|
||||
{
|
||||
return CV_ELEM_SIZE(type_);
|
||||
}
|
||||
|
||||
inline
|
||||
int cv::ogl::Buffer::elemSize1() const
|
||||
{
|
||||
return CV_ELEM_SIZE1(type_);
|
||||
}
|
||||
|
||||
///////
|
||||
|
||||
inline
|
||||
cv::ogl::Texture2D::Texture2D(int arows, int acols, Format aformat, bool autoRelease) : rows_(0), cols_(0), format_(NONE)
|
||||
{
|
||||
create(arows, acols, aformat, autoRelease);
|
||||
}
|
||||
|
||||
inline
|
||||
cv::ogl::Texture2D::Texture2D(Size asize, Format aformat, bool autoRelease) : rows_(0), cols_(0), format_(NONE)
|
||||
{
|
||||
create(asize, aformat, autoRelease);
|
||||
}
|
||||
|
||||
inline
|
||||
void cv::ogl::Texture2D::create(Size asize, Format aformat, bool autoRelease)
|
||||
{
|
||||
create(asize.height, asize.width, aformat, autoRelease);
|
||||
}
|
||||
|
||||
inline
|
||||
int cv::ogl::Texture2D::rows() const
|
||||
{
|
||||
return rows_;
|
||||
}
|
||||
|
||||
inline
|
||||
int cv::ogl::Texture2D::cols() const
|
||||
{
|
||||
return cols_;
|
||||
}
|
||||
|
||||
inline
|
||||
cv::Size cv::ogl::Texture2D::size() const
|
||||
{
|
||||
return Size(cols_, rows_);
|
||||
}
|
||||
|
||||
inline
|
||||
bool cv::ogl::Texture2D::empty() const
|
||||
{
|
||||
return rows_ == 0 || cols_ == 0;
|
||||
}
|
||||
|
||||
inline
|
||||
cv::ogl::Texture2D::Format cv::ogl::Texture2D::format() const
|
||||
{
|
||||
return format_;
|
||||
}
|
||||
|
||||
///////
|
||||
|
||||
inline
|
||||
cv::ogl::Arrays::Arrays() : size_(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline
|
||||
int cv::ogl::Arrays::size() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
inline
|
||||
bool cv::ogl::Arrays::empty() const
|
||||
{
|
||||
return size_ == 0;
|
||||
}
|
||||
|
||||
//! @endcond
|
||||
|
||||
#endif /* OPENCV_CORE_OPENGL_HPP */
|
||||
@@ -1,284 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_OPENGL_INTEROP_HPP__
|
||||
#define __OPENCV_OPENGL_INTEROP_HPP__
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/opengl_interop_deprecated.hpp"
|
||||
|
||||
namespace cv { namespace ogl {
|
||||
|
||||
/////////////////// OpenGL Objects ///////////////////
|
||||
|
||||
//! Smart pointer for OpenGL buffer memory with reference counting.
|
||||
class CV_EXPORTS Buffer
|
||||
{
|
||||
public:
|
||||
enum Target
|
||||
{
|
||||
ARRAY_BUFFER = 0x8892, //!< The buffer will be used as a source for vertex data
|
||||
ELEMENT_ARRAY_BUFFER = 0x8893, //!< The buffer will be used for indices (in glDrawElements, for example)
|
||||
PIXEL_PACK_BUFFER = 0x88EB, //!< The buffer will be used for reading from OpenGL textures
|
||||
PIXEL_UNPACK_BUFFER = 0x88EC //!< The buffer will be used for writing to OpenGL textures
|
||||
};
|
||||
|
||||
enum Access
|
||||
{
|
||||
READ_ONLY = 0x88B8,
|
||||
WRITE_ONLY = 0x88B9,
|
||||
READ_WRITE = 0x88BA
|
||||
};
|
||||
|
||||
//! create empty buffer
|
||||
Buffer();
|
||||
|
||||
//! create buffer from existed buffer id
|
||||
Buffer(int arows, int acols, int atype, unsigned int abufId, bool autoRelease = false);
|
||||
Buffer(Size asize, int atype, unsigned int abufId, bool autoRelease = false);
|
||||
|
||||
//! create buffer
|
||||
Buffer(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
Buffer(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
|
||||
//! copy from host/device memory
|
||||
explicit Buffer(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
|
||||
//! create buffer
|
||||
void create(int arows, int acols, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
void create(Size asize, int atype, Target target = ARRAY_BUFFER, bool autoRelease = false) { create(asize.height, asize.width, atype, target, autoRelease); }
|
||||
|
||||
//! release memory and delete buffer object
|
||||
void release();
|
||||
|
||||
//! set auto release mode (if true, release will be called in object's destructor)
|
||||
void setAutoRelease(bool flag);
|
||||
|
||||
//! copy from host/device memory
|
||||
void copyFrom(InputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false);
|
||||
|
||||
//! copy to host/device memory
|
||||
void copyTo(OutputArray arr, Target target = ARRAY_BUFFER, bool autoRelease = false) const;
|
||||
|
||||
//! create copy of current buffer
|
||||
Buffer clone(Target target = ARRAY_BUFFER, bool autoRelease = false) const;
|
||||
|
||||
//! bind buffer for specified target
|
||||
void bind(Target target) const;
|
||||
|
||||
//! unbind any buffers from specified target
|
||||
static void unbind(Target target);
|
||||
|
||||
//! map to host memory
|
||||
Mat mapHost(Access access);
|
||||
void unmapHost();
|
||||
|
||||
//! map to device memory
|
||||
gpu::GpuMat mapDevice();
|
||||
void unmapDevice();
|
||||
|
||||
int rows() const { return rows_; }
|
||||
int cols() const { return cols_; }
|
||||
Size size() const { return Size(cols_, rows_); }
|
||||
bool empty() const { return rows_ == 0 || cols_ == 0; }
|
||||
|
||||
int type() const { return type_; }
|
||||
int depth() const { return CV_MAT_DEPTH(type_); }
|
||||
int channels() const { return CV_MAT_CN(type_); }
|
||||
int elemSize() const { return CV_ELEM_SIZE(type_); }
|
||||
int elemSize1() const { return CV_ELEM_SIZE1(type_); }
|
||||
|
||||
unsigned int bufId() const;
|
||||
|
||||
class Impl;
|
||||
|
||||
private:
|
||||
Ptr<Impl> impl_;
|
||||
int rows_;
|
||||
int cols_;
|
||||
int type_;
|
||||
};
|
||||
|
||||
//! Smart pointer for OpenGL 2D texture memory with reference counting.
|
||||
class CV_EXPORTS Texture2D
|
||||
{
|
||||
public:
|
||||
enum Format
|
||||
{
|
||||
NONE = 0,
|
||||
DEPTH_COMPONENT = 0x1902, //!< Depth
|
||||
RGB = 0x1907, //!< Red, Green, Blue
|
||||
RGBA = 0x1908 //!< Red, Green, Blue, Alpha
|
||||
};
|
||||
|
||||
//! create empty texture
|
||||
Texture2D();
|
||||
|
||||
//! create texture from existed texture id
|
||||
Texture2D(int arows, int acols, Format aformat, unsigned int atexId, bool autoRelease = false);
|
||||
Texture2D(Size asize, Format aformat, unsigned int atexId, bool autoRelease = false);
|
||||
|
||||
//! create texture
|
||||
Texture2D(int arows, int acols, Format aformat, bool autoRelease = false);
|
||||
Texture2D(Size asize, Format aformat, bool autoRelease = false);
|
||||
|
||||
//! copy from host/device memory
|
||||
explicit Texture2D(InputArray arr, bool autoRelease = false);
|
||||
|
||||
//! create texture
|
||||
void create(int arows, int acols, Format aformat, bool autoRelease = false);
|
||||
void create(Size asize, Format aformat, bool autoRelease = false) { create(asize.height, asize.width, aformat, autoRelease); }
|
||||
|
||||
//! release memory and delete texture object
|
||||
void release();
|
||||
|
||||
//! set auto release mode (if true, release will be called in object's destructor)
|
||||
void setAutoRelease(bool flag);
|
||||
|
||||
//! copy from host/device memory
|
||||
void copyFrom(InputArray arr, bool autoRelease = false);
|
||||
|
||||
//! copy to host/device memory
|
||||
void copyTo(OutputArray arr, int ddepth = CV_32F, bool autoRelease = false) const;
|
||||
|
||||
//! bind texture to current active texture unit for GL_TEXTURE_2D target
|
||||
void bind() const;
|
||||
|
||||
int rows() const { return rows_; }
|
||||
int cols() const { return cols_; }
|
||||
Size size() const { return Size(cols_, rows_); }
|
||||
bool empty() const { return rows_ == 0 || cols_ == 0; }
|
||||
|
||||
Format format() const { return format_; }
|
||||
|
||||
unsigned int texId() const;
|
||||
|
||||
class Impl;
|
||||
|
||||
private:
|
||||
Ptr<Impl> impl_;
|
||||
int rows_;
|
||||
int cols_;
|
||||
Format format_;
|
||||
};
|
||||
|
||||
//! OpenGL Arrays
|
||||
class CV_EXPORTS Arrays
|
||||
{
|
||||
public:
|
||||
Arrays();
|
||||
|
||||
void setVertexArray(InputArray vertex);
|
||||
void resetVertexArray();
|
||||
|
||||
void setColorArray(InputArray color);
|
||||
void resetColorArray();
|
||||
|
||||
void setNormalArray(InputArray normal);
|
||||
void resetNormalArray();
|
||||
|
||||
void setTexCoordArray(InputArray texCoord);
|
||||
void resetTexCoordArray();
|
||||
|
||||
void release();
|
||||
|
||||
void setAutoRelease(bool flag);
|
||||
|
||||
void bind() const;
|
||||
|
||||
int size() const { return size_; }
|
||||
bool empty() const { return size_ == 0; }
|
||||
|
||||
private:
|
||||
int size_;
|
||||
Buffer vertex_;
|
||||
Buffer color_;
|
||||
Buffer normal_;
|
||||
Buffer texCoord_;
|
||||
};
|
||||
|
||||
/////////////////// Render Functions ///////////////////
|
||||
|
||||
//! render texture rectangle in window
|
||||
CV_EXPORTS void render(const Texture2D& tex,
|
||||
Rect_<double> wndRect = Rect_<double>(0.0, 0.0, 1.0, 1.0),
|
||||
Rect_<double> texRect = Rect_<double>(0.0, 0.0, 1.0, 1.0));
|
||||
|
||||
//! render mode
|
||||
enum {
|
||||
POINTS = 0x0000,
|
||||
LINES = 0x0001,
|
||||
LINE_LOOP = 0x0002,
|
||||
LINE_STRIP = 0x0003,
|
||||
TRIANGLES = 0x0004,
|
||||
TRIANGLE_STRIP = 0x0005,
|
||||
TRIANGLE_FAN = 0x0006,
|
||||
QUADS = 0x0007,
|
||||
QUAD_STRIP = 0x0008,
|
||||
POLYGON = 0x0009
|
||||
};
|
||||
|
||||
//! render OpenGL arrays
|
||||
CV_EXPORTS void render(const Arrays& arr, int mode = POINTS, Scalar color = Scalar::all(255));
|
||||
CV_EXPORTS void render(const Arrays& arr, InputArray indices, int mode = POINTS, Scalar color = Scalar::all(255));
|
||||
|
||||
}} // namespace cv::gl
|
||||
|
||||
namespace cv { namespace gpu {
|
||||
|
||||
//! set a CUDA device to use OpenGL interoperability
|
||||
CV_EXPORTS void setGlDevice(int device = 0);
|
||||
|
||||
}}
|
||||
|
||||
namespace cv {
|
||||
|
||||
template <> CV_EXPORTS void Ptr<cv::ogl::Buffer::Impl>::delete_obj();
|
||||
template <> CV_EXPORTS void Ptr<cv::ogl::Texture2D::Impl>::delete_obj();
|
||||
|
||||
}
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __OPENCV_OPENGL_INTEROP_HPP__
|
||||
@@ -1,330 +0,0 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_OPENGL_INTEROP_DEPRECATED_HPP__
|
||||
#define __OPENCV_OPENGL_INTEROP_DEPRECATED_HPP__
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
//! Smart pointer for OpenGL buffer memory with reference counting.
|
||||
class CV_EXPORTS GlBuffer
|
||||
{
|
||||
public:
|
||||
enum Usage
|
||||
{
|
||||
ARRAY_BUFFER = 0x8892, // buffer will use for OpenGL arrays (vertices, colors, normals, etc)
|
||||
TEXTURE_BUFFER = 0x88EC // buffer will ise for OpenGL textures
|
||||
};
|
||||
|
||||
//! create empty buffer
|
||||
explicit GlBuffer(Usage usage);
|
||||
|
||||
//! create buffer
|
||||
GlBuffer(int rows, int cols, int type, Usage usage);
|
||||
GlBuffer(Size size, int type, Usage usage);
|
||||
|
||||
//! copy from host/device memory
|
||||
GlBuffer(InputArray mat, Usage usage);
|
||||
|
||||
void create(int rows, int cols, int type, Usage usage);
|
||||
void create(Size size, int type, Usage usage);
|
||||
void create(int rows, int cols, int type);
|
||||
void create(Size size, int type);
|
||||
|
||||
void release();
|
||||
|
||||
//! copy from host/device memory
|
||||
void copyFrom(InputArray mat);
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
//! map to host memory
|
||||
Mat mapHost();
|
||||
void unmapHost();
|
||||
|
||||
//! map to device memory
|
||||
gpu::GpuMat mapDevice();
|
||||
void unmapDevice();
|
||||
|
||||
inline int rows() const { return rows_; }
|
||||
inline int cols() const { return cols_; }
|
||||
inline Size size() const { return Size(cols_, rows_); }
|
||||
inline bool empty() const { return rows_ == 0 || cols_ == 0; }
|
||||
|
||||
inline int type() const { return type_; }
|
||||
inline int depth() const { return CV_MAT_DEPTH(type_); }
|
||||
inline int channels() const { return CV_MAT_CN(type_); }
|
||||
inline int elemSize() const { return CV_ELEM_SIZE(type_); }
|
||||
inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
|
||||
|
||||
inline Usage usage() const { return usage_; }
|
||||
|
||||
class Impl;
|
||||
private:
|
||||
int rows_;
|
||||
int cols_;
|
||||
int type_;
|
||||
Usage usage_;
|
||||
|
||||
Ptr<Impl> impl_;
|
||||
};
|
||||
|
||||
template <> CV_EXPORTS void Ptr<GlBuffer::Impl>::delete_obj();
|
||||
|
||||
//! Smart pointer for OpenGL 2d texture memory with reference counting.
|
||||
class CV_EXPORTS GlTexture
|
||||
{
|
||||
public:
|
||||
//! create empty texture
|
||||
GlTexture();
|
||||
|
||||
//! create texture
|
||||
GlTexture(int rows, int cols, int type);
|
||||
GlTexture(Size size, int type);
|
||||
|
||||
//! copy from host/device memory
|
||||
explicit GlTexture(InputArray mat, bool bgra = true);
|
||||
|
||||
void create(int rows, int cols, int type);
|
||||
void create(Size size, int type);
|
||||
void release();
|
||||
|
||||
//! copy from host/device memory
|
||||
void copyFrom(InputArray mat, bool bgra = true);
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
inline int rows() const { return rows_; }
|
||||
inline int cols() const { return cols_; }
|
||||
inline Size size() const { return Size(cols_, rows_); }
|
||||
inline bool empty() const { return rows_ == 0 || cols_ == 0; }
|
||||
|
||||
inline int type() const { return type_; }
|
||||
inline int depth() const { return CV_MAT_DEPTH(type_); }
|
||||
inline int channels() const { return CV_MAT_CN(type_); }
|
||||
inline int elemSize() const { return CV_ELEM_SIZE(type_); }
|
||||
inline int elemSize1() const { return CV_ELEM_SIZE1(type_); }
|
||||
|
||||
class Impl;
|
||||
private:
|
||||
int rows_;
|
||||
int cols_;
|
||||
int type_;
|
||||
|
||||
Ptr<Impl> impl_;
|
||||
GlBuffer buf_;
|
||||
};
|
||||
|
||||
template <> CV_EXPORTS void Ptr<GlTexture::Impl>::delete_obj();
|
||||
|
||||
//! OpenGL Arrays
|
||||
class CV_EXPORTS GlArrays
|
||||
{
|
||||
public:
|
||||
inline GlArrays()
|
||||
: vertex_(GlBuffer::ARRAY_BUFFER), color_(GlBuffer::ARRAY_BUFFER), bgra_(true), normal_(GlBuffer::ARRAY_BUFFER), texCoord_(GlBuffer::ARRAY_BUFFER)
|
||||
{
|
||||
}
|
||||
|
||||
void setVertexArray(InputArray vertex);
|
||||
inline void resetVertexArray() { vertex_.release(); }
|
||||
|
||||
void setColorArray(InputArray color, bool bgra = true);
|
||||
inline void resetColorArray() { color_.release(); }
|
||||
|
||||
void setNormalArray(InputArray normal);
|
||||
inline void resetNormalArray() { normal_.release(); }
|
||||
|
||||
void setTexCoordArray(InputArray texCoord);
|
||||
inline void resetTexCoordArray() { texCoord_.release(); }
|
||||
|
||||
void bind() const;
|
||||
void unbind() const;
|
||||
|
||||
inline int rows() const { return vertex_.rows(); }
|
||||
inline int cols() const { return vertex_.cols(); }
|
||||
inline Size size() const { return vertex_.size(); }
|
||||
inline bool empty() const { return vertex_.empty(); }
|
||||
|
||||
private:
|
||||
GlBuffer vertex_;
|
||||
GlBuffer color_;
|
||||
bool bgra_;
|
||||
GlBuffer normal_;
|
||||
GlBuffer texCoord_;
|
||||
};
|
||||
|
||||
//! OpenGL Font
|
||||
class CV_EXPORTS GlFont
|
||||
{
|
||||
public:
|
||||
enum Weight
|
||||
{
|
||||
WEIGHT_LIGHT = 300,
|
||||
WEIGHT_NORMAL = 400,
|
||||
WEIGHT_SEMIBOLD = 600,
|
||||
WEIGHT_BOLD = 700,
|
||||
WEIGHT_BLACK = 900
|
||||
};
|
||||
|
||||
enum Style
|
||||
{
|
||||
STYLE_NORMAL = 0,
|
||||
STYLE_ITALIC = 1,
|
||||
STYLE_UNDERLINE = 2
|
||||
};
|
||||
|
||||
static Ptr<GlFont> get(const std::string& family, int height = 12, Weight weight = WEIGHT_NORMAL, Style style = STYLE_NORMAL);
|
||||
|
||||
void draw(const char* str, int len) const;
|
||||
|
||||
inline const std::string& family() const { return family_; }
|
||||
inline int height() const { return height_; }
|
||||
inline Weight weight() const { return weight_; }
|
||||
inline Style style() const { return style_; }
|
||||
|
||||
private:
|
||||
GlFont(const std::string& family, int height, Weight weight, Style style);
|
||||
|
||||
std::string family_;
|
||||
int height_;
|
||||
Weight weight_;
|
||||
Style style_;
|
||||
|
||||
unsigned int base_;
|
||||
|
||||
GlFont(const GlFont&);
|
||||
GlFont& operator =(const GlFont&);
|
||||
};
|
||||
|
||||
//! render functions
|
||||
|
||||
//! render texture rectangle in window
|
||||
CV_EXPORTS void render(const GlTexture& tex,
|
||||
Rect_<double> wndRect = Rect_<double>(0.0, 0.0, 1.0, 1.0),
|
||||
Rect_<double> texRect = Rect_<double>(0.0, 0.0, 1.0, 1.0));
|
||||
|
||||
//! render mode
|
||||
namespace RenderMode {
|
||||
enum {
|
||||
POINTS = 0x0000,
|
||||
LINES = 0x0001,
|
||||
LINE_LOOP = 0x0002,
|
||||
LINE_STRIP = 0x0003,
|
||||
TRIANGLES = 0x0004,
|
||||
TRIANGLE_STRIP = 0x0005,
|
||||
TRIANGLE_FAN = 0x0006,
|
||||
QUADS = 0x0007,
|
||||
QUAD_STRIP = 0x0008,
|
||||
POLYGON = 0x0009
|
||||
};
|
||||
}
|
||||
|
||||
//! render OpenGL arrays
|
||||
CV_EXPORTS void render(const GlArrays& arr, int mode = RenderMode::POINTS, Scalar color = Scalar::all(255));
|
||||
|
||||
CV_EXPORTS void render(const std::string& str, const Ptr<GlFont>& font, Scalar color, Point2d pos);
|
||||
|
||||
//! OpenGL camera
|
||||
class CV_EXPORTS GlCamera
|
||||
{
|
||||
public:
|
||||
GlCamera();
|
||||
|
||||
void lookAt(Point3d eye, Point3d center, Point3d up);
|
||||
void setCameraPos(Point3d pos, double yaw, double pitch, double roll);
|
||||
|
||||
void setScale(Point3d scale);
|
||||
|
||||
void setProjectionMatrix(const Mat& projectionMatrix, bool transpose = true);
|
||||
void setPerspectiveProjection(double fov, double aspect, double zNear, double zFar);
|
||||
void setOrthoProjection(double left, double right, double bottom, double top, double zNear, double zFar);
|
||||
|
||||
void setupProjectionMatrix() const;
|
||||
void setupModelViewMatrix() const;
|
||||
|
||||
private:
|
||||
Point3d eye_;
|
||||
Point3d center_;
|
||||
Point3d up_;
|
||||
|
||||
Point3d pos_;
|
||||
double yaw_;
|
||||
double pitch_;
|
||||
double roll_;
|
||||
|
||||
bool useLookAtParams_;
|
||||
|
||||
Point3d scale_;
|
||||
|
||||
Mat projectionMatrix_;
|
||||
|
||||
double fov_;
|
||||
double aspect_;
|
||||
|
||||
double left_;
|
||||
double right_;
|
||||
double bottom_;
|
||||
double top_;
|
||||
|
||||
double zNear_;
|
||||
double zFar_;
|
||||
|
||||
bool perspectiveProjection_;
|
||||
};
|
||||
|
||||
inline void GlBuffer::create(Size _size, int _type, Usage _usage) { create(_size.height, _size.width, _type, _usage); }
|
||||
inline void GlBuffer::create(int _rows, int _cols, int _type) { create(_rows, _cols, _type, usage()); }
|
||||
inline void GlBuffer::create(Size _size, int _type) { create(_size.height, _size.width, _type, usage()); }
|
||||
inline void GlTexture::create(Size _size, int _type) { create(_size.height, _size.width, _type); }
|
||||
|
||||
} // namespace cv
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __OPENCV_OPENGL_INTEROP_DEPRECATED_HPP__
|
||||
+191
-3707
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,302 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the OpenCV Foundation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_OPTIM_HPP
|
||||
#define OPENCV_OPTIM_HPP
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
/** @addtogroup core_optim
|
||||
The algorithms in this section minimize or maximize function value within specified constraints or
|
||||
without any constraints.
|
||||
@{
|
||||
*/
|
||||
|
||||
/** @brief Basic interface for all solvers
|
||||
*/
|
||||
class CV_EXPORTS MinProblemSolver : public Algorithm
|
||||
{
|
||||
public:
|
||||
/** @brief Represents function being optimized
|
||||
*/
|
||||
class CV_EXPORTS Function
|
||||
{
|
||||
public:
|
||||
virtual ~Function() {}
|
||||
virtual int getDims() const = 0;
|
||||
virtual double getGradientEps() const;
|
||||
virtual double calc(const double* x) const = 0;
|
||||
virtual void getGradient(const double* x,double* grad);
|
||||
};
|
||||
|
||||
/** @brief Getter for the optimized function.
|
||||
|
||||
The optimized function is represented by Function interface, which requires derivatives to
|
||||
implement the sole method calc(double*) to evaluate the function.
|
||||
|
||||
@return Smart-pointer to an object that implements Function interface - it represents the
|
||||
function that is being optimized. It can be empty, if no function was given so far.
|
||||
*/
|
||||
virtual Ptr<Function> getFunction() const = 0;
|
||||
|
||||
/** @brief Setter for the optimized function.
|
||||
|
||||
*It should be called at least once before the call to* minimize(), as default value is not usable.
|
||||
|
||||
@param f The new function to optimize.
|
||||
*/
|
||||
virtual void setFunction(const Ptr<Function>& f) = 0;
|
||||
|
||||
/** @brief Getter for the previously set terminal criteria for this algorithm.
|
||||
|
||||
@return Deep copy of the terminal criteria used at the moment.
|
||||
*/
|
||||
virtual TermCriteria getTermCriteria() const = 0;
|
||||
|
||||
/** @brief Set terminal criteria for solver.
|
||||
|
||||
This method *is not necessary* to be called before the first call to minimize(), as the default
|
||||
value is sensible.
|
||||
|
||||
Algorithm stops when the number of function evaluations done exceeds termcrit.maxCount, when
|
||||
the function values at the vertices of simplex are within termcrit.epsilon range or simplex
|
||||
becomes so small that it can enclosed in a box with termcrit.epsilon sides, whatever comes
|
||||
first.
|
||||
@param termcrit Terminal criteria to be used, represented as cv::TermCriteria structure.
|
||||
*/
|
||||
virtual void setTermCriteria(const TermCriteria& termcrit) = 0;
|
||||
|
||||
/** @brief actually runs the algorithm and performs the minimization.
|
||||
|
||||
The sole input parameter determines the centroid of the starting simplex (roughly, it tells
|
||||
where to start), all the others (terminal criteria, initial step, function to be minimized) are
|
||||
supposed to be set via the setters before the call to this method or the default values (not
|
||||
always sensible) will be used.
|
||||
|
||||
@param x The initial point, that will become a centroid of an initial simplex. After the algorithm
|
||||
will terminate, it will be setted to the point where the algorithm stops, the point of possible
|
||||
minimum.
|
||||
@return The value of a function at the point found.
|
||||
*/
|
||||
virtual double minimize(InputOutputArray x) = 0;
|
||||
};
|
||||
|
||||
/** @brief This class is used to perform the non-linear non-constrained minimization of a function,
|
||||
|
||||
defined on an `n`-dimensional Euclidean space, using the **Nelder-Mead method**, also known as
|
||||
**downhill simplex method**. The basic idea about the method can be obtained from
|
||||
<http://en.wikipedia.org/wiki/Nelder-Mead_method>.
|
||||
|
||||
It should be noted, that this method, although deterministic, is rather a heuristic and therefore
|
||||
may converge to a local minima, not necessary a global one. It is iterative optimization technique,
|
||||
which at each step uses an information about the values of a function evaluated only at `n+1`
|
||||
points, arranged as a *simplex* in `n`-dimensional space (hence the second name of the method). At
|
||||
each step new point is chosen to evaluate function at, obtained value is compared with previous
|
||||
ones and based on this information simplex changes it's shape , slowly moving to the local minimum.
|
||||
Thus this method is using *only* function values to make decision, on contrary to, say, Nonlinear
|
||||
Conjugate Gradient method (which is also implemented in optim).
|
||||
|
||||
Algorithm stops when the number of function evaluations done exceeds termcrit.maxCount, when the
|
||||
function values at the vertices of simplex are within termcrit.epsilon range or simplex becomes so
|
||||
small that it can enclosed in a box with termcrit.epsilon sides, whatever comes first, for some
|
||||
defined by user positive integer termcrit.maxCount and positive non-integer termcrit.epsilon.
|
||||
|
||||
@note DownhillSolver is a derivative of the abstract interface
|
||||
cv::MinProblemSolver, which in turn is derived from the Algorithm interface and is used to
|
||||
encapsulate the functionality, common to all non-linear optimization algorithms in the optim
|
||||
module.
|
||||
|
||||
@note term criteria should meet following condition:
|
||||
@code
|
||||
termcrit.type == (TermCriteria::MAX_ITER + TermCriteria::EPS) && termcrit.epsilon > 0 && termcrit.maxCount > 0
|
||||
@endcode
|
||||
*/
|
||||
class CV_EXPORTS DownhillSolver : public MinProblemSolver
|
||||
{
|
||||
public:
|
||||
/** @brief Returns the initial step that will be used in downhill simplex algorithm.
|
||||
|
||||
@param step Initial step that will be used in algorithm. Note, that although corresponding setter
|
||||
accepts column-vectors as well as row-vectors, this method will return a row-vector.
|
||||
@see DownhillSolver::setInitStep
|
||||
*/
|
||||
virtual void getInitStep(OutputArray step) const=0;
|
||||
|
||||
/** @brief Sets the initial step that will be used in downhill simplex algorithm.
|
||||
|
||||
Step, together with initial point (givin in DownhillSolver::minimize) are two `n`-dimensional
|
||||
vectors that are used to determine the shape of initial simplex. Roughly said, initial point
|
||||
determines the position of a simplex (it will become simplex's centroid), while step determines the
|
||||
spread (size in each dimension) of a simplex. To be more precise, if \f$s,x_0\in\mathbb{R}^n\f$ are
|
||||
the initial step and initial point respectively, the vertices of a simplex will be:
|
||||
\f$v_0:=x_0-\frac{1}{2} s\f$ and \f$v_i:=x_0+s_i\f$ for \f$i=1,2,\dots,n\f$ where \f$s_i\f$ denotes
|
||||
projections of the initial step of *n*-th coordinate (the result of projection is treated to be
|
||||
vector given by \f$s_i:=e_i\cdot\left<e_i\cdot s\right>\f$, where \f$e_i\f$ form canonical basis)
|
||||
|
||||
@param step Initial step that will be used in algorithm. Roughly said, it determines the spread
|
||||
(size in each dimension) of an initial simplex.
|
||||
*/
|
||||
virtual void setInitStep(InputArray step)=0;
|
||||
|
||||
/** @brief This function returns the reference to the ready-to-use DownhillSolver object.
|
||||
|
||||
All the parameters are optional, so this procedure can be called even without parameters at
|
||||
all. In this case, the default values will be used. As default value for terminal criteria are
|
||||
the only sensible ones, MinProblemSolver::setFunction() and DownhillSolver::setInitStep()
|
||||
should be called upon the obtained object, if the respective parameters were not given to
|
||||
create(). Otherwise, the two ways (give parameters to createDownhillSolver() or miss them out
|
||||
and call the MinProblemSolver::setFunction() and DownhillSolver::setInitStep()) are absolutely
|
||||
equivalent (and will drop the same errors in the same way, should invalid input be detected).
|
||||
@param f Pointer to the function that will be minimized, similarly to the one you submit via
|
||||
MinProblemSolver::setFunction.
|
||||
@param initStep Initial step, that will be used to construct the initial simplex, similarly to the one
|
||||
you submit via MinProblemSolver::setInitStep.
|
||||
@param termcrit Terminal criteria to the algorithm, similarly to the one you submit via
|
||||
MinProblemSolver::setTermCriteria.
|
||||
*/
|
||||
static Ptr<DownhillSolver> create(const Ptr<MinProblemSolver::Function>& f=Ptr<MinProblemSolver::Function>(),
|
||||
InputArray initStep=Mat_<double>(1,1,0.0),
|
||||
TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5000,0.000001));
|
||||
};
|
||||
|
||||
/** @brief This class is used to perform the non-linear non-constrained minimization of a function
|
||||
with known gradient,
|
||||
|
||||
defined on an *n*-dimensional Euclidean space, using the **Nonlinear Conjugate Gradient method**.
|
||||
The implementation was done based on the beautifully clear explanatory article [An Introduction to
|
||||
the Conjugate Gradient Method Without the Agonizing
|
||||
Pain](http://www.cs.cmu.edu/~quake-papers/painless-conjugate-gradient.pdf) by Jonathan Richard
|
||||
Shewchuk. The method can be seen as an adaptation of a standard Conjugate Gradient method (see, for
|
||||
example <http://en.wikipedia.org/wiki/Conjugate_gradient_method>) for numerically solving the
|
||||
systems of linear equations.
|
||||
|
||||
It should be noted, that this method, although deterministic, is rather a heuristic method and
|
||||
therefore may converge to a local minima, not necessary a global one. What is even more disastrous,
|
||||
most of its behaviour is ruled by gradient, therefore it essentially cannot distinguish between
|
||||
local minima and maxima. Therefore, if it starts sufficiently near to the local maximum, it may
|
||||
converge to it. Another obvious restriction is that it should be possible to compute the gradient of
|
||||
a function at any point, thus it is preferable to have analytic expression for gradient and
|
||||
computational burden should be born by the user.
|
||||
|
||||
The latter responsibility is accompilished via the getGradient method of a
|
||||
MinProblemSolver::Function interface (which represents function being optimized). This method takes
|
||||
point a point in *n*-dimensional space (first argument represents the array of coordinates of that
|
||||
point) and comput its gradient (it should be stored in the second argument as an array).
|
||||
|
||||
@note class ConjGradSolver thus does not add any new methods to the basic MinProblemSolver interface.
|
||||
|
||||
@note term criteria should meet following condition:
|
||||
@code
|
||||
termcrit.type == (TermCriteria::MAX_ITER + TermCriteria::EPS) && termcrit.epsilon > 0 && termcrit.maxCount > 0
|
||||
// or
|
||||
termcrit.type == TermCriteria::MAX_ITER) && termcrit.maxCount > 0
|
||||
@endcode
|
||||
*/
|
||||
class CV_EXPORTS ConjGradSolver : public MinProblemSolver
|
||||
{
|
||||
public:
|
||||
/** @brief This function returns the reference to the ready-to-use ConjGradSolver object.
|
||||
|
||||
All the parameters are optional, so this procedure can be called even without parameters at
|
||||
all. In this case, the default values will be used. As default value for terminal criteria are
|
||||
the only sensible ones, MinProblemSolver::setFunction() should be called upon the obtained
|
||||
object, if the function was not given to create(). Otherwise, the two ways (submit it to
|
||||
create() or miss it out and call the MinProblemSolver::setFunction()) are absolutely equivalent
|
||||
(and will drop the same errors in the same way, should invalid input be detected).
|
||||
@param f Pointer to the function that will be minimized, similarly to the one you submit via
|
||||
MinProblemSolver::setFunction.
|
||||
@param termcrit Terminal criteria to the algorithm, similarly to the one you submit via
|
||||
MinProblemSolver::setTermCriteria.
|
||||
*/
|
||||
static Ptr<ConjGradSolver> create(const Ptr<MinProblemSolver::Function>& f=Ptr<ConjGradSolver::Function>(),
|
||||
TermCriteria termcrit=TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS,5000,0.000001));
|
||||
};
|
||||
|
||||
//! return codes for cv::solveLP() function
|
||||
enum SolveLPResult
|
||||
{
|
||||
SOLVELP_UNBOUNDED = -2, //!< problem is unbounded (target function can achieve arbitrary high values)
|
||||
SOLVELP_UNFEASIBLE = -1, //!< problem is unfeasible (there are no points that satisfy all the constraints imposed)
|
||||
SOLVELP_SINGLE = 0, //!< there is only one maximum for target function
|
||||
SOLVELP_MULTI = 1 //!< there are multiple maxima for target function - the arbitrary one is returned
|
||||
};
|
||||
|
||||
/** @brief Solve given (non-integer) linear programming problem using the Simplex Algorithm (Simplex Method).
|
||||
|
||||
What we mean here by "linear programming problem" (or LP problem, for short) can be formulated as:
|
||||
|
||||
\f[\mbox{Maximize } c\cdot x\\
|
||||
\mbox{Subject to:}\\
|
||||
Ax\leq b\\
|
||||
x\geq 0\f]
|
||||
|
||||
Where \f$c\f$ is fixed `1`-by-`n` row-vector, \f$A\f$ is fixed `m`-by-`n` matrix, \f$b\f$ is fixed `m`-by-`1`
|
||||
column vector and \f$x\f$ is an arbitrary `n`-by-`1` column vector, which satisfies the constraints.
|
||||
|
||||
Simplex algorithm is one of many algorithms that are designed to handle this sort of problems
|
||||
efficiently. Although it is not optimal in theoretical sense (there exist algorithms that can solve
|
||||
any problem written as above in polynomial time, while simplex method degenerates to exponential
|
||||
time for some special cases), it is well-studied, easy to implement and is shown to work well for
|
||||
real-life purposes.
|
||||
|
||||
The particular implementation is taken almost verbatim from **Introduction to Algorithms, third
|
||||
edition** by T. H. Cormen, C. E. Leiserson, R. L. Rivest and Clifford Stein. In particular, the
|
||||
Bland's rule <http://en.wikipedia.org/wiki/Bland%27s_rule> is used to prevent cycling.
|
||||
|
||||
@param Func This row-vector corresponds to \f$c\f$ in the LP problem formulation (see above). It should
|
||||
contain 32- or 64-bit floating point numbers. As a convenience, column-vector may be also submitted,
|
||||
in the latter case it is understood to correspond to \f$c^T\f$.
|
||||
@param Constr `m`-by-`n+1` matrix, whose rightmost column corresponds to \f$b\f$ in formulation above
|
||||
and the remaining to \f$A\f$. It should containt 32- or 64-bit floating point numbers.
|
||||
@param z The solution will be returned here as a column-vector - it corresponds to \f$c\f$ in the
|
||||
formulation above. It will contain 64-bit floating point numbers.
|
||||
@return One of cv::SolveLPResult
|
||||
*/
|
||||
CV_EXPORTS_W int solveLP(const Mat& Func, const Mat& Constr, Mat& z);
|
||||
|
||||
//! @}
|
||||
|
||||
}// cv
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
// Copyright (C) 2016, Intel Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
|
||||
// OpenVX related definitions and declarations
|
||||
|
||||
#pragma once
|
||||
#ifndef OPENCV_OVX_HPP
|
||||
#define OPENCV_OVX_HPP
|
||||
|
||||
#include "cvdef.h"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
/// Check if use of OpenVX is possible
|
||||
CV_EXPORTS_W bool haveOpenVX();
|
||||
|
||||
/// Check if use of OpenVX is enabled
|
||||
CV_EXPORTS_W bool useOpenVX();
|
||||
|
||||
/// Enable/disable use of OpenVX
|
||||
CV_EXPORTS_W void setUseOpenVX(bool flag);
|
||||
} // namespace cv
|
||||
|
||||
#endif // OPENCV_OVX_HPP
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,172 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_PRIVATE_CUDA_HPP
|
||||
#define OPENCV_CORE_PRIVATE_CUDA_HPP
|
||||
|
||||
#ifndef __OPENCV_BUILD
|
||||
# error this is a private header which should not be used from outside of the OpenCV library
|
||||
#endif
|
||||
|
||||
#include "cvconfig.h"
|
||||
|
||||
#include "opencv2/core/cvdef.h"
|
||||
#include "opencv2/core/base.hpp"
|
||||
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
|
||||
#ifdef HAVE_CUDA
|
||||
# include <cuda.h>
|
||||
# include <cuda_runtime.h>
|
||||
# include <npp.h>
|
||||
# include "opencv2/core/cuda_stream_accessor.hpp"
|
||||
# include "opencv2/core/cuda/common.hpp"
|
||||
|
||||
# define NPP_VERSION (NPP_VERSION_MAJOR * 1000 + NPP_VERSION_MINOR * 100 + NPP_VERSION_BUILD)
|
||||
|
||||
# define CUDART_MINIMUM_REQUIRED_VERSION 6050
|
||||
|
||||
# if (CUDART_VERSION < CUDART_MINIMUM_REQUIRED_VERSION)
|
||||
# error "Insufficient Cuda Runtime library version, please update it."
|
||||
# endif
|
||||
|
||||
# if defined(CUDA_ARCH_BIN_OR_PTX_10)
|
||||
# error "OpenCV CUDA module doesn't support NVIDIA compute capability 1.0"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
namespace cv { namespace cuda {
|
||||
CV_EXPORTS cv::String getNppErrorMessage(int code);
|
||||
CV_EXPORTS cv::String getCudaDriverApiErrorMessage(int code);
|
||||
|
||||
CV_EXPORTS GpuMat getInputMat(InputArray _src, Stream& stream);
|
||||
|
||||
CV_EXPORTS GpuMat getOutputMat(OutputArray _dst, int rows, int cols, int type, Stream& stream);
|
||||
static inline GpuMat getOutputMat(OutputArray _dst, Size size, int type, Stream& stream)
|
||||
{
|
||||
return getOutputMat(_dst, size.height, size.width, type, stream);
|
||||
}
|
||||
|
||||
CV_EXPORTS void syncOutput(const GpuMat& dst, OutputArray _dst, Stream& stream);
|
||||
}}
|
||||
|
||||
#ifndef HAVE_CUDA
|
||||
|
||||
static inline void throw_no_cuda() { CV_Error(cv::Error::GpuNotSupported, "The library is compiled without CUDA support"); }
|
||||
|
||||
#else // HAVE_CUDA
|
||||
|
||||
static inline void throw_no_cuda() { CV_Error(cv::Error::StsNotImplemented, "The called functionality is disabled for current build or platform"); }
|
||||
|
||||
namespace cv { namespace cuda
|
||||
{
|
||||
class CV_EXPORTS BufferPool
|
||||
{
|
||||
public:
|
||||
explicit BufferPool(Stream& stream);
|
||||
|
||||
GpuMat getBuffer(int rows, int cols, int type);
|
||||
GpuMat getBuffer(Size size, int type) { return getBuffer(size.height, size.width, type); }
|
||||
|
||||
GpuMat::Allocator* getAllocator() const { return allocator_; }
|
||||
|
||||
private:
|
||||
GpuMat::Allocator* allocator_;
|
||||
};
|
||||
|
||||
static inline void checkNppError(int code, const char* file, const int line, const char* func)
|
||||
{
|
||||
if (code < 0)
|
||||
cv::error(cv::Error::GpuApiCallError, getNppErrorMessage(code), func, file, line);
|
||||
}
|
||||
|
||||
static inline void checkCudaDriverApiError(int code, const char* file, const int line, const char* func)
|
||||
{
|
||||
if (code != CUDA_SUCCESS)
|
||||
cv::error(cv::Error::GpuApiCallError, getCudaDriverApiErrorMessage(code), func, file, line);
|
||||
}
|
||||
|
||||
template<int n> struct NPPTypeTraits;
|
||||
template<> struct NPPTypeTraits<CV_8U> { typedef Npp8u npp_type; };
|
||||
template<> struct NPPTypeTraits<CV_8S> { typedef Npp8s npp_type; };
|
||||
template<> struct NPPTypeTraits<CV_16U> { typedef Npp16u npp_type; };
|
||||
template<> struct NPPTypeTraits<CV_16S> { typedef Npp16s npp_type; };
|
||||
template<> struct NPPTypeTraits<CV_32S> { typedef Npp32s npp_type; };
|
||||
template<> struct NPPTypeTraits<CV_32F> { typedef Npp32f npp_type; };
|
||||
template<> struct NPPTypeTraits<CV_64F> { typedef Npp64f npp_type; };
|
||||
|
||||
class NppStreamHandler
|
||||
{
|
||||
public:
|
||||
inline explicit NppStreamHandler(Stream& newStream)
|
||||
{
|
||||
oldStream = nppGetStream();
|
||||
nppSetStream(StreamAccessor::getStream(newStream));
|
||||
}
|
||||
|
||||
inline explicit NppStreamHandler(cudaStream_t newStream)
|
||||
{
|
||||
oldStream = nppGetStream();
|
||||
nppSetStream(newStream);
|
||||
}
|
||||
|
||||
inline ~NppStreamHandler()
|
||||
{
|
||||
nppSetStream(oldStream);
|
||||
}
|
||||
|
||||
private:
|
||||
cudaStream_t oldStream;
|
||||
};
|
||||
}}
|
||||
|
||||
#define nppSafeCall(expr) cv::cuda::checkNppError(expr, __FILE__, __LINE__, CV_Func)
|
||||
#define cuSafeCall(expr) cv::cuda::checkCudaDriverApiError(expr, __FILE__, __LINE__, CV_Func)
|
||||
|
||||
#endif // HAVE_CUDA
|
||||
|
||||
//! @endcond
|
||||
|
||||
#endif // OPENCV_CORE_PRIVATE_CUDA_HPP
|
||||
@@ -0,0 +1,585 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_PRIVATE_HPP
|
||||
#define OPENCV_CORE_PRIVATE_HPP
|
||||
|
||||
#ifndef __OPENCV_BUILD
|
||||
# error this is a private header which should not be used from outside of the OpenCV library
|
||||
#endif
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "cvconfig.h"
|
||||
|
||||
#ifdef HAVE_EIGEN
|
||||
# if defined __GNUC__ && defined __APPLE__
|
||||
# pragma GCC diagnostic ignored "-Wshadow"
|
||||
# endif
|
||||
# include <Eigen/Core>
|
||||
# include "opencv2/core/eigen.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_TBB
|
||||
# include "tbb/tbb.h"
|
||||
# include "tbb/task.h"
|
||||
# undef min
|
||||
# undef max
|
||||
#endif
|
||||
|
||||
#if defined HAVE_FP16 && (defined __F16C__ || (defined _MSC_VER && _MSC_VER >= 1700))
|
||||
# include <immintrin.h>
|
||||
# define CV_FP16 1
|
||||
#elif defined HAVE_FP16 && defined __GNUC__
|
||||
# define CV_FP16 1
|
||||
#endif
|
||||
|
||||
#ifndef CV_FP16
|
||||
# define CV_FP16 0
|
||||
#endif
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
namespace cv
|
||||
{
|
||||
#ifdef HAVE_TBB
|
||||
|
||||
typedef tbb::blocked_range<int> BlockedRange;
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_for( const BlockedRange& range, const Body& body )
|
||||
{
|
||||
tbb::parallel_for(range, body);
|
||||
}
|
||||
|
||||
typedef tbb::split Split;
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_reduce( const BlockedRange& range, Body& body )
|
||||
{
|
||||
tbb::parallel_reduce(range, body);
|
||||
}
|
||||
|
||||
typedef tbb::concurrent_vector<Rect> ConcurrentRectVector;
|
||||
#else
|
||||
class BlockedRange
|
||||
{
|
||||
public:
|
||||
BlockedRange() : _begin(0), _end(0), _grainsize(0) {}
|
||||
BlockedRange(int b, int e, int g=1) : _begin(b), _end(e), _grainsize(g) {}
|
||||
int begin() const { return _begin; }
|
||||
int end() const { return _end; }
|
||||
int grainsize() const { return _grainsize; }
|
||||
|
||||
protected:
|
||||
int _begin, _end, _grainsize;
|
||||
};
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_for( const BlockedRange& range, const Body& body )
|
||||
{
|
||||
body(range);
|
||||
}
|
||||
typedef std::vector<Rect> ConcurrentRectVector;
|
||||
|
||||
class Split {};
|
||||
|
||||
template<typename Body> static inline
|
||||
void parallel_reduce( const BlockedRange& range, Body& body )
|
||||
{
|
||||
body(range);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Returns a static string if there is a parallel framework,
|
||||
// NULL otherwise.
|
||||
CV_EXPORTS const char* currentParallelFramework();
|
||||
} //namespace cv
|
||||
|
||||
/****************************************************************************************\
|
||||
* Common declarations *
|
||||
\****************************************************************************************/
|
||||
|
||||
/* the alignment of all the allocated buffers */
|
||||
#define CV_MALLOC_ALIGN 16
|
||||
|
||||
/* IEEE754 constants and macros */
|
||||
#define CV_TOGGLE_FLT(x) ((x)^((int)(x) < 0 ? 0x7fffffff : 0))
|
||||
#define CV_TOGGLE_DBL(x) ((x)^((int64)(x) < 0 ? CV_BIG_INT(0x7fffffffffffffff) : 0))
|
||||
|
||||
static inline void* cvAlignPtr( const void* ptr, int align = 32 )
|
||||
{
|
||||
CV_DbgAssert ( (align & (align-1)) == 0 );
|
||||
return (void*)( ((size_t)ptr + align - 1) & ~(size_t)(align-1) );
|
||||
}
|
||||
|
||||
static inline int cvAlign( int size, int align )
|
||||
{
|
||||
CV_DbgAssert( (align & (align-1)) == 0 && size < INT_MAX );
|
||||
return (size + align - 1) & -align;
|
||||
}
|
||||
|
||||
#ifdef IPL_DEPTH_8U
|
||||
static inline cv::Size cvGetMatSize( const CvMat* mat )
|
||||
{
|
||||
return cv::Size(mat->cols, mat->rows);
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace cv
|
||||
{
|
||||
CV_EXPORTS void scalarToRawData(const cv::Scalar& s, void* buf, int type, int unroll_to = 0);
|
||||
}
|
||||
|
||||
// property implementation macros
|
||||
|
||||
#define CV_IMPL_PROPERTY_RO(type, name, member) \
|
||||
inline type get##name() const { return member; }
|
||||
|
||||
#define CV_HELP_IMPL_PROPERTY(r_type, w_type, name, member) \
|
||||
CV_IMPL_PROPERTY_RO(r_type, name, member) \
|
||||
inline void set##name(w_type val) { member = val; }
|
||||
|
||||
#define CV_HELP_WRAP_PROPERTY(r_type, w_type, name, internal_name, internal_obj) \
|
||||
r_type get##name() const { return internal_obj.get##internal_name(); } \
|
||||
void set##name(w_type val) { internal_obj.set##internal_name(val); }
|
||||
|
||||
#define CV_IMPL_PROPERTY(type, name, member) CV_HELP_IMPL_PROPERTY(type, type, name, member)
|
||||
#define CV_IMPL_PROPERTY_S(type, name, member) CV_HELP_IMPL_PROPERTY(type, const type &, name, member)
|
||||
|
||||
#define CV_WRAP_PROPERTY(type, name, internal_name, internal_obj) CV_HELP_WRAP_PROPERTY(type, type, name, internal_name, internal_obj)
|
||||
#define CV_WRAP_PROPERTY_S(type, name, internal_name, internal_obj) CV_HELP_WRAP_PROPERTY(type, const type &, name, internal_name, internal_obj)
|
||||
|
||||
#define CV_WRAP_SAME_PROPERTY(type, name, internal_obj) CV_WRAP_PROPERTY(type, name, name, internal_obj)
|
||||
#define CV_WRAP_SAME_PROPERTY_S(type, name, internal_obj) CV_WRAP_PROPERTY_S(type, name, name, internal_obj)
|
||||
|
||||
/****************************************************************************************\
|
||||
* Structures and macros for integration with IPP *
|
||||
\****************************************************************************************/
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
#include "ipp.h"
|
||||
|
||||
#ifndef IPP_VERSION_UPDATE // prior to 7.1
|
||||
#define IPP_VERSION_UPDATE 0
|
||||
#endif
|
||||
|
||||
#define IPP_VERSION_X100 (IPP_VERSION_MAJOR * 100 + IPP_VERSION_MINOR*10 + IPP_VERSION_UPDATE)
|
||||
|
||||
// General define for ipp function disabling
|
||||
#define IPP_DISABLE_BLOCK 0
|
||||
|
||||
#ifdef CV_MALLOC_ALIGN
|
||||
#undef CV_MALLOC_ALIGN
|
||||
#endif
|
||||
#define CV_MALLOC_ALIGN 32 // required for AVX optimization
|
||||
|
||||
#define setIppErrorStatus() cv::ipp::setIppStatus(-1, CV_Func, __FILE__, __LINE__)
|
||||
|
||||
static inline IppiSize ippiSize(int width, int height)
|
||||
{
|
||||
IppiSize size = { width, height };
|
||||
return size;
|
||||
}
|
||||
|
||||
static inline IppiSize ippiSize(const cv::Size & _size)
|
||||
{
|
||||
IppiSize size = { _size.width, _size.height };
|
||||
return size;
|
||||
}
|
||||
|
||||
static inline IppiPoint ippiPoint(const cv::Point & _point)
|
||||
{
|
||||
IppiPoint point = { _point.x, _point.y };
|
||||
return point;
|
||||
}
|
||||
|
||||
static inline IppiPoint ippiPoint(int x, int y)
|
||||
{
|
||||
IppiPoint point = { x, y };
|
||||
return point;
|
||||
}
|
||||
|
||||
static inline IppiBorderType ippiGetBorderType(int borderTypeNI)
|
||||
{
|
||||
return borderTypeNI == cv::BORDER_CONSTANT ? ippBorderConst :
|
||||
borderTypeNI == cv::BORDER_WRAP ? ippBorderWrap :
|
||||
borderTypeNI == cv::BORDER_REPLICATE ? ippBorderRepl :
|
||||
borderTypeNI == cv::BORDER_REFLECT_101 ? ippBorderMirror :
|
||||
borderTypeNI == cv::BORDER_REFLECT ? ippBorderMirrorR : (IppiBorderType)-1;
|
||||
}
|
||||
|
||||
static inline IppDataType ippiGetDataType(int depth)
|
||||
{
|
||||
return depth == CV_8U ? ipp8u :
|
||||
depth == CV_8S ? ipp8s :
|
||||
depth == CV_16U ? ipp16u :
|
||||
depth == CV_16S ? ipp16s :
|
||||
depth == CV_32S ? ipp32s :
|
||||
depth == CV_32F ? ipp32f :
|
||||
depth == CV_64F ? ipp64f : (IppDataType)-1;
|
||||
}
|
||||
|
||||
// IPP temporary buffer hepler
|
||||
template<typename T>
|
||||
class IppAutoBuffer
|
||||
{
|
||||
public:
|
||||
IppAutoBuffer() { m_pBuffer = NULL; }
|
||||
IppAutoBuffer(int size) { Alloc(size); }
|
||||
~IppAutoBuffer() { Release(); }
|
||||
T* Alloc(int size) { m_pBuffer = (T*)ippMalloc(size); return m_pBuffer; }
|
||||
void Release() { if(m_pBuffer) ippFree(m_pBuffer); }
|
||||
inline operator T* () { return (T*)m_pBuffer;}
|
||||
inline operator const T* () const { return (const T*)m_pBuffer;}
|
||||
private:
|
||||
// Disable copy operations
|
||||
IppAutoBuffer(IppAutoBuffer &) {}
|
||||
IppAutoBuffer& operator =(const IppAutoBuffer &) {return *this;}
|
||||
|
||||
T* m_pBuffer;
|
||||
};
|
||||
|
||||
#else
|
||||
#define IPP_VERSION_X100 0
|
||||
#endif
|
||||
|
||||
#if defined HAVE_IPP
|
||||
#if IPP_VERSION_X100 >= 900
|
||||
#define IPP_INITIALIZER(FEAT) \
|
||||
{ \
|
||||
if(FEAT) \
|
||||
ippSetCpuFeatures(FEAT); \
|
||||
else \
|
||||
ippInit(); \
|
||||
}
|
||||
#elif IPP_VERSION_X100 >= 800
|
||||
#define IPP_INITIALIZER(FEAT) \
|
||||
{ \
|
||||
ippInit(); \
|
||||
}
|
||||
#else
|
||||
#define IPP_INITIALIZER(FEAT) \
|
||||
{ \
|
||||
ippStaticInit(); \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CVAPI_EXPORTS
|
||||
#define IPP_INITIALIZER_AUTO \
|
||||
struct __IppInitializer__ \
|
||||
{ \
|
||||
__IppInitializer__() \
|
||||
{IPP_INITIALIZER(cv::ipp::getIppFeatures())} \
|
||||
}; \
|
||||
static struct __IppInitializer__ __ipp_initializer__;
|
||||
#else
|
||||
#define IPP_INITIALIZER_AUTO
|
||||
#endif
|
||||
#else
|
||||
#define IPP_INITIALIZER
|
||||
#define IPP_INITIALIZER_AUTO
|
||||
#endif
|
||||
|
||||
#define CV_IPP_CHECK_COND (cv::ipp::useIPP())
|
||||
#define CV_IPP_CHECK() if(CV_IPP_CHECK_COND)
|
||||
|
||||
#ifdef HAVE_IPP
|
||||
|
||||
#ifdef CV_IPP_RUN_VERBOSE
|
||||
#define CV_IPP_RUN_(condition, func, ...) \
|
||||
{ \
|
||||
if (cv::ipp::useIPP() && (condition) && (func)) \
|
||||
{ \
|
||||
printf("%s: IPP implementation is running\n", CV_Func); \
|
||||
fflush(stdout); \
|
||||
CV_IMPL_ADD(CV_IMPL_IPP); \
|
||||
return __VA_ARGS__; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
printf("%s: Plain implementation is running\n", CV_Func); \
|
||||
fflush(stdout); \
|
||||
} \
|
||||
}
|
||||
#elif defined CV_IPP_RUN_ASSERT
|
||||
#define CV_IPP_RUN_(condition, func, ...) \
|
||||
{ \
|
||||
if (cv::ipp::useIPP() && (condition)) \
|
||||
{ \
|
||||
if(func) \
|
||||
{ \
|
||||
CV_IMPL_ADD(CV_IMPL_IPP); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
setIppErrorStatus(); \
|
||||
CV_Error(cv::Error::StsAssert, #func); \
|
||||
} \
|
||||
return __VA_ARGS__; \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define CV_IPP_RUN_(condition, func, ...) \
|
||||
if (cv::ipp::useIPP() && (condition) && (func)) \
|
||||
{ \
|
||||
CV_IMPL_ADD(CV_IMPL_IPP); \
|
||||
return __VA_ARGS__; \
|
||||
}
|
||||
#endif
|
||||
#define CV_IPP_RUN_FAST(func, ...) \
|
||||
if (cv::ipp::useIPP() && (func)) \
|
||||
{ \
|
||||
CV_IMPL_ADD(CV_IMPL_IPP); \
|
||||
return __VA_ARGS__; \
|
||||
}
|
||||
#else
|
||||
#define CV_IPP_RUN_(condition, func, ...)
|
||||
#define CV_IPP_RUN_FAST(func, ...)
|
||||
#endif
|
||||
|
||||
#define CV_IPP_RUN(condition, func, ...) CV_IPP_RUN_((condition), (func), __VA_ARGS__)
|
||||
|
||||
|
||||
#ifndef IPPI_CALL
|
||||
# define IPPI_CALL(func) CV_Assert((func) >= 0)
|
||||
#endif
|
||||
|
||||
/* IPP-compatible return codes */
|
||||
typedef enum CvStatus
|
||||
{
|
||||
CV_BADMEMBLOCK_ERR = -113,
|
||||
CV_INPLACE_NOT_SUPPORTED_ERR= -112,
|
||||
CV_UNMATCHED_ROI_ERR = -111,
|
||||
CV_NOTFOUND_ERR = -110,
|
||||
CV_BADCONVERGENCE_ERR = -109,
|
||||
|
||||
CV_BADDEPTH_ERR = -107,
|
||||
CV_BADROI_ERR = -106,
|
||||
CV_BADHEADER_ERR = -105,
|
||||
CV_UNMATCHED_FORMATS_ERR = -104,
|
||||
CV_UNSUPPORTED_COI_ERR = -103,
|
||||
CV_UNSUPPORTED_CHANNELS_ERR = -102,
|
||||
CV_UNSUPPORTED_DEPTH_ERR = -101,
|
||||
CV_UNSUPPORTED_FORMAT_ERR = -100,
|
||||
|
||||
CV_BADARG_ERR = -49, //ipp comp
|
||||
CV_NOTDEFINED_ERR = -48, //ipp comp
|
||||
|
||||
CV_BADCHANNELS_ERR = -47, //ipp comp
|
||||
CV_BADRANGE_ERR = -44, //ipp comp
|
||||
CV_BADSTEP_ERR = -29, //ipp comp
|
||||
|
||||
CV_BADFLAG_ERR = -12,
|
||||
CV_DIV_BY_ZERO_ERR = -11, //ipp comp
|
||||
CV_BADCOEF_ERR = -10,
|
||||
|
||||
CV_BADFACTOR_ERR = -7,
|
||||
CV_BADPOINT_ERR = -6,
|
||||
CV_BADSCALE_ERR = -4,
|
||||
CV_OUTOFMEM_ERR = -3,
|
||||
CV_NULLPTR_ERR = -2,
|
||||
CV_BADSIZE_ERR = -1,
|
||||
CV_NO_ERR = 0,
|
||||
CV_OK = CV_NO_ERR
|
||||
}
|
||||
CvStatus;
|
||||
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
namespace tegra {
|
||||
|
||||
CV_EXPORTS bool useTegra();
|
||||
CV_EXPORTS void setUseTegra(bool flag);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_INSTRUMENTATION
|
||||
namespace cv
|
||||
{
|
||||
namespace instr
|
||||
{
|
||||
struct InstrTLSStruct
|
||||
{
|
||||
InstrTLSStruct()
|
||||
{
|
||||
pCurrentNode = NULL;
|
||||
}
|
||||
InstrNode* pCurrentNode;
|
||||
};
|
||||
|
||||
class InstrStruct
|
||||
{
|
||||
public:
|
||||
InstrStruct()
|
||||
{
|
||||
useInstr = false;
|
||||
flags = FLAGS_MAPPING;
|
||||
maxDepth = 0;
|
||||
|
||||
rootNode.m_payload = NodeData("ROOT", NULL, 0, NULL, false, TYPE_GENERAL, IMPL_PLAIN);
|
||||
tlsStruct.get()->pCurrentNode = &rootNode;
|
||||
}
|
||||
|
||||
Mutex mutexCreate;
|
||||
Mutex mutexCount;
|
||||
|
||||
bool useInstr;
|
||||
int flags;
|
||||
int maxDepth;
|
||||
InstrNode rootNode;
|
||||
TLSData<InstrTLSStruct> tlsStruct;
|
||||
};
|
||||
|
||||
class CV_EXPORTS IntrumentationRegion
|
||||
{
|
||||
public:
|
||||
IntrumentationRegion(const char* funName, const char* fileName, int lineNum, void *retAddress, bool alwaysExpand, TYPE instrType = TYPE_GENERAL, IMPL implType = IMPL_PLAIN);
|
||||
~IntrumentationRegion();
|
||||
|
||||
private:
|
||||
bool m_disabled; // region status
|
||||
uint64 m_regionTicks;
|
||||
};
|
||||
|
||||
CV_EXPORTS InstrStruct& getInstrumentStruct();
|
||||
InstrTLSStruct& getInstrumentTLSStruct();
|
||||
CV_EXPORTS InstrNode* getCurrentNode();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#define CV_INSTRUMENT_GET_RETURN_ADDRESS _ReturnAddress()
|
||||
#else
|
||||
#define CV_INSTRUMENT_GET_RETURN_ADDRESS __builtin_extract_return_addr(__builtin_return_address(0))
|
||||
#endif
|
||||
|
||||
// Instrument region
|
||||
#define CV_INSTRUMENT_REGION_META(NAME, ALWAYS_EXPAND, TYPE, IMPL) ::cv::instr::IntrumentationRegion __instr_region__(NAME, __FILE__, __LINE__, CV_INSTRUMENT_GET_RETURN_ADDRESS, ALWAYS_EXPAND, TYPE, IMPL);
|
||||
#define CV_INSTRUMENT_REGION_CUSTOM_META(NAME, ALWAYS_EXPAND, TYPE, IMPL)\
|
||||
void *__curr_address__ = [&]() {return CV_INSTRUMENT_GET_RETURN_ADDRESS;}();\
|
||||
::cv::instr::IntrumentationRegion __instr_region__(NAME, __FILE__, __LINE__, __curr_address__, false, ::cv::instr::TYPE_GENERAL, ::cv::instr::IMPL_PLAIN);
|
||||
// Instrument functions with non-void return type
|
||||
#define CV_INSTRUMENT_FUN_RT_META(TYPE, IMPL, ERROR_COND, FUN, ...) ([&]()\
|
||||
{\
|
||||
if(::cv::instr::useInstrumentation()){\
|
||||
::cv::instr::IntrumentationRegion __instr__(#FUN, __FILE__, __LINE__, NULL, false, TYPE, IMPL);\
|
||||
try{\
|
||||
auto status = ((FUN)(__VA_ARGS__));\
|
||||
if(ERROR_COND){\
|
||||
::cv::instr::getCurrentNode()->m_payload.m_funError = true;\
|
||||
CV_INSTRUMENT_MARK_META(IMPL, #FUN " - BadExit");\
|
||||
}\
|
||||
return status;\
|
||||
}catch(...){\
|
||||
::cv::instr::getCurrentNode()->m_payload.m_funError = true;\
|
||||
CV_INSTRUMENT_MARK_META(IMPL, #FUN " - BadExit");\
|
||||
throw;\
|
||||
}\
|
||||
}else{\
|
||||
return ((FUN)(__VA_ARGS__));\
|
||||
}\
|
||||
}())
|
||||
// Instrument functions with void return type
|
||||
#define CV_INSTRUMENT_FUN_RV_META(TYPE, IMPL, FUN, ...) ([&]()\
|
||||
{\
|
||||
if(::cv::instr::useInstrumentation()){\
|
||||
::cv::instr::IntrumentationRegion __instr__(#FUN, __FILE__, __LINE__, NULL, false, TYPE, IMPL);\
|
||||
try{\
|
||||
(FUN)(__VA_ARGS__);\
|
||||
}catch(...){\
|
||||
::cv::instr::getCurrentNode()->m_payload.m_funError = true;\
|
||||
CV_INSTRUMENT_MARK_META(IMPL, #FUN "- BadExit");\
|
||||
throw;\
|
||||
}\
|
||||
}else{\
|
||||
(FUN)(__VA_ARGS__);\
|
||||
}\
|
||||
}())
|
||||
// Instrumentation information marker
|
||||
#define CV_INSTRUMENT_MARK_META(IMPL, NAME, ...) {::cv::instr::IntrumentationRegion __instr_mark__(NAME, __FILE__, __LINE__, NULL, false, ::cv::instr::TYPE_MARKER, IMPL);}
|
||||
|
||||
///// General instrumentation
|
||||
// General OpenCV region instrumentation macro
|
||||
#define CV_INSTRUMENT_REGION() CV_INSTRUMENT_REGION_META(__FUNCTION__, false, ::cv::instr::TYPE_GENERAL, ::cv::instr::IMPL_PLAIN)
|
||||
// Custom OpenCV region instrumentation macro
|
||||
#define CV_INSTRUMENT_REGION_NAME(NAME) CV_INSTRUMENT_REGION_CUSTOM_META(NAME, false, ::cv::instr::TYPE_GENERAL, ::cv::instr::IMPL_PLAIN)
|
||||
// Instrumentation for parallel_for_ or other regions which forks and gathers threads
|
||||
#define CV_INSTRUMENT_REGION_MT_FORK() CV_INSTRUMENT_REGION_META(__FUNCTION__, true, ::cv::instr::TYPE_GENERAL, ::cv::instr::IMPL_PLAIN);
|
||||
|
||||
///// IPP instrumentation
|
||||
// Wrapper region instrumentation macro
|
||||
#define CV_INSTRUMENT_REGION_IPP() CV_INSTRUMENT_REGION_META(__FUNCTION__, false, ::cv::instr::TYPE_WRAPPER, ::cv::instr::IMPL_IPP)
|
||||
// Function instrumentation macro
|
||||
#define CV_INSTRUMENT_FUN_IPP(FUN, ...) CV_INSTRUMENT_FUN_RT_META(::cv::instr::TYPE_FUN, ::cv::instr::IMPL_IPP, status < 0, FUN, __VA_ARGS__)
|
||||
// Diagnostic markers
|
||||
#define CV_INSTRUMENT_MARK_IPP(NAME) CV_INSTRUMENT_MARK_META(::cv::instr::IMPL_IPP, NAME)
|
||||
|
||||
///// OpenCL instrumentation
|
||||
// Wrapper region instrumentation macro
|
||||
#define CV_INSTRUMENT_REGION_OPENCL() CV_INSTRUMENT_REGION_META(__FUNCTION__, false, ::cv::instr::TYPE_WRAPPER, ::cv::instr::IMPL_OPENCL)
|
||||
// OpenCL kernel compilation wrapper
|
||||
#define CV_INSTRUMENT_REGION_OPENCL_COMPILE(NAME) CV_INSTRUMENT_REGION_META(NAME, false, ::cv::instr::TYPE_WRAPPER, ::cv::instr::IMPL_OPENCL)
|
||||
// OpenCL kernel run wrapper
|
||||
#define CV_INSTRUMENT_REGION_OPENCL_RUN(NAME) CV_INSTRUMENT_REGION_META(NAME, false, ::cv::instr::TYPE_FUN, ::cv::instr::IMPL_OPENCL)
|
||||
// Diagnostic markers
|
||||
#define CV_INSTRUMENT_MARK_OPENCL(NAME) CV_INSTRUMENT_MARK_META(::cv::instr::IMPL_OPENCL, NAME)
|
||||
#else
|
||||
#define CV_INSTRUMENT_REGION_META(...)
|
||||
|
||||
#define CV_INSTRUMENT_REGION()
|
||||
#define CV_INSTRUMENT_REGION_NAME(...)
|
||||
#define CV_INSTRUMENT_REGION_MT_FORK()
|
||||
|
||||
#define CV_INSTRUMENT_REGION_IPP()
|
||||
#define CV_INSTRUMENT_FUN_IPP(FUN, ...) ((FUN)(__VA_ARGS__))
|
||||
#define CV_INSTRUMENT_MARK_IPP(...)
|
||||
|
||||
#define CV_INSTRUMENT_REGION_OPENCL()
|
||||
#define CV_INSTRUMENT_REGION_OPENCL_COMPILE(...)
|
||||
#define CV_INSTRUMENT_REGION_OPENCL_RUN(...)
|
||||
#define CV_INSTRUMENT_MARK_OPENCL(...)
|
||||
#endif
|
||||
|
||||
//! @endcond
|
||||
|
||||
#endif // OPENCV_CORE_PRIVATE_HPP
|
||||
@@ -0,0 +1,379 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, NVIDIA Corporation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the copyright holders or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_PTR_INL_HPP
|
||||
#define OPENCV_CORE_PTR_INL_HPP
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
namespace cv {
|
||||
|
||||
template<typename Y>
|
||||
void DefaultDeleter<Y>::operator () (Y* p) const
|
||||
{
|
||||
delete p;
|
||||
}
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct PtrOwner
|
||||
{
|
||||
PtrOwner() : refCount(1)
|
||||
{}
|
||||
|
||||
void incRef()
|
||||
{
|
||||
CV_XADD(&refCount, 1);
|
||||
}
|
||||
|
||||
void decRef()
|
||||
{
|
||||
if (CV_XADD(&refCount, -1) == 1) deleteSelf();
|
||||
}
|
||||
|
||||
protected:
|
||||
/* This doesn't really need to be virtual, since PtrOwner is never deleted
|
||||
directly, but it doesn't hurt and it helps avoid warnings. */
|
||||
virtual ~PtrOwner()
|
||||
{}
|
||||
|
||||
virtual void deleteSelf() = 0;
|
||||
|
||||
private:
|
||||
unsigned int refCount;
|
||||
|
||||
// noncopyable
|
||||
PtrOwner(const PtrOwner&);
|
||||
PtrOwner& operator = (const PtrOwner&);
|
||||
};
|
||||
|
||||
template<typename Y, typename D>
|
||||
struct PtrOwnerImpl : PtrOwner
|
||||
{
|
||||
PtrOwnerImpl(Y* p, D d) : owned(p), deleter(d)
|
||||
{}
|
||||
|
||||
void deleteSelf()
|
||||
{
|
||||
deleter(owned);
|
||||
delete this;
|
||||
}
|
||||
|
||||
private:
|
||||
Y* owned;
|
||||
D deleter;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>::Ptr() : owner(NULL), stored(NULL)
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<T>::Ptr(Y* p)
|
||||
: owner(p
|
||||
? new detail::PtrOwnerImpl<Y, DefaultDeleter<Y> >(p, DefaultDeleter<Y>())
|
||||
: NULL),
|
||||
stored(p)
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y, typename D>
|
||||
Ptr<T>::Ptr(Y* p, D d)
|
||||
: owner(p
|
||||
? new detail::PtrOwnerImpl<Y, D>(p, d)
|
||||
: NULL),
|
||||
stored(p)
|
||||
{}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>::Ptr(const Ptr& o) : owner(o.owner), stored(o.stored)
|
||||
{
|
||||
if (owner) owner->incRef();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<T>::Ptr(const Ptr<Y>& o) : owner(o.owner), stored(o.stored)
|
||||
{
|
||||
if (owner) owner->incRef();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<T>::Ptr(const Ptr<Y>& o, T* p) : owner(o.owner), stored(p)
|
||||
{
|
||||
if (owner) owner->incRef();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>::~Ptr()
|
||||
{
|
||||
release();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>& Ptr<T>::operator = (const Ptr<T>& o)
|
||||
{
|
||||
Ptr(o).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<T>& Ptr<T>::operator = (const Ptr<Y>& o)
|
||||
{
|
||||
Ptr(o).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Ptr<T>::release()
|
||||
{
|
||||
if (owner) owner->decRef();
|
||||
owner = NULL;
|
||||
stored = NULL;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
void Ptr<T>::reset(Y* p)
|
||||
{
|
||||
Ptr(p).swap(*this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y, typename D>
|
||||
void Ptr<T>::reset(Y* p, D d)
|
||||
{
|
||||
Ptr(p, d).swap(*this);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Ptr<T>::swap(Ptr<T>& o)
|
||||
{
|
||||
std::swap(owner, o.owner);
|
||||
std::swap(stored, o.stored);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* Ptr<T>::get() const
|
||||
{
|
||||
return stored;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
typename detail::RefOrVoid<T>::type Ptr<T>::operator * () const
|
||||
{
|
||||
return *stored;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* Ptr<T>::operator -> () const
|
||||
{
|
||||
return stored;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>::operator T* () const
|
||||
{
|
||||
return stored;
|
||||
}
|
||||
|
||||
|
||||
template<typename T>
|
||||
bool Ptr<T>::empty() const
|
||||
{
|
||||
return !stored;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<Y> Ptr<T>::staticCast() const
|
||||
{
|
||||
return Ptr<Y>(*this, static_cast<Y*>(stored));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<Y> Ptr<T>::constCast() const
|
||||
{
|
||||
return Ptr<Y>(*this, const_cast<Y*>(stored));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Y>
|
||||
Ptr<Y> Ptr<T>::dynamicCast() const
|
||||
{
|
||||
return Ptr<Y>(*this, dynamic_cast<Y*>(stored));
|
||||
}
|
||||
|
||||
#ifdef CV_CXX_MOVE_SEMANTICS
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>::Ptr(Ptr&& o) : owner(o.owner), stored(o.stored)
|
||||
{
|
||||
o.owner = NULL;
|
||||
o.stored = NULL;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T>& Ptr<T>::operator = (Ptr<T>&& o)
|
||||
{
|
||||
if (this == &o)
|
||||
return *this;
|
||||
|
||||
release();
|
||||
owner = o.owner;
|
||||
stored = o.stored;
|
||||
o.owner = NULL;
|
||||
o.stored = NULL;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
template<typename T>
|
||||
void swap(Ptr<T>& ptr1, Ptr<T>& ptr2){
|
||||
ptr1.swap(ptr2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool operator == (const Ptr<T>& ptr1, const Ptr<T>& ptr2)
|
||||
{
|
||||
return ptr1.get() == ptr2.get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool operator != (const Ptr<T>& ptr1, const Ptr<T>& ptr2)
|
||||
{
|
||||
return ptr1.get() != ptr2.get();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
Ptr<T> makePtr()
|
||||
{
|
||||
return Ptr<T>(new T());
|
||||
}
|
||||
|
||||
template<typename T, typename A1>
|
||||
Ptr<T> makePtr(const A1& a1)
|
||||
{
|
||||
return Ptr<T>(new T(a1));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5, a6));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7, a8));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10, typename A11>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10, const A11& a11)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11));
|
||||
}
|
||||
|
||||
template<typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10, typename A11, typename A12>
|
||||
Ptr<T> makePtr(const A1& a1, const A2& a2, const A3& a3, const A4& a4, const A5& a5, const A6& a6, const A7& a7, const A8& a8, const A9& a9, const A10& a10, const A11& a11, const A12& a12)
|
||||
{
|
||||
return Ptr<T>(new T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12));
|
||||
}
|
||||
} // namespace cv
|
||||
|
||||
//! @endcond
|
||||
|
||||
#endif // OPENCV_CORE_PTR_INL_HPP
|
||||
@@ -0,0 +1,150 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Copyright (C) 2014, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_SATURATE_HPP
|
||||
#define OPENCV_CORE_SATURATE_HPP
|
||||
|
||||
#include "opencv2/core/cvdef.h"
|
||||
#include "opencv2/core/fast_math.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
//! @addtogroup core_utils
|
||||
//! @{
|
||||
|
||||
/////////////// saturate_cast (used in image & signal processing) ///////////////////
|
||||
|
||||
/** @brief Template function for accurate conversion from one primitive type to another.
|
||||
|
||||
The functions saturate_cast resemble the standard C++ cast operations, such as static_cast\<T\>()
|
||||
and others. They perform an efficient and accurate conversion from one primitive type to another
|
||||
(see the introduction chapter). saturate in the name means that when the input value v is out of the
|
||||
range of the target type, the result is not formed just by taking low bits of the input, but instead
|
||||
the value is clipped. For example:
|
||||
@code
|
||||
uchar a = saturate_cast<uchar>(-100); // a = 0 (UCHAR_MIN)
|
||||
short b = saturate_cast<short>(33333.33333); // b = 32767 (SHRT_MAX)
|
||||
@endcode
|
||||
Such clipping is done when the target type is unsigned char , signed char , unsigned short or
|
||||
signed short . For 32-bit integers, no clipping is done.
|
||||
|
||||
When the parameter is a floating-point value and the target type is an integer (8-, 16- or 32-bit),
|
||||
the floating-point value is first rounded to the nearest integer and then clipped if needed (when
|
||||
the target type is 8- or 16-bit).
|
||||
|
||||
This operation is used in the simplest or most complex image processing functions in OpenCV.
|
||||
|
||||
@param v Function parameter.
|
||||
@sa add, subtract, multiply, divide, Mat::convertTo
|
||||
*/
|
||||
template<typename _Tp> static inline _Tp saturate_cast(uchar v) { return _Tp(v); }
|
||||
/** @overload */
|
||||
template<typename _Tp> static inline _Tp saturate_cast(schar v) { return _Tp(v); }
|
||||
/** @overload */
|
||||
template<typename _Tp> static inline _Tp saturate_cast(ushort v) { return _Tp(v); }
|
||||
/** @overload */
|
||||
template<typename _Tp> static inline _Tp saturate_cast(short v) { return _Tp(v); }
|
||||
/** @overload */
|
||||
template<typename _Tp> static inline _Tp saturate_cast(unsigned v) { return _Tp(v); }
|
||||
/** @overload */
|
||||
template<typename _Tp> static inline _Tp saturate_cast(int v) { return _Tp(v); }
|
||||
/** @overload */
|
||||
template<typename _Tp> static inline _Tp saturate_cast(float v) { return _Tp(v); }
|
||||
/** @overload */
|
||||
template<typename _Tp> static inline _Tp saturate_cast(double v) { return _Tp(v); }
|
||||
/** @overload */
|
||||
template<typename _Tp> static inline _Tp saturate_cast(int64 v) { return _Tp(v); }
|
||||
/** @overload */
|
||||
template<typename _Tp> static inline _Tp saturate_cast(uint64 v) { return _Tp(v); }
|
||||
|
||||
template<> inline uchar saturate_cast<uchar>(schar v) { return (uchar)std::max((int)v, 0); }
|
||||
template<> inline uchar saturate_cast<uchar>(ushort v) { return (uchar)std::min((unsigned)v, (unsigned)UCHAR_MAX); }
|
||||
template<> inline uchar saturate_cast<uchar>(int v) { return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); }
|
||||
template<> inline uchar saturate_cast<uchar>(short v) { return saturate_cast<uchar>((int)v); }
|
||||
template<> inline uchar saturate_cast<uchar>(unsigned v) { return (uchar)std::min(v, (unsigned)UCHAR_MAX); }
|
||||
template<> inline uchar saturate_cast<uchar>(float v) { int iv = cvRound(v); return saturate_cast<uchar>(iv); }
|
||||
template<> inline uchar saturate_cast<uchar>(double v) { int iv = cvRound(v); return saturate_cast<uchar>(iv); }
|
||||
template<> inline uchar saturate_cast<uchar>(int64 v) { return (uchar)((uint64)v <= (uint64)UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); }
|
||||
template<> inline uchar saturate_cast<uchar>(uint64 v) { return (uchar)std::min(v, (uint64)UCHAR_MAX); }
|
||||
|
||||
template<> inline schar saturate_cast<schar>(uchar v) { return (schar)std::min((int)v, SCHAR_MAX); }
|
||||
template<> inline schar saturate_cast<schar>(ushort v) { return (schar)std::min((unsigned)v, (unsigned)SCHAR_MAX); }
|
||||
template<> inline schar saturate_cast<schar>(int v) { return (schar)((unsigned)(v-SCHAR_MIN) <= (unsigned)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); }
|
||||
template<> inline schar saturate_cast<schar>(short v) { return saturate_cast<schar>((int)v); }
|
||||
template<> inline schar saturate_cast<schar>(unsigned v) { return (schar)std::min(v, (unsigned)SCHAR_MAX); }
|
||||
template<> inline schar saturate_cast<schar>(float v) { int iv = cvRound(v); return saturate_cast<schar>(iv); }
|
||||
template<> inline schar saturate_cast<schar>(double v) { int iv = cvRound(v); return saturate_cast<schar>(iv); }
|
||||
template<> inline schar saturate_cast<schar>(int64 v) { return (schar)((uint64)((int64)v-SCHAR_MIN) <= (uint64)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); }
|
||||
template<> inline schar saturate_cast<schar>(uint64 v) { return (schar)std::min(v, (uint64)SCHAR_MAX); }
|
||||
|
||||
template<> inline ushort saturate_cast<ushort>(schar v) { return (ushort)std::max((int)v, 0); }
|
||||
template<> inline ushort saturate_cast<ushort>(short v) { return (ushort)std::max((int)v, 0); }
|
||||
template<> inline ushort saturate_cast<ushort>(int v) { return (ushort)((unsigned)v <= (unsigned)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); }
|
||||
template<> inline ushort saturate_cast<ushort>(unsigned v) { return (ushort)std::min(v, (unsigned)USHRT_MAX); }
|
||||
template<> inline ushort saturate_cast<ushort>(float v) { int iv = cvRound(v); return saturate_cast<ushort>(iv); }
|
||||
template<> inline ushort saturate_cast<ushort>(double v) { int iv = cvRound(v); return saturate_cast<ushort>(iv); }
|
||||
template<> inline ushort saturate_cast<ushort>(int64 v) { return (ushort)((uint64)v <= (uint64)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); }
|
||||
template<> inline ushort saturate_cast<ushort>(uint64 v) { return (ushort)std::min(v, (uint64)USHRT_MAX); }
|
||||
|
||||
template<> inline short saturate_cast<short>(ushort v) { return (short)std::min((int)v, SHRT_MAX); }
|
||||
template<> inline short saturate_cast<short>(int v) { return (short)((unsigned)(v - SHRT_MIN) <= (unsigned)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); }
|
||||
template<> inline short saturate_cast<short>(unsigned v) { return (short)std::min(v, (unsigned)SHRT_MAX); }
|
||||
template<> inline short saturate_cast<short>(float v) { int iv = cvRound(v); return saturate_cast<short>(iv); }
|
||||
template<> inline short saturate_cast<short>(double v) { int iv = cvRound(v); return saturate_cast<short>(iv); }
|
||||
template<> inline short saturate_cast<short>(int64 v) { return (short)((uint64)((int64)v - SHRT_MIN) <= (uint64)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); }
|
||||
template<> inline short saturate_cast<short>(uint64 v) { return (short)std::min(v, (uint64)SHRT_MAX); }
|
||||
|
||||
template<> inline int saturate_cast<int>(float v) { return cvRound(v); }
|
||||
template<> inline int saturate_cast<int>(double v) { return cvRound(v); }
|
||||
|
||||
// we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc.
|
||||
template<> inline unsigned saturate_cast<unsigned>(float v) { return cvRound(v); }
|
||||
template<> inline unsigned saturate_cast<unsigned>(double v) { return cvRound(v); }
|
||||
|
||||
//! @}
|
||||
|
||||
} // cv
|
||||
|
||||
#endif // OPENCV_CORE_SATURATE_HPP
|
||||
@@ -0,0 +1,652 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2015, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_SSE_UTILS_HPP
|
||||
#define OPENCV_CORE_SSE_UTILS_HPP
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error sse_utils.hpp header must be compiled as C++
|
||||
#endif
|
||||
|
||||
#include "opencv2/core/cvdef.h"
|
||||
|
||||
//! @addtogroup core_utils_sse
|
||||
//! @{
|
||||
|
||||
#if CV_SSE2
|
||||
|
||||
inline void _mm_deinterleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1)
|
||||
{
|
||||
__m128i layer1_chunk0 = _mm_unpacklo_epi8(v_r0, v_g0);
|
||||
__m128i layer1_chunk1 = _mm_unpackhi_epi8(v_r0, v_g0);
|
||||
__m128i layer1_chunk2 = _mm_unpacklo_epi8(v_r1, v_g1);
|
||||
__m128i layer1_chunk3 = _mm_unpackhi_epi8(v_r1, v_g1);
|
||||
|
||||
__m128i layer2_chunk0 = _mm_unpacklo_epi8(layer1_chunk0, layer1_chunk2);
|
||||
__m128i layer2_chunk1 = _mm_unpackhi_epi8(layer1_chunk0, layer1_chunk2);
|
||||
__m128i layer2_chunk2 = _mm_unpacklo_epi8(layer1_chunk1, layer1_chunk3);
|
||||
__m128i layer2_chunk3 = _mm_unpackhi_epi8(layer1_chunk1, layer1_chunk3);
|
||||
|
||||
__m128i layer3_chunk0 = _mm_unpacklo_epi8(layer2_chunk0, layer2_chunk2);
|
||||
__m128i layer3_chunk1 = _mm_unpackhi_epi8(layer2_chunk0, layer2_chunk2);
|
||||
__m128i layer3_chunk2 = _mm_unpacklo_epi8(layer2_chunk1, layer2_chunk3);
|
||||
__m128i layer3_chunk3 = _mm_unpackhi_epi8(layer2_chunk1, layer2_chunk3);
|
||||
|
||||
__m128i layer4_chunk0 = _mm_unpacklo_epi8(layer3_chunk0, layer3_chunk2);
|
||||
__m128i layer4_chunk1 = _mm_unpackhi_epi8(layer3_chunk0, layer3_chunk2);
|
||||
__m128i layer4_chunk2 = _mm_unpacklo_epi8(layer3_chunk1, layer3_chunk3);
|
||||
__m128i layer4_chunk3 = _mm_unpackhi_epi8(layer3_chunk1, layer3_chunk3);
|
||||
|
||||
v_r0 = _mm_unpacklo_epi8(layer4_chunk0, layer4_chunk2);
|
||||
v_r1 = _mm_unpackhi_epi8(layer4_chunk0, layer4_chunk2);
|
||||
v_g0 = _mm_unpacklo_epi8(layer4_chunk1, layer4_chunk3);
|
||||
v_g1 = _mm_unpackhi_epi8(layer4_chunk1, layer4_chunk3);
|
||||
}
|
||||
|
||||
inline void _mm_deinterleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0,
|
||||
__m128i & v_g1, __m128i & v_b0, __m128i & v_b1)
|
||||
{
|
||||
__m128i layer1_chunk0 = _mm_unpacklo_epi8(v_r0, v_g1);
|
||||
__m128i layer1_chunk1 = _mm_unpackhi_epi8(v_r0, v_g1);
|
||||
__m128i layer1_chunk2 = _mm_unpacklo_epi8(v_r1, v_b0);
|
||||
__m128i layer1_chunk3 = _mm_unpackhi_epi8(v_r1, v_b0);
|
||||
__m128i layer1_chunk4 = _mm_unpacklo_epi8(v_g0, v_b1);
|
||||
__m128i layer1_chunk5 = _mm_unpackhi_epi8(v_g0, v_b1);
|
||||
|
||||
__m128i layer2_chunk0 = _mm_unpacklo_epi8(layer1_chunk0, layer1_chunk3);
|
||||
__m128i layer2_chunk1 = _mm_unpackhi_epi8(layer1_chunk0, layer1_chunk3);
|
||||
__m128i layer2_chunk2 = _mm_unpacklo_epi8(layer1_chunk1, layer1_chunk4);
|
||||
__m128i layer2_chunk3 = _mm_unpackhi_epi8(layer1_chunk1, layer1_chunk4);
|
||||
__m128i layer2_chunk4 = _mm_unpacklo_epi8(layer1_chunk2, layer1_chunk5);
|
||||
__m128i layer2_chunk5 = _mm_unpackhi_epi8(layer1_chunk2, layer1_chunk5);
|
||||
|
||||
__m128i layer3_chunk0 = _mm_unpacklo_epi8(layer2_chunk0, layer2_chunk3);
|
||||
__m128i layer3_chunk1 = _mm_unpackhi_epi8(layer2_chunk0, layer2_chunk3);
|
||||
__m128i layer3_chunk2 = _mm_unpacklo_epi8(layer2_chunk1, layer2_chunk4);
|
||||
__m128i layer3_chunk3 = _mm_unpackhi_epi8(layer2_chunk1, layer2_chunk4);
|
||||
__m128i layer3_chunk4 = _mm_unpacklo_epi8(layer2_chunk2, layer2_chunk5);
|
||||
__m128i layer3_chunk5 = _mm_unpackhi_epi8(layer2_chunk2, layer2_chunk5);
|
||||
|
||||
__m128i layer4_chunk0 = _mm_unpacklo_epi8(layer3_chunk0, layer3_chunk3);
|
||||
__m128i layer4_chunk1 = _mm_unpackhi_epi8(layer3_chunk0, layer3_chunk3);
|
||||
__m128i layer4_chunk2 = _mm_unpacklo_epi8(layer3_chunk1, layer3_chunk4);
|
||||
__m128i layer4_chunk3 = _mm_unpackhi_epi8(layer3_chunk1, layer3_chunk4);
|
||||
__m128i layer4_chunk4 = _mm_unpacklo_epi8(layer3_chunk2, layer3_chunk5);
|
||||
__m128i layer4_chunk5 = _mm_unpackhi_epi8(layer3_chunk2, layer3_chunk5);
|
||||
|
||||
v_r0 = _mm_unpacklo_epi8(layer4_chunk0, layer4_chunk3);
|
||||
v_r1 = _mm_unpackhi_epi8(layer4_chunk0, layer4_chunk3);
|
||||
v_g0 = _mm_unpacklo_epi8(layer4_chunk1, layer4_chunk4);
|
||||
v_g1 = _mm_unpackhi_epi8(layer4_chunk1, layer4_chunk4);
|
||||
v_b0 = _mm_unpacklo_epi8(layer4_chunk2, layer4_chunk5);
|
||||
v_b1 = _mm_unpackhi_epi8(layer4_chunk2, layer4_chunk5);
|
||||
}
|
||||
|
||||
inline void _mm_deinterleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1,
|
||||
__m128i & v_b0, __m128i & v_b1, __m128i & v_a0, __m128i & v_a1)
|
||||
{
|
||||
__m128i layer1_chunk0 = _mm_unpacklo_epi8(v_r0, v_b0);
|
||||
__m128i layer1_chunk1 = _mm_unpackhi_epi8(v_r0, v_b0);
|
||||
__m128i layer1_chunk2 = _mm_unpacklo_epi8(v_r1, v_b1);
|
||||
__m128i layer1_chunk3 = _mm_unpackhi_epi8(v_r1, v_b1);
|
||||
__m128i layer1_chunk4 = _mm_unpacklo_epi8(v_g0, v_a0);
|
||||
__m128i layer1_chunk5 = _mm_unpackhi_epi8(v_g0, v_a0);
|
||||
__m128i layer1_chunk6 = _mm_unpacklo_epi8(v_g1, v_a1);
|
||||
__m128i layer1_chunk7 = _mm_unpackhi_epi8(v_g1, v_a1);
|
||||
|
||||
__m128i layer2_chunk0 = _mm_unpacklo_epi8(layer1_chunk0, layer1_chunk4);
|
||||
__m128i layer2_chunk1 = _mm_unpackhi_epi8(layer1_chunk0, layer1_chunk4);
|
||||
__m128i layer2_chunk2 = _mm_unpacklo_epi8(layer1_chunk1, layer1_chunk5);
|
||||
__m128i layer2_chunk3 = _mm_unpackhi_epi8(layer1_chunk1, layer1_chunk5);
|
||||
__m128i layer2_chunk4 = _mm_unpacklo_epi8(layer1_chunk2, layer1_chunk6);
|
||||
__m128i layer2_chunk5 = _mm_unpackhi_epi8(layer1_chunk2, layer1_chunk6);
|
||||
__m128i layer2_chunk6 = _mm_unpacklo_epi8(layer1_chunk3, layer1_chunk7);
|
||||
__m128i layer2_chunk7 = _mm_unpackhi_epi8(layer1_chunk3, layer1_chunk7);
|
||||
|
||||
__m128i layer3_chunk0 = _mm_unpacklo_epi8(layer2_chunk0, layer2_chunk4);
|
||||
__m128i layer3_chunk1 = _mm_unpackhi_epi8(layer2_chunk0, layer2_chunk4);
|
||||
__m128i layer3_chunk2 = _mm_unpacklo_epi8(layer2_chunk1, layer2_chunk5);
|
||||
__m128i layer3_chunk3 = _mm_unpackhi_epi8(layer2_chunk1, layer2_chunk5);
|
||||
__m128i layer3_chunk4 = _mm_unpacklo_epi8(layer2_chunk2, layer2_chunk6);
|
||||
__m128i layer3_chunk5 = _mm_unpackhi_epi8(layer2_chunk2, layer2_chunk6);
|
||||
__m128i layer3_chunk6 = _mm_unpacklo_epi8(layer2_chunk3, layer2_chunk7);
|
||||
__m128i layer3_chunk7 = _mm_unpackhi_epi8(layer2_chunk3, layer2_chunk7);
|
||||
|
||||
__m128i layer4_chunk0 = _mm_unpacklo_epi8(layer3_chunk0, layer3_chunk4);
|
||||
__m128i layer4_chunk1 = _mm_unpackhi_epi8(layer3_chunk0, layer3_chunk4);
|
||||
__m128i layer4_chunk2 = _mm_unpacklo_epi8(layer3_chunk1, layer3_chunk5);
|
||||
__m128i layer4_chunk3 = _mm_unpackhi_epi8(layer3_chunk1, layer3_chunk5);
|
||||
__m128i layer4_chunk4 = _mm_unpacklo_epi8(layer3_chunk2, layer3_chunk6);
|
||||
__m128i layer4_chunk5 = _mm_unpackhi_epi8(layer3_chunk2, layer3_chunk6);
|
||||
__m128i layer4_chunk6 = _mm_unpacklo_epi8(layer3_chunk3, layer3_chunk7);
|
||||
__m128i layer4_chunk7 = _mm_unpackhi_epi8(layer3_chunk3, layer3_chunk7);
|
||||
|
||||
v_r0 = _mm_unpacklo_epi8(layer4_chunk0, layer4_chunk4);
|
||||
v_r1 = _mm_unpackhi_epi8(layer4_chunk0, layer4_chunk4);
|
||||
v_g0 = _mm_unpacklo_epi8(layer4_chunk1, layer4_chunk5);
|
||||
v_g1 = _mm_unpackhi_epi8(layer4_chunk1, layer4_chunk5);
|
||||
v_b0 = _mm_unpacklo_epi8(layer4_chunk2, layer4_chunk6);
|
||||
v_b1 = _mm_unpackhi_epi8(layer4_chunk2, layer4_chunk6);
|
||||
v_a0 = _mm_unpacklo_epi8(layer4_chunk3, layer4_chunk7);
|
||||
v_a1 = _mm_unpackhi_epi8(layer4_chunk3, layer4_chunk7);
|
||||
}
|
||||
|
||||
inline void _mm_interleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1)
|
||||
{
|
||||
__m128i v_mask = _mm_set1_epi16(0x00ff);
|
||||
|
||||
__m128i layer4_chunk0 = _mm_packus_epi16(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask));
|
||||
__m128i layer4_chunk2 = _mm_packus_epi16(_mm_srli_epi16(v_r0, 8), _mm_srli_epi16(v_r1, 8));
|
||||
__m128i layer4_chunk1 = _mm_packus_epi16(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask));
|
||||
__m128i layer4_chunk3 = _mm_packus_epi16(_mm_srli_epi16(v_g0, 8), _mm_srli_epi16(v_g1, 8));
|
||||
|
||||
__m128i layer3_chunk0 = _mm_packus_epi16(_mm_and_si128(layer4_chunk0, v_mask), _mm_and_si128(layer4_chunk1, v_mask));
|
||||
__m128i layer3_chunk2 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk0, 8), _mm_srli_epi16(layer4_chunk1, 8));
|
||||
__m128i layer3_chunk1 = _mm_packus_epi16(_mm_and_si128(layer4_chunk2, v_mask), _mm_and_si128(layer4_chunk3, v_mask));
|
||||
__m128i layer3_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk2, 8), _mm_srli_epi16(layer4_chunk3, 8));
|
||||
|
||||
__m128i layer2_chunk0 = _mm_packus_epi16(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask));
|
||||
__m128i layer2_chunk2 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk0, 8), _mm_srli_epi16(layer3_chunk1, 8));
|
||||
__m128i layer2_chunk1 = _mm_packus_epi16(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask));
|
||||
__m128i layer2_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk2, 8), _mm_srli_epi16(layer3_chunk3, 8));
|
||||
|
||||
__m128i layer1_chunk0 = _mm_packus_epi16(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask));
|
||||
__m128i layer1_chunk2 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk0, 8), _mm_srli_epi16(layer2_chunk1, 8));
|
||||
__m128i layer1_chunk1 = _mm_packus_epi16(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask));
|
||||
__m128i layer1_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk2, 8), _mm_srli_epi16(layer2_chunk3, 8));
|
||||
|
||||
v_r0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask));
|
||||
v_g0 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk0, 8), _mm_srli_epi16(layer1_chunk1, 8));
|
||||
v_r1 = _mm_packus_epi16(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask));
|
||||
v_g1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk2, 8), _mm_srli_epi16(layer1_chunk3, 8));
|
||||
}
|
||||
|
||||
inline void _mm_interleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0,
|
||||
__m128i & v_g1, __m128i & v_b0, __m128i & v_b1)
|
||||
{
|
||||
__m128i v_mask = _mm_set1_epi16(0x00ff);
|
||||
|
||||
__m128i layer4_chunk0 = _mm_packus_epi16(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask));
|
||||
__m128i layer4_chunk3 = _mm_packus_epi16(_mm_srli_epi16(v_r0, 8), _mm_srli_epi16(v_r1, 8));
|
||||
__m128i layer4_chunk1 = _mm_packus_epi16(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask));
|
||||
__m128i layer4_chunk4 = _mm_packus_epi16(_mm_srli_epi16(v_g0, 8), _mm_srli_epi16(v_g1, 8));
|
||||
__m128i layer4_chunk2 = _mm_packus_epi16(_mm_and_si128(v_b0, v_mask), _mm_and_si128(v_b1, v_mask));
|
||||
__m128i layer4_chunk5 = _mm_packus_epi16(_mm_srli_epi16(v_b0, 8), _mm_srli_epi16(v_b1, 8));
|
||||
|
||||
__m128i layer3_chunk0 = _mm_packus_epi16(_mm_and_si128(layer4_chunk0, v_mask), _mm_and_si128(layer4_chunk1, v_mask));
|
||||
__m128i layer3_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk0, 8), _mm_srli_epi16(layer4_chunk1, 8));
|
||||
__m128i layer3_chunk1 = _mm_packus_epi16(_mm_and_si128(layer4_chunk2, v_mask), _mm_and_si128(layer4_chunk3, v_mask));
|
||||
__m128i layer3_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk2, 8), _mm_srli_epi16(layer4_chunk3, 8));
|
||||
__m128i layer3_chunk2 = _mm_packus_epi16(_mm_and_si128(layer4_chunk4, v_mask), _mm_and_si128(layer4_chunk5, v_mask));
|
||||
__m128i layer3_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk4, 8), _mm_srli_epi16(layer4_chunk5, 8));
|
||||
|
||||
__m128i layer2_chunk0 = _mm_packus_epi16(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask));
|
||||
__m128i layer2_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk0, 8), _mm_srli_epi16(layer3_chunk1, 8));
|
||||
__m128i layer2_chunk1 = _mm_packus_epi16(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask));
|
||||
__m128i layer2_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk2, 8), _mm_srli_epi16(layer3_chunk3, 8));
|
||||
__m128i layer2_chunk2 = _mm_packus_epi16(_mm_and_si128(layer3_chunk4, v_mask), _mm_and_si128(layer3_chunk5, v_mask));
|
||||
__m128i layer2_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk4, 8), _mm_srli_epi16(layer3_chunk5, 8));
|
||||
|
||||
__m128i layer1_chunk0 = _mm_packus_epi16(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask));
|
||||
__m128i layer1_chunk3 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk0, 8), _mm_srli_epi16(layer2_chunk1, 8));
|
||||
__m128i layer1_chunk1 = _mm_packus_epi16(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask));
|
||||
__m128i layer1_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk2, 8), _mm_srli_epi16(layer2_chunk3, 8));
|
||||
__m128i layer1_chunk2 = _mm_packus_epi16(_mm_and_si128(layer2_chunk4, v_mask), _mm_and_si128(layer2_chunk5, v_mask));
|
||||
__m128i layer1_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk4, 8), _mm_srli_epi16(layer2_chunk5, 8));
|
||||
|
||||
v_r0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask));
|
||||
v_g1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk0, 8), _mm_srli_epi16(layer1_chunk1, 8));
|
||||
v_r1 = _mm_packus_epi16(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask));
|
||||
v_b0 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk2, 8), _mm_srli_epi16(layer1_chunk3, 8));
|
||||
v_g0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk4, v_mask), _mm_and_si128(layer1_chunk5, v_mask));
|
||||
v_b1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk4, 8), _mm_srli_epi16(layer1_chunk5, 8));
|
||||
}
|
||||
|
||||
inline void _mm_interleave_epi8(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1,
|
||||
__m128i & v_b0, __m128i & v_b1, __m128i & v_a0, __m128i & v_a1)
|
||||
{
|
||||
__m128i v_mask = _mm_set1_epi16(0x00ff);
|
||||
|
||||
__m128i layer4_chunk0 = _mm_packus_epi16(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask));
|
||||
__m128i layer4_chunk4 = _mm_packus_epi16(_mm_srli_epi16(v_r0, 8), _mm_srli_epi16(v_r1, 8));
|
||||
__m128i layer4_chunk1 = _mm_packus_epi16(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask));
|
||||
__m128i layer4_chunk5 = _mm_packus_epi16(_mm_srli_epi16(v_g0, 8), _mm_srli_epi16(v_g1, 8));
|
||||
__m128i layer4_chunk2 = _mm_packus_epi16(_mm_and_si128(v_b0, v_mask), _mm_and_si128(v_b1, v_mask));
|
||||
__m128i layer4_chunk6 = _mm_packus_epi16(_mm_srli_epi16(v_b0, 8), _mm_srli_epi16(v_b1, 8));
|
||||
__m128i layer4_chunk3 = _mm_packus_epi16(_mm_and_si128(v_a0, v_mask), _mm_and_si128(v_a1, v_mask));
|
||||
__m128i layer4_chunk7 = _mm_packus_epi16(_mm_srli_epi16(v_a0, 8), _mm_srli_epi16(v_a1, 8));
|
||||
|
||||
__m128i layer3_chunk0 = _mm_packus_epi16(_mm_and_si128(layer4_chunk0, v_mask), _mm_and_si128(layer4_chunk1, v_mask));
|
||||
__m128i layer3_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk0, 8), _mm_srli_epi16(layer4_chunk1, 8));
|
||||
__m128i layer3_chunk1 = _mm_packus_epi16(_mm_and_si128(layer4_chunk2, v_mask), _mm_and_si128(layer4_chunk3, v_mask));
|
||||
__m128i layer3_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk2, 8), _mm_srli_epi16(layer4_chunk3, 8));
|
||||
__m128i layer3_chunk2 = _mm_packus_epi16(_mm_and_si128(layer4_chunk4, v_mask), _mm_and_si128(layer4_chunk5, v_mask));
|
||||
__m128i layer3_chunk6 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk4, 8), _mm_srli_epi16(layer4_chunk5, 8));
|
||||
__m128i layer3_chunk3 = _mm_packus_epi16(_mm_and_si128(layer4_chunk6, v_mask), _mm_and_si128(layer4_chunk7, v_mask));
|
||||
__m128i layer3_chunk7 = _mm_packus_epi16(_mm_srli_epi16(layer4_chunk6, 8), _mm_srli_epi16(layer4_chunk7, 8));
|
||||
|
||||
__m128i layer2_chunk0 = _mm_packus_epi16(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask));
|
||||
__m128i layer2_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk0, 8), _mm_srli_epi16(layer3_chunk1, 8));
|
||||
__m128i layer2_chunk1 = _mm_packus_epi16(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask));
|
||||
__m128i layer2_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk2, 8), _mm_srli_epi16(layer3_chunk3, 8));
|
||||
__m128i layer2_chunk2 = _mm_packus_epi16(_mm_and_si128(layer3_chunk4, v_mask), _mm_and_si128(layer3_chunk5, v_mask));
|
||||
__m128i layer2_chunk6 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk4, 8), _mm_srli_epi16(layer3_chunk5, 8));
|
||||
__m128i layer2_chunk3 = _mm_packus_epi16(_mm_and_si128(layer3_chunk6, v_mask), _mm_and_si128(layer3_chunk7, v_mask));
|
||||
__m128i layer2_chunk7 = _mm_packus_epi16(_mm_srli_epi16(layer3_chunk6, 8), _mm_srli_epi16(layer3_chunk7, 8));
|
||||
|
||||
__m128i layer1_chunk0 = _mm_packus_epi16(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask));
|
||||
__m128i layer1_chunk4 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk0, 8), _mm_srli_epi16(layer2_chunk1, 8));
|
||||
__m128i layer1_chunk1 = _mm_packus_epi16(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask));
|
||||
__m128i layer1_chunk5 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk2, 8), _mm_srli_epi16(layer2_chunk3, 8));
|
||||
__m128i layer1_chunk2 = _mm_packus_epi16(_mm_and_si128(layer2_chunk4, v_mask), _mm_and_si128(layer2_chunk5, v_mask));
|
||||
__m128i layer1_chunk6 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk4, 8), _mm_srli_epi16(layer2_chunk5, 8));
|
||||
__m128i layer1_chunk3 = _mm_packus_epi16(_mm_and_si128(layer2_chunk6, v_mask), _mm_and_si128(layer2_chunk7, v_mask));
|
||||
__m128i layer1_chunk7 = _mm_packus_epi16(_mm_srli_epi16(layer2_chunk6, 8), _mm_srli_epi16(layer2_chunk7, 8));
|
||||
|
||||
v_r0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask));
|
||||
v_b0 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk0, 8), _mm_srli_epi16(layer1_chunk1, 8));
|
||||
v_r1 = _mm_packus_epi16(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask));
|
||||
v_b1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk2, 8), _mm_srli_epi16(layer1_chunk3, 8));
|
||||
v_g0 = _mm_packus_epi16(_mm_and_si128(layer1_chunk4, v_mask), _mm_and_si128(layer1_chunk5, v_mask));
|
||||
v_a0 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk4, 8), _mm_srli_epi16(layer1_chunk5, 8));
|
||||
v_g1 = _mm_packus_epi16(_mm_and_si128(layer1_chunk6, v_mask), _mm_and_si128(layer1_chunk7, v_mask));
|
||||
v_a1 = _mm_packus_epi16(_mm_srli_epi16(layer1_chunk6, 8), _mm_srli_epi16(layer1_chunk7, 8));
|
||||
}
|
||||
|
||||
inline void _mm_deinterleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1)
|
||||
{
|
||||
__m128i layer1_chunk0 = _mm_unpacklo_epi16(v_r0, v_g0);
|
||||
__m128i layer1_chunk1 = _mm_unpackhi_epi16(v_r0, v_g0);
|
||||
__m128i layer1_chunk2 = _mm_unpacklo_epi16(v_r1, v_g1);
|
||||
__m128i layer1_chunk3 = _mm_unpackhi_epi16(v_r1, v_g1);
|
||||
|
||||
__m128i layer2_chunk0 = _mm_unpacklo_epi16(layer1_chunk0, layer1_chunk2);
|
||||
__m128i layer2_chunk1 = _mm_unpackhi_epi16(layer1_chunk0, layer1_chunk2);
|
||||
__m128i layer2_chunk2 = _mm_unpacklo_epi16(layer1_chunk1, layer1_chunk3);
|
||||
__m128i layer2_chunk3 = _mm_unpackhi_epi16(layer1_chunk1, layer1_chunk3);
|
||||
|
||||
__m128i layer3_chunk0 = _mm_unpacklo_epi16(layer2_chunk0, layer2_chunk2);
|
||||
__m128i layer3_chunk1 = _mm_unpackhi_epi16(layer2_chunk0, layer2_chunk2);
|
||||
__m128i layer3_chunk2 = _mm_unpacklo_epi16(layer2_chunk1, layer2_chunk3);
|
||||
__m128i layer3_chunk3 = _mm_unpackhi_epi16(layer2_chunk1, layer2_chunk3);
|
||||
|
||||
v_r0 = _mm_unpacklo_epi16(layer3_chunk0, layer3_chunk2);
|
||||
v_r1 = _mm_unpackhi_epi16(layer3_chunk0, layer3_chunk2);
|
||||
v_g0 = _mm_unpacklo_epi16(layer3_chunk1, layer3_chunk3);
|
||||
v_g1 = _mm_unpackhi_epi16(layer3_chunk1, layer3_chunk3);
|
||||
}
|
||||
|
||||
inline void _mm_deinterleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0,
|
||||
__m128i & v_g1, __m128i & v_b0, __m128i & v_b1)
|
||||
{
|
||||
__m128i layer1_chunk0 = _mm_unpacklo_epi16(v_r0, v_g1);
|
||||
__m128i layer1_chunk1 = _mm_unpackhi_epi16(v_r0, v_g1);
|
||||
__m128i layer1_chunk2 = _mm_unpacklo_epi16(v_r1, v_b0);
|
||||
__m128i layer1_chunk3 = _mm_unpackhi_epi16(v_r1, v_b0);
|
||||
__m128i layer1_chunk4 = _mm_unpacklo_epi16(v_g0, v_b1);
|
||||
__m128i layer1_chunk5 = _mm_unpackhi_epi16(v_g0, v_b1);
|
||||
|
||||
__m128i layer2_chunk0 = _mm_unpacklo_epi16(layer1_chunk0, layer1_chunk3);
|
||||
__m128i layer2_chunk1 = _mm_unpackhi_epi16(layer1_chunk0, layer1_chunk3);
|
||||
__m128i layer2_chunk2 = _mm_unpacklo_epi16(layer1_chunk1, layer1_chunk4);
|
||||
__m128i layer2_chunk3 = _mm_unpackhi_epi16(layer1_chunk1, layer1_chunk4);
|
||||
__m128i layer2_chunk4 = _mm_unpacklo_epi16(layer1_chunk2, layer1_chunk5);
|
||||
__m128i layer2_chunk5 = _mm_unpackhi_epi16(layer1_chunk2, layer1_chunk5);
|
||||
|
||||
__m128i layer3_chunk0 = _mm_unpacklo_epi16(layer2_chunk0, layer2_chunk3);
|
||||
__m128i layer3_chunk1 = _mm_unpackhi_epi16(layer2_chunk0, layer2_chunk3);
|
||||
__m128i layer3_chunk2 = _mm_unpacklo_epi16(layer2_chunk1, layer2_chunk4);
|
||||
__m128i layer3_chunk3 = _mm_unpackhi_epi16(layer2_chunk1, layer2_chunk4);
|
||||
__m128i layer3_chunk4 = _mm_unpacklo_epi16(layer2_chunk2, layer2_chunk5);
|
||||
__m128i layer3_chunk5 = _mm_unpackhi_epi16(layer2_chunk2, layer2_chunk5);
|
||||
|
||||
v_r0 = _mm_unpacklo_epi16(layer3_chunk0, layer3_chunk3);
|
||||
v_r1 = _mm_unpackhi_epi16(layer3_chunk0, layer3_chunk3);
|
||||
v_g0 = _mm_unpacklo_epi16(layer3_chunk1, layer3_chunk4);
|
||||
v_g1 = _mm_unpackhi_epi16(layer3_chunk1, layer3_chunk4);
|
||||
v_b0 = _mm_unpacklo_epi16(layer3_chunk2, layer3_chunk5);
|
||||
v_b1 = _mm_unpackhi_epi16(layer3_chunk2, layer3_chunk5);
|
||||
}
|
||||
|
||||
inline void _mm_deinterleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1,
|
||||
__m128i & v_b0, __m128i & v_b1, __m128i & v_a0, __m128i & v_a1)
|
||||
{
|
||||
__m128i layer1_chunk0 = _mm_unpacklo_epi16(v_r0, v_b0);
|
||||
__m128i layer1_chunk1 = _mm_unpackhi_epi16(v_r0, v_b0);
|
||||
__m128i layer1_chunk2 = _mm_unpacklo_epi16(v_r1, v_b1);
|
||||
__m128i layer1_chunk3 = _mm_unpackhi_epi16(v_r1, v_b1);
|
||||
__m128i layer1_chunk4 = _mm_unpacklo_epi16(v_g0, v_a0);
|
||||
__m128i layer1_chunk5 = _mm_unpackhi_epi16(v_g0, v_a0);
|
||||
__m128i layer1_chunk6 = _mm_unpacklo_epi16(v_g1, v_a1);
|
||||
__m128i layer1_chunk7 = _mm_unpackhi_epi16(v_g1, v_a1);
|
||||
|
||||
__m128i layer2_chunk0 = _mm_unpacklo_epi16(layer1_chunk0, layer1_chunk4);
|
||||
__m128i layer2_chunk1 = _mm_unpackhi_epi16(layer1_chunk0, layer1_chunk4);
|
||||
__m128i layer2_chunk2 = _mm_unpacklo_epi16(layer1_chunk1, layer1_chunk5);
|
||||
__m128i layer2_chunk3 = _mm_unpackhi_epi16(layer1_chunk1, layer1_chunk5);
|
||||
__m128i layer2_chunk4 = _mm_unpacklo_epi16(layer1_chunk2, layer1_chunk6);
|
||||
__m128i layer2_chunk5 = _mm_unpackhi_epi16(layer1_chunk2, layer1_chunk6);
|
||||
__m128i layer2_chunk6 = _mm_unpacklo_epi16(layer1_chunk3, layer1_chunk7);
|
||||
__m128i layer2_chunk7 = _mm_unpackhi_epi16(layer1_chunk3, layer1_chunk7);
|
||||
|
||||
__m128i layer3_chunk0 = _mm_unpacklo_epi16(layer2_chunk0, layer2_chunk4);
|
||||
__m128i layer3_chunk1 = _mm_unpackhi_epi16(layer2_chunk0, layer2_chunk4);
|
||||
__m128i layer3_chunk2 = _mm_unpacklo_epi16(layer2_chunk1, layer2_chunk5);
|
||||
__m128i layer3_chunk3 = _mm_unpackhi_epi16(layer2_chunk1, layer2_chunk5);
|
||||
__m128i layer3_chunk4 = _mm_unpacklo_epi16(layer2_chunk2, layer2_chunk6);
|
||||
__m128i layer3_chunk5 = _mm_unpackhi_epi16(layer2_chunk2, layer2_chunk6);
|
||||
__m128i layer3_chunk6 = _mm_unpacklo_epi16(layer2_chunk3, layer2_chunk7);
|
||||
__m128i layer3_chunk7 = _mm_unpackhi_epi16(layer2_chunk3, layer2_chunk7);
|
||||
|
||||
v_r0 = _mm_unpacklo_epi16(layer3_chunk0, layer3_chunk4);
|
||||
v_r1 = _mm_unpackhi_epi16(layer3_chunk0, layer3_chunk4);
|
||||
v_g0 = _mm_unpacklo_epi16(layer3_chunk1, layer3_chunk5);
|
||||
v_g1 = _mm_unpackhi_epi16(layer3_chunk1, layer3_chunk5);
|
||||
v_b0 = _mm_unpacklo_epi16(layer3_chunk2, layer3_chunk6);
|
||||
v_b1 = _mm_unpackhi_epi16(layer3_chunk2, layer3_chunk6);
|
||||
v_a0 = _mm_unpacklo_epi16(layer3_chunk3, layer3_chunk7);
|
||||
v_a1 = _mm_unpackhi_epi16(layer3_chunk3, layer3_chunk7);
|
||||
}
|
||||
|
||||
#if CV_SSE4_1
|
||||
|
||||
inline void _mm_interleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1)
|
||||
{
|
||||
__m128i v_mask = _mm_set1_epi32(0x0000ffff);
|
||||
|
||||
__m128i layer3_chunk0 = _mm_packus_epi32(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask));
|
||||
__m128i layer3_chunk2 = _mm_packus_epi32(_mm_srli_epi32(v_r0, 16), _mm_srli_epi32(v_r1, 16));
|
||||
__m128i layer3_chunk1 = _mm_packus_epi32(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask));
|
||||
__m128i layer3_chunk3 = _mm_packus_epi32(_mm_srli_epi32(v_g0, 16), _mm_srli_epi32(v_g1, 16));
|
||||
|
||||
__m128i layer2_chunk0 = _mm_packus_epi32(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask));
|
||||
__m128i layer2_chunk2 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk0, 16), _mm_srli_epi32(layer3_chunk1, 16));
|
||||
__m128i layer2_chunk1 = _mm_packus_epi32(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask));
|
||||
__m128i layer2_chunk3 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk2, 16), _mm_srli_epi32(layer3_chunk3, 16));
|
||||
|
||||
__m128i layer1_chunk0 = _mm_packus_epi32(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask));
|
||||
__m128i layer1_chunk2 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk0, 16), _mm_srli_epi32(layer2_chunk1, 16));
|
||||
__m128i layer1_chunk1 = _mm_packus_epi32(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask));
|
||||
__m128i layer1_chunk3 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk2, 16), _mm_srli_epi32(layer2_chunk3, 16));
|
||||
|
||||
v_r0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask));
|
||||
v_g0 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk0, 16), _mm_srli_epi32(layer1_chunk1, 16));
|
||||
v_r1 = _mm_packus_epi32(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask));
|
||||
v_g1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk2, 16), _mm_srli_epi32(layer1_chunk3, 16));
|
||||
}
|
||||
|
||||
inline void _mm_interleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0,
|
||||
__m128i & v_g1, __m128i & v_b0, __m128i & v_b1)
|
||||
{
|
||||
__m128i v_mask = _mm_set1_epi32(0x0000ffff);
|
||||
|
||||
__m128i layer3_chunk0 = _mm_packus_epi32(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask));
|
||||
__m128i layer3_chunk3 = _mm_packus_epi32(_mm_srli_epi32(v_r0, 16), _mm_srli_epi32(v_r1, 16));
|
||||
__m128i layer3_chunk1 = _mm_packus_epi32(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask));
|
||||
__m128i layer3_chunk4 = _mm_packus_epi32(_mm_srli_epi32(v_g0, 16), _mm_srli_epi32(v_g1, 16));
|
||||
__m128i layer3_chunk2 = _mm_packus_epi32(_mm_and_si128(v_b0, v_mask), _mm_and_si128(v_b1, v_mask));
|
||||
__m128i layer3_chunk5 = _mm_packus_epi32(_mm_srli_epi32(v_b0, 16), _mm_srli_epi32(v_b1, 16));
|
||||
|
||||
__m128i layer2_chunk0 = _mm_packus_epi32(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask));
|
||||
__m128i layer2_chunk3 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk0, 16), _mm_srli_epi32(layer3_chunk1, 16));
|
||||
__m128i layer2_chunk1 = _mm_packus_epi32(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask));
|
||||
__m128i layer2_chunk4 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk2, 16), _mm_srli_epi32(layer3_chunk3, 16));
|
||||
__m128i layer2_chunk2 = _mm_packus_epi32(_mm_and_si128(layer3_chunk4, v_mask), _mm_and_si128(layer3_chunk5, v_mask));
|
||||
__m128i layer2_chunk5 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk4, 16), _mm_srli_epi32(layer3_chunk5, 16));
|
||||
|
||||
__m128i layer1_chunk0 = _mm_packus_epi32(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask));
|
||||
__m128i layer1_chunk3 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk0, 16), _mm_srli_epi32(layer2_chunk1, 16));
|
||||
__m128i layer1_chunk1 = _mm_packus_epi32(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask));
|
||||
__m128i layer1_chunk4 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk2, 16), _mm_srli_epi32(layer2_chunk3, 16));
|
||||
__m128i layer1_chunk2 = _mm_packus_epi32(_mm_and_si128(layer2_chunk4, v_mask), _mm_and_si128(layer2_chunk5, v_mask));
|
||||
__m128i layer1_chunk5 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk4, 16), _mm_srli_epi32(layer2_chunk5, 16));
|
||||
|
||||
v_r0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask));
|
||||
v_g1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk0, 16), _mm_srli_epi32(layer1_chunk1, 16));
|
||||
v_r1 = _mm_packus_epi32(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask));
|
||||
v_b0 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk2, 16), _mm_srli_epi32(layer1_chunk3, 16));
|
||||
v_g0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk4, v_mask), _mm_and_si128(layer1_chunk5, v_mask));
|
||||
v_b1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk4, 16), _mm_srli_epi32(layer1_chunk5, 16));
|
||||
}
|
||||
|
||||
inline void _mm_interleave_epi16(__m128i & v_r0, __m128i & v_r1, __m128i & v_g0, __m128i & v_g1,
|
||||
__m128i & v_b0, __m128i & v_b1, __m128i & v_a0, __m128i & v_a1)
|
||||
{
|
||||
__m128i v_mask = _mm_set1_epi32(0x0000ffff);
|
||||
|
||||
__m128i layer3_chunk0 = _mm_packus_epi32(_mm_and_si128(v_r0, v_mask), _mm_and_si128(v_r1, v_mask));
|
||||
__m128i layer3_chunk4 = _mm_packus_epi32(_mm_srli_epi32(v_r0, 16), _mm_srli_epi32(v_r1, 16));
|
||||
__m128i layer3_chunk1 = _mm_packus_epi32(_mm_and_si128(v_g0, v_mask), _mm_and_si128(v_g1, v_mask));
|
||||
__m128i layer3_chunk5 = _mm_packus_epi32(_mm_srli_epi32(v_g0, 16), _mm_srli_epi32(v_g1, 16));
|
||||
__m128i layer3_chunk2 = _mm_packus_epi32(_mm_and_si128(v_b0, v_mask), _mm_and_si128(v_b1, v_mask));
|
||||
__m128i layer3_chunk6 = _mm_packus_epi32(_mm_srli_epi32(v_b0, 16), _mm_srli_epi32(v_b1, 16));
|
||||
__m128i layer3_chunk3 = _mm_packus_epi32(_mm_and_si128(v_a0, v_mask), _mm_and_si128(v_a1, v_mask));
|
||||
__m128i layer3_chunk7 = _mm_packus_epi32(_mm_srli_epi32(v_a0, 16), _mm_srli_epi32(v_a1, 16));
|
||||
|
||||
__m128i layer2_chunk0 = _mm_packus_epi32(_mm_and_si128(layer3_chunk0, v_mask), _mm_and_si128(layer3_chunk1, v_mask));
|
||||
__m128i layer2_chunk4 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk0, 16), _mm_srli_epi32(layer3_chunk1, 16));
|
||||
__m128i layer2_chunk1 = _mm_packus_epi32(_mm_and_si128(layer3_chunk2, v_mask), _mm_and_si128(layer3_chunk3, v_mask));
|
||||
__m128i layer2_chunk5 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk2, 16), _mm_srli_epi32(layer3_chunk3, 16));
|
||||
__m128i layer2_chunk2 = _mm_packus_epi32(_mm_and_si128(layer3_chunk4, v_mask), _mm_and_si128(layer3_chunk5, v_mask));
|
||||
__m128i layer2_chunk6 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk4, 16), _mm_srli_epi32(layer3_chunk5, 16));
|
||||
__m128i layer2_chunk3 = _mm_packus_epi32(_mm_and_si128(layer3_chunk6, v_mask), _mm_and_si128(layer3_chunk7, v_mask));
|
||||
__m128i layer2_chunk7 = _mm_packus_epi32(_mm_srli_epi32(layer3_chunk6, 16), _mm_srli_epi32(layer3_chunk7, 16));
|
||||
|
||||
__m128i layer1_chunk0 = _mm_packus_epi32(_mm_and_si128(layer2_chunk0, v_mask), _mm_and_si128(layer2_chunk1, v_mask));
|
||||
__m128i layer1_chunk4 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk0, 16), _mm_srli_epi32(layer2_chunk1, 16));
|
||||
__m128i layer1_chunk1 = _mm_packus_epi32(_mm_and_si128(layer2_chunk2, v_mask), _mm_and_si128(layer2_chunk3, v_mask));
|
||||
__m128i layer1_chunk5 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk2, 16), _mm_srli_epi32(layer2_chunk3, 16));
|
||||
__m128i layer1_chunk2 = _mm_packus_epi32(_mm_and_si128(layer2_chunk4, v_mask), _mm_and_si128(layer2_chunk5, v_mask));
|
||||
__m128i layer1_chunk6 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk4, 16), _mm_srli_epi32(layer2_chunk5, 16));
|
||||
__m128i layer1_chunk3 = _mm_packus_epi32(_mm_and_si128(layer2_chunk6, v_mask), _mm_and_si128(layer2_chunk7, v_mask));
|
||||
__m128i layer1_chunk7 = _mm_packus_epi32(_mm_srli_epi32(layer2_chunk6, 16), _mm_srli_epi32(layer2_chunk7, 16));
|
||||
|
||||
v_r0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk0, v_mask), _mm_and_si128(layer1_chunk1, v_mask));
|
||||
v_b0 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk0, 16), _mm_srli_epi32(layer1_chunk1, 16));
|
||||
v_r1 = _mm_packus_epi32(_mm_and_si128(layer1_chunk2, v_mask), _mm_and_si128(layer1_chunk3, v_mask));
|
||||
v_b1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk2, 16), _mm_srli_epi32(layer1_chunk3, 16));
|
||||
v_g0 = _mm_packus_epi32(_mm_and_si128(layer1_chunk4, v_mask), _mm_and_si128(layer1_chunk5, v_mask));
|
||||
v_a0 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk4, 16), _mm_srli_epi32(layer1_chunk5, 16));
|
||||
v_g1 = _mm_packus_epi32(_mm_and_si128(layer1_chunk6, v_mask), _mm_and_si128(layer1_chunk7, v_mask));
|
||||
v_a1 = _mm_packus_epi32(_mm_srli_epi32(layer1_chunk6, 16), _mm_srli_epi32(layer1_chunk7, 16));
|
||||
}
|
||||
|
||||
#endif // CV_SSE4_1
|
||||
|
||||
inline void _mm_deinterleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, __m128 & v_g1)
|
||||
{
|
||||
__m128 layer1_chunk0 = _mm_unpacklo_ps(v_r0, v_g0);
|
||||
__m128 layer1_chunk1 = _mm_unpackhi_ps(v_r0, v_g0);
|
||||
__m128 layer1_chunk2 = _mm_unpacklo_ps(v_r1, v_g1);
|
||||
__m128 layer1_chunk3 = _mm_unpackhi_ps(v_r1, v_g1);
|
||||
|
||||
__m128 layer2_chunk0 = _mm_unpacklo_ps(layer1_chunk0, layer1_chunk2);
|
||||
__m128 layer2_chunk1 = _mm_unpackhi_ps(layer1_chunk0, layer1_chunk2);
|
||||
__m128 layer2_chunk2 = _mm_unpacklo_ps(layer1_chunk1, layer1_chunk3);
|
||||
__m128 layer2_chunk3 = _mm_unpackhi_ps(layer1_chunk1, layer1_chunk3);
|
||||
|
||||
v_r0 = _mm_unpacklo_ps(layer2_chunk0, layer2_chunk2);
|
||||
v_r1 = _mm_unpackhi_ps(layer2_chunk0, layer2_chunk2);
|
||||
v_g0 = _mm_unpacklo_ps(layer2_chunk1, layer2_chunk3);
|
||||
v_g1 = _mm_unpackhi_ps(layer2_chunk1, layer2_chunk3);
|
||||
}
|
||||
|
||||
inline void _mm_deinterleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0,
|
||||
__m128 & v_g1, __m128 & v_b0, __m128 & v_b1)
|
||||
{
|
||||
__m128 layer1_chunk0 = _mm_unpacklo_ps(v_r0, v_g1);
|
||||
__m128 layer1_chunk1 = _mm_unpackhi_ps(v_r0, v_g1);
|
||||
__m128 layer1_chunk2 = _mm_unpacklo_ps(v_r1, v_b0);
|
||||
__m128 layer1_chunk3 = _mm_unpackhi_ps(v_r1, v_b0);
|
||||
__m128 layer1_chunk4 = _mm_unpacklo_ps(v_g0, v_b1);
|
||||
__m128 layer1_chunk5 = _mm_unpackhi_ps(v_g0, v_b1);
|
||||
|
||||
__m128 layer2_chunk0 = _mm_unpacklo_ps(layer1_chunk0, layer1_chunk3);
|
||||
__m128 layer2_chunk1 = _mm_unpackhi_ps(layer1_chunk0, layer1_chunk3);
|
||||
__m128 layer2_chunk2 = _mm_unpacklo_ps(layer1_chunk1, layer1_chunk4);
|
||||
__m128 layer2_chunk3 = _mm_unpackhi_ps(layer1_chunk1, layer1_chunk4);
|
||||
__m128 layer2_chunk4 = _mm_unpacklo_ps(layer1_chunk2, layer1_chunk5);
|
||||
__m128 layer2_chunk5 = _mm_unpackhi_ps(layer1_chunk2, layer1_chunk5);
|
||||
|
||||
v_r0 = _mm_unpacklo_ps(layer2_chunk0, layer2_chunk3);
|
||||
v_r1 = _mm_unpackhi_ps(layer2_chunk0, layer2_chunk3);
|
||||
v_g0 = _mm_unpacklo_ps(layer2_chunk1, layer2_chunk4);
|
||||
v_g1 = _mm_unpackhi_ps(layer2_chunk1, layer2_chunk4);
|
||||
v_b0 = _mm_unpacklo_ps(layer2_chunk2, layer2_chunk5);
|
||||
v_b1 = _mm_unpackhi_ps(layer2_chunk2, layer2_chunk5);
|
||||
}
|
||||
|
||||
inline void _mm_deinterleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, __m128 & v_g1,
|
||||
__m128 & v_b0, __m128 & v_b1, __m128 & v_a0, __m128 & v_a1)
|
||||
{
|
||||
__m128 layer1_chunk0 = _mm_unpacklo_ps(v_r0, v_b0);
|
||||
__m128 layer1_chunk1 = _mm_unpackhi_ps(v_r0, v_b0);
|
||||
__m128 layer1_chunk2 = _mm_unpacklo_ps(v_r1, v_b1);
|
||||
__m128 layer1_chunk3 = _mm_unpackhi_ps(v_r1, v_b1);
|
||||
__m128 layer1_chunk4 = _mm_unpacklo_ps(v_g0, v_a0);
|
||||
__m128 layer1_chunk5 = _mm_unpackhi_ps(v_g0, v_a0);
|
||||
__m128 layer1_chunk6 = _mm_unpacklo_ps(v_g1, v_a1);
|
||||
__m128 layer1_chunk7 = _mm_unpackhi_ps(v_g1, v_a1);
|
||||
|
||||
__m128 layer2_chunk0 = _mm_unpacklo_ps(layer1_chunk0, layer1_chunk4);
|
||||
__m128 layer2_chunk1 = _mm_unpackhi_ps(layer1_chunk0, layer1_chunk4);
|
||||
__m128 layer2_chunk2 = _mm_unpacklo_ps(layer1_chunk1, layer1_chunk5);
|
||||
__m128 layer2_chunk3 = _mm_unpackhi_ps(layer1_chunk1, layer1_chunk5);
|
||||
__m128 layer2_chunk4 = _mm_unpacklo_ps(layer1_chunk2, layer1_chunk6);
|
||||
__m128 layer2_chunk5 = _mm_unpackhi_ps(layer1_chunk2, layer1_chunk6);
|
||||
__m128 layer2_chunk6 = _mm_unpacklo_ps(layer1_chunk3, layer1_chunk7);
|
||||
__m128 layer2_chunk7 = _mm_unpackhi_ps(layer1_chunk3, layer1_chunk7);
|
||||
|
||||
v_r0 = _mm_unpacklo_ps(layer2_chunk0, layer2_chunk4);
|
||||
v_r1 = _mm_unpackhi_ps(layer2_chunk0, layer2_chunk4);
|
||||
v_g0 = _mm_unpacklo_ps(layer2_chunk1, layer2_chunk5);
|
||||
v_g1 = _mm_unpackhi_ps(layer2_chunk1, layer2_chunk5);
|
||||
v_b0 = _mm_unpacklo_ps(layer2_chunk2, layer2_chunk6);
|
||||
v_b1 = _mm_unpackhi_ps(layer2_chunk2, layer2_chunk6);
|
||||
v_a0 = _mm_unpacklo_ps(layer2_chunk3, layer2_chunk7);
|
||||
v_a1 = _mm_unpackhi_ps(layer2_chunk3, layer2_chunk7);
|
||||
}
|
||||
|
||||
inline void _mm_interleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, __m128 & v_g1)
|
||||
{
|
||||
const int mask_lo = _MM_SHUFFLE(2, 0, 2, 0), mask_hi = _MM_SHUFFLE(3, 1, 3, 1);
|
||||
|
||||
__m128 layer2_chunk0 = _mm_shuffle_ps(v_r0, v_r1, mask_lo);
|
||||
__m128 layer2_chunk2 = _mm_shuffle_ps(v_r0, v_r1, mask_hi);
|
||||
__m128 layer2_chunk1 = _mm_shuffle_ps(v_g0, v_g1, mask_lo);
|
||||
__m128 layer2_chunk3 = _mm_shuffle_ps(v_g0, v_g1, mask_hi);
|
||||
|
||||
__m128 layer1_chunk0 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_lo);
|
||||
__m128 layer1_chunk2 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_hi);
|
||||
__m128 layer1_chunk1 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_lo);
|
||||
__m128 layer1_chunk3 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_hi);
|
||||
|
||||
v_r0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_lo);
|
||||
v_g0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_hi);
|
||||
v_r1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_lo);
|
||||
v_g1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_hi);
|
||||
}
|
||||
|
||||
inline void _mm_interleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0,
|
||||
__m128 & v_g1, __m128 & v_b0, __m128 & v_b1)
|
||||
{
|
||||
const int mask_lo = _MM_SHUFFLE(2, 0, 2, 0), mask_hi = _MM_SHUFFLE(3, 1, 3, 1);
|
||||
|
||||
__m128 layer2_chunk0 = _mm_shuffle_ps(v_r0, v_r1, mask_lo);
|
||||
__m128 layer2_chunk3 = _mm_shuffle_ps(v_r0, v_r1, mask_hi);
|
||||
__m128 layer2_chunk1 = _mm_shuffle_ps(v_g0, v_g1, mask_lo);
|
||||
__m128 layer2_chunk4 = _mm_shuffle_ps(v_g0, v_g1, mask_hi);
|
||||
__m128 layer2_chunk2 = _mm_shuffle_ps(v_b0, v_b1, mask_lo);
|
||||
__m128 layer2_chunk5 = _mm_shuffle_ps(v_b0, v_b1, mask_hi);
|
||||
|
||||
__m128 layer1_chunk0 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_lo);
|
||||
__m128 layer1_chunk3 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_hi);
|
||||
__m128 layer1_chunk1 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_lo);
|
||||
__m128 layer1_chunk4 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_hi);
|
||||
__m128 layer1_chunk2 = _mm_shuffle_ps(layer2_chunk4, layer2_chunk5, mask_lo);
|
||||
__m128 layer1_chunk5 = _mm_shuffle_ps(layer2_chunk4, layer2_chunk5, mask_hi);
|
||||
|
||||
v_r0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_lo);
|
||||
v_g1 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_hi);
|
||||
v_r1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_lo);
|
||||
v_b0 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_hi);
|
||||
v_g0 = _mm_shuffle_ps(layer1_chunk4, layer1_chunk5, mask_lo);
|
||||
v_b1 = _mm_shuffle_ps(layer1_chunk4, layer1_chunk5, mask_hi);
|
||||
}
|
||||
|
||||
inline void _mm_interleave_ps(__m128 & v_r0, __m128 & v_r1, __m128 & v_g0, __m128 & v_g1,
|
||||
__m128 & v_b0, __m128 & v_b1, __m128 & v_a0, __m128 & v_a1)
|
||||
{
|
||||
const int mask_lo = _MM_SHUFFLE(2, 0, 2, 0), mask_hi = _MM_SHUFFLE(3, 1, 3, 1);
|
||||
|
||||
__m128 layer2_chunk0 = _mm_shuffle_ps(v_r0, v_r1, mask_lo);
|
||||
__m128 layer2_chunk4 = _mm_shuffle_ps(v_r0, v_r1, mask_hi);
|
||||
__m128 layer2_chunk1 = _mm_shuffle_ps(v_g0, v_g1, mask_lo);
|
||||
__m128 layer2_chunk5 = _mm_shuffle_ps(v_g0, v_g1, mask_hi);
|
||||
__m128 layer2_chunk2 = _mm_shuffle_ps(v_b0, v_b1, mask_lo);
|
||||
__m128 layer2_chunk6 = _mm_shuffle_ps(v_b0, v_b1, mask_hi);
|
||||
__m128 layer2_chunk3 = _mm_shuffle_ps(v_a0, v_a1, mask_lo);
|
||||
__m128 layer2_chunk7 = _mm_shuffle_ps(v_a0, v_a1, mask_hi);
|
||||
|
||||
__m128 layer1_chunk0 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_lo);
|
||||
__m128 layer1_chunk4 = _mm_shuffle_ps(layer2_chunk0, layer2_chunk1, mask_hi);
|
||||
__m128 layer1_chunk1 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_lo);
|
||||
__m128 layer1_chunk5 = _mm_shuffle_ps(layer2_chunk2, layer2_chunk3, mask_hi);
|
||||
__m128 layer1_chunk2 = _mm_shuffle_ps(layer2_chunk4, layer2_chunk5, mask_lo);
|
||||
__m128 layer1_chunk6 = _mm_shuffle_ps(layer2_chunk4, layer2_chunk5, mask_hi);
|
||||
__m128 layer1_chunk3 = _mm_shuffle_ps(layer2_chunk6, layer2_chunk7, mask_lo);
|
||||
__m128 layer1_chunk7 = _mm_shuffle_ps(layer2_chunk6, layer2_chunk7, mask_hi);
|
||||
|
||||
v_r0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_lo);
|
||||
v_b0 = _mm_shuffle_ps(layer1_chunk0, layer1_chunk1, mask_hi);
|
||||
v_r1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_lo);
|
||||
v_b1 = _mm_shuffle_ps(layer1_chunk2, layer1_chunk3, mask_hi);
|
||||
v_g0 = _mm_shuffle_ps(layer1_chunk4, layer1_chunk5, mask_lo);
|
||||
v_a0 = _mm_shuffle_ps(layer1_chunk4, layer1_chunk5, mask_hi);
|
||||
v_g1 = _mm_shuffle_ps(layer1_chunk6, layer1_chunk7, mask_lo);
|
||||
v_a1 = _mm_shuffle_ps(layer1_chunk6, layer1_chunk7, mask_hi);
|
||||
}
|
||||
|
||||
#endif // CV_SSE2
|
||||
|
||||
//! @}
|
||||
|
||||
#endif //OPENCV_CORE_SSE_UTILS_HPP
|
||||
@@ -0,0 +1,326 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_TRAITS_HPP
|
||||
#define OPENCV_CORE_TRAITS_HPP
|
||||
|
||||
#include "opencv2/core/cvdef.h"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
|
||||
//! @addtogroup core_basic
|
||||
//! @{
|
||||
|
||||
/** @brief Template "trait" class for OpenCV primitive data types.
|
||||
|
||||
A primitive OpenCV data type is one of unsigned char, bool, signed char, unsigned short, signed
|
||||
short, int, float, double, or a tuple of values of one of these types, where all the values in the
|
||||
tuple have the same type. Any primitive type from the list can be defined by an identifier in the
|
||||
form CV_\<bit-depth\>{U|S|F}C(\<number_of_channels\>), for example: uchar \~ CV_8UC1, 3-element
|
||||
floating-point tuple \~ CV_32FC3, and so on. A universal OpenCV structure that is able to store a
|
||||
single instance of such a primitive data type is Vec. Multiple instances of such a type can be
|
||||
stored in a std::vector, Mat, Mat_, SparseMat, SparseMat_, or any other container that is able to
|
||||
store Vec instances.
|
||||
|
||||
The DataType class is basically used to provide a description of such primitive data types without
|
||||
adding any fields or methods to the corresponding classes (and it is actually impossible to add
|
||||
anything to primitive C/C++ data types). This technique is known in C++ as class traits. It is not
|
||||
DataType itself that is used but its specialized versions, such as:
|
||||
@code
|
||||
template<> class DataType<uchar>
|
||||
{
|
||||
typedef uchar value_type;
|
||||
typedef int work_type;
|
||||
typedef uchar channel_type;
|
||||
enum { channel_type = CV_8U, channels = 1, fmt='u', type = CV_8U };
|
||||
};
|
||||
...
|
||||
template<typename _Tp> DataType<std::complex<_Tp> >
|
||||
{
|
||||
typedef std::complex<_Tp> value_type;
|
||||
typedef std::complex<_Tp> work_type;
|
||||
typedef _Tp channel_type;
|
||||
// DataDepth is another helper trait class
|
||||
enum { depth = DataDepth<_Tp>::value, channels=2,
|
||||
fmt=(channels-1)*256+DataDepth<_Tp>::fmt,
|
||||
type=CV_MAKETYPE(depth, channels) };
|
||||
};
|
||||
...
|
||||
@endcode
|
||||
The main purpose of this class is to convert compilation-time type information to an
|
||||
OpenCV-compatible data type identifier, for example:
|
||||
@code
|
||||
// allocates a 30x40 floating-point matrix
|
||||
Mat A(30, 40, DataType<float>::type);
|
||||
|
||||
Mat B = Mat_<std::complex<double> >(3, 3);
|
||||
// the statement below will print 6, 2 , that is depth == CV_64F, channels == 2
|
||||
cout << B.depth() << ", " << B.channels() << endl;
|
||||
@endcode
|
||||
So, such traits are used to tell OpenCV which data type you are working with, even if such a type is
|
||||
not native to OpenCV. For example, the matrix B initialization above is compiled because OpenCV
|
||||
defines the proper specialized template class DataType\<complex\<_Tp\> \> . This mechanism is also
|
||||
useful (and used in OpenCV this way) for generic algorithms implementations.
|
||||
*/
|
||||
template<typename _Tp> class DataType
|
||||
{
|
||||
public:
|
||||
typedef _Tp value_type;
|
||||
typedef value_type work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 1,
|
||||
depth = -1,
|
||||
channels = 1,
|
||||
fmt = 0,
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<bool>
|
||||
{
|
||||
public:
|
||||
typedef bool value_type;
|
||||
typedef int work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_8U,
|
||||
channels = 1,
|
||||
fmt = (int)'u',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<uchar>
|
||||
{
|
||||
public:
|
||||
typedef uchar value_type;
|
||||
typedef int work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_8U,
|
||||
channels = 1,
|
||||
fmt = (int)'u',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<schar>
|
||||
{
|
||||
public:
|
||||
typedef schar value_type;
|
||||
typedef int work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_8S,
|
||||
channels = 1,
|
||||
fmt = (int)'c',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<char>
|
||||
{
|
||||
public:
|
||||
typedef schar value_type;
|
||||
typedef int work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_8S,
|
||||
channels = 1,
|
||||
fmt = (int)'c',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<ushort>
|
||||
{
|
||||
public:
|
||||
typedef ushort value_type;
|
||||
typedef int work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_16U,
|
||||
channels = 1,
|
||||
fmt = (int)'w',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<short>
|
||||
{
|
||||
public:
|
||||
typedef short value_type;
|
||||
typedef int work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_16S,
|
||||
channels = 1,
|
||||
fmt = (int)'s',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<int>
|
||||
{
|
||||
public:
|
||||
typedef int value_type;
|
||||
typedef value_type work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_32S,
|
||||
channels = 1,
|
||||
fmt = (int)'i',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<float>
|
||||
{
|
||||
public:
|
||||
typedef float value_type;
|
||||
typedef value_type work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_32F,
|
||||
channels = 1,
|
||||
fmt = (int)'f',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
template<> class DataType<double>
|
||||
{
|
||||
public:
|
||||
typedef double value_type;
|
||||
typedef value_type work_type;
|
||||
typedef value_type channel_type;
|
||||
typedef value_type vec_type;
|
||||
enum { generic_type = 0,
|
||||
depth = CV_64F,
|
||||
channels = 1,
|
||||
fmt = (int)'d',
|
||||
type = CV_MAKETYPE(depth, channels)
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
/** @brief A helper class for cv::DataType
|
||||
|
||||
The class is specialized for each fundamental numerical data type supported by OpenCV. It provides
|
||||
DataDepth<T>::value constant.
|
||||
*/
|
||||
template<typename _Tp> class DataDepth
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
value = DataType<_Tp>::depth,
|
||||
fmt = DataType<_Tp>::fmt
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<int _depth> class TypeDepth
|
||||
{
|
||||
enum { depth = CV_USRTYPE1 };
|
||||
typedef void value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_8U>
|
||||
{
|
||||
enum { depth = CV_8U };
|
||||
typedef uchar value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_8S>
|
||||
{
|
||||
enum { depth = CV_8S };
|
||||
typedef schar value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_16U>
|
||||
{
|
||||
enum { depth = CV_16U };
|
||||
typedef ushort value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_16S>
|
||||
{
|
||||
enum { depth = CV_16S };
|
||||
typedef short value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_32S>
|
||||
{
|
||||
enum { depth = CV_32S };
|
||||
typedef int value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_32F>
|
||||
{
|
||||
enum { depth = CV_32F };
|
||||
typedef float value_type;
|
||||
};
|
||||
|
||||
template<> class TypeDepth<CV_64F>
|
||||
{
|
||||
enum { depth = CV_64F };
|
||||
typedef double value_type;
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
||||
} // cv
|
||||
|
||||
#endif // OPENCV_CORE_TRAITS_HPP
|
||||
File diff suppressed because it is too large
Load Diff
+462
-521
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,77 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html.
|
||||
|
||||
// Copyright (C) 2015, Itseez, Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
|
||||
#ifndef OPENCV_CORE_VA_INTEL_HPP
|
||||
#define OPENCV_CORE_VA_INTEL_HPP
|
||||
|
||||
#ifndef __cplusplus
|
||||
# error va_intel.hpp header must be compiled as C++
|
||||
#endif
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "ocl.hpp"
|
||||
|
||||
#if defined(HAVE_VA)
|
||||
# include "va/va.h"
|
||||
#else // HAVE_VA
|
||||
# if !defined(_VA_H_)
|
||||
typedef void* VADisplay;
|
||||
typedef unsigned int VASurfaceID;
|
||||
# endif // !_VA_H_
|
||||
#endif // HAVE_VA
|
||||
|
||||
namespace cv { namespace va_intel {
|
||||
|
||||
/** @addtogroup core_va_intel
|
||||
This section describes Intel VA-API/OpenCL (CL-VA) interoperability.
|
||||
|
||||
To enable CL-VA interoperability support, configure OpenCV using CMake with WITH_VA_INTEL=ON . Currently VA-API is
|
||||
supported on Linux only. You should also install Intel Media Server Studio (MSS) to use this feature. You may
|
||||
have to specify the path(s) to MSS components for cmake in environment variables: VA_INTEL_MSDK_ROOT for Media SDK
|
||||
(default is "/opt/intel/mediasdk"), and VA_INTEL_IOCL_ROOT for Intel OpenCL (default is "/opt/intel/opencl").
|
||||
|
||||
To use CL-VA interoperability you should first create VADisplay (libva), and then call initializeContextFromVA()
|
||||
function to create OpenCL context and set up interoperability.
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/////////////////// CL-VA Interoperability Functions ///////////////////
|
||||
|
||||
namespace ocl {
|
||||
using namespace cv::ocl;
|
||||
|
||||
// TODO static functions in the Context class
|
||||
/** @brief Creates OpenCL context from VA.
|
||||
@param display - VADisplay for which CL interop should be established.
|
||||
@param tryInterop - try to set up for interoperability, if true; set up for use slow copy if false.
|
||||
@return Returns reference to OpenCL Context
|
||||
*/
|
||||
CV_EXPORTS Context& initializeContextFromVA(VADisplay display, bool tryInterop = true);
|
||||
|
||||
} // namespace cv::va_intel::ocl
|
||||
|
||||
/** @brief Converts InputArray to VASurfaceID object.
|
||||
@param display - VADisplay object.
|
||||
@param src - source InputArray.
|
||||
@param surface - destination VASurfaceID object.
|
||||
@param size - size of image represented by VASurfaceID object.
|
||||
*/
|
||||
CV_EXPORTS void convertToVASurface(VADisplay display, InputArray src, VASurfaceID surface, Size size);
|
||||
|
||||
/** @brief Converts VASurfaceID object to OutputArray.
|
||||
@param display - VADisplay object.
|
||||
@param surface - source VASurfaceID object.
|
||||
@param size - size of image represented by VASurfaceID object.
|
||||
@param dst - destination OutputArray.
|
||||
*/
|
||||
CV_EXPORTS void convertFromVASurface(VADisplay display, VASurfaceID surface, Size size, OutputArray dst);
|
||||
|
||||
//! @}
|
||||
|
||||
}} // namespace cv::va_intel
|
||||
|
||||
#endif /* OPENCV_CORE_VA_INTEL_HPP */
|
||||
@@ -10,7 +10,10 @@
|
||||
// Intel License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright( C) 2000, Intel Corporation, all rights reserved.
|
||||
// Copyright( C) 2000-2015, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2011-2013, NVIDIA Corporation, all rights reserved.
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Copyright (C) 2015, Itseez Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
@@ -44,29 +47,25 @@
|
||||
Usefull to test in user programs
|
||||
*/
|
||||
|
||||
#ifndef __OPENCV_VERSION_HPP__
|
||||
#define __OPENCV_VERSION_HPP__
|
||||
#ifndef OPENCV_VERSION_HPP
|
||||
#define OPENCV_VERSION_HPP
|
||||
|
||||
#define CV_VERSION_EPOCH 2
|
||||
#define CV_VERSION_MAJOR 4
|
||||
#define CV_VERSION_MINOR 8
|
||||
#define CV_VERSION_MAJOR 3
|
||||
#define CV_VERSION_MINOR 2
|
||||
#define CV_VERSION_REVISION 0
|
||||
#define CV_VERSION_STATUS ""
|
||||
|
||||
#define CVAUX_STR_EXP(__A) #__A
|
||||
#define CVAUX_STR(__A) CVAUX_STR_EXP(__A)
|
||||
|
||||
#define CVAUX_STRW_EXP(__A) L#__A
|
||||
#define CVAUX_STRW_EXP(__A) L ## #__A
|
||||
#define CVAUX_STRW(__A) CVAUX_STRW_EXP(__A)
|
||||
|
||||
#if CV_VERSION_REVISION
|
||||
# define CV_VERSION CVAUX_STR(CV_VERSION_EPOCH) "." CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR) "." CVAUX_STR(CV_VERSION_REVISION)
|
||||
#else
|
||||
# define CV_VERSION CVAUX_STR(CV_VERSION_EPOCH) "." CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR)
|
||||
#endif
|
||||
#define CV_VERSION CVAUX_STR(CV_VERSION_MAJOR) "." CVAUX_STR(CV_VERSION_MINOR) "." CVAUX_STR(CV_VERSION_REVISION) CV_VERSION_STATUS
|
||||
|
||||
/* old style version constants*/
|
||||
#define CV_MAJOR_VERSION CV_VERSION_EPOCH
|
||||
#define CV_MINOR_VERSION CV_VERSION_MAJOR
|
||||
#define CV_SUBMINOR_VERSION CV_VERSION_MINOR
|
||||
#define CV_MAJOR_VERSION CV_VERSION_MAJOR
|
||||
#define CV_MINOR_VERSION CV_VERSION_MINOR
|
||||
#define CV_SUBMINOR_VERSION CV_VERSION_REVISION
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
/*M//////////////////////////////////////////////////////////////////////////////
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to
|
||||
@@ -36,69 +36,11 @@
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Image class which provides a thin layer around an IplImage. The goals
|
||||
// of the class design are:
|
||||
// 1. All the data has explicit ownership to avoid memory leaks
|
||||
// 2. No hidden allocations or copies for performance.
|
||||
// 3. Easy access to OpenCV methods (which will access IPP if available)
|
||||
// 4. Can easily treat external data as an image
|
||||
// 5. Easy to create images which are subsets of other images
|
||||
// 6. Fast pixel access which can take advantage of number of channels
|
||||
// if known at compile time.
|
||||
//
|
||||
// The WImage class is the image class which provides the data accessors.
|
||||
// The 'W' comes from the fact that it is also a wrapper around the popular
|
||||
// but inconvenient IplImage class. A WImage can be constructed either using a
|
||||
// WImageBuffer class which allocates and frees the data,
|
||||
// or using a WImageView class which constructs a subimage or a view into
|
||||
// external data. The view class does no memory management. Each class
|
||||
// actually has two versions, one when the number of channels is known at
|
||||
// compile time and one when it isn't. Using the one with the number of
|
||||
// channels specified can provide some compile time optimizations by using the
|
||||
// fact that the number of channels is a constant.
|
||||
//
|
||||
// We use the convention (c,r) to refer to column c and row r with (0,0) being
|
||||
// the upper left corner. This is similar to standard Euclidean coordinates
|
||||
// with the first coordinate varying in the horizontal direction and the second
|
||||
// coordinate varying in the vertical direction.
|
||||
// Thus (c,r) is usually in the domain [0, width) X [0, height)
|
||||
//
|
||||
// Example usage:
|
||||
// WImageBuffer3_b im(5,7); // Make a 5X7 3 channel image of type uchar
|
||||
// WImageView3_b sub_im(im, 2,2, 3,3); // 3X3 submatrix
|
||||
// vector<float> vec(10, 3.0f);
|
||||
// WImageView1_f user_im(&vec[0], 2, 5); // 2X5 image w/ supplied data
|
||||
//
|
||||
// im.SetZero(); // same as cvSetZero(im.Ipl())
|
||||
// *im(2, 3) = 15; // Modify the element at column 2, row 3
|
||||
// MySetRand(&sub_im);
|
||||
//
|
||||
// // Copy the second row into the first. This can be done with no memory
|
||||
// // allocation and will use SSE if IPP is available.
|
||||
// int w = im.Width();
|
||||
// im.View(0,0, w,1).CopyFrom(im.View(0,1, w,1));
|
||||
//
|
||||
// // Doesn't care about source of data since using WImage
|
||||
// void MySetRand(WImage_b* im) { // Works with any number of channels
|
||||
// for (int r = 0; r < im->Height(); ++r) {
|
||||
// float* row = im->Row(r);
|
||||
// for (int c = 0; c < im->Width(); ++c) {
|
||||
// for (int ch = 0; ch < im->Channels(); ++ch, ++row) {
|
||||
// *row = uchar(rand() & 255);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Functions that are not part of the basic image allocation, viewing, and
|
||||
// access should come from OpenCV, except some useful functions that are not
|
||||
// part of OpenCV can be found in wimage_util.h
|
||||
#ifndef __OPENCV_CORE_WIMAGE_HPP__
|
||||
#define __OPENCV_CORE_WIMAGE_HPP__
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_CORE_WIMAGE_HPP
|
||||
#define OPENCV_CORE_WIMAGE_HPP
|
||||
|
||||
#include "opencv2/core/core_c.h"
|
||||
|
||||
@@ -106,6 +48,9 @@
|
||||
|
||||
namespace cv {
|
||||
|
||||
//! @addtogroup core
|
||||
//! @{
|
||||
|
||||
template <typename T> class WImage;
|
||||
template <typename T> class WImageBuffer;
|
||||
template <typename T> class WImageView;
|
||||
@@ -165,12 +110,63 @@ typedef WImageC<ushort, 3> WImage3_16u;
|
||||
typedef WImageViewC<ushort, 3> WImageView3_16u;
|
||||
typedef WImageBufferC<ushort, 3> WImageBuffer3_16u;
|
||||
|
||||
//
|
||||
// WImage definitions
|
||||
//
|
||||
// This WImage class gives access to the data it refers to. It can be
|
||||
// constructed either by allocating the data with a WImageBuffer class or
|
||||
// using the WImageView class to refer to a subimage or outside data.
|
||||
/** @brief Image class which provides a thin layer around an IplImage.
|
||||
|
||||
The goals of the class design are:
|
||||
|
||||
-# All the data has explicit ownership to avoid memory leaks
|
||||
-# No hidden allocations or copies for performance.
|
||||
-# Easy access to OpenCV methods (which will access IPP if available)
|
||||
-# Can easily treat external data as an image
|
||||
-# Easy to create images which are subsets of other images
|
||||
-# Fast pixel access which can take advantage of number of channels if known at compile time.
|
||||
|
||||
The WImage class is the image class which provides the data accessors. The 'W' comes from the fact
|
||||
that it is also a wrapper around the popular but inconvenient IplImage class. A WImage can be
|
||||
constructed either using a WImageBuffer class which allocates and frees the data, or using a
|
||||
WImageView class which constructs a subimage or a view into external data. The view class does no
|
||||
memory management. Each class actually has two versions, one when the number of channels is known
|
||||
at compile time and one when it isn't. Using the one with the number of channels specified can
|
||||
provide some compile time optimizations by using the fact that the number of channels is a
|
||||
constant.
|
||||
|
||||
We use the convention (c,r) to refer to column c and row r with (0,0) being the upper left corner.
|
||||
This is similar to standard Euclidean coordinates with the first coordinate varying in the
|
||||
horizontal direction and the second coordinate varying in the vertical direction. Thus (c,r) is
|
||||
usually in the domain [0, width) X [0, height)
|
||||
|
||||
Example usage:
|
||||
@code
|
||||
WImageBuffer3_b im(5,7); // Make a 5X7 3 channel image of type uchar
|
||||
WImageView3_b sub_im(im, 2,2, 3,3); // 3X3 submatrix
|
||||
vector<float> vec(10, 3.0f);
|
||||
WImageView1_f user_im(&vec[0], 2, 5); // 2X5 image w/ supplied data
|
||||
|
||||
im.SetZero(); // same as cvSetZero(im.Ipl())
|
||||
*im(2, 3) = 15; // Modify the element at column 2, row 3
|
||||
MySetRand(&sub_im);
|
||||
|
||||
// Copy the second row into the first. This can be done with no memory
|
||||
// allocation and will use SSE if IPP is available.
|
||||
int w = im.Width();
|
||||
im.View(0,0, w,1).CopyFrom(im.View(0,1, w,1));
|
||||
|
||||
// Doesn't care about source of data since using WImage
|
||||
void MySetRand(WImage_b* im) { // Works with any number of channels
|
||||
for (int r = 0; r < im->Height(); ++r) {
|
||||
float* row = im->Row(r);
|
||||
for (int c = 0; c < im->Width(); ++c) {
|
||||
for (int ch = 0; ch < im->Channels(); ++ch, ++row) {
|
||||
*row = uchar(rand() & 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@endcode
|
||||
|
||||
Functions that are not part of the basic image allocation, viewing, and access should come from
|
||||
OpenCV, except some useful functions that are not part of OpenCV can be found in wimage_util.h
|
||||
*/
|
||||
template<typename T>
|
||||
class WImage
|
||||
{
|
||||
@@ -252,10 +248,10 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Image class when both the pixel type and number of channels
|
||||
// are known at compile time. This wrapper will speed up some of the operations
|
||||
// like accessing individual pixels using the () operator.
|
||||
/** Image class when both the pixel type and number of channels
|
||||
are known at compile time. This wrapper will speed up some of the operations
|
||||
like accessing individual pixels using the () operator.
|
||||
*/
|
||||
template<typename T, int C>
|
||||
class WImageC : public WImage<T>
|
||||
{
|
||||
@@ -292,12 +288,9 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// WImageBuffer definitions
|
||||
//
|
||||
// Image class which owns the data, so it can be allocated and is always
|
||||
// freed. It cannot be copied but can be explicity cloned.
|
||||
//
|
||||
/** Image class which owns the data, so it can be allocated and is always
|
||||
freed. It cannot be copied but can be explicity cloned.
|
||||
*/
|
||||
template<typename T>
|
||||
class WImageBuffer : public WImage<T>
|
||||
{
|
||||
@@ -352,8 +345,8 @@ private:
|
||||
void operator=(const WImageBuffer&);
|
||||
};
|
||||
|
||||
// Like a WImageBuffer class but when the number of channels is known
|
||||
// at compile time.
|
||||
/** Like a WImageBuffer class but when the number of channels is known at compile time.
|
||||
*/
|
||||
template<typename T, int C>
|
||||
class WImageBufferC : public WImageC<T, C>
|
||||
{
|
||||
@@ -409,14 +402,10 @@ private:
|
||||
void operator=(const WImageBufferC&);
|
||||
};
|
||||
|
||||
//
|
||||
// WImageView definitions
|
||||
//
|
||||
// View into an image class which allows treating a subimage as an image
|
||||
// or treating external data as an image
|
||||
//
|
||||
template<typename T>
|
||||
class WImageView : public WImage<T>
|
||||
/** View into an image class which allows treating a subimage as an image or treating external data
|
||||
as an image
|
||||
*/
|
||||
template<typename T> class WImageView : public WImage<T>
|
||||
{
|
||||
public:
|
||||
typedef typename WImage<T>::BaseType BaseType;
|
||||
@@ -518,15 +507,9 @@ inline int WImage<float>::Depth() const {return IPL_DEPTH_32F; }
|
||||
template<>
|
||||
inline int WImage<double>::Depth() const {return IPL_DEPTH_64F; }
|
||||
|
||||
//
|
||||
// Pure virtual destructors still need to be defined.
|
||||
//
|
||||
template<typename T> inline WImage<T>::~WImage() {}
|
||||
template<typename T, int C> inline WImageC<T, C>::~WImageC() {}
|
||||
|
||||
//
|
||||
// Allocate ImageData
|
||||
//
|
||||
template<typename T>
|
||||
inline void WImageBuffer<T>::Allocate(int width, int height, int nchannels)
|
||||
{
|
||||
@@ -547,9 +530,6 @@ inline void WImageBufferC<T, C>::Allocate(int width, int height)
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ImageView methods
|
||||
//
|
||||
template<typename T>
|
||||
WImageView<T>::WImageView(WImage<T>* img, int c, int r, int width, int height)
|
||||
: WImage<T>(0)
|
||||
@@ -614,6 +594,8 @@ WImageViewC<T, C> WImageC<T, C>::View(int c, int r, int width, int height) {
|
||||
return WImageViewC<T, C>(this, c, r, width, height);
|
||||
}
|
||||
|
||||
//! @} core
|
||||
|
||||
} // end of namespace
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
/* OpenCV compiled as static or dynamic libs */
|
||||
#define BUILD_SHARED_LIBS
|
||||
|
||||
/* Compile for 'real' NVIDIA GPU architectures */
|
||||
#define CUDA_ARCH_BIN ""
|
||||
|
||||
/* Create PTX or BIN for 1.0 compute capability */
|
||||
/* #undef CUDA_ARCH_BIN_OR_PTX_10 */
|
||||
|
||||
/* NVIDIA GPU features are used */
|
||||
#define CUDA_ARCH_FEATURES ""
|
||||
|
||||
/* Compile for 'virtual' NVIDIA PTX architectures */
|
||||
#define CUDA_ARCH_PTX ""
|
||||
|
||||
/* AVFoundation video libraries */
|
||||
/* #undef HAVE_AVFOUNDATION */
|
||||
|
||||
/* V4L capturing support */
|
||||
/* #undef HAVE_CAMV4L */
|
||||
|
||||
/* V4L2 capturing support */
|
||||
/* #undef HAVE_CAMV4L2 */
|
||||
|
||||
/* Carbon windowing environment */
|
||||
/* #undef HAVE_CARBON */
|
||||
|
||||
/* AMD's Basic Linear Algebra Subprograms Library*/
|
||||
/* #undef HAVE_CLAMDBLAS */
|
||||
|
||||
/* AMD's OpenCL Fast Fourier Transform Library*/
|
||||
/* #undef HAVE_CLAMDFFT */
|
||||
|
||||
/* Clp support */
|
||||
/* #undef HAVE_CLP */
|
||||
|
||||
/* Cocoa API */
|
||||
/* #undef HAVE_COCOA */
|
||||
|
||||
/* C= */
|
||||
/* #undef HAVE_CSTRIPES */
|
||||
|
||||
/* NVidia Cuda Basic Linear Algebra Subprograms (BLAS) API*/
|
||||
/* #undef HAVE_CUBLAS */
|
||||
|
||||
/* NVidia Cuda Runtime API*/
|
||||
/* #undef HAVE_CUDA */
|
||||
|
||||
/* NVidia Cuda Fast Fourier Transform (FFT) API*/
|
||||
/* #undef HAVE_CUFFT */
|
||||
|
||||
/* IEEE1394 capturing support */
|
||||
/* #undef HAVE_DC1394 */
|
||||
|
||||
/* IEEE1394 capturing support - libdc1394 v2.x */
|
||||
/* #undef HAVE_DC1394_2 */
|
||||
|
||||
/* DirectX */
|
||||
#define HAVE_DIRECTX
|
||||
#define HAVE_DIRECTX_NV12
|
||||
#define HAVE_D3D11
|
||||
#define HAVE_D3D10
|
||||
#define HAVE_D3D9
|
||||
|
||||
/* DirectShow Video Capture library */
|
||||
#define HAVE_DSHOW
|
||||
|
||||
/* Eigen Matrix & Linear Algebra Library */
|
||||
/* #undef HAVE_EIGEN */
|
||||
|
||||
/* FFMpeg video library */
|
||||
#define HAVE_FFMPEG
|
||||
|
||||
/* Geospatial Data Abstraction Library */
|
||||
/* #undef HAVE_GDAL */
|
||||
|
||||
/* GStreamer multimedia framework */
|
||||
/* #undef HAVE_GSTREAMER */
|
||||
|
||||
/* GTK+ 2.0 Thread support */
|
||||
/* #undef HAVE_GTHREAD */
|
||||
|
||||
/* GTK+ 2.x toolkit */
|
||||
/* #undef HAVE_GTK */
|
||||
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
/* #undef HAVE_INTTYPES_H */
|
||||
|
||||
/* Intel Perceptual Computing SDK library */
|
||||
/* #undef HAVE_INTELPERC */
|
||||
|
||||
/* Intel Integrated Performance Primitives */
|
||||
#define HAVE_IPP
|
||||
#define HAVE_IPP_ICV_ONLY
|
||||
|
||||
/* Intel IPP Async */
|
||||
/* #undef HAVE_IPP_A */
|
||||
|
||||
/* JPEG-2000 codec */
|
||||
#define HAVE_JASPER
|
||||
|
||||
/* IJG JPEG codec */
|
||||
#define HAVE_JPEG
|
||||
|
||||
/* libpng/png.h needs to be included */
|
||||
/* #undef HAVE_LIBPNG_PNG_H */
|
||||
|
||||
/* GDCM DICOM codec */
|
||||
/* #undef HAVE_GDCM */
|
||||
|
||||
/* V4L/V4L2 capturing support via libv4l */
|
||||
/* #undef HAVE_LIBV4L */
|
||||
|
||||
/* Microsoft Media Foundation Capture library */
|
||||
/* #undef HAVE_MSMF */
|
||||
|
||||
/* NVidia Video Decoding API*/
|
||||
/* #undef HAVE_NVCUVID */
|
||||
|
||||
/* NVidia Video Encoding API*/
|
||||
/* #undef HAVE_NVCUVENC */
|
||||
|
||||
/* OpenCL Support */
|
||||
#define HAVE_OPENCL
|
||||
/* #undef HAVE_OPENCL_STATIC */
|
||||
/* #undef HAVE_OPENCL_SVM */
|
||||
|
||||
/* OpenEXR codec */
|
||||
#define HAVE_OPENEXR
|
||||
|
||||
/* OpenGL support*/
|
||||
/* #undef HAVE_OPENGL */
|
||||
|
||||
/* OpenNI library */
|
||||
/* #undef HAVE_OPENNI */
|
||||
|
||||
/* OpenNI library */
|
||||
/* #undef HAVE_OPENNI2 */
|
||||
|
||||
/* PNG codec */
|
||||
#define HAVE_PNG
|
||||
|
||||
/* Posix threads (pthreads) */
|
||||
/* #undef HAVE_PTHREADS */
|
||||
|
||||
/* parallel_for with pthreads */
|
||||
/* #undef HAVE_PTHREADS_PF */
|
||||
|
||||
/* Qt support */
|
||||
/* #undef HAVE_QT */
|
||||
|
||||
/* Qt OpenGL support */
|
||||
/* #undef HAVE_QT_OPENGL */
|
||||
|
||||
/* QuickTime video libraries */
|
||||
/* #undef HAVE_QUICKTIME */
|
||||
|
||||
/* QTKit video libraries */
|
||||
/* #undef HAVE_QTKIT */
|
||||
|
||||
/* Intel Threading Building Blocks */
|
||||
/* #undef HAVE_TBB */
|
||||
|
||||
/* TIFF codec */
|
||||
#define HAVE_TIFF
|
||||
|
||||
/* Unicap video capture library */
|
||||
/* #undef HAVE_UNICAP */
|
||||
|
||||
/* Video for Windows support */
|
||||
#define HAVE_VFW
|
||||
|
||||
/* V4L2 capturing support in videoio.h */
|
||||
/* #undef HAVE_VIDEOIO */
|
||||
|
||||
/* Win32 UI */
|
||||
#define HAVE_WIN32UI
|
||||
|
||||
/* XIMEA camera support */
|
||||
/* #undef HAVE_XIMEA */
|
||||
|
||||
/* Xine video library */
|
||||
/* #undef HAVE_XINE */
|
||||
|
||||
/* Define if your processor stores words with the most significant byte
|
||||
first (like Motorola and SPARC, unlike Intel and VAX). */
|
||||
/* #undef WORDS_BIGENDIAN */
|
||||
|
||||
/* gPhoto2 library */
|
||||
/* #undef HAVE_GPHOTO2 */
|
||||
|
||||
/* VA library (libva) */
|
||||
/* #undef HAVE_VA */
|
||||
|
||||
/* Intel VA-API/OpenCL */
|
||||
/* #undef HAVE_VA_INTEL */
|
||||
|
||||
/* Lapack */
|
||||
/* #undef HAVE_LAPACK */
|
||||
|
||||
/* FP16 */
|
||||
#define HAVE_FP16
|
||||
|
||||
/* Library was compiled with functions instrumentation */
|
||||
/* #undef ENABLE_INSTRUMENTATION */
|
||||
|
||||
/* OpenVX */
|
||||
/* #undef HAVE_OPENVX */
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,531 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_FLANN_HPP
|
||||
#define OPENCV_FLANN_HPP
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/flann/miniflann.hpp"
|
||||
#include "opencv2/flann/flann_base.hpp"
|
||||
|
||||
/**
|
||||
@defgroup flann Clustering and Search in Multi-Dimensional Spaces
|
||||
|
||||
This section documents OpenCV's interface to the FLANN library. FLANN (Fast Library for Approximate
|
||||
Nearest Neighbors) is a library that contains a collection of algorithms optimized for fast nearest
|
||||
neighbor search in large datasets and for high dimensional features. More information about FLANN
|
||||
can be found in @cite Muja2009 .
|
||||
*/
|
||||
|
||||
namespace cvflann
|
||||
{
|
||||
CV_EXPORTS flann_distance_t flann_distance_type();
|
||||
FLANN_DEPRECATED CV_EXPORTS void set_distance_type(flann_distance_t distance_type, int order);
|
||||
}
|
||||
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace flann
|
||||
{
|
||||
|
||||
|
||||
//! @addtogroup flann
|
||||
//! @{
|
||||
|
||||
template <typename T> struct CvType {};
|
||||
template <> struct CvType<unsigned char> { static int type() { return CV_8U; } };
|
||||
template <> struct CvType<char> { static int type() { return CV_8S; } };
|
||||
template <> struct CvType<unsigned short> { static int type() { return CV_16U; } };
|
||||
template <> struct CvType<short> { static int type() { return CV_16S; } };
|
||||
template <> struct CvType<int> { static int type() { return CV_32S; } };
|
||||
template <> struct CvType<float> { static int type() { return CV_32F; } };
|
||||
template <> struct CvType<double> { static int type() { return CV_64F; } };
|
||||
|
||||
|
||||
// bring the flann parameters into this namespace
|
||||
using ::cvflann::get_param;
|
||||
using ::cvflann::print_params;
|
||||
|
||||
// bring the flann distances into this namespace
|
||||
using ::cvflann::L2_Simple;
|
||||
using ::cvflann::L2;
|
||||
using ::cvflann::L1;
|
||||
using ::cvflann::MinkowskiDistance;
|
||||
using ::cvflann::MaxDistance;
|
||||
using ::cvflann::HammingLUT;
|
||||
using ::cvflann::Hamming;
|
||||
using ::cvflann::Hamming2;
|
||||
using ::cvflann::HistIntersectionDistance;
|
||||
using ::cvflann::HellingerDistance;
|
||||
using ::cvflann::ChiSquareDistance;
|
||||
using ::cvflann::KL_Divergence;
|
||||
|
||||
|
||||
/** @brief The FLANN nearest neighbor index class. This class is templated with the type of elements for which
|
||||
the index is built.
|
||||
*/
|
||||
template <typename Distance>
|
||||
class GenericIndex
|
||||
{
|
||||
public:
|
||||
typedef typename Distance::ElementType ElementType;
|
||||
typedef typename Distance::ResultType DistanceType;
|
||||
|
||||
/** @brief Constructs a nearest neighbor search index for a given dataset.
|
||||
|
||||
@param features Matrix of containing the features(points) to index. The size of the matrix is
|
||||
num_features x feature_dimensionality and the data type of the elements in the matrix must
|
||||
coincide with the type of the index.
|
||||
@param params Structure containing the index parameters. The type of index that will be
|
||||
constructed depends on the type of this parameter. See the description.
|
||||
@param distance
|
||||
|
||||
The method constructs a fast search structure from a set of features using the specified algorithm
|
||||
with specified parameters, as defined by params. params is a reference to one of the following class
|
||||
IndexParams descendants:
|
||||
|
||||
- **LinearIndexParams** When passing an object of this type, the index will perform a linear,
|
||||
brute-force search. :
|
||||
@code
|
||||
struct LinearIndexParams : public IndexParams
|
||||
{
|
||||
};
|
||||
@endcode
|
||||
- **KDTreeIndexParams** When passing an object of this type the index constructed will consist of
|
||||
a set of randomized kd-trees which will be searched in parallel. :
|
||||
@code
|
||||
struct KDTreeIndexParams : public IndexParams
|
||||
{
|
||||
KDTreeIndexParams( int trees = 4 );
|
||||
};
|
||||
@endcode
|
||||
- **KMeansIndexParams** When passing an object of this type the index constructed will be a
|
||||
hierarchical k-means tree. :
|
||||
@code
|
||||
struct KMeansIndexParams : public IndexParams
|
||||
{
|
||||
KMeansIndexParams(
|
||||
int branching = 32,
|
||||
int iterations = 11,
|
||||
flann_centers_init_t centers_init = CENTERS_RANDOM,
|
||||
float cb_index = 0.2 );
|
||||
};
|
||||
@endcode
|
||||
- **CompositeIndexParams** When using a parameters object of this type the index created
|
||||
combines the randomized kd-trees and the hierarchical k-means tree. :
|
||||
@code
|
||||
struct CompositeIndexParams : public IndexParams
|
||||
{
|
||||
CompositeIndexParams(
|
||||
int trees = 4,
|
||||
int branching = 32,
|
||||
int iterations = 11,
|
||||
flann_centers_init_t centers_init = CENTERS_RANDOM,
|
||||
float cb_index = 0.2 );
|
||||
};
|
||||
@endcode
|
||||
- **LshIndexParams** When using a parameters object of this type the index created uses
|
||||
multi-probe LSH (by Multi-Probe LSH: Efficient Indexing for High-Dimensional Similarity Search
|
||||
by Qin Lv, William Josephson, Zhe Wang, Moses Charikar, Kai Li., Proceedings of the 33rd
|
||||
International Conference on Very Large Data Bases (VLDB). Vienna, Austria. September 2007) :
|
||||
@code
|
||||
struct LshIndexParams : public IndexParams
|
||||
{
|
||||
LshIndexParams(
|
||||
unsigned int table_number,
|
||||
unsigned int key_size,
|
||||
unsigned int multi_probe_level );
|
||||
};
|
||||
@endcode
|
||||
- **AutotunedIndexParams** When passing an object of this type the index created is
|
||||
automatically tuned to offer the best performance, by choosing the optimal index type
|
||||
(randomized kd-trees, hierarchical kmeans, linear) and parameters for the dataset provided. :
|
||||
@code
|
||||
struct AutotunedIndexParams : public IndexParams
|
||||
{
|
||||
AutotunedIndexParams(
|
||||
float target_precision = 0.9,
|
||||
float build_weight = 0.01,
|
||||
float memory_weight = 0,
|
||||
float sample_fraction = 0.1 );
|
||||
};
|
||||
@endcode
|
||||
- **SavedIndexParams** This object type is used for loading a previously saved index from the
|
||||
disk. :
|
||||
@code
|
||||
struct SavedIndexParams : public IndexParams
|
||||
{
|
||||
SavedIndexParams( String filename );
|
||||
};
|
||||
@endcode
|
||||
*/
|
||||
GenericIndex(const Mat& features, const ::cvflann::IndexParams& params, Distance distance = Distance());
|
||||
|
||||
~GenericIndex();
|
||||
|
||||
/** @brief Performs a K-nearest neighbor search for a given query point using the index.
|
||||
|
||||
@param query The query point
|
||||
@param indices Vector that will contain the indices of the K-nearest neighbors found. It must have
|
||||
at least knn size.
|
||||
@param dists Vector that will contain the distances to the K-nearest neighbors found. It must have
|
||||
at least knn size.
|
||||
@param knn Number of nearest neighbors to search for.
|
||||
@param params SearchParams
|
||||
*/
|
||||
void knnSearch(const std::vector<ElementType>& query, std::vector<int>& indices,
|
||||
std::vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& params);
|
||||
void knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& params);
|
||||
|
||||
int radiusSearch(const std::vector<ElementType>& query, std::vector<int>& indices,
|
||||
std::vector<DistanceType>& dists, DistanceType radius, const ::cvflann::SearchParams& params);
|
||||
int radiusSearch(const Mat& query, Mat& indices, Mat& dists,
|
||||
DistanceType radius, const ::cvflann::SearchParams& params);
|
||||
|
||||
void save(String filename) { nnIndex->save(filename); }
|
||||
|
||||
int veclen() const { return nnIndex->veclen(); }
|
||||
|
||||
int size() const { return nnIndex->size(); }
|
||||
|
||||
::cvflann::IndexParams getParameters() { return nnIndex->getParameters(); }
|
||||
|
||||
FLANN_DEPRECATED const ::cvflann::IndexParams* getIndexParameters() { return nnIndex->getIndexParameters(); }
|
||||
|
||||
private:
|
||||
::cvflann::Index<Distance>* nnIndex;
|
||||
};
|
||||
|
||||
//! @cond IGNORED
|
||||
|
||||
#define FLANN_DISTANCE_CHECK \
|
||||
if ( ::cvflann::flann_distance_type() != cvflann::FLANN_DIST_L2) { \
|
||||
printf("[WARNING] You are using cv::flann::Index (or cv::flann::GenericIndex) and have also changed "\
|
||||
"the distance using cvflann::set_distance_type. This is no longer working as expected "\
|
||||
"(cv::flann::Index always uses L2). You should create the index templated on the distance, "\
|
||||
"for example for L1 distance use: GenericIndex< L1<float> > \n"); \
|
||||
}
|
||||
|
||||
|
||||
template <typename Distance>
|
||||
GenericIndex<Distance>::GenericIndex(const Mat& dataset, const ::cvflann::IndexParams& params, Distance distance)
|
||||
{
|
||||
CV_Assert(dataset.type() == CvType<ElementType>::type());
|
||||
CV_Assert(dataset.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_dataset((ElementType*)dataset.ptr<ElementType>(0), dataset.rows, dataset.cols);
|
||||
|
||||
nnIndex = new ::cvflann::Index<Distance>(m_dataset, params, distance);
|
||||
|
||||
FLANN_DISTANCE_CHECK
|
||||
|
||||
nnIndex->buildIndex();
|
||||
}
|
||||
|
||||
template <typename Distance>
|
||||
GenericIndex<Distance>::~GenericIndex()
|
||||
{
|
||||
delete nnIndex;
|
||||
}
|
||||
|
||||
template <typename Distance>
|
||||
void GenericIndex<Distance>::knnSearch(const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& searchParams)
|
||||
{
|
||||
::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size());
|
||||
::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size());
|
||||
::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size());
|
||||
|
||||
FLANN_DISTANCE_CHECK
|
||||
|
||||
nnIndex->knnSearch(m_query,m_indices,m_dists,knn,searchParams);
|
||||
}
|
||||
|
||||
|
||||
template <typename Distance>
|
||||
void GenericIndex<Distance>::knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& searchParams)
|
||||
{
|
||||
CV_Assert(queries.type() == CvType<ElementType>::type());
|
||||
CV_Assert(queries.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_queries((ElementType*)queries.ptr<ElementType>(0), queries.rows, queries.cols);
|
||||
|
||||
CV_Assert(indices.type() == CV_32S);
|
||||
CV_Assert(indices.isContinuous());
|
||||
::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols);
|
||||
|
||||
CV_Assert(dists.type() == CvType<DistanceType>::type());
|
||||
CV_Assert(dists.isContinuous());
|
||||
::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols);
|
||||
|
||||
FLANN_DISTANCE_CHECK
|
||||
|
||||
nnIndex->knnSearch(m_queries,m_indices,m_dists,knn, searchParams);
|
||||
}
|
||||
|
||||
template <typename Distance>
|
||||
int GenericIndex<Distance>::radiusSearch(const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams)
|
||||
{
|
||||
::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size());
|
||||
::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size());
|
||||
::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size());
|
||||
|
||||
FLANN_DISTANCE_CHECK
|
||||
|
||||
return nnIndex->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
|
||||
}
|
||||
|
||||
template <typename Distance>
|
||||
int GenericIndex<Distance>::radiusSearch(const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams)
|
||||
{
|
||||
CV_Assert(query.type() == CvType<ElementType>::type());
|
||||
CV_Assert(query.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_query((ElementType*)query.ptr<ElementType>(0), query.rows, query.cols);
|
||||
|
||||
CV_Assert(indices.type() == CV_32S);
|
||||
CV_Assert(indices.isContinuous());
|
||||
::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols);
|
||||
|
||||
CV_Assert(dists.type() == CvType<DistanceType>::type());
|
||||
CV_Assert(dists.isContinuous());
|
||||
::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols);
|
||||
|
||||
FLANN_DISTANCE_CHECK
|
||||
|
||||
return nnIndex->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
|
||||
}
|
||||
|
||||
//! @endcond
|
||||
|
||||
/**
|
||||
* @deprecated Use GenericIndex class instead
|
||||
*/
|
||||
template <typename T>
|
||||
class Index_
|
||||
{
|
||||
public:
|
||||
typedef typename L2<T>::ElementType ElementType;
|
||||
typedef typename L2<T>::ResultType DistanceType;
|
||||
|
||||
FLANN_DEPRECATED Index_(const Mat& dataset, const ::cvflann::IndexParams& params)
|
||||
{
|
||||
printf("[WARNING] The cv::flann::Index_<T> class is deperecated, use cv::flann::GenericIndex<Distance> instead\n");
|
||||
|
||||
CV_Assert(dataset.type() == CvType<ElementType>::type());
|
||||
CV_Assert(dataset.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_dataset((ElementType*)dataset.ptr<ElementType>(0), dataset.rows, dataset.cols);
|
||||
|
||||
if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L2 ) {
|
||||
nnIndex_L1 = NULL;
|
||||
nnIndex_L2 = new ::cvflann::Index< L2<ElementType> >(m_dataset, params);
|
||||
}
|
||||
else if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L1 ) {
|
||||
nnIndex_L1 = new ::cvflann::Index< L1<ElementType> >(m_dataset, params);
|
||||
nnIndex_L2 = NULL;
|
||||
}
|
||||
else {
|
||||
printf("[ERROR] cv::flann::Index_<T> only provides backwards compatibility for the L1 and L2 distances. "
|
||||
"For other distance types you must use cv::flann::GenericIndex<Distance>\n");
|
||||
CV_Assert(0);
|
||||
}
|
||||
if (nnIndex_L1) nnIndex_L1->buildIndex();
|
||||
if (nnIndex_L2) nnIndex_L2->buildIndex();
|
||||
}
|
||||
FLANN_DEPRECATED ~Index_()
|
||||
{
|
||||
if (nnIndex_L1) delete nnIndex_L1;
|
||||
if (nnIndex_L2) delete nnIndex_L2;
|
||||
}
|
||||
|
||||
FLANN_DEPRECATED void knnSearch(const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, int knn, const ::cvflann::SearchParams& searchParams)
|
||||
{
|
||||
::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size());
|
||||
::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size());
|
||||
::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size());
|
||||
|
||||
if (nnIndex_L1) nnIndex_L1->knnSearch(m_query,m_indices,m_dists,knn,searchParams);
|
||||
if (nnIndex_L2) nnIndex_L2->knnSearch(m_query,m_indices,m_dists,knn,searchParams);
|
||||
}
|
||||
FLANN_DEPRECATED void knnSearch(const Mat& queries, Mat& indices, Mat& dists, int knn, const ::cvflann::SearchParams& searchParams)
|
||||
{
|
||||
CV_Assert(queries.type() == CvType<ElementType>::type());
|
||||
CV_Assert(queries.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_queries((ElementType*)queries.ptr<ElementType>(0), queries.rows, queries.cols);
|
||||
|
||||
CV_Assert(indices.type() == CV_32S);
|
||||
CV_Assert(indices.isContinuous());
|
||||
::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols);
|
||||
|
||||
CV_Assert(dists.type() == CvType<DistanceType>::type());
|
||||
CV_Assert(dists.isContinuous());
|
||||
::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols);
|
||||
|
||||
if (nnIndex_L1) nnIndex_L1->knnSearch(m_queries,m_indices,m_dists,knn, searchParams);
|
||||
if (nnIndex_L2) nnIndex_L2->knnSearch(m_queries,m_indices,m_dists,knn, searchParams);
|
||||
}
|
||||
|
||||
FLANN_DEPRECATED int radiusSearch(const std::vector<ElementType>& query, std::vector<int>& indices, std::vector<DistanceType>& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams)
|
||||
{
|
||||
::cvflann::Matrix<ElementType> m_query((ElementType*)&query[0], 1, query.size());
|
||||
::cvflann::Matrix<int> m_indices(&indices[0], 1, indices.size());
|
||||
::cvflann::Matrix<DistanceType> m_dists(&dists[0], 1, dists.size());
|
||||
|
||||
if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
|
||||
if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
|
||||
}
|
||||
|
||||
FLANN_DEPRECATED int radiusSearch(const Mat& query, Mat& indices, Mat& dists, DistanceType radius, const ::cvflann::SearchParams& searchParams)
|
||||
{
|
||||
CV_Assert(query.type() == CvType<ElementType>::type());
|
||||
CV_Assert(query.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_query((ElementType*)query.ptr<ElementType>(0), query.rows, query.cols);
|
||||
|
||||
CV_Assert(indices.type() == CV_32S);
|
||||
CV_Assert(indices.isContinuous());
|
||||
::cvflann::Matrix<int> m_indices((int*)indices.ptr<int>(0), indices.rows, indices.cols);
|
||||
|
||||
CV_Assert(dists.type() == CvType<DistanceType>::type());
|
||||
CV_Assert(dists.isContinuous());
|
||||
::cvflann::Matrix<DistanceType> m_dists((DistanceType*)dists.ptr<DistanceType>(0), dists.rows, dists.cols);
|
||||
|
||||
if (nnIndex_L1) return nnIndex_L1->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
|
||||
if (nnIndex_L2) return nnIndex_L2->radiusSearch(m_query,m_indices,m_dists,radius,searchParams);
|
||||
}
|
||||
|
||||
FLANN_DEPRECATED void save(String filename)
|
||||
{
|
||||
if (nnIndex_L1) nnIndex_L1->save(filename);
|
||||
if (nnIndex_L2) nnIndex_L2->save(filename);
|
||||
}
|
||||
|
||||
FLANN_DEPRECATED int veclen() const
|
||||
{
|
||||
if (nnIndex_L1) return nnIndex_L1->veclen();
|
||||
if (nnIndex_L2) return nnIndex_L2->veclen();
|
||||
}
|
||||
|
||||
FLANN_DEPRECATED int size() const
|
||||
{
|
||||
if (nnIndex_L1) return nnIndex_L1->size();
|
||||
if (nnIndex_L2) return nnIndex_L2->size();
|
||||
}
|
||||
|
||||
FLANN_DEPRECATED ::cvflann::IndexParams getParameters()
|
||||
{
|
||||
if (nnIndex_L1) return nnIndex_L1->getParameters();
|
||||
if (nnIndex_L2) return nnIndex_L2->getParameters();
|
||||
|
||||
}
|
||||
|
||||
FLANN_DEPRECATED const ::cvflann::IndexParams* getIndexParameters()
|
||||
{
|
||||
if (nnIndex_L1) return nnIndex_L1->getIndexParameters();
|
||||
if (nnIndex_L2) return nnIndex_L2->getIndexParameters();
|
||||
}
|
||||
|
||||
private:
|
||||
// providing backwards compatibility for L2 and L1 distances (most common)
|
||||
::cvflann::Index< L2<ElementType> >* nnIndex_L2;
|
||||
::cvflann::Index< L1<ElementType> >* nnIndex_L1;
|
||||
};
|
||||
|
||||
|
||||
/** @brief Clusters features using hierarchical k-means algorithm.
|
||||
|
||||
@param features The points to be clustered. The matrix must have elements of type
|
||||
Distance::ElementType.
|
||||
@param centers The centers of the clusters obtained. The matrix must have type
|
||||
Distance::ResultType. The number of rows in this matrix represents the number of clusters desired,
|
||||
however, because of the way the cut in the hierarchical tree is chosen, the number of clusters
|
||||
computed will be the highest number of the form (branching-1)\*k+1 that's lower than the number of
|
||||
clusters desired, where branching is the tree's branching factor (see description of the
|
||||
KMeansIndexParams).
|
||||
@param params Parameters used in the construction of the hierarchical k-means tree.
|
||||
@param d Distance to be used for clustering.
|
||||
|
||||
The method clusters the given feature vectors by constructing a hierarchical k-means tree and
|
||||
choosing a cut in the tree that minimizes the cluster's variance. It returns the number of clusters
|
||||
found.
|
||||
*/
|
||||
template <typename Distance>
|
||||
int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::KMeansIndexParams& params,
|
||||
Distance d = Distance())
|
||||
{
|
||||
typedef typename Distance::ElementType ElementType;
|
||||
typedef typename Distance::ResultType DistanceType;
|
||||
|
||||
CV_Assert(features.type() == CvType<ElementType>::type());
|
||||
CV_Assert(features.isContinuous());
|
||||
::cvflann::Matrix<ElementType> m_features((ElementType*)features.ptr<ElementType>(0), features.rows, features.cols);
|
||||
|
||||
CV_Assert(centers.type() == CvType<DistanceType>::type());
|
||||
CV_Assert(centers.isContinuous());
|
||||
::cvflann::Matrix<DistanceType> m_centers((DistanceType*)centers.ptr<DistanceType>(0), centers.rows, centers.cols);
|
||||
|
||||
return ::cvflann::hierarchicalClustering<Distance>(m_features, m_centers, params, d);
|
||||
}
|
||||
|
||||
/** @deprecated
|
||||
*/
|
||||
template <typename ELEM_TYPE, typename DIST_TYPE>
|
||||
FLANN_DEPRECATED int hierarchicalClustering(const Mat& features, Mat& centers, const ::cvflann::KMeansIndexParams& params)
|
||||
{
|
||||
printf("[WARNING] cv::flann::hierarchicalClustering<ELEM_TYPE,DIST_TYPE> is deprecated, use "
|
||||
"cv::flann::hierarchicalClustering<Distance> instead\n");
|
||||
|
||||
if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L2 ) {
|
||||
return hierarchicalClustering< L2<ELEM_TYPE> >(features, centers, params);
|
||||
}
|
||||
else if ( ::cvflann::flann_distance_type() == cvflann::FLANN_DIST_L1 ) {
|
||||
return hierarchicalClustering< L1<ELEM_TYPE> >(features, centers, params);
|
||||
}
|
||||
else {
|
||||
printf("[ERROR] cv::flann::hierarchicalClustering<ELEM_TYPE,DIST_TYPE> only provides backwards "
|
||||
"compatibility for the L1 and L2 distances. "
|
||||
"For other distance types you must use cv::flann::hierarchicalClustering<Distance>\n");
|
||||
CV_Assert(0);
|
||||
}
|
||||
}
|
||||
|
||||
//! @} flann
|
||||
|
||||
} } // namespace cv::flann
|
||||
|
||||
#endif
|
||||
+36
-16
@@ -44,13 +44,11 @@ struct base_any_policy
|
||||
virtual void clone(void* const* src, void** dest) = 0;
|
||||
virtual void move(void* const* src, void** dest) = 0;
|
||||
virtual void* get_value(void** src) = 0;
|
||||
virtual const void* get_value(void* const * src) = 0;
|
||||
virtual ::size_t get_size() = 0;
|
||||
virtual const std::type_info& type() = 0;
|
||||
virtual void print(std::ostream& out, void* const* src) = 0;
|
||||
|
||||
#ifdef OPENCV_CAN_BREAK_BINARY_COMPATIBILITY
|
||||
virtual ~base_any_policy() {}
|
||||
#endif
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@@ -72,6 +70,7 @@ struct small_any_policy : typed_base_any_policy<T>
|
||||
virtual void clone(void* const* src, void** dest) { *dest = *src; }
|
||||
virtual void move(void* const* src, void** dest) { *dest = *src; }
|
||||
virtual void* get_value(void** src) { return reinterpret_cast<void*>(src); }
|
||||
virtual const void* get_value(void* const * src) { return reinterpret_cast<const void*>(src); }
|
||||
virtual void print(std::ostream& out, void* const* src) { out << *reinterpret_cast<T const*>(src); }
|
||||
};
|
||||
|
||||
@@ -80,7 +79,8 @@ struct big_any_policy : typed_base_any_policy<T>
|
||||
{
|
||||
virtual void static_delete(void** x)
|
||||
{
|
||||
if (* x) delete (* reinterpret_cast<T**>(x)); *x = NULL;
|
||||
if (* x) delete (* reinterpret_cast<T**>(x));
|
||||
*x = NULL;
|
||||
}
|
||||
virtual void copy_from_value(void const* src, void** dest)
|
||||
{
|
||||
@@ -96,6 +96,7 @@ struct big_any_policy : typed_base_any_policy<T>
|
||||
**reinterpret_cast<T**>(dest) = **reinterpret_cast<T* const*>(src);
|
||||
}
|
||||
virtual void* get_value(void** src) { return *src; }
|
||||
virtual const void* get_value(void* const * src) { return *src; }
|
||||
virtual void print(std::ostream& out, void* const* src) { out << *reinterpret_cast<T const*>(*src); }
|
||||
};
|
||||
|
||||
@@ -109,6 +110,11 @@ template<> inline void big_any_policy<flann_algorithm_t>::print(std::ostream& ou
|
||||
out << int(*reinterpret_cast<flann_algorithm_t const*>(*src));
|
||||
}
|
||||
|
||||
template<> inline void big_any_policy<cv::String>::print(std::ostream& out, void* const* src)
|
||||
{
|
||||
out << (*reinterpret_cast<cv::String const*>(*src)).c_str();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
struct choose_policy
|
||||
{
|
||||
@@ -150,13 +156,27 @@ SMALL_POLICY(bool);
|
||||
|
||||
#undef SMALL_POLICY
|
||||
|
||||
/// This function will return a different policy for each type.
|
||||
template<typename T>
|
||||
base_any_policy* get_policy()
|
||||
template <typename T>
|
||||
class SinglePolicy
|
||||
{
|
||||
SinglePolicy();
|
||||
SinglePolicy(const SinglePolicy& other);
|
||||
SinglePolicy& operator=(const SinglePolicy& other);
|
||||
|
||||
public:
|
||||
static base_any_policy* get_policy();
|
||||
|
||||
private:
|
||||
static typename choose_policy<T>::type policy;
|
||||
return &policy;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
typename choose_policy<T>::type SinglePolicy<T>::policy;
|
||||
|
||||
/// This function will return a different policy for each type.
|
||||
template <typename T>
|
||||
inline base_any_policy* SinglePolicy<T>::get_policy() { return &policy; }
|
||||
|
||||
} // namespace anyimpl
|
||||
|
||||
struct any
|
||||
@@ -170,26 +190,26 @@ public:
|
||||
/// Initializing constructor.
|
||||
template <typename T>
|
||||
any(const T& x)
|
||||
: policy(anyimpl::get_policy<anyimpl::empty_any>()), object(NULL)
|
||||
: policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL)
|
||||
{
|
||||
assign(x);
|
||||
}
|
||||
|
||||
/// Empty constructor.
|
||||
any()
|
||||
: policy(anyimpl::get_policy<anyimpl::empty_any>()), object(NULL)
|
||||
: policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL)
|
||||
{ }
|
||||
|
||||
/// Special initializing constructor for string literals.
|
||||
any(const char* x)
|
||||
: policy(anyimpl::get_policy<anyimpl::empty_any>()), object(NULL)
|
||||
: policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL)
|
||||
{
|
||||
assign(x);
|
||||
}
|
||||
|
||||
/// Copy constructor.
|
||||
any(const any& x)
|
||||
: policy(anyimpl::get_policy<anyimpl::empty_any>()), object(NULL)
|
||||
: policy(anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy()), object(NULL)
|
||||
{
|
||||
assign(x);
|
||||
}
|
||||
@@ -214,7 +234,7 @@ public:
|
||||
any& assign(const T& x)
|
||||
{
|
||||
reset();
|
||||
policy = anyimpl::get_policy<T>();
|
||||
policy = anyimpl::SinglePolicy<T>::get_policy();
|
||||
policy->copy_from_value(&x, &object);
|
||||
return *this;
|
||||
}
|
||||
@@ -255,7 +275,7 @@ public:
|
||||
const T& cast() const
|
||||
{
|
||||
if (policy->type() != typeid(T)) throw anyimpl::bad_any_cast();
|
||||
T* r = reinterpret_cast<T*>(policy->get_value(const_cast<void **>(&object)));
|
||||
const T* r = reinterpret_cast<const T*>(policy->get_value(&object));
|
||||
return *r;
|
||||
}
|
||||
|
||||
@@ -269,7 +289,7 @@ public:
|
||||
void reset()
|
||||
{
|
||||
policy->static_delete(&object);
|
||||
policy = anyimpl::get_policy<anyimpl::empty_any>();
|
||||
policy = anyimpl::SinglePolicy<anyimpl::empty_any>::get_policy();
|
||||
}
|
||||
|
||||
/// Returns true if the two types are the same.
|
||||
|
||||
@@ -99,18 +99,22 @@ public:
|
||||
*/
|
||||
virtual void buildIndex()
|
||||
{
|
||||
std::ostringstream stream;
|
||||
bestParams_ = estimateBuildParams();
|
||||
print_params(bestParams_, stream);
|
||||
Logger::info("----------------------------------------------------\n");
|
||||
Logger::info("Autotuned parameters:\n");
|
||||
print_params(bestParams_);
|
||||
Logger::info("%s", stream.str().c_str());
|
||||
Logger::info("----------------------------------------------------\n");
|
||||
|
||||
bestIndex_ = create_index_by_type(dataset_, bestParams_, distance_);
|
||||
bestIndex_->buildIndex();
|
||||
speedup_ = estimateSearchParams(bestSearchParams_);
|
||||
stream.str(std::string());
|
||||
print_params(bestSearchParams_, stream);
|
||||
Logger::info("----------------------------------------------------\n");
|
||||
Logger::info("Search parameters:\n");
|
||||
print_params(bestSearchParams_);
|
||||
Logger::info("%s", stream.str().c_str());
|
||||
Logger::info("----------------------------------------------------\n");
|
||||
}
|
||||
|
||||
@@ -270,7 +274,7 @@ private:
|
||||
// struct KMeansSimpleDownhillFunctor {
|
||||
//
|
||||
// Autotune& autotuner;
|
||||
// KMeansSimpleDownhillFunctor(Autotune& autotuner_) : autotuner(autotuner_) {};
|
||||
// KMeansSimpleDownhillFunctor(Autotune& autotuner_) : autotuner(autotuner_) {}
|
||||
//
|
||||
// float operator()(int* params) {
|
||||
//
|
||||
@@ -295,7 +299,7 @@ private:
|
||||
// struct KDTreeSimpleDownhillFunctor {
|
||||
//
|
||||
// Autotune& autotuner;
|
||||
// KDTreeSimpleDownhillFunctor(Autotune& autotuner_) : autotuner(autotuner_) {};
|
||||
// KDTreeSimpleDownhillFunctor(Autotune& autotuner_) : autotuner(autotuner_) {}
|
||||
//
|
||||
// float operator()(int* params) {
|
||||
// float maxFloat = numeric_limits<float>::max();
|
||||
@@ -373,6 +377,7 @@ private:
|
||||
// evaluate kdtree for all parameter combinations
|
||||
for (size_t i = 0; i < FLANN_ARRAY_LEN(testTrees); ++i) {
|
||||
CostData cost;
|
||||
cost.params["algorithm"] = FLANN_INDEX_KDTREE;
|
||||
cost.params["trees"] = testTrees[i];
|
||||
|
||||
evaluate_kdtree(cost);
|
||||
|
||||
@@ -107,6 +107,7 @@ enum flann_centers_init_t
|
||||
FLANN_CENTERS_RANDOM = 0,
|
||||
FLANN_CENTERS_GONZALES = 1,
|
||||
FLANN_CENTERS_KMEANSPP = 2,
|
||||
FLANN_CENTERS_GROUPWISE = 3,
|
||||
|
||||
// deprecated constants, should use the FLANN_CENTERS_* ones instead
|
||||
CENTERS_RANDOM = 0,
|
||||
|
||||
+129
-41
@@ -384,41 +384,6 @@ struct HammingLUT
|
||||
typedef unsigned char ElementType;
|
||||
typedef int ResultType;
|
||||
|
||||
/** this will count the bits in a ^ b
|
||||
*/
|
||||
ResultType operator()(const unsigned char* a, const unsigned char* b, int size) const
|
||||
{
|
||||
static const uchar popCountTable[] =
|
||||
{
|
||||
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
|
||||
};
|
||||
ResultType result = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
result += popCountTable[a[i] ^ b[i]];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor
|
||||
* bit count of A exclusive XOR'ed with B
|
||||
*/
|
||||
struct HammingLUT2
|
||||
{
|
||||
typedef False is_kdtree_distance;
|
||||
typedef False is_vector_space_distance;
|
||||
|
||||
typedef unsigned char ElementType;
|
||||
typedef int ResultType;
|
||||
|
||||
/** this will count the bits in a ^ b
|
||||
*/
|
||||
ResultType operator()(const unsigned char* a, const unsigned char* b, size_t size) const
|
||||
@@ -630,7 +595,7 @@ struct HellingerDistance
|
||||
typedef typename Accumulator<T>::Type ResultType;
|
||||
|
||||
/**
|
||||
* Compute the histogram intersection distance
|
||||
* Compute the Hellinger distance
|
||||
*/
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType /*worst_dist*/ = -1) const
|
||||
@@ -663,7 +628,8 @@ struct HellingerDistance
|
||||
template <typename U, typename V>
|
||||
inline ResultType accum_dist(const U& a, const V& b, int) const
|
||||
{
|
||||
return sqrt(static_cast<ResultType>(a)) - sqrt(static_cast<ResultType>(b));
|
||||
ResultType diff = sqrt(static_cast<ResultType>(a)) - sqrt(static_cast<ResultType>(b));
|
||||
return diff * diff;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -741,7 +707,7 @@ struct KL_Divergence
|
||||
Iterator1 last = a + size;
|
||||
|
||||
while (a < last) {
|
||||
if (* a != 0) {
|
||||
if (* b != 0) {
|
||||
ResultType ratio = (ResultType)(*a / *b);
|
||||
if (ratio>0) {
|
||||
result += *a * log(ratio);
|
||||
@@ -764,9 +730,11 @@ struct KL_Divergence
|
||||
inline ResultType accum_dist(const U& a, const V& b, int) const
|
||||
{
|
||||
ResultType result = ResultType();
|
||||
ResultType ratio = (ResultType)(a / b);
|
||||
if (ratio>0) {
|
||||
result = a * log(ratio);
|
||||
if( *b != 0 ) {
|
||||
ResultType ratio = (ResultType)(a / b);
|
||||
if (ratio>0) {
|
||||
result = a * log(ratio);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -812,6 +780,126 @@ struct ZeroIterator
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Depending on processed distances, some of them are already squared (e.g. L2)
|
||||
* and some are not (e.g.Hamming). In KMeans++ for instance we want to be sure
|
||||
* we are working on ^2 distances, thus following templates to ensure that.
|
||||
*/
|
||||
template <typename Distance, typename ElementType>
|
||||
struct squareDistance
|
||||
{
|
||||
typedef typename Distance::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return dist*dist; }
|
||||
};
|
||||
|
||||
|
||||
template <typename ElementType>
|
||||
struct squareDistance<L2_Simple<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename L2_Simple<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return dist; }
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
struct squareDistance<L2<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename L2<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return dist; }
|
||||
};
|
||||
|
||||
|
||||
template <typename ElementType>
|
||||
struct squareDistance<MinkowskiDistance<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename MinkowskiDistance<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return dist; }
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
struct squareDistance<HellingerDistance<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename HellingerDistance<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return dist; }
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
struct squareDistance<ChiSquareDistance<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename ChiSquareDistance<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return dist; }
|
||||
};
|
||||
|
||||
|
||||
template <typename Distance>
|
||||
typename Distance::ResultType ensureSquareDistance( typename Distance::ResultType dist )
|
||||
{
|
||||
typedef typename Distance::ElementType ElementType;
|
||||
|
||||
squareDistance<Distance, ElementType> dummy;
|
||||
return dummy( dist );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* ...and a template to ensure the user that he will process the normal distance,
|
||||
* and not squared distance, without loosing processing time calling sqrt(ensureSquareDistance)
|
||||
* that will result in doing actually sqrt(dist*dist) for L1 distance for instance.
|
||||
*/
|
||||
template <typename Distance, typename ElementType>
|
||||
struct simpleDistance
|
||||
{
|
||||
typedef typename Distance::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return dist; }
|
||||
};
|
||||
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<L2_Simple<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename L2_Simple<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<L2<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename L2<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<MinkowskiDistance<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename MinkowskiDistance<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<HellingerDistance<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename HellingerDistance<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
template <typename ElementType>
|
||||
struct simpleDistance<ChiSquareDistance<ElementType>, ElementType>
|
||||
{
|
||||
typedef typename ChiSquareDistance<ElementType>::ResultType ResultType;
|
||||
ResultType operator()( ResultType dist ) { return sqrt(dist); }
|
||||
};
|
||||
|
||||
|
||||
template <typename Distance>
|
||||
typename Distance::ResultType ensureSimpleDistance( typename Distance::ResultType dist )
|
||||
{
|
||||
typedef typename Distance::ElementType ElementType;
|
||||
|
||||
simpleDistance<Distance, ElementType> dummy;
|
||||
return dummy( dist );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //OPENCV_FLANN_DIST_H_
|
||||
|
||||
@@ -57,14 +57,14 @@ namespace cvflann {
|
||||
class DynamicBitset
|
||||
{
|
||||
public:
|
||||
/** @param default constructor
|
||||
/** default constructor
|
||||
*/
|
||||
DynamicBitset()
|
||||
{
|
||||
}
|
||||
|
||||
/** @param only constructor we use in our code
|
||||
* @param the size of the bitset (in bits)
|
||||
/** only constructor we use in our code
|
||||
* @param sz the size of the bitset (in bits)
|
||||
*/
|
||||
DynamicBitset(size_t sz)
|
||||
{
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
return bitset_.empty();
|
||||
}
|
||||
|
||||
/** @param set all the bits to 0
|
||||
/** set all the bits to 0
|
||||
*/
|
||||
void reset()
|
||||
{
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
}
|
||||
|
||||
/** @brief set one bit to 0
|
||||
* @param
|
||||
* @param index
|
||||
*/
|
||||
void reset(size_t index)
|
||||
{
|
||||
@@ -106,15 +106,15 @@ public:
|
||||
* This function is useful when resetting a given set of bits so that the
|
||||
* whole bitset ends up being 0: if that's the case, we don't care about setting
|
||||
* other bits to 0
|
||||
* @param
|
||||
* @param index
|
||||
*/
|
||||
void reset_block(size_t index)
|
||||
{
|
||||
bitset_[index / cell_bit_size_] = 0;
|
||||
}
|
||||
|
||||
/** @param resize the bitset so that it contains at least size bits
|
||||
* @param size
|
||||
/** resize the bitset so that it contains at least sz bits
|
||||
* @param sz
|
||||
*/
|
||||
void resize(size_t sz)
|
||||
{
|
||||
@@ -122,7 +122,7 @@ public:
|
||||
bitset_.resize(sz / cell_bit_size_ + 1);
|
||||
}
|
||||
|
||||
/** @param set a bit to true
|
||||
/** set a bit to true
|
||||
* @param index the index of the bit to set to 1
|
||||
*/
|
||||
void set(size_t index)
|
||||
@@ -130,14 +130,14 @@ public:
|
||||
bitset_[index / cell_bit_size_] |= size_t(1) << (index % cell_bit_size_);
|
||||
}
|
||||
|
||||
/** @param gives the number of contained bits
|
||||
/** gives the number of contained bits
|
||||
*/
|
||||
size_t size() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
/** @param check if a bit is set
|
||||
/** check if a bit is set
|
||||
* @param index the index of the bit to check
|
||||
* @return true if the bit is set
|
||||
*/
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user