This commit is contained in:
EnoxSoftware 2017-02-07 20:51:41 +09:00
Коммит 2d29725bbe
75 изменённых файлов: 46669 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 847a608eedc99b549a75b0e7be923e43
folderAsset: yes
timeCreated: 1485712416
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: f8e325dd55ce5d14d8ee840dc280b787
folderAsset: yes
timeCreated: 1485712887
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,130 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: AnonymousRectQuadMaterial
m_Shader: {fileID: 10750, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _BumpMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailAlbedoMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailMask
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailNormalMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _EmissionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MainTex
second:
m_Texture: {fileID: 2800000, guid: d59d2b4cb4feaee44850a4e28bc7741e, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MetallicGlossMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _OcclusionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _ParallaxMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _BumpScale
second: 1
- first:
name: _Cutoff
second: 0.5
- first:
name: _DetailNormalMapScale
second: 1
- first:
name: _DstBlend
second: 0
- first:
name: _EmissionScaleUI
second: 0
- first:
name: _Glossiness
second: 0.5
- first:
name: _LineWidth
second: 0.1
- first:
name: _Metallic
second: 0
- first:
name: _Mode
second: 0
- first:
name: _OcclusionStrength
second: 1
- first:
name: _Parallax
second: 0.02
- first:
name: _SrcBlend
second: 1
- first:
name: _UVSec
second: 0
- first:
name: _ZWrite
second: 1
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: _EmissionColor
second: {r: 0, g: 0, b: 0, a: 1}
- first:
name: _EmissionColorUI
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: _GridColor
second: {r: 1, g: 1, b: 1, a: 0}
- first:
name: _LineColor
second: {r: 1, g: 0, b: 0, a: 1}

Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e2e427520636a714996e857b955c0141
timeCreated: 1485932116
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,76 @@
 Shader "Custom/WireFrame"
{
Properties
{
_LineColor ("Line Color", Color) = (1,1,1,1)
_GridColor ("Grid Color", Color) = (1,1,1,0)
_LineWidth ("Line Width", float) = 0.01
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"PreviewType"="Plane"
}
Lighting Off
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
uniform float4 _LineColor;
uniform float4 _GridColor;
uniform float _LineWidth;
// vertex input: position, uv1, uv2
struct appdata
{
float4 vertex : POSITION;
float4 texcoord1 : TEXCOORD0;
float4 color : COLOR;
};
struct v2f
{
float4 pos : POSITION;
float4 texcoord1 : TEXCOORD0;
float4 color : COLOR;
};
v2f vert (appdata v)
{
v2f o;
o.pos = mul( UNITY_MATRIX_MVP, v.vertex);
o.texcoord1 = v.texcoord1;
o.color = v.color;
return o;
}
fixed4 frag(v2f i) : COLOR
{
fixed4 answer;
float lx = step(_LineWidth, i.texcoord1.x);
float ly = step(_LineWidth, i.texcoord1.y);
float hx = step(i.texcoord1.x, 1 - _LineWidth);
float hy = step(i.texcoord1.y, 1 - _LineWidth);
answer = lerp(_LineColor, _GridColor, lx*ly*hx*hy);
return answer;
}
ENDCG
}
}
Fallback "Vertex Colored", 1
}

Просмотреть файл

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 125ad2e4c9dcbba4da6a4d216f7402ea
timeCreated: 1485932116
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,175 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: WireFrameMaterial
m_Shader: {fileID: 4800000, guid: 125ad2e4c9dcbba4da6a4d216f7402ea, type: 3}
m_ShaderKeywords: _EMISSION _USEMAINTEX_ON
m_LightmapFlags: 1
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _BumpMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailAlbedoMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailMask
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _DetailNormalMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _EmissionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _EmissionTex
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MainTex
second:
m_Texture: {fileID: 2800000, guid: 26105aa181290a04bbfd64779008dee3, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _MetallicGlossMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _OcclusionMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
- first:
name: _ParallaxMap
second:
m_Texture: {fileID: 0}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _BumpScale
second: 1
- first:
name: _ColorWriteMask
second: 15
- first:
name: _Cull
second: 2
- first:
name: _Cutoff
second: 0.5
- first:
name: _DetailNormalMapScale
second: 1
- first:
name: _DstBlend
second: 0
- first:
name: _EmissionScaleUI
second: 0
- first:
name: _GlossMapScale
second: 1
- first:
name: _Glossiness
second: 0.5
- first:
name: _GlossyReflections
second: 1
- first:
name: _LineWidth
second: 0.1
- first:
name: _Metallic
second: 0
- first:
name: _Mode
second: 0
- first:
name: _OcclusionStrength
second: 1
- first:
name: _Parallax
second: 0.02
- first:
name: _SmoothnessTextureChannel
second: 0
- first:
name: _SpecularHighlights
second: 1
- first:
name: _SrcBlend
second: 1
- first:
name: _UVSec
second: 0
- first:
name: _UseColor
second: 0
- first:
name: _UseEmissionTex
second: 0
- first:
name: _UseMainTex
second: 1
- first:
name: _WireThickness
second: 100
- first:
name: _ZTest
second: 4
- first:
name: _ZWrite
second: 1
m_Colors:
- first:
name: _BaseColor
second: {r: 0, g: 0, b: 0, a: 1}
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: _EmissionColor
second: {r: 0, g: 0, b: 0, a: 1}
- first:
name: _EmissionColorUI
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: _GridColor
second: {r: 1, g: 1, b: 1, a: 0}
- first:
name: _LineColor
second: {r: 1, g: 0, b: 0, a: 1}
- first:
name: _WireColor
second: {r: 1, g: 1, b: 1, a: 1}

Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a3eb1be26a6d1394c84942fa95295f98
timeCreated: 1485932116
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,90 @@
Shader "AR/HolographicImageBlend"
{
// referring to the https://forum.unity3d.com/threads/holographic-photo-blending-with-photocapture.416023/.
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_VignetteScale ("Vignette Scale", RANGE(0,2)) = 0
_VignetteOffset ("Vignette Offset" , Vector) = (0,0,0,0)
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertexPositionInProjectionSpace : SV_POSITION;
float2 uv : TEXCOORD0;
float4 vertexInProjectionSpace : TEXCOORD1;
};
sampler2D _MainTex;
float4x4 _WorldToCameraMatrix;
float4x4 _CameraProjectionMatrix;
float _VignetteScale;
float4 _VignetteOffset;
v2f vert (appdata v)
{
v2f o;
o.vertexPositionInProjectionSpace = mul(UNITY_MATRIX_MVP, v.vertex);
// Calculate the vertex position in world space.
float4 vertexPositionInWorldSpace = mul(unity_ObjectToWorld, float4(v.vertex.xyz,1));
// Now take the world space vertex position and transform it so that
// it is relative to the physical web camera on the HoloLens.
float4 vertexPositionInCameraSpace = mul(_WorldToCameraMatrix, float4(vertexPositionInWorldSpace.xyz,1));
// Convert our camera relative vertex into clip space.
o.vertexInProjectionSpace = mul(_CameraProjectionMatrix, float4(vertexPositionInCameraSpace.xyz, 1.0));
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// Transform the vertex into normalized coordinate space. Basically
// we want to map where our vertex should be on the screen into the -1 to 1 range
// for both the x and y axes.
float2 signedUV = i.vertexInProjectionSpace.xy / i.vertexInProjectionSpace.w;
// The HoloLens uses an additive display so the color black will
// be transparent. If the texture is smaller than the canvas, color the extra
// area on the canvas black so it will be transparent on the HoloLens.
if(abs(signedUV.x) > 1.0 || abs(signedUV.y) > 1.0)
{
return fixed4( 0.0, 0.0, 0.0, 0.0);
}
// Currently our signedUV's x and y coordinates will fall between -1 and 1.
// We need to map this range from 0 to 1 so that we can sample our texture.
float2 uv = signedUV * 0.5 + float2(0.5, 0.5);
fixed4 finalColor = tex2D(_MainTex, uv);
// Finally add a circular vignette effect starting from the center
// of the image.
signedUV.x = signedUV.x + _VignetteOffset.x*2;
signedUV.y = signedUV.y + _VignetteOffset.y*2;
finalColor *= 1.0 -(length(signedUV) * _VignetteScale);
return finalColor;
}
ENDCG
}
}
}

Просмотреть файл

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 5ea4faa0446148445b06b0b0a453f5ec
timeCreated: 1484969656
licenseType: Free
ShaderImporter:
defaultTextures: []
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,34 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: holographicImageBlend_material
m_Shader: {fileID: 4800000, guid: 5ea4faa0446148445b06b0b0a453f5ec, type: 3}
m_ShaderKeywords:
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _MainTex
second:
m_Texture: {fileID: 2800000, guid: e266aedc629209a4196966ac4bf20d68, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _VignetteScale
second: 0
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: _VignetteOffset
second: {r: 0, g: 0, b: 0, a: 0}

Просмотреть файл

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 88de79a80cfa4dc42a041ce745ba291f
NativeFormatImporter:
userData:

Просмотреть файл

@ -0,0 +1,34 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 6
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_Name: quad_material
m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 5
m_CustomRenderQueue: -1
stringTagMap: {}
m_SavedProperties:
serializedVersion: 2
m_TexEnvs:
- first:
name: _MainTex
second:
m_Texture: {fileID: 2800000, guid: e266aedc629209a4196966ac4bf20d68, type: 3}
m_Scale: {x: 1, y: 1}
m_Offset: {x: 0, y: 0}
m_Floats:
- first:
name: _VignetteScale
second: 0
m_Colors:
- first:
name: _Color
second: {r: 1, g: 1, b: 1, a: 1}
- first:
name: _VignetteOffset
second: {r: 0, g: 0, b: 0, a: 0}

Просмотреть файл

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 56562dd66b290634b865ecdd615f8440
NativeFormatImporter:
userData:

Просмотреть файл

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: cf4f04fe6d60ff44dba520bcb9afdde3
folderAsset: yes
timeCreated: 1485712948
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 56 KiB

Просмотреть файл

@ -0,0 +1,84 @@
fileFormatVersion: 2
guid: d59d2b4cb4feaee44850a4e28bc7741e
timeCreated: 1486397788
licenseType: Free
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 4
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 1
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- buildTarget: DefaultTexturePlatform
maxTextureSize: 256
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Standalone
maxTextureSize: 256
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
- buildTarget: Windows Store Apps
maxTextureSize: 256
textureFormat: -1
textureCompression: 0
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 62016c9698baf334e89f1c41edda59bb
folderAsset: yes
timeCreated: 1485712960
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: df9904a773cb5804ca6c5e03c1b7555d
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: e1c01ca879ef2ae44b6980a83cc01c75
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,961 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!29 &1
OcclusionCullingSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_OcclusionBakeSettings:
smallestOccluder: 5
smallestHole: 0.25
backfaceThreshold: 100
m_SceneGUID: 00000000000000000000000000000000
m_OcclusionCullingData: {fileID: 0}
--- !u!104 &2
RenderSettings:
m_ObjectHideFlags: 0
serializedVersion: 7
m_Fog: 0
m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1}
m_FogMode: 3
m_FogDensity: 0.01
m_LinearFogStart: 0
m_LinearFogEnd: 300
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 1
m_AmbientMode: 0
m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0}
m_HaloStrength: 0.5
m_FlareStrength: 1
m_FlareFadeSpeed: 3
m_HaloTexture: {fileID: 0}
m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0}
m_DefaultReflectionMode: 0
m_DefaultReflectionResolution: 128
m_ReflectionBounces: 1
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44657826, g: 0.49641263, b: 0.57481676, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0
serializedVersion: 7
m_GIWorkflowMode: 0
m_GISettings:
serializedVersion: 2
m_BounceScale: 1
m_IndirectOutputScale: 1
m_AlbedoBoost: 1
m_TemporalCoherenceThreshold: 1
m_EnvironmentLightingMode: 0
m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 4
m_Resolution: 2
m_BakeResolution: 40
m_TextureWidth: 1024
m_TextureHeight: 1024
m_AO: 0
m_AOMaxDistance: 1
m_CompAOExponent: 1
m_CompAOExponentDirect: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1
m_TextureCompression: 1
m_DirectLightInLightProbes: 1
m_FinalGather: 0
m_FinalGatherFiltering: 1
m_FinalGatherRayCount: 256
m_ReflectionCompression: 2
m_LightingDataAsset: {fileID: 0}
m_RuntimeCPUUsage: 25
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2
m_ObjectHideFlags: 0
m_BuildSettings:
serializedVersion: 2
agentTypeID: 0
agentRadius: 0.5
agentHeight: 2
agentSlope: 45
agentClimb: 0.4
ledgeDropHeight: 0
maxJumpAcrossDistance: 0
minRegionArea: 2
manualCellSize: 0
cellSize: 0.16666667
accuratePlacement: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &34117363
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 34117367}
- component: {fileID: 34117366}
- component: {fileID: 34117365}
- component: {fileID: 34117364}
- component: {fileID: 34117368}
m_Layer: 0
m_Name: PhotoCaptureCanvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!23 &34117364
MeshRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 34117363}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: 88de79a80cfa4dc42a041ce745ba291f, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!64 &34117365
MeshCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 34117363}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 0
serializedVersion: 2
m_Convex: 0
m_InflateMesh: 0
m_SkinWidth: 0.01
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!33 &34117366
MeshFilter:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 34117363}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!4 &34117367
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 34117363}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 10}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &34117368
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 34117363}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4ef4a715f18c9dd47915d7a51859c1ff, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &314898261
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 100008, guid: 4859e20a6237a7041959573320b6a033, type: 2}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 314898262}
- component: {fileID: 314898264}
- component: {fileID: 314898263}
m_Layer: 5
m_Name: Text
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &314898262
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 22400008, guid: 4859e20a6237a7041959573320b6a033,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 314898261}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2053462722}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &314898263
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 11400014, guid: 4859e20a6237a7041959573320b6a033,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 314898261}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.196, g: 0.196, b: 0.196, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 14
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 4
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: Back
--- !u!222 &314898264
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 22200004, guid: 4859e20a6237a7041959573320b6a033,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 314898261}
--- !u!1001 &906569370
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4000010560871102, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2}
propertyPath: m_RootOrder
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: d379ed0a5618c9f479f58bd83a2d0ad3, type: 2}
m_IsPrefabParent: 0
--- !u!1 &1004623802
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 100000, guid: 516b0ed7bbe49b54eb11d0acece129f1, type: 2}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1004623806}
- component: {fileID: 1004623805}
- component: {fileID: 1004623804}
- component: {fileID: 1004623803}
m_Layer: 0
m_Name: EventSystem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1004623803
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1004623802}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 911850839, guid: f7b54ff4a43d4fcf81b4538b678e0bcc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
m_NormalizedNavigationToScreenOffsetScalar: 500
m_TimeToPressOnTap: 0.3
--- !u!114 &1004623804
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 11400002, guid: 516b0ed7bbe49b54eb11d0acece129f1,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1004623802}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1077351063, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
--- !u!114 &1004623805
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 11400004, guid: 516b0ed7bbe49b54eb11d0acece129f1,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1004623802}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -619905303, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}
m_sendNavigationEvents: 1
m_DragThreshold: 5
--- !u!4 &1004623806
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 400000, guid: 516b0ed7bbe49b54eb11d0acece129f1, type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1004623802}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!20 &1053274014 stripped
Camera:
m_PrefabParentObject: {fileID: 20000013304850028, guid: d379ed0a5618c9f479f58bd83a2d0ad3,
type: 2}
m_PrefabInternal: {fileID: 906569370}
--- !u!1 &1204382163
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1204382171}
- component: {fileID: 1204382170}
- component: {fileID: 1204382169}
- component: {fileID: 1204382168}
- component: {fileID: 1204382167}
- component: {fileID: 1204382166}
- component: {fileID: 1204382165}
- component: {fileID: 1204382164}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1204382164
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1204382163}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ac8d5b128a1d8204fb76c86f47b75912, type: 3}
m_Name:
m_EditorClassIdentifier:
PivotAxis: 1
--- !u!114 &1204382165
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1204382163}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2be8bd2ebd8277c448d6d81c75517fee, type: 3}
m_Name:
m_EditorClassIdentifier:
TagalongDistance: 0.9
EnforceDistance: 1
PositionUpdateSpeed: 9.8
SmoothMotion: 1
SmoothingFactor: 0.75
--- !u!114 &1204382166
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1204382163}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fb69de839bd015f4099b5bd2c45e53e5, type: 3}
m_Name:
m_EditorClassIdentifier:
UseUnscaledTime: 1
PositionPerSecond: 30
RotationDegreesPerSecond: 720
RotationSpeedScaler: 0
ScalePerSecond: 5
SmoothLerpToTarget: 0
SmoothPositionLerpRatio: 0.5
SmoothRotationLerpRatio: 0.5
SmoothScaleLerpRatio: 0.5
--- !u!65 &1204382167
BoxCollider:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1204382163}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
m_Center: {x: 0, y: 0, z: 0}
--- !u!114 &1204382168
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1204382163}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1301386320, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &1204382169
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1204382163}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!223 &1204382170
Canvas:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1204382163}
m_Enabled: 1
serializedVersion: 2
m_RenderMode: 2
m_Camera: {fileID: 1053274014}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!224 &1204382171
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1204382163}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0.9}
m_LocalScale: {x: 0.0005, y: 0.0005, z: 0.0005}
m_Children:
- {fileID: 1267244721}
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 800, y: 496.1241}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &1267244720
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1267244721}
- component: {fileID: 1267244724}
- component: {fileID: 1267244723}
- component: {fileID: 1267244722}
m_Layer: 5
m_Name: Menu
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1267244721
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1267244720}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 2053462722}
m_Father: {fileID: 1204382171}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1267244722
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1267244720}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1297475563, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Padding:
m_Left: 0
m_Right: 0
m_Top: 0
m_Bottom: 0
m_ChildAlignment: 0
m_Spacing: 10
m_ChildForceExpandWidth: 0
m_ChildForceExpandHeight: 0
m_ChildControlWidth: 1
m_ChildControlHeight: 1
--- !u!114 &1267244723
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1267244720}
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 0.392}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
--- !u!222 &1267244724
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1267244720}
--- !u!1 &1448888927
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 1448888929}
- component: {fileID: 1448888928}
m_Layer: 0
m_Name: Directional Light
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!108 &1448888928
Light:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1448888927}
m_Enabled: 1
serializedVersion: 7
m_Type: 1
m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1}
m_Intensity: 1
m_Range: 10
m_SpotAngle: 30
m_CookieSize: 10
m_Shadows:
m_Type: 2
m_Resolution: -1
m_CustomResolution: -1
m_Strength: 1
m_Bias: 0.05
m_NormalBias: 0.4
m_NearPlane: 0.2
m_Cookie: {fileID: 0}
m_DrawHalo: 0
m_Flare: {fileID: 0}
m_RenderMode: 0
m_CullingMask:
serializedVersion: 2
m_Bits: 4294967295
m_Lightmapping: 4
m_AreaSize: {x: 1, y: 1}
m_BounceIntensity: 1
m_ShadowRadius: 0
m_ShadowAngle: 0
--- !u!4 &1448888929
Transform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 1448888927}
m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261}
m_LocalPosition: {x: 0, y: 3, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1001 &1880953870
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4000013535415816, guid: b2db04283121ca74495c2ee000fb4243, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000013535415816, guid: b2db04283121ca74495c2ee000fb4243, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000013535415816, guid: b2db04283121ca74495c2ee000fb4243, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000013535415816, guid: b2db04283121ca74495c2ee000fb4243, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000013535415816, guid: b2db04283121ca74495c2ee000fb4243, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000013535415816, guid: b2db04283121ca74495c2ee000fb4243, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000013535415816, guid: b2db04283121ca74495c2ee000fb4243, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4000013535415816, guid: b2db04283121ca74495c2ee000fb4243, type: 2}
propertyPath: m_RootOrder
value: 6
objectReference: {fileID: 0}
- target: {fileID: 114000013851064060, guid: b2db04283121ca74495c2ee000fb4243,
type: 2}
propertyPath: MinCursorDistance
value: 0.9
objectReference: {fileID: 0}
- target: {fileID: 114000013851064060, guid: b2db04283121ca74495c2ee000fb4243,
type: 2}
propertyPath: DefaultCursorDistance
value: 0.9
objectReference: {fileID: 0}
- target: {fileID: 4000013535415816, guid: b2db04283121ca74495c2ee000fb4243, type: 2}
propertyPath: m_LocalScale.x
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4000013535415816, guid: b2db04283121ca74495c2ee000fb4243, type: 2}
propertyPath: m_LocalScale.y
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4000013535415816, guid: b2db04283121ca74495c2ee000fb4243, type: 2}
propertyPath: m_LocalScale.z
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: b2db04283121ca74495c2ee000fb4243, type: 2}
m_IsPrefabParent: 0
--- !u!1 &2053462721
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 100004, guid: 4859e20a6237a7041959573320b6a033, type: 2}
m_PrefabInternal: {fileID: 0}
serializedVersion: 5
m_Component:
- component: {fileID: 2053462722}
- component: {fileID: 2053462726}
- component: {fileID: 2053462725}
- component: {fileID: 2053462724}
- component: {fileID: 2053462723}
m_Layer: 5
m_Name: BackButton
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &2053462722
RectTransform:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 22400004, guid: 4859e20a6237a7041959573320b6a033,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2053462721}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 314898262}
m_Father: {fileID: 1267244721}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &2053462723
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 11400006, guid: 4859e20a6237a7041959573320b6a033,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2053462721}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1679637790, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreLayout: 0
m_MinWidth: -1
m_MinHeight: -1
m_PreferredWidth: 160
m_PreferredHeight: 40
m_FlexibleWidth: -1
m_FlexibleHeight: -1
--- !u!114 &2053462724
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 11400008, guid: 4859e20a6237a7041959573320b6a033,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2053462721}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1392445389, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1}
m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1}
m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608}
m_ColorMultiplier: 1
m_FadeDuration: 0.1
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 2053462725}
m_OnClick:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 34117368}
m_MethodName: OnBackButton
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
--- !u!114 &2053462725
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 11400010, guid: 4859e20a6237a7041959573320b6a033,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2053462721}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
--- !u!222 &2053462726
CanvasRenderer:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 22200002, guid: 4859e20a6237a7041959573320b6a033,
type: 2}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2053462721}
--- !u!1001 &2060851756
Prefab:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4000011656901714, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2}
propertyPath: m_RootOrder
value: 5
objectReference: {fileID: 0}
m_RemovedComponents: []
m_ParentPrefab: {fileID: 100100000, guid: 3eddd1c29199313478dd3f912bfab2ab, type: 2}
m_IsPrefabParent: 0

Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e89ceb2c24c45d844b87c3e07cd240dc
timeCreated: 1486374533
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: baa2a4dbb3054d14090050638224d277
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: 0234af6998912c54d80d30fd71ea3dac
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 3a58626d3c947ef4e9c22d0f4a104715
DefaultImporter:
userData:

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: ae54b3be70768f64e9b1a300c7cdeff9
DefaultImporter:
userData:

Просмотреть файл

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 57937f7a43d097548a3253fb97ed2c9b
folderAsset: yes
timeCreated: 1485712968
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,968 @@
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement;
#endif
using OpenCVForUnity;
using Rect = OpenCVForUnity.Rect;
#if UNITY_WSA
#if NETFX_CORE
using System.Threading;
using System.Threading.Tasks;
#else
#endif
#else
using System.Threading;
#endif
using PositionsVector = System.Collections.Generic.List<OpenCVForUnity.Rect>;
namespace HoloLensWithOpenCVForUnityExample
{
/// <summary>
/// HoloLens anonymous face example.
/// </summary>
[RequireComponent(typeof(OptimizationWebCamTextureToMatHelper))]
public class HoloLensAnonymousFaceExample : MonoBehaviour
{
/// <summary>
/// The gray mat.
/// </summary>
Mat grayMat;
/// <summary>
/// The texture.
/// </summary>
Texture2D texture;
#if !UNITY_WEBGL || UNITY_EDITOR
/// <summary>
/// The cascade.
/// </summary>
CascadeClassifier cascade;
Rect[] rectsWhereRegions;
private List<TrackedObject> trackedObjects = new List<TrackedObject> ();
private List<float> weightsPositionsSmoothing = new List<float> ();
private List<float> weightsSizesSmoothing = new List<float> ();
private Parameters parameters;
private InnerParameters innerParameters;
private volatile ThreadComm threadComm = new ThreadComm ();
private System.Object thisLock = new System.Object ();
private volatile bool isThreadRunning = false;
private Mat grayMat4Thread;
private CascadeClassifier regionCascade;
List<Rect> detectedObjectsInRegions = new List<Rect> ();
List<Rect> resultObjects = new List<Rect> ();
private volatile bool didUpdateTheDetectionResult = false;
private MatOfRect resultDetect;
#endif
// for Thread
#if UNITY_WSA
#if NETFX_CORE
private Task task_ = null;
private CancellationTokenSource tokenSource_ = null;
#else
#endif
#elif !UNITY_WEBGL || UNITY_EDITOR
private volatile bool shouldStopThread = false;
#endif
/// <summary>
/// The web cam texture to mat helper.
/// </summary>
OptimizationWebCamTextureToMatHelper webCamTextureToMatHelper;
// Renderer quad_renderer = null;
OpenCVForUnity.Rect processingAreaRect;
// public Vector2 outsideClippingRatio = new Vector2(0.17f, 0.19f);
public Vector2 outsideClippingRatio = new Vector2(0.043f, 0.041f);
public Vector2 clippingOffset = new Vector2(0.043f, -0.041f);
Matrix4x4 projectionMatrix;
RectOverlay rectOverlay;
public float overlayDistance = 2;
// Use this for initialization
void Start ()
{
#if !UNITY_WEBGL || UNITY_EDITOR
weightsPositionsSmoothing.Add (1);
weightsSizesSmoothing.Add (0.5f);
weightsSizesSmoothing.Add (0.3f);
weightsSizesSmoothing.Add (0.2f);
//parameters.minObjectSize = 96;
//parameters.maxObjectSize = int.MaxValue;
//parameters.scaleFactor = 1.1f;
//parameters.minNeighbors = 2;
parameters.maxTrackLifetime = 5;
innerParameters.numLastPositionsToTrack = 4;
innerParameters.numStepsToWaitBeforeFirstShow = 6;
innerParameters.numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown = 3;
innerParameters.numStepsToShowWithoutDetecting = 3;
innerParameters.coeffTrackingWindowSize = 2.0f;
innerParameters.coeffObjectSizeToTrack = 0.85f;
innerParameters.coeffObjectSpeedUsingInPrediction = 0.8f;
#endif
webCamTextureToMatHelper = gameObject.GetComponent<OptimizationWebCamTextureToMatHelper> ();
webCamTextureToMatHelper.Init ();
rectOverlay = gameObject.GetComponent<RectOverlay> ();
}
/// <summary>
/// Raises the web cam texture to mat helper inited event.
/// </summary>
public void OnWebCamTextureToMatHelperInited ()
{
Debug.Log ("OnWebCamTextureToMatHelperInited");
Mat webCamTextureMat = webCamTextureToMatHelper.GetDownScaleMat(webCamTextureToMatHelper.GetMat ());
// texture = new Texture2D (webCamTextureMat.cols (), webCamTextureMat.rows (), TextureFormat.RGBA32, false);
//
// gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
Debug.Log ("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);
processingAreaRect = new OpenCVForUnity.Rect ((int)(webCamTextureMat.cols ()*(outsideClippingRatio.x - clippingOffset.x)), (int)(webCamTextureMat.rows ()*(outsideClippingRatio.y + clippingOffset.y)),
(int)(webCamTextureMat.cols ()*(1f-outsideClippingRatio.x*2)), (int)(webCamTextureMat.rows ()*(1f-outsideClippingRatio.y*2)));
processingAreaRect = processingAreaRect.intersect (new OpenCVForUnity.Rect(0,0,webCamTextureMat.cols (),webCamTextureMat.rows ()));
// quad_renderer = gameObject.GetComponent<Renderer> () as Renderer;
// quad_renderer.sharedMaterial.SetTexture ("_MainTex", texture);
projectionMatrix = Matrix4x4.identity;
projectionMatrix.m00 = 2.31029f;
projectionMatrix.m01 = 0.00000f;
projectionMatrix.m02 = 0.09614f;
projectionMatrix.m03 = 0.00000f;
projectionMatrix.m10 = 0.00000f;
projectionMatrix.m11 = 4.10427f;
projectionMatrix.m12 = -0.06231f;
projectionMatrix.m13 = 0.00000f;
projectionMatrix.m20 = 0.00000f;
projectionMatrix.m21 = 0.00000f;
projectionMatrix.m22 = -1.00000f;
projectionMatrix.m23 = 0.00000f;
projectionMatrix.m30 = 0.00000f;
projectionMatrix.m31 = 0.00000f;
projectionMatrix.m32 = -1.00000f;
projectionMatrix.m33 = 0.00000f;
#if !UNITY_WEBGL || UNITY_EDITOR
grayMat = new Mat (webCamTextureMat.rows (), webCamTextureMat.cols (), CvType.CV_8UC1);
regionCascade = new CascadeClassifier ();
regionCascade.load (Utils.getFilePath ("lbpcascade_frontalface.xml"));
if (regionCascade.empty ()) {
Debug.LogError ("cascade file is not loaded.Please copy from “OpenCVForUnity/StreamingAssets/” to “Assets/StreamingAssets/” folder. ");
}
initThread ();
#endif
}
/// <summary>
/// Raises the web cam texture to mat helper disposed event.
/// </summary>
public void OnWebCamTextureToMatHelperDisposed ()
{
Debug.Log ("OnWebCamTextureToMatHelperDisposed");
#if !UNITY_WEBGL || UNITY_EDITOR
StopThread ();
if (grayMat4Thread != null)
grayMat4Thread.Dispose ();
if (cascade != null)
cascade.Dispose ();
if (grayMat != null)
grayMat.Dispose ();
if (regionCascade != null)
regionCascade.Dispose ();
#endif
}
/// <summary>
/// Raises the web cam texture to mat helper error occurred event.
/// </summary>
/// <param name="errorCode">Error code.</param>
public void OnWebCamTextureToMatHelperErrorOccurred(WebCamTextureToMatHelper.ErrorCode errorCode){
Debug.Log ("OnWebCamTextureToMatHelperErrorOccurred " + errorCode);
}
// Update is called once per frame
void Update ()
{
#if !UNITY_WEBGL || UNITY_EDITOR
if (webCamTextureToMatHelper.IsPlaying () && webCamTextureToMatHelper.DidUpdateThisFrame ()) {
Mat rgbaMat = webCamTextureToMatHelper.GetDownScaleMat(webCamTextureToMatHelper.GetMat ());
Mat rgbaMatClipROI = new Mat(rgbaMat, processingAreaRect);
Imgproc.cvtColor (rgbaMatClipROI, grayMat, Imgproc.COLOR_RGBA2GRAY);
// fill all black.
// Imgproc.rectangle (rgbaMatClipROI, new Point (0, 0), new Point (rgbaMat.width (), rgbaMat.height ()), new Scalar (0, 0, 0, 0), -1);
Imgproc.equalizeHist (grayMat, grayMat);
if (!threadComm.shouldDetectInMultiThread) {
grayMat.copyTo (grayMat4Thread);
threadComm.shouldDetectInMultiThread = true;
}
// OpenCVForUnity.Rect[] rects;
if (didUpdateTheDetectionResult) {
didUpdateTheDetectionResult = false;
lock (thisLock) {
//Debug.Log("DetectionBasedTracker::process: get _rectsWhereRegions were got from resultDetect");
rectsWhereRegions = resultDetect.toArray ();
// rects = resultDetect.toArray ();
}
// for (int i = 0; i < rects.Length; i++) {
// Imgproc.rectangle (rgbaMatClipROI, new Point (rects [i].x, rects [i].y), new Point (rects [i].x + rects [i].width, rects [i].y + rects [i].height), new Scalar (0, 0, 255, 255), 2);
// }
} else {
//Debug.Log("DetectionBasedTracker::process: get _rectsWhereRegions from previous positions");
rectsWhereRegions = new Rect[trackedObjects.Count];
for (int i = 0; i < trackedObjects.Count; i++) {
int n = trackedObjects [i].lastPositions.Count;
//if (n > 0) UnityEngine.Debug.LogError("n > 0 is false");
Rect r = trackedObjects [i].lastPositions [n - 1].clone ();
if (r.area () == 0) {
Debug.Log ("DetectionBasedTracker::process: ERROR: ATTENTION: strange algorithm's behavior: trackedObjects[i].rect() is empty");
continue;
}
//correction by speed of rectangle
if (n > 1) {
Point center = centerRect (r);
Point center_prev = centerRect (trackedObjects [i].lastPositions [n - 2]);
Point shift = new Point ((center.x - center_prev.x) * innerParameters.coeffObjectSpeedUsingInPrediction,
(center.y - center_prev.y) * innerParameters.coeffObjectSpeedUsingInPrediction);
r.x += (int)Math.Round (shift.x);
r.y += (int)Math.Round (shift.y);
}
rectsWhereRegions [i] = r;
}
// rects = rectsWhereRegions;
// for (int i = 0; i < rects.Length; i++) {
// Imgproc.rectangle (rgbaMatClipROI, new Point (rects [i].x, rects [i].y), new Point (rects [i].x + rects [i].width, rects [i].y + rects [i].height), new Scalar (0, 255, 0, 255), 2);
// }
}
if (rectsWhereRegions.Length > 0) {
detectedObjectsInRegions.Clear ();
int len = rectsWhereRegions.Length;
for (int i = 0; i < len; i++) {
detectInRegion (grayMat, rectsWhereRegions [i], detectedObjectsInRegions);
}
}
updateTrackedObjects (detectedObjectsInRegions);
getObjects (resultObjects);
//getSmoothingObjects (resultObjects);
int rectsCount = resultObjects.Count;
UnityEngine.Rect[] overlayRects = new UnityEngine.Rect[rectsCount];
float width = rgbaMat.width ();
float height = rgbaMat.height ();
float offsetX = processingAreaRect.x / width;
float offsetY = processingAreaRect.y / height;
for (int i = 0; i < resultObjects.Count; i++) {
overlayRects[i] = new UnityEngine.Rect(offsetX + (resultObjects[i].x/width)
, offsetY + (resultObjects[i].y/height)
, resultObjects[i].width/width
// , resultObjects[i].height/height);
, resultObjects[i].width/height);
}
rectOverlay.DrawRects(overlayRects);
rgbaMatClipROI.Dispose ();
}
if (webCamTextureToMatHelper.IsPlaying ()) {
Matrix4x4 cameraToWorldMatrix = Camera.main.cameraToWorldMatrix;;
Vector3 ccCameraSpacePos = UnProjectVector(projectionMatrix, new Vector3(0.0f, 0.0f, overlayDistance));
Vector3 tlCameraSpacePos = UnProjectVector(projectionMatrix, new Vector3(-overlayDistance, overlayDistance, overlayDistance));
//position
Vector3 position = cameraToWorldMatrix.MultiplyPoint3x4(ccCameraSpacePos);
gameObject.transform.position = position;
//scale
Vector3 scale = new Vector3(Mathf.Abs(tlCameraSpacePos.x - ccCameraSpacePos.x)*2, Mathf.Abs(tlCameraSpacePos.y - ccCameraSpacePos.y)*2, 1);
gameObject.transform.localScale = scale;
// Rotate the canvas object so that it faces the user.
Quaternion rotation = Quaternion.LookRotation (-cameraToWorldMatrix.GetColumn (2), cameraToWorldMatrix.GetColumn (1));
gameObject.transform.rotation = rotation;
rectOverlay.UpdateOverlayTransform(gameObject.transform);
}
#else
if (webCamTextureToMatHelper.IsPlaying () && webCamTextureToMatHelper.DidUpdateThisFrame ()) {
Mat rgbaMat = webCamTextureToMatHelper.GetMat ();
Imgproc.putText (rgbaMat, "WebGL platform does not support multi-threading.", new Point (5, rgbaMat.rows () - 10), Core.FONT_HERSHEY_SIMPLEX, 0.5, new Scalar (255, 255, 255, 255), 1, Imgproc.LINE_AA, false);
Utils.matToTexture2D (rgbaMat, texture, webCamTextureToMatHelper.GetBufferColors ());
}
#endif
}
public Vector3 UnProjectVector(Matrix4x4 proj, Vector3 to)
{
Vector3 from = new Vector3(0, 0, 0);
var axsX = proj.GetRow(0);
var axsY = proj.GetRow(1);
var axsZ = proj.GetRow(2);
from.z = to.z / axsZ.z;
from.y = (to.y - (from.z * axsY.z)) / axsY.y;
from.x = (to.x - (from.z * axsX.z)) / axsX.x;
return from;
}
#if !UNITY_WEBGL || UNITY_EDITOR
private void initThread ()
{
StopThread ();
grayMat4Thread = new Mat ();
cascade = new CascadeClassifier ();
cascade.load(Utils.getFilePath ("haarcascade_frontalface_alt.xml"));
if (cascade.empty ()) {
Debug.LogError ("cascade file is not loaded.Please copy from “OpenCVForUnity/StreamingAssets/” to “Assets/StreamingAssets/” folder. ");
}
threadComm.shouldDetectInMultiThread = false;
StartThread ();
}
#if UNITY_WSA
#if NETFX_CORE
private void ThreadWorker()
{
if (isThreadRunning) return;
Debug.Log("Thread Start");
isThreadRunning = true;
threadComm.shouldDetectInMultiThread = false;
didUpdateTheDetectionResult = false;
tokenSource_ = new CancellationTokenSource();
task_ =Task.Factory.StartNew(
(o)=>
{
ThreadComm comm = o as ThreadComm;
while(true)
{
tokenSource_.Token.ThrowIfCancellationRequested();
if(!comm.shouldDetectInMultiThread) continue;
MatOfRect faces = new MatOfRect();
if (cascade != null)
cascade.detectMultiScale(grayMat4Thread, faces, 1.1, 2, Objdetect.CASCADE_SCALE_IMAGE, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(grayMat4Thread.height() * 0.1, grayMat4Thread.height() * 0.1), new Size());
lock (thisLock){
resultDetect = faces;
}
comm.shouldDetectInMultiThread = false;
didUpdateTheDetectionResult = true;
}
}
, threadComm
, tokenSource_.Token
).ContinueWith(t =>
{
tokenSource_.Dispose();
tokenSource_ = null;
isThreadRunning = false;
});
}
#else
private void ThreadWorker()
{
if (isThreadRunning) return;
Debug.Log("Thread Start");
isThreadRunning = true;
threadComm.shouldDetectInMultiThread = false;
didUpdateTheDetectionResult = false;
StartCoroutine("ThreadCoroutine", threadComm);
}
IEnumerator ThreadCoroutine(System.Object o)
{
ThreadComm comm = o as ThreadComm;
while (true)
{
while (!comm.shouldDetectInMultiThread) { yield return null; }
MatOfRect faces = new MatOfRect();
if (cascade != null)
cascade.detectMultiScale(grayMat4Thread, faces, 1.1, 2, Objdetect.CASCADE_SCALE_IMAGE, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(grayMat4Thread.height() * 0.1, grayMat4Thread.height() * 0.1), new Size());
lock (thisLock){
resultDetect = faces;
}
comm.shouldDetectInMultiThread = false;
didUpdateTheDetectionResult = true;
}
}
#endif
#else
private void ThreadWorker ()
{
if (isThreadRunning)
return;
Debug.Log ("Thread Start");
isThreadRunning = true;
shouldStopThread = false;
threadComm.shouldDetectInMultiThread = false;
didUpdateTheDetectionResult = false;
ThreadPool.QueueUserWorkItem (_ThreadWorker, threadComm);
}
private void _ThreadWorker (System.Object o)
{
ThreadComm comm = o as ThreadComm;
while (!shouldStopThread) {
if (!comm.shouldDetectInMultiThread)
continue;
MatOfRect faces = new MatOfRect ();
if (cascade != null)
cascade.detectMultiScale (grayMat4Thread, faces, 1.1, 2, Objdetect.CASCADE_SCALE_IMAGE, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size (grayMat4Thread.height () * 0.1, grayMat4Thread.height () * 0.1), new Size ());
//Thread.Sleep(200);
lock (thisLock) {
resultDetect = faces;
}
comm.shouldDetectInMultiThread = false;
didUpdateTheDetectionResult = true;
}
isThreadRunning = false;
}
#endif
public class ThreadComm : System.Object
{
public bool shouldDetectInMultiThread = false;
}
public void StartThread ()
{
ThreadWorker ();
}
public void StopThread ()
{
if (!isThreadRunning)
return;
#if UNITY_WSA
#if NETFX_CORE
tokenSource_.Cancel();
task_ = null;
#else
StopCoroutine("ThreadCoroutine");
isThreadRunning = false;
#endif
#else
shouldStopThread = true;
#endif
while (isThreadRunning) {
//Wait threading stop
}
Debug.Log ("Thread Stop");
}
private void getObjects (List<Rect> result)
{
result.Clear ();
for (int i = 0; i < trackedObjects.Count; i++) {
if ((trackedObjects [i].numDetectedFrames <= innerParameters.numStepsToWaitBeforeFirstShow)
|| (trackedObjects [i].numFramesNotDetected > innerParameters.numStepsToShowWithoutDetecting)) {
}else{
result.Add(trackedObjects[i].lastPositions[trackedObjects[i].lastPositions.Count - 1]);
}
}
}
private void getSmoothingObjects (List<Rect> result)
{
result.Clear ();
for (int i = 0; i < trackedObjects.Count; i++) {
Rect r = calcTrackedObjectPositionToShow (i);
if (r.area () == 0) {
continue;
}
result.Add (r);
//LOGD("DetectionBasedTracker::process: found a object with SIZE %d x %d, rect={%d, %d, %d x %d}", r.width, r.height, r.x, r.y, r.width, r.height);
}
}
public enum TrackedState : int
{
NEW_RECTANGLE = -1,
INTERSECTED_RECTANGLE = -2
}
private void updateTrackedObjects (List<Rect> detectedObjects)
{
int N1 = (int)trackedObjects.Count;
int N2 = (int)detectedObjects.Count;
for (int i = 0; i < N1; i++) {
trackedObjects [i].numDetectedFrames++;
}
int[] correspondence = new int[N2];
for (int i = 0; i < N2; i++) {
correspondence [i] = (int)TrackedState.NEW_RECTANGLE;
}
for (int i = 0; i < N1; i++) {
TrackedObject curObject = trackedObjects [i];
int bestIndex = -1;
int bestArea = -1;
int numpositions = (int)curObject.lastPositions.Count;
//if (numpositions > 0) UnityEngine.Debug.LogError("numpositions > 0 is false");
Rect prevRect = curObject.lastPositions [numpositions - 1];
for (int j = 0; j < N2; j++) {
if (correspondence [j] >= 0) {
//Debug.Log("DetectionBasedTracker::updateTrackedObjects: j=" + i + " is rejected, because it has correspondence=" + correspondence[j]);
continue;
}
if (correspondence [j] != (int)TrackedState.NEW_RECTANGLE) {
//Debug.Log("DetectionBasedTracker::updateTrackedObjects: j=" + j + " is rejected, because it is intersected with another rectangle");
continue;
}
Rect r = Intersect (prevRect, detectedObjects [j]);
if ((r.width > 0) && (r.height > 0)) {
//LOGD("DetectionBasedTracker::updateTrackedObjects: There is intersection between prevRect and detectedRect, r={%d, %d, %d x %d}",
// r.x, r.y, r.width, r.height);
correspondence [j] = (int)TrackedState.INTERSECTED_RECTANGLE;
if (r.area () > bestArea) {
//LOGD("DetectionBasedTracker::updateTrackedObjects: The area of intersection is %d, it is better than bestArea=%d", r.area(), bestArea);
bestIndex = j;
bestArea = (int)r.area ();
}
}
}
if (bestIndex >= 0) {
//LOGD("DetectionBasedTracker::updateTrackedObjects: The best correspondence for i=%d is j=%d", i, bestIndex);
correspondence [bestIndex] = i;
for (int j = 0; j < N2; j++) {
if (correspondence [j] >= 0)
continue;
Rect r = Intersect (detectedObjects [j], detectedObjects [bestIndex]);
if ((r.width > 0) && (r.height > 0)) {
//LOGD("DetectionBasedTracker::updateTrackedObjects: Found intersection between "
// "rectangles j=%d and bestIndex=%d, rectangle j=%d is marked as intersected", j, bestIndex, j);
correspondence [j] = (int)TrackedState.INTERSECTED_RECTANGLE;
}
}
} else {
//LOGD("DetectionBasedTracker::updateTrackedObjects: There is no correspondence for i=%d ", i);
curObject.numFramesNotDetected++;
}
}
//LOGD("DetectionBasedTracker::updateTrackedObjects: start second cycle");
for (int j = 0; j < N2; j++) {
int i = correspondence [j];
if (i >= 0) {//add position
//Debug.Log("DetectionBasedTracker::updateTrackedObjects: add position");
trackedObjects [i].lastPositions.Add (detectedObjects [j]);
while ((int)trackedObjects [i].lastPositions.Count > (int)innerParameters.numLastPositionsToTrack) {
trackedObjects [i].lastPositions.Remove (trackedObjects [i].lastPositions [0]);
}
trackedObjects [i].numFramesNotDetected = 0;
} else if (i == (int)TrackedState.NEW_RECTANGLE) { //new object
//Debug.Log("DetectionBasedTracker::updateTrackedObjects: new object");
trackedObjects.Add (new TrackedObject (detectedObjects [j]));
} else {
Debug.Log ("DetectionBasedTracker::updateTrackedObjects: was auxiliary intersection");
}
}
int t = 0;
TrackedObject it;
while (t < trackedObjects.Count) {
it = trackedObjects [t];
if ((it.numFramesNotDetected > parameters.maxTrackLifetime)
||
((it.numDetectedFrames <= innerParameters.numStepsToWaitBeforeFirstShow)
&&
(it.numFramesNotDetected > innerParameters.numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown))) {
//int numpos = (int)it.lastPositions.Count;
//if (numpos > 0) UnityEngine.Debug.LogError("numpos > 0 is false");
//Rect r = it.lastPositions [numpos - 1];
//Debug.Log("DetectionBasedTracker::updateTrackedObjects: deleted object " + r.x + " " + r.y + " " + r.width + " " + r.height);
trackedObjects.Remove (it);
} else {
t++;
}
}
}
private void detectInRegion (Mat img, Rect r, List<Rect> detectedObjectsInRegions)
{
Rect r0 = new Rect (new Point (), img.size ());
Rect r1 = new Rect (r.x, r.y, r.width, r.height);
Inflate (r1, (int)((r1.width * innerParameters.coeffTrackingWindowSize) - r1.width) / 2,
(int)((r1.height * innerParameters.coeffTrackingWindowSize) - r1.height) / 2);
r1 = Intersect (r0, r1);
if ((r1.width <= 0) || (r1.height <= 0)) {
Debug.Log ("DetectionBasedTracker::detectInRegion: Empty intersection");
return;
}
int d = Math.Min (r.width, r.height);
d = (int)Math.Round (d * innerParameters.coeffObjectSizeToTrack);
MatOfRect tmpobjects = new MatOfRect ();
Mat img1 = new Mat (img, r1);//subimage for rectangle -- without data copying
regionCascade.detectMultiScale (img1, tmpobjects, 1.1, 2, 0 | Objdetect.CASCADE_DO_CANNY_PRUNING | Objdetect.CASCADE_SCALE_IMAGE | Objdetect.CASCADE_FIND_BIGGEST_OBJECT, new Size (d, d), new Size ());
Rect[] tmpobjectsArray = tmpobjects.toArray ();
int len = tmpobjectsArray.Length;
for (int i = 0; i < len; i++) {
Rect tmp = tmpobjectsArray [i];
Rect curres = new Rect (new Point (tmp.x + r1.x, tmp.y + r1.y), tmp.size ());
detectedObjectsInRegions.Add (curres);
}
}
private Rect calcTrackedObjectPositionToShow (int i)
{
if ((i < 0) || (i >= trackedObjects.Count)) {
Debug.Log ("DetectionBasedTracker::calcTrackedObjectPositionToShow: ERROR: wrong i=" + i);
return new Rect ();
}
if (trackedObjects [i].numDetectedFrames <= innerParameters.numStepsToWaitBeforeFirstShow) {
//Debug.Log("DetectionBasedTracker::calcTrackedObjectPositionToShow: " + "trackedObjects[" + i + "].numDetectedFrames=" + trackedObjects[i].numDetectedFrames + " <= numStepsToWaitBeforeFirstShow=" + innerParameters.numStepsToWaitBeforeFirstShow + " --- return empty Rect()");
return new Rect ();
}
if (trackedObjects [i].numFramesNotDetected > innerParameters.numStepsToShowWithoutDetecting) {
return new Rect ();
}
List<Rect> lastPositions = trackedObjects [i].lastPositions;
int N = lastPositions.Count;
if (N <= 0) {
Debug.Log ("DetectionBasedTracker::calcTrackedObjectPositionToShow: ERROR: no positions for i=" + i);
return new Rect ();
}
int Nsize = Math.Min (N, (int)weightsSizesSmoothing.Count);
int Ncenter = Math.Min (N, (int)weightsPositionsSmoothing.Count);
Point center = new Point ();
double w = 0, h = 0;
if (Nsize > 0) {
double sum = 0;
for (int j = 0; j < Nsize; j++) {
int k = N - j - 1;
w += lastPositions [k].width * weightsSizesSmoothing [j];
h += lastPositions [k].height * weightsSizesSmoothing [j];
sum += weightsSizesSmoothing [j];
}
w /= sum;
h /= sum;
} else {
w = lastPositions [N - 1].width;
h = lastPositions [N - 1].height;
}
if (Ncenter > 0) {
double sum = 0;
for (int j = 0; j < Ncenter; j++) {
int k = N - j - 1;
Point tl = lastPositions [k].tl ();
Point br = lastPositions [k].br ();
Point c1;
//c1=tl;
//c1=c1* 0.5f;//
c1 = new Point (tl.x * 0.5f, tl.y * 0.5f);
Point c2;
//c2=br;
//c2=c2*0.5f;
c2 = new Point (br.x * 0.5f, br.y * 0.5f);
//c1=c1+c2;
c1 = new Point (c1.x + c2.x, c1.y + c2.y);
//center=center+ (c1 * weightsPositionsSmoothing[j]);
center = new Point (center.x + (c1.x * weightsPositionsSmoothing [j]), center.y + (c1.y * weightsPositionsSmoothing [j]));
sum += weightsPositionsSmoothing [j];
}
//center *= (float)(1 / sum);
center = new Point (center.x * (1 / sum), center.y * (1 / sum));
} else {
int k = N - 1;
Point tl = lastPositions [k].tl ();
Point br = lastPositions [k].br ();
Point c1;
//c1=tl;
//c1=c1* 0.5f;
c1 = new Point (tl.x * 0.5f, tl.y * 0.5f);
Point c2;
//c2=br;
//c2=c2*0.5f;
c2 = new Point (br.x * 0.5f, br.y * 0.5f);
//center=c1+c2;
center = new Point (c1.x + c2.x, c1.y + c2.y);
}
//Point2f tl=center-(Point2f(w,h)*0.5);
Point tl2 = new Point (center.x - (w * 0.5f), center.y - (h * 0.5f));
//Rect res(cvRound(tl.x), cvRound(tl.y), cvRound(w), cvRound(h));
Rect res = new Rect ((int)Math.Round (tl2.x), (int)Math.Round (tl2.y), (int)Math.Round (w), (int)Math.Round (h));
//LOGD("DetectionBasedTracker::calcTrackedObjectPositionToShow: Result for i=%d: {%d, %d, %d x %d}", i, res.x, res.y, res.width, res.height);
return res;
}
public Point centerRect (Rect r)
{
return new Point (r.x + (r.width / 2), r.y + (r.height / 2));
}
public Rect Intersect (Rect a, Rect b)
{
int x1 = Math.Max (a.x, b.x);
int x2 = Math.Min (a.x + a.width, b.x + b.width);
int y1 = Math.Max (a.y, b.y);
int y2 = Math.Min (a.y + a.height, b.y + b.height);
if (x2 >= x1 && y2 >= y1)
return new Rect (x1, y1, x2 - x1, y2 - y1);
else
return new Rect ();
}
public Rect Inflate (Rect rect, int x, int y)
{
rect.x -= x;
rect.y -= y;
rect.width += (2 * x);
rect.height += (2 * y);
return rect;
}
#endif
/// <summary>
/// Raises the disable event.
/// </summary>
void OnDisable ()
{
webCamTextureToMatHelper.Dispose ();
}
/// <summary>
/// Raises the back button event.
/// </summary>
public void OnBackButton ()
{
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
SceneManager.LoadScene ("HoloLensWithOpenCVForUnityExample");
#else
Application.LoadLevel ("HoloLensWithOpenCVForUnityExample");
#endif
}
/// <summary>
/// Raises the play button event.
/// </summary>
public void OnPlayButton ()
{
webCamTextureToMatHelper.Play ();
}
/// <summary>
/// Raises the pause button event.
/// </summary>
public void OnPauseButton ()
{
webCamTextureToMatHelper.Pause ();
}
/// <summary>
/// Raises the stop button event.
/// </summary>
public void OnStopButton ()
{
webCamTextureToMatHelper.Stop ();
}
/// <summary>
/// Raises the change camera button event.
/// </summary>
public void OnChangeCameraButton ()
{
webCamTextureToMatHelper.Init (null, webCamTextureToMatHelper.requestWidth, webCamTextureToMatHelper.requestHeight, !webCamTextureToMatHelper.requestIsFrontFacing);
}
public struct Parameters
{
//public int minObjectSize;
//public int maxObjectSize;
//public float scaleFactor;
//public int minNeighbors;
public int maxTrackLifetime;
//public int minDetectionPeriod; //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0
};
public struct InnerParameters
{
public int numLastPositionsToTrack;
public int numStepsToWaitBeforeFirstShow;
public int numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown;
public int numStepsToShowWithoutDetecting;
public float coeffTrackingWindowSize;
public float coeffObjectSizeToTrack;
public float coeffObjectSpeedUsingInPrediction;
};
public class TrackedObject
{
public PositionsVector lastPositions;
public int numDetectedFrames;
public int numFramesNotDetected;
public int id;
static private int _id = 0;
public TrackedObject (OpenCVForUnity.Rect rect)
{
lastPositions = new PositionsVector ();
numDetectedFrames = 1;
numFramesNotDetected = 0;
lastPositions.Add (rect.clone ());
_id = getNextId ();
id = _id;
}
static int getNextId ()
{
_id++;
return _id;
}
}
}
}

Просмотреть файл

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 5bb34cb1364ecec44ac4e696776a544d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,328 @@
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement;
#endif
using OpenCVForUnity;
namespace HoloLensWithOpenCVForUnityExample
{
/// <summary>
/// HoloLens ComicFilter example.
/// referring to the http://dev.classmethod.jp/smartphone/opencv-manga-2/.
/// </summary>
[RequireComponent(typeof(OptimizationWebCamTextureToMatHelper))]
public class HoloLensComicFilterExample : MonoBehaviour
{
/// <summary>
/// The gray mat.
/// </summary>
Mat grayMat;
/// <summary>
/// The line mat.
/// </summary>
Mat lineMat;
/// <summary>
/// The mask mat.
/// </summary>
Mat maskMat;
/// <summary>
/// The background mat.
/// </summary>
Mat bgMat;
/// <summary>
/// The dst mat.
/// </summary>
Mat dstMat;
/// <summary>
/// The gray pixels.
/// </summary>
byte[] grayPixels;
/// <summary>
/// The mask pixels.
/// </summary>
byte[] maskPixels;
/// <summary>
/// The texture.
/// </summary>
Texture2D texture;
/// <summary>
/// The web cam texture to mat helper.
/// </summary>
OptimizationWebCamTextureToMatHelper webCamTextureToMatHelper;
Renderer quad_renderer = null;
OpenCVForUnity.Rect processingAreaRect;
public Vector2 outsideClippingRatio = new Vector2(0.17f, 0.19f);
public Vector2 clippingOffset = new Vector2(0.043f, -0.041f);
public float vignetteScale = 1.8f;
// Debug
// public Vector2 outsideClippingRatio = new Vector2(0.0f, 0.0f);
// public Vector2 clippingOffset = new Vector2(0.0f, 0.0f);
// public float vignetteScale = 0.3f;
Mat dstMatClippingROI;
// Use this for initialization
void Start ()
{
webCamTextureToMatHelper = gameObject.GetComponent<OptimizationWebCamTextureToMatHelper> ();
webCamTextureToMatHelper.Init ();
}
/// <summary>
/// Raises the web cam texture to mat helper inited event.
/// </summary>
public void OnWebCamTextureToMatHelperInited ()
{
Debug.Log ("OnWebCamTextureToMatHelperInited");
Mat webCamTextureMat = webCamTextureToMatHelper.GetDownScaleMat( webCamTextureToMatHelper.GetMat ());
texture = new Texture2D (webCamTextureMat.cols (), webCamTextureMat.rows (), TextureFormat.RGBA32, false);
gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
Debug.Log ("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);
processingAreaRect = new OpenCVForUnity.Rect ((int)(webCamTextureMat.cols ()*(outsideClippingRatio.x - clippingOffset.x)), (int)(webCamTextureMat.rows ()*(outsideClippingRatio.y + clippingOffset.y)),
(int)(webCamTextureMat.cols ()*(1f-outsideClippingRatio.x*2)), (int)(webCamTextureMat.rows ()*(1f-outsideClippingRatio.y*2)));
processingAreaRect = processingAreaRect.intersect (new OpenCVForUnity.Rect(0,0,webCamTextureMat.cols (),webCamTextureMat.rows ()));
dstMat = new Mat (webCamTextureMat.rows (), webCamTextureMat.cols (), CvType.CV_8UC1);
dstMatClippingROI = new Mat (dstMat, processingAreaRect);
// fill all black.
//Imgproc.rectangle (dstMat, new Point (0, 0), new Point (dstMat.width (), dstMat.height ()), new Scalar (0, 0, 0, 0), -1);
grayMat = new Mat (dstMatClippingROI.rows (), dstMatClippingROI.cols (), CvType.CV_8UC1);
lineMat = new Mat (dstMatClippingROI.rows (), dstMatClippingROI.cols (), CvType.CV_8UC1);
maskMat = new Mat (dstMatClippingROI.rows (), dstMatClippingROI.cols (), CvType.CV_8UC1);
//create a striped background.
bgMat = new Mat (dstMatClippingROI.rows (), dstMatClippingROI.cols (), CvType.CV_8UC1, new Scalar (255));
for (int i = 0; i < bgMat.rows ()*2.5f; i=i+4) {
Imgproc.line (bgMat, new Point (0, 0 + i), new Point (bgMat.cols (), -bgMat.cols () + i), new Scalar (0), 1);
}
grayPixels = new byte[grayMat.cols () * grayMat.rows () * grayMat.channels ()];
maskPixels = new byte[maskMat.cols () * maskMat.rows () * maskMat.channels ()];
quad_renderer = gameObject.GetComponent<Renderer> () as Renderer;
quad_renderer.sharedMaterial.SetTexture ("_MainTex", texture);
quad_renderer.sharedMaterial.SetVector ("_VignetteOffset", new Vector4(clippingOffset.x, clippingOffset.y));
Matrix4x4 projectionMatrix = Matrix4x4.identity;
projectionMatrix.m00 = 2.31029f;
projectionMatrix.m01 = 0.00000f;
projectionMatrix.m02 = 0.09614f;
projectionMatrix.m03 = 0.00000f;
projectionMatrix.m10 = 0.00000f;
projectionMatrix.m11 = 4.10427f;
projectionMatrix.m12 = -0.06231f;
projectionMatrix.m13 = 0.00000f;
projectionMatrix.m20 = 0.00000f;
projectionMatrix.m21 = 0.00000f;
projectionMatrix.m22 = -1.00000f;
projectionMatrix.m23 = 0.00000f;
projectionMatrix.m30 = 0.00000f;
projectionMatrix.m31 = 0.00000f;
projectionMatrix.m32 = -1.00000f;
projectionMatrix.m33 = 0.00000f;
quad_renderer.sharedMaterial.SetMatrix ("_CameraProjectionMatrix", projectionMatrix);
quad_renderer.sharedMaterial.SetFloat ("_VignetteScale", vignetteScale);
float halfOfVerticalFov = Mathf.Atan (1.0f / projectionMatrix.m11);
float aspectRatio = (1.0f / Mathf.Tan (halfOfVerticalFov)) / projectionMatrix.m00;
Debug.Log ("halfOfVerticalFov " + halfOfVerticalFov);
Debug.Log ("aspectRatio " + aspectRatio);
//
//Imgproc.rectangle (dstMat, new Point (0, 0), new Point (webCamTextureMat.width (), webCamTextureMat.height ()), new Scalar (126, 126, 126, 255), -1);
//
}
/// <summary>
/// Raises the web cam texture to mat helper disposed event.
/// </summary>
public void OnWebCamTextureToMatHelperDisposed ()
{
Debug.Log ("OnWebCamTextureToMatHelperDisposed");
grayMat.Dispose ();
lineMat.Dispose ();
maskMat.Dispose ();
bgMat.Dispose ();
dstMat.Dispose ();
dstMatClippingROI.Dispose ();
grayPixels = null;
maskPixels = null;
}
/// <summary>
/// Raises the web cam texture to mat helper error occurred event.
/// </summary>
/// <param name="errorCode">Error code.</param>
public void OnWebCamTextureToMatHelperErrorOccurred(WebCamTextureToMatHelper.ErrorCode errorCode){
Debug.Log ("OnWebCamTextureToMatHelperErrorOccurred " + errorCode);
}
// Update is called once per frame
void Update ()
{
if (webCamTextureToMatHelper.IsPlaying () && webCamTextureToMatHelper.DidUpdateThisFrame ()) {
Mat rgbaMat = webCamTextureToMatHelper.GetDownScaleMat(webCamTextureToMatHelper.GetMat ());
Mat rgbaMatClipROI = new Mat(rgbaMat, processingAreaRect);
Imgproc.cvtColor (rgbaMatClipROI, grayMat, Imgproc.COLOR_RGBA2GRAY);
bgMat.copyTo (dstMatClippingROI);
Imgproc.GaussianBlur (grayMat, lineMat, new Size (3, 3), 0);
grayMat.get (0, 0, grayPixels);
for (int i = 0; i < grayPixels.Length; i++) {
maskPixels [i] = 0;
if (grayPixels [i] < 70) {
grayPixels [i] = 0;
maskPixels [i] = 1;
} else if (70 <= grayPixels [i] && grayPixels [i] < 120) {
grayPixels [i] = 100;
} else {
grayPixels [i] = 255;
maskPixels [i] = 1;
}
}
grayMat.put (0, 0, grayPixels);
maskMat.put (0, 0, maskPixels);
grayMat.copyTo (dstMatClippingROI, maskMat);
Imgproc.Canny (lineMat, lineMat, 20, 120);
lineMat.copyTo (maskMat);
Core.bitwise_not (lineMat, lineMat);
lineMat.copyTo (dstMatClippingROI, maskMat);
// Imgproc.putText (dstMat, "W:" + dstMat.width () + " H:" + dstMat.height () + " SO:" + Screen.orientation, new Point (5, dstMat.rows () - 10), Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar (0), 2, Imgproc.LINE_AA, false);
Imgproc.cvtColor(dstMat, rgbaMat, Imgproc.COLOR_GRAY2RGBA);
//
//Imgproc.rectangle (rgbaMat, new Point (0, 0), new Point (rgbaMat.width (), rgbaMat.height ()), new Scalar (255, 0, 0, 255), 2);
//Imgproc.rectangle (rgbaMat, displayAreaClippingRect.tl(), displayAreaClippingRect.br(), new Scalar (255, 0, 0, 255), 2);
//
Utils.fastMatToTexture2D(rgbaMat, texture);
rgbaMatClipROI.Dispose ();
}
if (webCamTextureToMatHelper.IsPlaying ()) {
Matrix4x4 cameraToWorldMatrix = Camera.main.cameraToWorldMatrix;;
Matrix4x4 worldToCameraMatrix = cameraToWorldMatrix.inverse;
texture.wrapMode = TextureWrapMode.Clamp;
quad_renderer.sharedMaterial.SetMatrix ("_WorldToCameraMatrix", worldToCameraMatrix);
// Position the canvas object slightly in front
// of the real world web camera.
Vector3 position = cameraToWorldMatrix.GetColumn (3) - cameraToWorldMatrix.GetColumn (2);
// Rotate the canvas object so that it faces the user.
Quaternion rotation = Quaternion.LookRotation (-cameraToWorldMatrix.GetColumn (2), cameraToWorldMatrix.GetColumn (1));
gameObject.transform.position = position;
gameObject.transform.rotation = rotation;
}
}
/// <summary>
/// Raises the disable event.
/// </summary>
void OnDisable ()
{
webCamTextureToMatHelper.Dispose ();
}
/// <summary>
/// Raises the back button event.
/// </summary>
public void OnBackButton ()
{
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
SceneManager.LoadScene ("HoloLensWithOpenCVForUnityExample");
#else
Application.LoadLevel ("HoloLensWithOpenCVForUnityExample");
#endif
}
/// <summary>
/// Raises the play button event.
/// </summary>
public void OnPlayButton ()
{
webCamTextureToMatHelper.Play ();
}
/// <summary>
/// Raises the pause button event.
/// </summary>
public void OnPauseButton ()
{
webCamTextureToMatHelper.Pause ();
}
/// <summary>
/// Raises the stop button event.
/// </summary>
public void OnStopButton ()
{
webCamTextureToMatHelper.Stop ();
}
/// <summary>
/// Raises the change camera button event.
/// </summary>
public void OnChangeCameraButton ()
{
webCamTextureToMatHelper.Init (null, webCamTextureToMatHelper.requestWidth, webCamTextureToMatHelper.requestHeight, !webCamTextureToMatHelper.requestIsFrontFacing);
}
}
}

Просмотреть файл

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 9be3c273b791f5d4cb415aa461ec8e5f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,220 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.VR.WSA.WebCam;
using UnityEngine.VR.WSA.Input;
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement;
#endif
using OpenCVForUnity;
namespace HoloLensWithOpenCVForUnityExample
{
/// <summary>
/// HoloLens photo capture example.
/// referring to the https://forum.unity3d.com/threads/holographic-photo-blending-with-photocapture.416023/.
/// </summary>
public class HoloLensPhotoCaptureExample:MonoBehaviour
{
GestureRecognizer m_GestureRecognizer;
GameObject m_Canvas = null;
Renderer m_CanvasRenderer = null;
PhotoCapture m_PhotoCaptureObj;
CameraParameters m_CameraParameters;
bool m_CapturingPhoto = false;
Texture2D m_Texture = null;
Mat rgbaMat;
/// <summary>
/// The gray mat.
/// </summary>
Mat grayMat;
/// <summary>
/// The cascade.
/// </summary>
CascadeClassifier cascade;
/// <summary>
/// The faces.
/// </summary>
MatOfRect faces;
/// <summary>
/// The colors.
/// </summary>
Color32[] colors;
void Start ()
{
m_Canvas = GameObject.Find ("PhotoCaptureCanvas");
m_CanvasRenderer = m_Canvas.GetComponent<Renderer> () as Renderer;
Initialize ();
}
void SetupGestureRecognizer ()
{
m_GestureRecognizer = new GestureRecognizer ();
m_GestureRecognizer.SetRecognizableGestures (GestureSettings.Tap);
m_GestureRecognizer.TappedEvent += OnTappedEvent;
m_GestureRecognizer.StartCapturingGestures ();
m_CapturingPhoto = false;
}
void Initialize ()
{
Debug.Log ("Initializing...");
List<Resolution> resolutions = new List<Resolution> (PhotoCapture.SupportedResolutions);
Resolution selectedResolution = resolutions [1];
foreach (var item in resolutions) {
Debug.Log ("resolution width " + item.width + " height " + item.height);
}
m_CameraParameters = new CameraParameters (WebCamMode.PhotoMode);
m_CameraParameters.cameraResolutionWidth = selectedResolution.width;
m_CameraParameters.cameraResolutionHeight = selectedResolution.height;
m_CameraParameters.hologramOpacity = 0.0f;
m_CameraParameters.pixelFormat = CapturePixelFormat.BGRA32;
m_Texture = new Texture2D (selectedResolution.width, selectedResolution.height, TextureFormat.BGRA32, false);
rgbaMat = new Mat (m_Texture.height, m_Texture.width, CvType.CV_8UC4);
colors = new Color32[rgbaMat.cols () * rgbaMat.rows ()];
grayMat = new Mat (rgbaMat.rows (), rgbaMat.cols (), CvType.CV_8UC1);
faces = new MatOfRect ();
cascade = new CascadeClassifier ();
cascade.load (Utils.getFilePath ("haarcascade_frontalface_alt.xml"));
PhotoCapture.CreateAsync (false, OnCreatedPhotoCaptureObject);
}
void OnCreatedPhotoCaptureObject (PhotoCapture captureObject)
{
m_PhotoCaptureObj = captureObject;
m_PhotoCaptureObj.StartPhotoModeAsync (m_CameraParameters, OnStartPhotoMode);
}
void OnStartPhotoMode (PhotoCapture.PhotoCaptureResult result)
{
SetupGestureRecognizer ();
Debug.Log ("Ready!");
Debug.Log ("Air Tap to take a picture.");
}
void OnTappedEvent (InteractionSourceKind source, int tapCount, Ray headRay)
{
if (m_CapturingPhoto) {
return;
}
m_CapturingPhoto = true;
Debug.Log ("Taking picture...");
m_PhotoCaptureObj.TakePhotoAsync (OnPhotoCaptured);
}
void OnPhotoCaptured (PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)
{
Matrix4x4 cameraToWorldMatrix;
photoCaptureFrame.TryGetCameraToWorldMatrix (out cameraToWorldMatrix);
Matrix4x4 worldToCameraMatrix = cameraToWorldMatrix.inverse;
Matrix4x4 projectionMatrix;
photoCaptureFrame.TryGetProjectionMatrix (out projectionMatrix);
photoCaptureFrame.UploadImageDataToTexture (m_Texture);
Utils.texture2DToMat (m_Texture, rgbaMat);
Imgproc.cvtColor (rgbaMat, grayMat, Imgproc.COLOR_RGBA2GRAY);
Imgproc.equalizeHist (grayMat, grayMat);
// fill all black.
// Imgproc.rectangle (rgbaMat, new Point (0, 0), new Point (rgbaMat.width (), rgbaMat.height ()), new Scalar (0, 0, 0, 0), -1);
// draw an edge lines.
Imgproc.rectangle (rgbaMat, new Point (0, 0), new Point (rgbaMat.width (), rgbaMat.height ()), new Scalar (255, 0, 0, 255), 2);
// draw a diagonal line.
// Imgproc.line (rgbaMat, new Point (0, 0), new Point (rgbaMat.cols (), rgbaMat.rows ()), new Scalar (255, 0, 0, 255));
if (cascade != null)
cascade.detectMultiScale (grayMat, faces, 1.1, 2, 2, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size (grayMat.cols () * 0.05, grayMat.rows () * 0.05), new Size ());
OpenCVForUnity.Rect[] rects = faces.toArray ();
for (int i = 0; i < rects.Length; i++) {
// Debug.Log ("detect faces " + rects [i]);
Imgproc.rectangle (rgbaMat, new Point (rects [i].x, rects [i].y), new Point (rects [i].x + rects [i].width, rects [i].y + rects [i].height), new Scalar (255, 0, 0, 255), 2);
}
Imgproc.putText (rgbaMat, "W:" + rgbaMat.width () + " H:" + rgbaMat.height () + " SO:" + Screen.orientation, new Point (5, rgbaMat.rows () - 10), Core.FONT_HERSHEY_SIMPLEX, 1.5, new Scalar (0, 255, 0, 255), 2, Imgproc.LINE_AA, false);
Utils.matToTexture2D (rgbaMat, m_Texture, colors);
m_Texture.wrapMode = TextureWrapMode.Clamp;
m_CanvasRenderer.sharedMaterial.SetTexture ("_MainTex", m_Texture);
m_CanvasRenderer.sharedMaterial.SetMatrix ("_WorldToCameraMatrix", worldToCameraMatrix);
m_CanvasRenderer.sharedMaterial.SetMatrix ("_CameraProjectionMatrix", projectionMatrix);
m_CanvasRenderer.sharedMaterial.SetFloat ("_VignetteScale", 0.0f);
// Position the canvas object slightly in front
// of the real world web camera.
Vector3 position = cameraToWorldMatrix.GetColumn (3) - cameraToWorldMatrix.GetColumn (2);
// Rotate the canvas object so that it faces the user.
Quaternion rotation = Quaternion.LookRotation (-cameraToWorldMatrix.GetColumn (2), cameraToWorldMatrix.GetColumn (1));
m_Canvas.transform.position = position;
m_Canvas.transform.rotation = rotation;
Debug.Log ("Took picture!");
m_CapturingPhoto = false;
}
/// <summary>
/// Raises the disable event.
/// </summary>
void OnDisable ()
{
if (m_GestureRecognizer != null && m_GestureRecognizer.IsCapturingGestures()) {
m_GestureRecognizer.StopCapturingGestures ();
m_GestureRecognizer.TappedEvent -= OnTappedEvent;
m_GestureRecognizer.Dispose ();
}
if (rgbaMat != null)
rgbaMat.Dispose ();
if (grayMat != null)
grayMat.Dispose ();
if (cascade != null)
cascade.Dispose ();
}
/// <summary>
/// Raises the back button event.
/// </summary>
public void OnBackButton ()
{
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
SceneManager.LoadScene ("HoloLensWithOpenCVForUnityExample");
#else
Application.LoadLevel ("HoloLensWithOpenCVForUnityExample");
#endif
}
}
}

Просмотреть файл

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4ef4a715f18c9dd47915d7a51859c1ff
timeCreated: 1486374533
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,996 @@
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement;
#endif
using OpenCVForUnity;
using Rect = OpenCVForUnity.Rect;
#if UNITY_WSA
#if NETFX_CORE
using System.Threading;
using System.Threading.Tasks;
#else
#endif
#else
using System.Threading;
#endif
using PositionsVector = System.Collections.Generic.List<OpenCVForUnity.Rect>;
namespace HoloLensWithOpenCVForUnityExample
{
/// <summary>
/// HoloLens webCamTexture async detect face example.
/// This cord referred to https://github.com/Itseez/opencv/blob/master/modules/objdetect/src/detection_based_tracker.cpp.
/// </summary>
[RequireComponent(typeof(OptimizationWebCamTextureToMatHelper))]
public class HoloLensWebCamTextureAsyncDetectFaceExample : MonoBehaviour
{
/// <summary>
/// The gray mat.
/// </summary>
Mat grayMat;
/// <summary>
/// The texture.
/// </summary>
Texture2D texture;
#if !UNITY_WEBGL || UNITY_EDITOR
/// <summary>
/// The cascade.
/// </summary>
CascadeClassifier cascade;
Rect[] rectsWhereRegions;
private List<TrackedObject> trackedObjects = new List<TrackedObject> ();
private List<float> weightsPositionsSmoothing = new List<float> ();
private List<float> weightsSizesSmoothing = new List<float> ();
private Parameters parameters;
private InnerParameters innerParameters;
private volatile ThreadComm threadComm = new ThreadComm ();
private System.Object thisLock = new System.Object ();
private volatile bool isThreadRunning = false;
private Mat grayMat4Thread;
private CascadeClassifier regionCascade;
List<Rect> detectedObjectsInRegions = new List<Rect> ();
List<Rect> resultObjects = new List<Rect> ();
private volatile bool didUpdateTheDetectionResult = false;
private MatOfRect resultDetect;
#endif
// for Thread
#if UNITY_WSA
#if NETFX_CORE
private Task task_ = null;
private CancellationTokenSource tokenSource_ = null;
#else
#endif
#elif !UNITY_WEBGL || UNITY_EDITOR
private volatile bool shouldStopThread = false;
#endif
/// <summary>
/// The web cam texture to mat helper.
/// </summary>
OptimizationWebCamTextureToMatHelper webCamTextureToMatHelper;
Renderer quad_renderer = null;
OpenCVForUnity.Rect processingAreaRect;
// public Vector2 outsideClippingRatio = new Vector2(0.17f, 0.19f);
public Vector2 outsideClippingRatio = new Vector2(0.043f, 0.041f);
public Vector2 clippingOffset = new Vector2(0.043f, -0.041f);
/// <summary>
/// The is showing webcam image.
/// </summary>
public bool isShowingWebCamImage = false;
/// <summary>
/// The is showing webcam image toggle.
/// </summary>
public Toggle isShowingWebCamImageToggle;
/// <summary>
/// The is showing debug face rects.
/// </summary>
public bool isShowingDebugFaceRects = false;
/// <summary>
/// The is showing debug face rects toggle.
/// </summary>
public Toggle isShowingDebugFaceRectsToggle;
// Use this for initialization
void Start ()
{
#if !UNITY_WEBGL || UNITY_EDITOR
weightsPositionsSmoothing.Add (1);
weightsSizesSmoothing.Add (0.5f);
weightsSizesSmoothing.Add (0.3f);
weightsSizesSmoothing.Add (0.2f);
//parameters.minObjectSize = 96;
//parameters.maxObjectSize = int.MaxValue;
//parameters.scaleFactor = 1.1f;
//parameters.minNeighbors = 2;
parameters.maxTrackLifetime = 5;
innerParameters.numLastPositionsToTrack = 4;
innerParameters.numStepsToWaitBeforeFirstShow = 6;
innerParameters.numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown = 3;
innerParameters.numStepsToShowWithoutDetecting = 3;
innerParameters.coeffTrackingWindowSize = 2.0f;
innerParameters.coeffObjectSizeToTrack = 0.85f;
innerParameters.coeffObjectSpeedUsingInPrediction = 0.8f;
#endif
webCamTextureToMatHelper = gameObject.GetComponent<OptimizationWebCamTextureToMatHelper> ();
webCamTextureToMatHelper.Init ();
}
/// <summary>
/// Raises the web cam texture to mat helper inited event.
/// </summary>
public void OnWebCamTextureToMatHelperInited ()
{
Debug.Log ("OnWebCamTextureToMatHelperInited");
Mat webCamTextureMat = webCamTextureToMatHelper.GetDownScaleMat(webCamTextureToMatHelper.GetMat ());
texture = new Texture2D (webCamTextureMat.cols (), webCamTextureMat.rows (), TextureFormat.RGBA32, false);
gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
Debug.Log ("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);
processingAreaRect = new OpenCVForUnity.Rect ((int)(webCamTextureMat.cols ()*(outsideClippingRatio.x - clippingOffset.x)), (int)(webCamTextureMat.rows ()*(outsideClippingRatio.y + clippingOffset.y)),
(int)(webCamTextureMat.cols ()*(1f-outsideClippingRatio.x*2)), (int)(webCamTextureMat.rows ()*(1f-outsideClippingRatio.y*2)));
processingAreaRect = processingAreaRect.intersect (new OpenCVForUnity.Rect(0,0,webCamTextureMat.cols (),webCamTextureMat.rows ()));
quad_renderer = gameObject.GetComponent<Renderer> () as Renderer;
quad_renderer.sharedMaterial.SetTexture ("_MainTex", texture);
quad_renderer.sharedMaterial.SetVector ("_VignetteOffset", new Vector4(clippingOffset.x, clippingOffset.y));
Matrix4x4 projectionMatrix = Matrix4x4.identity;
projectionMatrix.m00 = 2.31029f;
projectionMatrix.m01 = 0.00000f;
projectionMatrix.m02 = 0.09614f;
projectionMatrix.m03 = 0.00000f;
projectionMatrix.m10 = 0.00000f;
projectionMatrix.m11 = 4.10427f;
projectionMatrix.m12 = -0.06231f;
projectionMatrix.m13 = 0.00000f;
projectionMatrix.m20 = 0.00000f;
projectionMatrix.m21 = 0.00000f;
projectionMatrix.m22 = -1.00000f;
projectionMatrix.m23 = 0.00000f;
projectionMatrix.m30 = 0.00000f;
projectionMatrix.m31 = 0.00000f;
projectionMatrix.m32 = -1.00000f;
projectionMatrix.m33 = 0.00000f;
quad_renderer.sharedMaterial.SetMatrix ("_CameraProjectionMatrix", projectionMatrix);
quad_renderer.sharedMaterial.SetFloat ("_VignetteScale", 0.0f);
#if !UNITY_WEBGL || UNITY_EDITOR
grayMat = new Mat (webCamTextureMat.rows (), webCamTextureMat.cols (), CvType.CV_8UC1);
regionCascade = new CascadeClassifier ();
regionCascade.load (Utils.getFilePath ("lbpcascade_frontalface.xml"));
if (regionCascade.empty ()) {
Debug.LogError ("cascade file is not loaded.Please copy from “OpenCVForUnity/StreamingAssets/” to “Assets/StreamingAssets/” folder. ");
}
initThread ();
#endif
}
/// <summary>
/// Raises the web cam texture to mat helper disposed event.
/// </summary>
public void OnWebCamTextureToMatHelperDisposed ()
{
Debug.Log ("OnWebCamTextureToMatHelperDisposed");
#if !UNITY_WEBGL || UNITY_EDITOR
StopThread ();
if (grayMat4Thread != null)
grayMat4Thread.Dispose ();
if (cascade != null)
cascade.Dispose ();
if (grayMat != null)
grayMat.Dispose ();
if (regionCascade != null)
regionCascade.Dispose ();
#endif
}
/// <summary>
/// Raises the web cam texture to mat helper error occurred event.
/// </summary>
/// <param name="errorCode">Error code.</param>
public void OnWebCamTextureToMatHelperErrorOccurred(WebCamTextureToMatHelper.ErrorCode errorCode){
Debug.Log ("OnWebCamTextureToMatHelperErrorOccurred " + errorCode);
}
// Update is called once per frame
void Update ()
{
#if !UNITY_WEBGL || UNITY_EDITOR
if (webCamTextureToMatHelper.IsPlaying () && webCamTextureToMatHelper.DidUpdateThisFrame ()) {
Mat rgbaMat = webCamTextureToMatHelper.GetDownScaleMat(webCamTextureToMatHelper.GetMat ());
Mat rgbaMatClipROI = new Mat(rgbaMat, processingAreaRect);
Imgproc.cvtColor (rgbaMatClipROI, grayMat, Imgproc.COLOR_RGBA2GRAY);
if (!isShowingWebCamImage) {
// fill all black.
Imgproc.rectangle (rgbaMatClipROI, new Point (0, 0), new Point (rgbaMat.width (), rgbaMat.height ()), new Scalar (0, 0, 0, 0), -1);
}
Imgproc.equalizeHist (grayMat, grayMat);
if (!threadComm.shouldDetectInMultiThread) {
grayMat.copyTo (grayMat4Thread);
threadComm.shouldDetectInMultiThread = true;
}
OpenCVForUnity.Rect[] rects;
if (didUpdateTheDetectionResult) {
didUpdateTheDetectionResult = false;
lock (thisLock) {
//Debug.Log("DetectionBasedTracker::process: get _rectsWhereRegions were got from resultDetect");
rectsWhereRegions = resultDetect.toArray ();
rects = resultDetect.toArray ();
}
if(isShowingDebugFaceRects) {
for (int i = 0; i < rects.Length; i++) {
Imgproc.rectangle (rgbaMatClipROI, new Point (rects [i].x, rects [i].y), new Point (rects [i].x + rects [i].width, rects [i].y + rects [i].height), new Scalar (0, 0, 255, 255), 2);
}
}
} else {
//Debug.Log("DetectionBasedTracker::process: get _rectsWhereRegions from previous positions");
rectsWhereRegions = new Rect[trackedObjects.Count];
for (int i = 0; i < trackedObjects.Count; i++) {
int n = trackedObjects [i].lastPositions.Count;
//if (n > 0) UnityEngine.Debug.LogError("n > 0 is false");
Rect r = trackedObjects [i].lastPositions [n - 1].clone ();
if (r.area () == 0) {
Debug.Log ("DetectionBasedTracker::process: ERROR: ATTENTION: strange algorithm's behavior: trackedObjects[i].rect() is empty");
continue;
}
//correction by speed of rectangle
if (n > 1) {
Point center = centerRect (r);
Point center_prev = centerRect (trackedObjects [i].lastPositions [n - 2]);
Point shift = new Point ((center.x - center_prev.x) * innerParameters.coeffObjectSpeedUsingInPrediction,
(center.y - center_prev.y) * innerParameters.coeffObjectSpeedUsingInPrediction);
r.x += (int)Math.Round (shift.x);
r.y += (int)Math.Round (shift.y);
}
rectsWhereRegions [i] = r;
}
rects = rectsWhereRegions;
if(isShowingDebugFaceRects) {
for (int i = 0; i < rects.Length; i++) {
Imgproc.rectangle (rgbaMatClipROI, new Point (rects [i].x, rects [i].y), new Point (rects [i].x + rects [i].width, rects [i].y + rects [i].height), new Scalar (0, 255, 0, 255), 2);
}
}
}
if (rectsWhereRegions.Length > 0) {
detectedObjectsInRegions.Clear ();
int len = rectsWhereRegions.Length;
for (int i = 0; i < len; i++) {
detectInRegion (grayMat, rectsWhereRegions [i], detectedObjectsInRegions);
}
}
updateTrackedObjects (detectedObjectsInRegions);
getObjects (resultObjects);
//getSmoothingObjects (resultObjects);
rects = resultObjects.ToArray ();
for (int i = 0; i < rects.Length; i++) {
//Debug.Log ("detect faces " + rects [i]);
Imgproc.rectangle (rgbaMatClipROI, new Point (rects [i].x, rects [i].y), new Point (rects [i].x + rects [i].width, rects [i].y + rects [i].height), new Scalar (255, 0, 0, 255), 2);
}
if(isShowingDebugFaceRects)
{
Imgproc.rectangle (rgbaMat, new Point (0, 0), new Point (rgbaMat.width (), rgbaMat.height ()), new Scalar (255, 0, 0, 255), 2);
Imgproc.rectangle (rgbaMat, processingAreaRect.tl(), processingAreaRect.br(), new Scalar (255, 0, 0, 255), 2);
}
Utils.matToTexture2D (rgbaMat, texture, webCamTextureToMatHelper.GetBufferColors ());
rgbaMatClipROI.Dispose ();
}
if (webCamTextureToMatHelper.IsPlaying ()) {
Matrix4x4 cameraToWorldMatrix = Camera.main.cameraToWorldMatrix;;
Matrix4x4 worldToCameraMatrix = cameraToWorldMatrix.inverse;
texture.wrapMode = TextureWrapMode.Clamp;
quad_renderer.sharedMaterial.SetMatrix ("_WorldToCameraMatrix", worldToCameraMatrix);
// Position the canvas object slightly in front
// of the real world web camera.
Vector3 position = cameraToWorldMatrix.GetColumn (3) - cameraToWorldMatrix.GetColumn (2);
// Rotate the canvas object so that it faces the user.
Quaternion rotation = Quaternion.LookRotation (-cameraToWorldMatrix.GetColumn (2), cameraToWorldMatrix.GetColumn (1));
gameObject.transform.position = position;
gameObject.transform.rotation = rotation;
}
#else
if (webCamTextureToMatHelper.IsPlaying () && webCamTextureToMatHelper.DidUpdateThisFrame ()) {
Mat rgbaMat = webCamTextureToMatHelper.GetMat ();
Imgproc.putText (rgbaMat, "WebGL platform does not support multi-threading.", new Point (5, rgbaMat.rows () - 10), Core.FONT_HERSHEY_SIMPLEX, 0.5, new Scalar (255, 255, 255, 255), 1, Imgproc.LINE_AA, false);
Utils.matToTexture2D (rgbaMat, texture, webCamTextureToMatHelper.GetBufferColors ());
}
#endif
}
#if !UNITY_WEBGL || UNITY_EDITOR
private void initThread ()
{
StopThread ();
grayMat4Thread = new Mat ();
cascade = new CascadeClassifier ();
cascade.load(Utils.getFilePath ("haarcascade_frontalface_alt.xml"));
if (cascade.empty ()) {
Debug.LogError ("cascade file is not loaded.Please copy from “OpenCVForUnity/StreamingAssets/” to “Assets/StreamingAssets/” folder. ");
}
threadComm.shouldDetectInMultiThread = false;
StartThread ();
}
#if UNITY_WSA
#if NETFX_CORE
private void ThreadWorker()
{
if (isThreadRunning) return;
Debug.Log("Thread Start");
isThreadRunning = true;
threadComm.shouldDetectInMultiThread = false;
didUpdateTheDetectionResult = false;
tokenSource_ = new CancellationTokenSource();
task_ =Task.Factory.StartNew(
(o)=>
{
ThreadComm comm = o as ThreadComm;
while(true)
{
tokenSource_.Token.ThrowIfCancellationRequested();
if(!comm.shouldDetectInMultiThread) continue;
MatOfRect faces = new MatOfRect();
if (cascade != null)
cascade.detectMultiScale(grayMat4Thread, faces, 1.1, 2, Objdetect.CASCADE_SCALE_IMAGE, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(grayMat4Thread.height() * 0.1, grayMat4Thread.height() * 0.1), new Size());
lock (thisLock){
resultDetect = faces;
}
comm.shouldDetectInMultiThread = false;
didUpdateTheDetectionResult = true;
}
}
, threadComm
, tokenSource_.Token
).ContinueWith(t =>
{
tokenSource_.Dispose();
tokenSource_ = null;
isThreadRunning = false;
});
}
#else
private void ThreadWorker()
{
if (isThreadRunning) return;
Debug.Log("Thread Start");
isThreadRunning = true;
threadComm.shouldDetectInMultiThread = false;
didUpdateTheDetectionResult = false;
StartCoroutine("ThreadCoroutine", threadComm);
}
IEnumerator ThreadCoroutine(System.Object o)
{
ThreadComm comm = o as ThreadComm;
while (true)
{
while (!comm.shouldDetectInMultiThread) { yield return null; }
MatOfRect faces = new MatOfRect();
if (cascade != null)
cascade.detectMultiScale(grayMat4Thread, faces, 1.1, 2, Objdetect.CASCADE_SCALE_IMAGE, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size(grayMat4Thread.height() * 0.1, grayMat4Thread.height() * 0.1), new Size());
lock (thisLock){
resultDetect = faces;
}
comm.shouldDetectInMultiThread = false;
didUpdateTheDetectionResult = true;
}
}
#endif
#else
private void ThreadWorker ()
{
if (isThreadRunning)
return;
Debug.Log ("Thread Start");
isThreadRunning = true;
shouldStopThread = false;
threadComm.shouldDetectInMultiThread = false;
didUpdateTheDetectionResult = false;
ThreadPool.QueueUserWorkItem (_ThreadWorker, threadComm);
}
private void _ThreadWorker (System.Object o)
{
ThreadComm comm = o as ThreadComm;
while (!shouldStopThread) {
if (!comm.shouldDetectInMultiThread)
continue;
MatOfRect faces = new MatOfRect ();
if (cascade != null)
cascade.detectMultiScale (grayMat4Thread, faces, 1.1, 2, Objdetect.CASCADE_SCALE_IMAGE, // TODO: objdetect.CV_HAAR_SCALE_IMAGE
new Size (grayMat4Thread.height () * 0.1, grayMat4Thread.height () * 0.1), new Size ());
//Thread.Sleep(200);
lock (thisLock) {
resultDetect = faces;
}
comm.shouldDetectInMultiThread = false;
didUpdateTheDetectionResult = true;
}
isThreadRunning = false;
}
#endif
public class ThreadComm : System.Object
{
public bool shouldDetectInMultiThread = false;
}
public void StartThread ()
{
ThreadWorker ();
}
public void StopThread ()
{
if (!isThreadRunning)
return;
#if UNITY_WSA
#if NETFX_CORE
tokenSource_.Cancel();
task_ = null;
#else
StopCoroutine("ThreadCoroutine");
isThreadRunning = false;
#endif
#else
shouldStopThread = true;
#endif
while (isThreadRunning) {
//Wait threading stop
}
Debug.Log ("Thread Stop");
}
private void getObjects (List<Rect> result)
{
result.Clear ();
for (int i = 0; i < trackedObjects.Count; i++) {
if ((trackedObjects [i].numDetectedFrames <= innerParameters.numStepsToWaitBeforeFirstShow)
|| (trackedObjects [i].numFramesNotDetected > innerParameters.numStepsToShowWithoutDetecting)) {
}else{
result.Add(trackedObjects[i].lastPositions[trackedObjects[i].lastPositions.Count - 1]);
}
}
}
private void getSmoothingObjects (List<Rect> result)
{
result.Clear ();
for (int i = 0; i < trackedObjects.Count; i++) {
Rect r = calcTrackedObjectPositionToShow (i);
if (r.area () == 0) {
continue;
}
result.Add (r);
//LOGD("DetectionBasedTracker::process: found a object with SIZE %d x %d, rect={%d, %d, %d x %d}", r.width, r.height, r.x, r.y, r.width, r.height);
}
}
public enum TrackedState : int
{
NEW_RECTANGLE = -1,
INTERSECTED_RECTANGLE = -2
}
private void updateTrackedObjects (List<Rect> detectedObjects)
{
int N1 = (int)trackedObjects.Count;
int N2 = (int)detectedObjects.Count;
for (int i = 0; i < N1; i++) {
trackedObjects [i].numDetectedFrames++;
}
int[] correspondence = new int[N2];
for (int i = 0; i < N2; i++) {
correspondence [i] = (int)TrackedState.NEW_RECTANGLE;
}
for (int i = 0; i < N1; i++) {
TrackedObject curObject = trackedObjects [i];
int bestIndex = -1;
int bestArea = -1;
int numpositions = (int)curObject.lastPositions.Count;
//if (numpositions > 0) UnityEngine.Debug.LogError("numpositions > 0 is false");
Rect prevRect = curObject.lastPositions [numpositions - 1];
for (int j = 0; j < N2; j++) {
if (correspondence [j] >= 0) {
//Debug.Log("DetectionBasedTracker::updateTrackedObjects: j=" + i + " is rejected, because it has correspondence=" + correspondence[j]);
continue;
}
if (correspondence [j] != (int)TrackedState.NEW_RECTANGLE) {
//Debug.Log("DetectionBasedTracker::updateTrackedObjects: j=" + j + " is rejected, because it is intersected with another rectangle");
continue;
}
Rect r = Intersect (prevRect, detectedObjects [j]);
if ((r.width > 0) && (r.height > 0)) {
//LOGD("DetectionBasedTracker::updateTrackedObjects: There is intersection between prevRect and detectedRect, r={%d, %d, %d x %d}",
// r.x, r.y, r.width, r.height);
correspondence [j] = (int)TrackedState.INTERSECTED_RECTANGLE;
if (r.area () > bestArea) {
//LOGD("DetectionBasedTracker::updateTrackedObjects: The area of intersection is %d, it is better than bestArea=%d", r.area(), bestArea);
bestIndex = j;
bestArea = (int)r.area ();
}
}
}
if (bestIndex >= 0) {
//LOGD("DetectionBasedTracker::updateTrackedObjects: The best correspondence for i=%d is j=%d", i, bestIndex);
correspondence [bestIndex] = i;
for (int j = 0; j < N2; j++) {
if (correspondence [j] >= 0)
continue;
Rect r = Intersect (detectedObjects [j], detectedObjects [bestIndex]);
if ((r.width > 0) && (r.height > 0)) {
//LOGD("DetectionBasedTracker::updateTrackedObjects: Found intersection between "
// "rectangles j=%d and bestIndex=%d, rectangle j=%d is marked as intersected", j, bestIndex, j);
correspondence [j] = (int)TrackedState.INTERSECTED_RECTANGLE;
}
}
} else {
//LOGD("DetectionBasedTracker::updateTrackedObjects: There is no correspondence for i=%d ", i);
curObject.numFramesNotDetected++;
}
}
//LOGD("DetectionBasedTracker::updateTrackedObjects: start second cycle");
for (int j = 0; j < N2; j++) {
int i = correspondence [j];
if (i >= 0) {//add position
//Debug.Log("DetectionBasedTracker::updateTrackedObjects: add position");
trackedObjects [i].lastPositions.Add (detectedObjects [j]);
while ((int)trackedObjects [i].lastPositions.Count > (int)innerParameters.numLastPositionsToTrack) {
trackedObjects [i].lastPositions.Remove (trackedObjects [i].lastPositions [0]);
}
trackedObjects [i].numFramesNotDetected = 0;
} else if (i == (int)TrackedState.NEW_RECTANGLE) { //new object
//Debug.Log("DetectionBasedTracker::updateTrackedObjects: new object");
trackedObjects.Add (new TrackedObject (detectedObjects [j]));
} else {
Debug.Log ("DetectionBasedTracker::updateTrackedObjects: was auxiliary intersection");
}
}
int t = 0;
TrackedObject it;
while (t < trackedObjects.Count) {
it = trackedObjects [t];
if ((it.numFramesNotDetected > parameters.maxTrackLifetime)
||
((it.numDetectedFrames <= innerParameters.numStepsToWaitBeforeFirstShow)
&&
(it.numFramesNotDetected > innerParameters.numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown))) {
//int numpos = (int)it.lastPositions.Count;
//if (numpos > 0) UnityEngine.Debug.LogError("numpos > 0 is false");
//Rect r = it.lastPositions [numpos - 1];
//Debug.Log("DetectionBasedTracker::updateTrackedObjects: deleted object " + r.x + " " + r.y + " " + r.width + " " + r.height);
trackedObjects.Remove (it);
} else {
t++;
}
}
}
private void detectInRegion (Mat img, Rect r, List<Rect> detectedObjectsInRegions)
{
Rect r0 = new Rect (new Point (), img.size ());
Rect r1 = new Rect (r.x, r.y, r.width, r.height);
Inflate (r1, (int)((r1.width * innerParameters.coeffTrackingWindowSize) - r1.width) / 2,
(int)((r1.height * innerParameters.coeffTrackingWindowSize) - r1.height) / 2);
r1 = Intersect (r0, r1);
if ((r1.width <= 0) || (r1.height <= 0)) {
Debug.Log ("DetectionBasedTracker::detectInRegion: Empty intersection");
return;
}
int d = Math.Min (r.width, r.height);
d = (int)Math.Round (d * innerParameters.coeffObjectSizeToTrack);
MatOfRect tmpobjects = new MatOfRect ();
Mat img1 = new Mat (img, r1);//subimage for rectangle -- without data copying
regionCascade.detectMultiScale (img1, tmpobjects, 1.1, 2, 0 | Objdetect.CASCADE_DO_CANNY_PRUNING | Objdetect.CASCADE_SCALE_IMAGE | Objdetect.CASCADE_FIND_BIGGEST_OBJECT, new Size (d, d), new Size ());
Rect[] tmpobjectsArray = tmpobjects.toArray ();
int len = tmpobjectsArray.Length;
for (int i = 0; i < len; i++) {
Rect tmp = tmpobjectsArray [i];
Rect curres = new Rect (new Point (tmp.x + r1.x, tmp.y + r1.y), tmp.size ());
detectedObjectsInRegions.Add (curres);
}
}
private Rect calcTrackedObjectPositionToShow (int i)
{
if ((i < 0) || (i >= trackedObjects.Count)) {
Debug.Log ("DetectionBasedTracker::calcTrackedObjectPositionToShow: ERROR: wrong i=" + i);
return new Rect ();
}
if (trackedObjects [i].numDetectedFrames <= innerParameters.numStepsToWaitBeforeFirstShow) {
//Debug.Log("DetectionBasedTracker::calcTrackedObjectPositionToShow: " + "trackedObjects[" + i + "].numDetectedFrames=" + trackedObjects[i].numDetectedFrames + " <= numStepsToWaitBeforeFirstShow=" + innerParameters.numStepsToWaitBeforeFirstShow + " --- return empty Rect()");
return new Rect ();
}
if (trackedObjects [i].numFramesNotDetected > innerParameters.numStepsToShowWithoutDetecting) {
return new Rect ();
}
List<Rect> lastPositions = trackedObjects [i].lastPositions;
int N = lastPositions.Count;
if (N <= 0) {
Debug.Log ("DetectionBasedTracker::calcTrackedObjectPositionToShow: ERROR: no positions for i=" + i);
return new Rect ();
}
int Nsize = Math.Min (N, (int)weightsSizesSmoothing.Count);
int Ncenter = Math.Min (N, (int)weightsPositionsSmoothing.Count);
Point center = new Point ();
double w = 0, h = 0;
if (Nsize > 0) {
double sum = 0;
for (int j = 0; j < Nsize; j++) {
int k = N - j - 1;
w += lastPositions [k].width * weightsSizesSmoothing [j];
h += lastPositions [k].height * weightsSizesSmoothing [j];
sum += weightsSizesSmoothing [j];
}
w /= sum;
h /= sum;
} else {
w = lastPositions [N - 1].width;
h = lastPositions [N - 1].height;
}
if (Ncenter > 0) {
double sum = 0;
for (int j = 0; j < Ncenter; j++) {
int k = N - j - 1;
Point tl = lastPositions [k].tl ();
Point br = lastPositions [k].br ();
Point c1;
//c1=tl;
//c1=c1* 0.5f;//
c1 = new Point (tl.x * 0.5f, tl.y * 0.5f);
Point c2;
//c2=br;
//c2=c2*0.5f;
c2 = new Point (br.x * 0.5f, br.y * 0.5f);
//c1=c1+c2;
c1 = new Point (c1.x + c2.x, c1.y + c2.y);
//center=center+ (c1 * weightsPositionsSmoothing[j]);
center = new Point (center.x + (c1.x * weightsPositionsSmoothing [j]), center.y + (c1.y * weightsPositionsSmoothing [j]));
sum += weightsPositionsSmoothing [j];
}
//center *= (float)(1 / sum);
center = new Point (center.x * (1 / sum), center.y * (1 / sum));
} else {
int k = N - 1;
Point tl = lastPositions [k].tl ();
Point br = lastPositions [k].br ();
Point c1;
//c1=tl;
//c1=c1* 0.5f;
c1 = new Point (tl.x * 0.5f, tl.y * 0.5f);
Point c2;
//c2=br;
//c2=c2*0.5f;
c2 = new Point (br.x * 0.5f, br.y * 0.5f);
//center=c1+c2;
center = new Point (c1.x + c2.x, c1.y + c2.y);
}
//Point2f tl=center-(Point2f(w,h)*0.5);
Point tl2 = new Point (center.x - (w * 0.5f), center.y - (h * 0.5f));
//Rect res(cvRound(tl.x), cvRound(tl.y), cvRound(w), cvRound(h));
Rect res = new Rect ((int)Math.Round (tl2.x), (int)Math.Round (tl2.y), (int)Math.Round (w), (int)Math.Round (h));
//LOGD("DetectionBasedTracker::calcTrackedObjectPositionToShow: Result for i=%d: {%d, %d, %d x %d}", i, res.x, res.y, res.width, res.height);
return res;
}
public Point centerRect (Rect r)
{
return new Point (r.x + (r.width / 2), r.y + (r.height / 2));
}
public Rect Intersect (Rect a, Rect b)
{
int x1 = Math.Max (a.x, b.x);
int x2 = Math.Min (a.x + a.width, b.x + b.width);
int y1 = Math.Max (a.y, b.y);
int y2 = Math.Min (a.y + a.height, b.y + b.height);
if (x2 >= x1 && y2 >= y1)
return new Rect (x1, y1, x2 - x1, y2 - y1);
else
return new Rect ();
}
public Rect Inflate (Rect rect, int x, int y)
{
rect.x -= x;
rect.y -= y;
rect.width += (2 * x);
rect.height += (2 * y);
return rect;
}
#endif
/// <summary>
/// Raises the disable event.
/// </summary>
void OnDisable ()
{
webCamTextureToMatHelper.Dispose ();
}
/// <summary>
/// Raises the back button event.
/// </summary>
public void OnBackButton ()
{
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
SceneManager.LoadScene ("HoloLensWithOpenCVForUnityExample");
#else
Application.LoadLevel ("HoloLensWithOpenCVForUnityExample");
#endif
}
/// <summary>
/// Raises the play button event.
/// </summary>
public void OnPlayButton ()
{
webCamTextureToMatHelper.Play ();
}
/// <summary>
/// Raises the pause button event.
/// </summary>
public void OnPauseButton ()
{
webCamTextureToMatHelper.Pause ();
}
/// <summary>
/// Raises the stop button event.
/// </summary>
public void OnStopButton ()
{
webCamTextureToMatHelper.Stop ();
}
/// <summary>
/// Raises the change camera button event.
/// </summary>
public void OnChangeCameraButton ()
{
webCamTextureToMatHelper.Init (null, webCamTextureToMatHelper.requestWidth, webCamTextureToMatHelper.requestHeight, !webCamTextureToMatHelper.requestIsFrontFacing);
}
/// <summary>
/// Raises the is showing webcam image toggle event.
/// </summary>
public void OnIsShowingWebCamImageToggle ()
{
if (isShowingWebCamImageToggle.isOn) {
isShowingWebCamImage = true;
} else {
isShowingWebCamImage = false;
}
}
/// <summary>
/// Raises the is showing debug face rects toggle event.
/// </summary>
public void OnIsShowingDebugFaceRectsToggle ()
{
if (isShowingDebugFaceRectsToggle.isOn) {
isShowingDebugFaceRects = true;
} else {
isShowingDebugFaceRects = false;
}
}
public struct Parameters
{
//public int minObjectSize;
//public int maxObjectSize;
//public float scaleFactor;
//public int minNeighbors;
public int maxTrackLifetime;
//public int minDetectionPeriod; //the minimal time between run of the big object detector (on the whole frame) in ms (1000 mean 1 sec), default=0
};
public struct InnerParameters
{
public int numLastPositionsToTrack;
public int numStepsToWaitBeforeFirstShow;
public int numStepsToTrackWithoutDetectingIfObjectHasNotBeenShown;
public int numStepsToShowWithoutDetecting;
public float coeffTrackingWindowSize;
public float coeffObjectSizeToTrack;
public float coeffObjectSpeedUsingInPrediction;
};
public class TrackedObject
{
public PositionsVector lastPositions;
public int numDetectedFrames;
public int numFramesNotDetected;
public int id;
static private int _id = 0;
public TrackedObject (OpenCVForUnity.Rect rect)
{
lastPositions = new PositionsVector ();
numDetectedFrames = 1;
numFramesNotDetected = 0;
lastPositions.Add (rect.clone ());
_id = getNextId ();
id = _id;
}
static int getNextId ()
{
_id++;
return _id;
}
}
}
}

Просмотреть файл

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 9b27c2b2cc8cce34591203b638eba5c7
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a33e7c7ff02dad547b04111e4274524c
timeCreated: 1486317126
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,79 @@
using UnityEngine;
using System.Collections;
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement;
#endif
namespace HoloLensWithOpenCVForUnityExample
{
public class HoloLensWithOpenCVForUnityExample : MonoBehaviour
{
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
public void OnShowLicenseButton ()
{
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
SceneManager.LoadScene ("ShowLicense");
#else
Application.LoadLevel ("ShowLicense");
#endif
}
public void OnHoloLensPhotoCaptureExample ()
{
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
SceneManager.LoadScene ("HoloLensPhotoCaptureExample");
#else
Application.LoadLevel ("HoloLensPhotoCaptureExample");
#endif
}
public void OnHoloLensComicFilterExample ()
{
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
SceneManager.LoadScene ("HoloLensComicFilterExample");
#else
Application.LoadLevel ("HoloLensComicFilterExample");
#endif
}
public void OnHoloLensWebCamTextureAsyncDetectFaceExample ()
{
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
SceneManager.LoadScene ("HoloLensWebCamTextureAsyncDetectFaceExample");
#else
Application.LoadLevel ("HoloLensWebCamTextureAsyncDetectFaceExample");
#endif
}
public void OnHoloLensWebCamTextureAsyncDetectFaceOverlayExample ()
{
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
SceneManager.LoadScene ("HoloLensWebCamTextureAsyncDetectFaceOverlayExample");
#else
Application.LoadLevel ("HoloLensWebCamTextureAsyncDetectFaceOverlayExample");
#endif
}
public void OnHoloLensAnonymousFaceExample ()
{
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
SceneManager.LoadScene ("HoloLensAnonymousFaceExample");
#else
Application.LoadLevel ("HoloLensAnonymousFaceExample");
#endif
}
}
}

Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 12316923d1e8fbd4ebb4f5befd979c3f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

Просмотреть файл

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 57a2fae5da021334cb3d5e1ce496af14
folderAsset: yes
timeCreated: 1485947528
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,108 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 1310916160803426}
m_IsPrefabParent: 1
--- !u!1 &1310916160803426
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4730149813125882}
- component: {fileID: 33764431675012396}
- component: {fileID: 64128452395709546}
- component: {fileID: 23543301954706110}
- component: {fileID: 114284179191554352}
m_Layer: 0
m_Name: AnonymousRectQuad
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4730149813125882
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1310916160803426}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!23 &23543301954706110
MeshRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1310916160803426}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: e2e427520636a714996e857b955c0141, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!33 &33764431675012396
MeshFilter:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1310916160803426}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!64 &64128452395709546
MeshCollider:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1310916160803426}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Convex: 0
m_InflateMesh: 0
m_SkinWidth: 0.01
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &114284179191554352
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1310916160803426}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c3d4fa01c2041f34ea0c4ada97f906c8, type: 3}
m_Name:
m_EditorClassIdentifier:

Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d31004bf844031146a0e2cc93ade395a
timeCreated: 1485956765
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,139 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace HoloLensWithOpenCVForUnityExample
{
public class ObjectPool : MonoBehaviour
{
public GameObject prefab;
public int maxCount = 100;
public int prepareCount = 0;
[SerializeField]
private int interval = 1;
private List<GameObject> pooledObjectList = new List<GameObject>();
private IEnumerator removeObjectCheckCoroutine;
void OnEnable()
{
if (interval > 0){
removeObjectCheckCoroutine = RemoveObjectCheck();
StartCoroutine(removeObjectCheckCoroutine);
}
}
void OnDisable()
{
if (removeObjectCheckCoroutine != null){
StopCoroutine(removeObjectCheckCoroutine);
removeObjectCheckCoroutine = null;
}
}
void OnDestroy()
{
DestroyAllObjects ();
}
public int Interval
{
get
{
return interval;
}
set
{
if (interval != value)
{
interval = value;
if (removeObjectCheckCoroutine != null){
StopCoroutine(removeObjectCheckCoroutine);
removeObjectCheckCoroutine = null;
}
if (interval > 0){
removeObjectCheckCoroutine = RemoveObjectCheck();
StartCoroutine(removeObjectCheckCoroutine);
}
}
}
}
public GameObject GetInstance()
{
return GetInstance(transform);
}
public GameObject GetInstance(Transform parent)
{
if (prefab == null){
Debug.LogWarning("prefab object is not set.");
return null;
}
pooledObjectList.RemoveAll((obj) => obj == null);
foreach (GameObject obj in pooledObjectList)
{
if (obj.activeSelf == false)
{
obj.SetActive(true);
return obj;
}
}
if (pooledObjectList.Count < maxCount)
{
GameObject obj = (GameObject)GameObject.Instantiate(prefab);
obj.SetActive(true);
obj.transform.SetParent (parent, false);
pooledObjectList.Add(obj);
return obj;
}
return null;
}
IEnumerator RemoveObjectCheck()
{
while (true)
{
RemoveObject(prepareCount);
yield return new WaitForSeconds(interval);
}
}
public void RemoveObject(int max)
{
if (pooledObjectList.Count > max)
{
int needRemoveCount = pooledObjectList.Count - max;
foreach (GameObject obj in pooledObjectList.ToArray())
{
if (needRemoveCount == 0)
{
break;
}
if (obj.activeSelf == false)
{
pooledObjectList.Remove(obj);
Destroy(obj);
needRemoveCount--;
}
}
}
}
public void DestroyAllObjects ()
{
foreach (var obj in pooledObjectList)
{
Destroy(obj);
}
pooledObjectList.Clear();
}
}
}

Просмотреть файл

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 26c6457357aaf0541a7914ce67900b0e
timeCreated: 1481980241
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,152 @@
using System;
using UnityEngine;
using System.Collections.Generic;
namespace HoloLensWithOpenCVForUnityExample
{
public class RectOverlay : MonoBehaviour
{
public int Interval = 1;
public int PoolSize = 50;
[SerializeField]
private GameObject baseObject;
public GameObject BaseObject
{
get {
return baseObject;
}
set {
baseObject = value;
setBaseObject(baseObject);
}
}
public float Width
{
get {
return targetWidth;
}
}
public float Height
{
get {
return targetHeight;
}
}
protected Transform overlayTransform;
protected Transform targetTransform;
protected float targetWidth = 0;
protected float targetHeight = 0;
protected ObjectPool objectPool;
void Awake()
{
init("RectOverlay");
}
void OnDestroy()
{
overlayTransform = null;
targetTransform = null;
targetWidth = 0;
targetHeight = 0;
if(objectPool != null)
{
Destroy(objectPool.gameObject);
objectPool = null;
}
}
protected GameObject getPoolObject(Transform parent)
{
if(objectPool == null) return null;
GameObject newObj = objectPool.GetInstance(parent);
if(newObj != null){
newObj.transform.SetParent (parent, false);
return newObj;
}else{
return null;
}
}
protected virtual void init(String name)
{
GameObject overlay = new GameObject(name);
overlayTransform = overlay.transform;
overlayTransform.parent = gameObject.transform.parent;
if(baseObject != null)
setBaseObject (baseObject);
}
protected virtual void setBaseObject (GameObject obj)
{
if (obj.GetComponent<RectQuad>() == null)
{
Debug.LogWarning("Object is not RectQuad.");
return;
}
if(objectPool != null){
Destroy(objectPool);
}
objectPool = overlayTransform.gameObject.AddComponent<ObjectPool>();
objectPool.prefab = obj;
objectPool.maxCount = PoolSize;
objectPool.prepareCount = (int)PoolSize / 2;
objectPool.Interval = Interval;
}
public virtual void UpdateOverlayTransform(Transform targetTransform)
{
if (targetTransform == null)
{
this.targetTransform = null;
return;
}
this.targetTransform = targetTransform;
targetWidth = targetTransform.localScale.x;
targetHeight = targetTransform.localScale.y;
overlayTransform.localPosition = targetTransform.localPosition;
overlayTransform.localRotation = targetTransform.localRotation;
overlayTransform.localScale = targetTransform.localScale;
}
public void DrawRects(UnityEngine.Rect[] rects)
{
if (rects == null)
throw new ArgumentNullException("rects");
if (targetTransform == null) return;
ResetRects();
foreach (UnityEngine.Rect rect in rects)
{
GameObject poolObject = getPoolObject(overlayTransform);
if (poolObject == null) return;
Debug.Log (rect);
var rectTransform = poolObject.transform;
rectTransform.localPosition = new Vector3(rect.x + rect.width / 2 -0.5f, 0.5f - rect.y - rect.height / 2, 0);
rectTransform.localScale = new Vector3(rect.width, rect.height, 1);
}
}
public void ResetRects()
{
foreach (Transform child in overlayTransform)
{
child.gameObject.SetActive(false);
}
}
}
}

Просмотреть файл

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 870b5855d58b2ad448d3b0c144be9933
timeCreated: 1485890794
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,67 @@
using System;
using UnityEngine;
namespace HoloLensWithOpenCVForUnityExample
{
[RequireComponent(typeof(MeshRenderer), typeof(MeshFilter), typeof(MeshCollider))]
public class RectQuad : MonoBehaviour
{
private MeshFilter meshFilter;
private MeshRenderer meshRenderer;
private MeshCollider meshCollider;
public MeshFilter MeshFilter
{
get { return meshFilter; }
}
public MeshRenderer MeshRenderer
{
get { return meshRenderer; }
}
public MeshCollider MeshCollider
{
get { return meshCollider; }
}
public int Id
{
get { return id; }
set { id = value; }
}
private int id = 0;
public Material Material
{
get { return material; }
}
private Material material;
void Awake()
{
meshFilter = this.GetComponent<MeshFilter>();
meshRenderer = this.GetComponent<MeshRenderer>();
meshCollider = this.GetComponent<MeshCollider>();
if (meshRenderer.material == null)
throw new Exception("Material does not exist.");
material = meshRenderer.material;
meshRenderer.sortingOrder = 32767;
}
void OnDestroy(){
if(meshFilter != null && meshFilter.mesh != null){
DestroyImmediate(meshFilter.mesh);
}
if(meshRenderer != null && meshRenderer.materials != null){
foreach(var m in meshRenderer.materials){
DestroyImmediate(m);
}
}
}
}
}

Просмотреть файл

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c3d4fa01c2041f34ea0c4ada97f906c8
timeCreated: 1485890794
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,108 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 1310916160803426}
m_IsPrefabParent: 1
--- !u!1 &1310916160803426
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 5
m_Component:
- component: {fileID: 4730149813125882}
- component: {fileID: 33764431675012396}
- component: {fileID: 64128452395709546}
- component: {fileID: 23543301954706110}
- component: {fileID: 114284179191554352}
m_Layer: 0
m_Name: RectQuad
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4730149813125882
Transform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1310916160803426}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!23 &23543301954706110
MeshRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1310916160803426}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_Materials:
- {fileID: 2100000, guid: a3eb1be26a6d1394c84942fa95295f98, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingOrder: 0
--- !u!33 &33764431675012396
MeshFilter:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1310916160803426}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!64 &64128452395709546
MeshCollider:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1310916160803426}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Convex: 0
m_InflateMesh: 0
m_SkinWidth: 0.01
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!114 &114284179191554352
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 1310916160803426}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c3d4fa01c2041f34ea0c4ada97f906c8, type: 3}
m_Name:
m_EditorClassIdentifier:

Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d4634d118a6b64b4eb5868f1a51cec92
timeCreated: 1485956765
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,34 @@
using UnityEngine;
using System.Collections;
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
using UnityEngine.SceneManagement;
#endif
namespace HoloLensWithOpenCVForUnityExample
{
public class ShowLicense : MonoBehaviour
{
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
}
public void OnBackButton ()
{
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
SceneManager.LoadScene ("HoloLensWithOpenCVForUnityExample");
#else
Application.LoadLevel ("HoloLensWithOpenCVForUnityExample");
#endif
}
}
}

Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5c4571f0273ed9841afba72c241ccc1d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

Просмотреть файл

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 04a547151ac0d1d479a085f761455da4
folderAsset: yes
timeCreated: 1486371514
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,80 @@
using UnityEngine;
using System.Collections;
using OpenCVForUnity;
namespace HoloLensWithOpenCVForUnityExample
{
/// <summary>
/// Optimization web cam texture to mat helper.
/// </summary>
public class OptimizationWebCamTextureToMatHelper : WebCamTextureToMatHelper
{
/// <summary>
/// The DOWNSAMPL e_ RATI.
/// </summary>
public float DOWNSCALE_RATIO = 2;
/// <summary>
/// The SKI p_ FRAME.
/// </summary>
public int SKIP_FRAMES = 2;
/// <summary>
/// The frame count.
/// </summary>
int frameCount;
/// <summary>
/// The rgba mat_downscale.
/// </summary>
Mat downScaleRgbaMat;
/// <summary>
/// Whether this frame is SkipFrame.
/// </summary>
/// <returns><c>true</c> if this instance is skip frame; otherwise, <c>false</c>.</returns>
public bool IsSkipFrame ()
{
frameCount++;
if (SKIP_FRAMES <= 0)
return true;
if (frameCount % SKIP_FRAMES == 0) {
return false;
}
return true;
}
/// <summary>
/// Get the Mat that downscaled the original Mat.
/// if DOWNSCALE <= 1 , return originalMat.
/// </summary>
/// <returns>The down scale mat.</returns>
/// <param name="originalMat">Original mat.</param>
public Mat GetDownScaleMat (Mat originalMat)
{
if (DOWNSCALE_RATIO <= 1)
return originalMat;
if (downScaleRgbaMat == null) {
downScaleRgbaMat = new Mat ();
}
Imgproc.resize (originalMat, downScaleRgbaMat, new Size (), 1.0 / DOWNSCALE_RATIO, 1.0 / DOWNSCALE_RATIO, Imgproc.INTER_LINEAR);
return downScaleRgbaMat;
}
public new void Dispose ()
{
if (downScaleRgbaMat != null) {
downScaleRgbaMat.Dispose ();
downScaleRgbaMat = null;
}
base.Dispose ();
}
}
}

Просмотреть файл

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 28e142b476c838049871b666621dda2e
timeCreated: 1482239018
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,510 @@
using OpenCVForUnity;
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
namespace HoloLensWithOpenCVForUnityExample
{
/// <summary>
/// Web cam texture to mat helper.
/// </summary>
public class WebCamTextureToMatHelper : MonoBehaviour
{
/// <summary>
/// The name of the device.
/// </summary>
public string requestDeviceName = null;
/// <summary>
/// The width.
/// </summary>
public int requestWidth = 640;
/// <summary>
/// The height.
/// </summary>
public int requestHeight = 480;
/// <summary>
/// Should use front facing.
/// </summary>
public bool requestIsFrontFacing = false;
/// <summary>
/// The flip vertical.
/// </summary>
public bool flipVertical = false;
/// <summary>
/// The flip horizontal.
/// </summary>
public bool flipHorizontal = false;
/// <summary>
/// The timeout frame count.
/// </summary>
public int timeoutFrameCount = 300;
/// <summary>
/// The on inited event.
/// </summary>
public UnityEvent OnInitedEvent;
/// <summary>
/// The on disposed event.
/// </summary>
public UnityEvent OnDisposedEvent;
/// <summary>
/// The on error occurred event.
/// </summary>
public ErrorUnityEvent OnErrorOccurredEvent;
/// <summary>
/// The web cam texture.
/// </summary>
WebCamTexture webCamTexture;
/// <summary>
/// The web cam device.
/// </summary>
WebCamDevice webCamDevice;
/// <summary>
/// The rgba mat.
/// </summary>
Mat rgbaMat;
/// <summary>
/// The rotated rgba mat
/// </summary>
Mat rotatedRgbaMat;
/// <summary>
/// The colors.
/// </summary>
Color32[] colors;
/// <summary>
/// The init waiting.
/// </summary>
bool initWaiting = false;
/// <summary>
/// The init done.
/// </summary>
bool initDone = false;
/// <summary>
/// The screenOrientation.
/// </summary>
ScreenOrientation screenOrientation = ScreenOrientation.Unknown;
[System.Serializable]
public enum ErrorCode :int
{
CAMERA_DEVICE_NOT_EXIST = 0,
TIMEOUT = 1,
}
[System.Serializable]
public class ErrorUnityEvent : UnityEngine.Events.UnityEvent<ErrorCode>
{
}
// Update is called once per frame
void Update ()
{
if (initDone) {
if (screenOrientation != Screen.orientation) {
StartCoroutine (init ());
}
}
}
/// <summary>
/// Init this instance.
/// </summary>
public void Init ()
{
if (initWaiting)
return;
if (OnInitedEvent == null)
OnInitedEvent = new UnityEvent ();
if (OnDisposedEvent == null)
OnDisposedEvent = new UnityEvent ();
if (OnErrorOccurredEvent == null)
OnErrorOccurredEvent = new ErrorUnityEvent ();
StartCoroutine (init ());
}
/// <summary>
/// Init this instance.
/// </summary>
/// <param name="deviceName">Device name.</param>
/// <param name="requestWidth">Request width.</param>
/// <param name="requestHeight">Request height.</param>
/// <param name="requestIsFrontFacing">If set to <c>true</c> request is front facing.</param>
/// <param name="OnInited">On inited.</param>
public void Init (string deviceName, int requestWidth, int requestHeight, bool requestIsFrontFacing)
{
if (initWaiting)
return;
this.requestDeviceName = deviceName;
this.requestWidth = requestWidth;
this.requestHeight = requestHeight;
this.requestIsFrontFacing = requestIsFrontFacing;
if (OnInitedEvent == null)
OnInitedEvent = new UnityEvent ();
if (OnDisposedEvent == null)
OnDisposedEvent = new UnityEvent ();
if (OnErrorOccurredEvent == null)
OnErrorOccurredEvent = new ErrorUnityEvent ();
StartCoroutine (init ());
}
/// <summary>
/// Init this instance by coroutine.
/// </summary>
private IEnumerator init ()
{
if (initDone)
dispose ();
initWaiting = true;
if (!String.IsNullOrEmpty (requestDeviceName)) {
//Debug.Log ("deviceName is "+requestDeviceName);
webCamTexture = new WebCamTexture (requestDeviceName, requestWidth, requestHeight);
} else {
//Debug.Log ("deviceName is null");
// Checks how many and which cameras are available on the device
for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++) {
if (WebCamTexture.devices [cameraIndex].isFrontFacing == requestIsFrontFacing) {
//Debug.Log (cameraIndex + " name " + WebCamTexture.devices [cameraIndex].name + " isFrontFacing " + WebCamTexture.devices [cameraIndex].isFrontFacing);
webCamDevice = WebCamTexture.devices [cameraIndex];
webCamTexture = new WebCamTexture (webCamDevice.name, requestWidth, requestHeight);
break;
}
}
}
if (webCamTexture == null) {
if (WebCamTexture.devices.Length > 0) {
webCamDevice = WebCamTexture.devices [0];
webCamTexture = new WebCamTexture (webCamDevice.name, requestWidth, requestHeight);
} else {
//Debug.Log("Camera device does not exist.");
initWaiting = false;
if (OnErrorOccurredEvent != null)
OnErrorOccurredEvent.Invoke (ErrorCode.CAMERA_DEVICE_NOT_EXIST);
yield break;
}
}
//Debug.Log ("name " + webCamTexture.name + " width " + webCamTexture.width + " height " + webCamTexture.height + " fps " + webCamTexture.requestedFPS);
// Starts the camera
webCamTexture.Play ();
int initCount = 0;
bool isTimeout = false;
while (true) {
if (initCount > timeoutFrameCount) {
isTimeout = true;
break;
}
// If you want to use webcamTexture.width and webcamTexture.height on iOS, you have to wait until webcamTexture.didUpdateThisFrame == 1, otherwise these two values will be equal to 16. (http://forum.unity3d.com/threads/webcamtexture-and-error-0x0502.123922/)
#if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
else if (webCamTexture.width > 16 && webCamTexture.height > 16) {
#else
else if (webCamTexture.didUpdateThisFrame) {
#if UNITY_IOS && !UNITY_EDITOR && UNITY_5_2
while (webCamTexture.width <= 16) {
if (initCount > timeoutFrameCount) {
isTimeout = true;
break;
}else {
initCount++;
}
webCamTexture.GetPixels32 ();
yield return new WaitForEndOfFrame ();
}
if (isTimeout) break;
#endif
#endif
Debug.Log ("name " + webCamTexture.name + " width " + webCamTexture.width + " height " + webCamTexture.height + " fps " + webCamTexture.requestedFPS);
Debug.Log ("videoRotationAngle " + webCamTexture.videoRotationAngle + " videoVerticallyMirrored " + webCamTexture.videoVerticallyMirrored + " isFrongFacing " + webCamDevice.isFrontFacing);
if (colors == null || colors.Length != webCamTexture.width * webCamTexture.height)
colors = new Color32[webCamTexture.width * webCamTexture.height];
rgbaMat = new Mat (webCamTexture.height, webCamTexture.width, CvType.CV_8UC4);
//Debug.Log ("Screen.orientation " + Screen.orientation);
screenOrientation = Screen.orientation;
#if !UNITY_EDITOR && !(UNITY_STANDALONE || UNITY_WEBGL)
if (screenOrientation == ScreenOrientation.Portrait || screenOrientation == ScreenOrientation.PortraitUpsideDown) {
rotatedRgbaMat = new Mat (webCamTexture.width, webCamTexture.height, CvType.CV_8UC4);
}
#endif
initWaiting = false;
initDone = true;
if (OnInitedEvent != null)
OnInitedEvent.Invoke ();
break;
} else {
initCount++;
yield return 0;
}
}
if (isTimeout) {
//Debug.Log("Init time out.");
webCamTexture.Stop ();
webCamTexture = null;
initWaiting = false;
if (OnErrorOccurredEvent != null)
OnErrorOccurredEvent.Invoke (ErrorCode.TIMEOUT);
}
}
/// <summary>
/// Ises the inited.
/// </summary>
/// <returns><c>true</c>, if inited was ised, <c>false</c> otherwise.</returns>
public bool IsInited ()
{
return initDone;
}
/// <summary>
/// Play this instance.
/// </summary>
public void Play ()
{
if (initDone)
webCamTexture.Play ();
}
/// <summary>
/// Pause this instance.
/// </summary>
public void Pause ()
{
if (initDone)
webCamTexture.Pause ();
}
/// <summary>
/// Stop this instance.
/// </summary>
public void Stop ()
{
if (initDone)
webCamTexture.Stop ();
}
/// <summary>
/// Ises the playing.
/// </summary>
/// <returns><c>true</c>, if playing was ised, <c>false</c> otherwise.</returns>
public bool IsPlaying ()
{
if (!initDone)
return false;
return webCamTexture.isPlaying;
}
/// <summary>
/// Gets the web cam texture.
/// </summary>
/// <returns>The web cam texture.</returns>
public WebCamTexture GetWebCamTexture ()
{
return (initDone) ? webCamTexture : null;
}
/// <summary>
/// Gets the web cam device.
/// </summary>
/// <returns>The web cam device.</returns>
public WebCamDevice GetWebCamDevice ()
{
return webCamDevice;
}
/// <summary>
/// Dids the update this frame.
/// </summary>
/// <returns><c>true</c>, if update this frame was dided, <c>false</c> otherwise.</returns>
public bool DidUpdateThisFrame ()
{
if (!initDone)
return false;
#if UNITY_IOS && !UNITY_EDITOR && (UNITY_4_6_3 || UNITY_4_6_4 || UNITY_5_0_0 || UNITY_5_0_1)
if (webCamTexture.width > 16 && webCamTexture.height > 16) {
return true;
} else {
return false;
}
#else
return webCamTexture.didUpdateThisFrame;
#endif
}
/// <summary>
/// Gets the mat.
/// </summary>
/// <returns>The mat.</returns>
public Mat GetMat ()
{
if (!initDone || !webCamTexture.isPlaying) {
if (rotatedRgbaMat != null) {
return rotatedRgbaMat;
} else {
return rgbaMat;
}
}
Utils.webCamTextureToMat (webCamTexture, rgbaMat, colors);
if (rotatedRgbaMat != null) {
using (Mat transposeRgbaMat = rgbaMat.t ()) {
Core.flip (transposeRgbaMat, rotatedRgbaMat, 1);
}
flipMat (rotatedRgbaMat);
return rotatedRgbaMat;
} else {
flipMat (rgbaMat);
return rgbaMat;
}
}
/// <summary>
/// Flips the mat.
/// </summary>
/// <param name="mat">Mat.</param>
private void flipMat (Mat mat)
{
int flipCode = int.MinValue;
if (webCamDevice.isFrontFacing) {
if (webCamTexture.videoRotationAngle == 0) {
flipCode = 1;
} else if (webCamTexture.videoRotationAngle == 90) {
flipCode = 1;
}
if (webCamTexture.videoRotationAngle == 180) {
flipCode = 0;
} else if (webCamTexture.videoRotationAngle == 270) {
flipCode = 0;
}
} else {
if (webCamTexture.videoRotationAngle == 180) {
flipCode = -1;
} else if (webCamTexture.videoRotationAngle == 270) {
flipCode = -1;
}
}
if (flipVertical) {
if (flipCode == int.MinValue) {
flipCode = 0;
} else if (flipCode == 0) {
flipCode = int.MinValue;
} else if (flipCode == 1) {
flipCode = -1;
} else if (flipCode == -1) {
flipCode = 1;
}
}
if (flipHorizontal) {
if (flipCode == int.MinValue) {
flipCode = 1;
} else if (flipCode == 0) {
flipCode = -1;
} else if (flipCode == 1) {
flipCode = int.MinValue;
} else if (flipCode == -1) {
flipCode = 0;
}
}
if (flipCode > int.MinValue) {
Core.flip (mat, mat, flipCode);
}
}
/// <summary>
/// Gets the buffer colors.
/// </summary>
/// <returns>The buffer colors.</returns>
public Color32[] GetBufferColors ()
{
return colors;
}
/// <summary>
/// To release the resources for the init method.
/// </summary>
private void dispose ()
{
initWaiting = false;
initDone = false;
if (webCamTexture != null) {
webCamTexture.Stop ();
webCamTexture = null;
}
if (rgbaMat != null) {
rgbaMat.Dispose ();
rgbaMat = null;
}
if (rotatedRgbaMat != null) {
rotatedRgbaMat.Dispose ();
rotatedRgbaMat = null;
}
if (OnDisposedEvent != null)
OnDisposedEvent.Invoke ();
}
/// <summary>
/// Releases all resource used by the <see cref="WebCamTextureToMatHelper"/> object.
/// </summary>
/// <remarks>Call <see cref="Dispose"/> when you are finished using the <see cref="WebCamTextureToMatHelper"/>. The
/// <see cref="Dispose"/> method leaves the <see cref="WebCamTextureToMatHelper"/> in an unusable state. After
/// calling <see cref="Dispose"/>, you must release all references to the <see cref="WebCamTextureToMatHelper"/> so
/// the garbage collector can reclaim the memory that the <see cref="WebCamTextureToMatHelper"/> was occupying.</remarks>
public void Dispose ()
{
if (initDone)
dispose ();
colors = null;
}
}
}

Просмотреть файл

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cf7241a4a46c10a4ba922cfa7a7f0f51
timeCreated: 1475593961
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Просмотреть файл

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d3ad44ece549ef14ebece2605f0af2e4
folderAsset: yes
timeCreated: 1485712356
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,6 @@
fileFormatVersion: 2
guid: a26867410cfa51c4eab8d3ae6c305616
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 75da48a14a9bfdf41b26021529d948a8
timeCreated: 1433693866
licenseType: Pro
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:

Двоичные данные
HoloLensWithOpenCVForUnityExample.unitypackage Normal file

Двоичный файл не отображается.

Двоичные данные
Light_Frame.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 12 KiB

42
README.md Normal file
Просмотреть файл

@ -0,0 +1,42 @@
HoloLens With OpenCVForUnity Example
====================
Demo Video
-----
[![](http://img.youtube.com/vi/bPCzhE0GP-g/0.jpg)](https://youtu.be/bPCzhE0GP-g)
Environment
-----
Windows 10
Unity 5.5.1f1
HoloToolKit v1.5.5.0
OpenCV for Unity 2.1.3(using OpenCVForUnityUWP_Beta3.unitypackage)
Setup
-----
* Create New Project. (HoloLensWithOpenCVForUnityExample)
* Import HoloToolKit-Unity-v1.5.5.0.unitypackage. (excluding "HoloToolKit-Examples" folder)
* Setup HoloToolKit. (HoloToolKit > Configure > Apply HoloLens Project Setting)
* Import OpenCVForUnityUWP_Beta3.unitypackage.
* Import HoloLensWithOpenCVForUnityExample.unitypackage.
* Add the "Assets/HoloLensWithOpenCVForUnityExample/Scenes/*.unity" files to "Scenes In Build" list in "Build Settings" window.
* Add the "WebCam" to "Publishing Settings > Capabilities" checklist in the "Player Settings" window.
* Build and Deploy. (See [https://developer.microsoft.com/en-us/windows/holographic/holograms_100](https://developer.microsoft.com/en-us/windows/holographic/holograms_100))
ScreenShot
-----
![screenshot01.jpg](screenshot01.jpg)
![screenshot02.jpg](screenshot02.jpg)
![screenshot03.jpg](screenshot01.jpg)
![screenshot04.jpg](screenshot04.jpg)
![Light_Frame.png](Light_Frame.png)

Двоичные данные
screenshot01.jpg Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 83 KiB

Двоичные данные
screenshot02.jpg Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 108 KiB

Двоичные данные
screenshot03.jpg Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 120 KiB

Двоичные данные
screenshot04.jpg Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 97 KiB