From a6f51765cb0c11b6dafc84a6878ebc0f2f9da01a Mon Sep 17 00:00:00 2001 From: Alexander Munch-Hansen Date: Mon, 4 Mar 2019 13:01:52 +0100 Subject: [PATCH] Contour kinda works --- AR-2b/Assets/Homo_script.cs | 7 +- AR-2b/Assets/contour_fuckery.unity | 979 +---------------------------- AR-2b/Assets/detection_script.cs | 2 +- AR-2b/Assets/detection_script_2.cs | 228 +++++++ 4 files changed, 240 insertions(+), 976 deletions(-) create mode 100644 AR-2b/Assets/detection_script_2.cs diff --git a/AR-2b/Assets/Homo_script.cs b/AR-2b/Assets/Homo_script.cs index 9a12e9f..0a2b2b3 100644 --- a/AR-2b/Assets/Homo_script.cs +++ b/AR-2b/Assets/Homo_script.cs @@ -162,7 +162,6 @@ public class Homo_script : MonoBehaviour Mat outputSkullMat = skullTextureMat.clone(); - Imgproc.warpPerspective(skullTextureMat, outputSkullMat, homo.inv(), new Size(outputSkullMat.width(), outputSkullMat.height())); var rectOutputMat = new Mat(outputMat, new OpenCVForUnity.CoreModule.Rect(0, 0, width, height)); @@ -170,12 +169,8 @@ public class Homo_script : MonoBehaviour MatDisplay.MatToTexture(rectOutputMat, ref outputTexture); - Mat anotherCamImg = camImageMat.clone(); - - Core.addWeighted(camImageMat, 0.95f, outputSkullMat, 0.4f, 0.0, anotherCamImg); - //Display the Mat that includes video feed and debug points - MatDisplay.DisplayMat(anotherCamImg, MatDisplaySettings.FULL_BACKGROUND); + MatDisplay.DisplayMat(camImageMat, MatDisplaySettings.FULL_BACKGROUND); rend.sharedMaterial.mainTexture = outputTexture; diff --git a/AR-2b/Assets/contour_fuckery.unity b/AR-2b/Assets/contour_fuckery.unity index d3b6a41..b28e055 100644 --- a/AR-2b/Assets/contour_fuckery.unity +++ b/AR-2b/Assets/contour_fuckery.unity @@ -112,598 +112,6 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} ---- !u!1 &67228971 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 67228975} - - component: {fileID: 67228974} - - component: {fileID: 67228973} - - component: {fileID: 67228972} - m_Layer: 0 - m_Name: Sphere_4 - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 0 ---- !u!135 &67228972 -SphereCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 67228971} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Radius: 0.5 - m_Center: {x: 0, y: 0, z: 0} ---- !u!23 &67228973 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 67228971} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 0 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 ---- !u!33 &67228974 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 67228971} - m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} ---- !u!4 &67228975 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 67228971} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0.455, y: 0.0042719864, z: -0.445} - m_LocalScale: {x: 0.099999994, y: 0.099999994, z: 0.099999994} - m_Children: [] - m_Father: {fileID: 723326983} - m_RootOrder: 4 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &172628998 stripped -GameObject: - m_CorrespondingSourceObject: {fileID: 100002, guid: b07d7c0ed92004731951cc02dfe544a4, - type: 3} - m_PrefabInstance: {fileID: 1590124969} - m_PrefabAsset: {fileID: 0} ---- !u!4 &172628999 stripped -Transform: - m_CorrespondingSourceObject: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, - type: 3} - m_PrefabInstance: {fileID: 1590124969} - m_PrefabAsset: {fileID: 0} ---- !u!114 &172629001 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 172628998} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: f4ea9ea3ecbdd4784bc2ad6084c3db79, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!1 &429717595 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 429717597} - - component: {fileID: 429717596} - - component: {fileID: 429717598} - m_Layer: 0 - m_Name: Homomographyt_inv - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!114 &429717596 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 429717595} - m_Enabled: 0 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c79e888c79d3e44b2909e45c5743be4a, type: 3} - m_Name: - m_EditorClassIdentifier: - cam: {fileID: 1447995929} - corner1: {fileID: 1437005650} - corner2: {fileID: 442480152} - corner3: {fileID: 566786898} - corner4: {fileID: 67228971} - fx: 650 - fy: 650 - cx: 320 - cy: 240 ---- !u!4 &429717597 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 429717595} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0.00042719865, z: -0.00008443883} - m_LocalScale: {x: 1.0827, y: 1.0827, z: 1.0827} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 3 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!114 &429717598 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 429717595} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 6c7b58b87574c40da867cab875fbf86f, type: 3} - m_Name: - m_EditorClassIdentifier: - cam: {fileID: 1447995929} - corner1: {fileID: 1437005650} - corner2: {fileID: 442480152} - corner3: {fileID: 566786898} - corner4: {fileID: 67228971} - fx: 650 - fy: 650 - cx: 320 - cy: 240 ---- !u!1 &442480152 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 442480156} - - component: {fileID: 442480155} - - component: {fileID: 442480154} - - component: {fileID: 442480153} - m_Layer: 0 - m_Name: Sphere_2 - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 0 ---- !u!135 &442480153 -SphereCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 442480152} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Radius: 0.5 - m_Center: {x: 0, y: 0, z: 0} ---- !u!23 &442480154 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 442480152} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 0 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 ---- !u!33 &442480155 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 442480152} - m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} ---- !u!4 &442480156 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 442480152} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 0.459, y: 0.0042719864, z: 0.459} - m_LocalScale: {x: 0.099999994, y: 0.099999994, z: 0.099999994} - m_Children: [] - m_Father: {fileID: 723326983} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &566786898 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 566786902} - - component: {fileID: 566786901} - - component: {fileID: 566786900} - - component: {fileID: 566786899} - m_Layer: 0 - m_Name: Sphere_3 - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 0 ---- !u!135 &566786899 -SphereCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 566786898} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Radius: 0.5 - m_Center: {x: 0, y: 0, z: 0} ---- !u!23 &566786900 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 566786898} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 0 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 ---- !u!33 &566786901 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 566786898} - m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} ---- !u!4 &566786902 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 566786898} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.473, y: 0.0042719864, z: -0.445} - m_LocalScale: {x: 0.099999994, y: 0.099999994, z: 0.099999994} - m_Children: [] - m_Father: {fileID: 723326983} - m_RootOrder: 3 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &582273323 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 582273327} - - component: {fileID: 582273326} - - component: {fileID: 582273325} - - component: {fileID: 582273324} - m_Layer: 0 - m_Name: pls - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!64 &582273324 -MeshCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 582273323} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 3 - m_Convex: 0 - m_CookingOptions: 14 - m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} ---- !u!23 &582273325 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 582273323} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: d07de9e9029cb4e08813867ec400ba4e, 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: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 0 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 ---- !u!33 &582273326 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 582273323} - m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0} ---- !u!4 &582273327 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 582273323} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: -0.0412, y: -0.034729052, z: 0.1054} - m_LocalScale: {x: 0.01, y: 0.01, z: 0.01} - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 4 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1 &723326977 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 723326983} - - component: {fileID: 723326982} - - component: {fileID: 723326981} - - component: {fileID: 723326980} - - component: {fileID: 723326979} - - component: {fileID: 723326978} - m_Layer: 0 - m_Name: SkullTarget_inv - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!33 &723326978 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 723326977} - m_Mesh: {fileID: 1736458375} ---- !u!23 &723326979 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 723326977} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 0 - m_ReflectionProbeUsage: 1 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2037860783} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 0 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 ---- !u!114 &723326980 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 723326977} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: -1770992566, guid: bab6fa851cf5a1a4bba3cec5f191cb8e, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!114 &723326981 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 723326977} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 5a917f0af64a6423093132dab321c15f, type: 3} - m_Name: - m_EditorClassIdentifier: ---- !u!114 &723326982 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 723326977} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: -1631628248, guid: bab6fa851cf5a1a4bba3cec5f191cb8e, type: 3} - m_Name: - m_EditorClassIdentifier: - mTrackableName: unwrapped_skull - mPreserveChildSize: 0 - mInitializedInEditor: 1 - mDataSetPath: Vuforia/AR-2.xml - mAspectRatio: 1 - mImageTargetType: 0 - mWidth: 0.1 - mHeight: 0.1 ---- !u!4 &723326983 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 723326977} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 0.00081562} - m_LocalScale: {x: 0.1, y: 0.1, z: 0.1} - m_Children: - - {fileID: 172628999} - - {fileID: 1437005654} - - {fileID: 442480156} - - {fileID: 566786902} - - {fileID: 67228975} - m_Father: {fileID: 0} - m_RootOrder: 2 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &813611124 GameObject: m_ObjectHideFlags: 0 @@ -773,97 +181,6 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} ---- !u!1 &1437005650 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 1437005654} - - component: {fileID: 1437005653} - - component: {fileID: 1437005652} - - component: {fileID: 1437005651} - m_Layer: 0 - m_Name: Sphere_1 - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 0 ---- !u!135 &1437005651 -SphereCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1437005650} - m_Material: {fileID: 0} - m_IsTrigger: 0 - m_Enabled: 1 - serializedVersion: 2 - m_Radius: 0.5 - m_Center: {x: 0, y: 0, z: 0} ---- !u!23 &1437005652 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1437005650} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_PreserveUVs: 0 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 0 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 ---- !u!33 &1437005653 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1437005650} - m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0} ---- !u!4 &1437005654 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1437005650} - m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: -0.461, y: 0.0042719864, z: 0.459} - m_LocalScale: {x: 0.099999994, y: 0.099999994, z: 0.099999994} - m_Children: [] - m_Father: {fileID: 723326983} - m_RootOrder: 1 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1447995925 GameObject: m_ObjectHideFlags: 0 @@ -877,6 +194,7 @@ GameObject: - component: {fileID: 1447995928} - component: {fileID: 1447995927} - component: {fileID: 1447995926} + - component: {fileID: 1447995931} m_Layer: 0 m_Name: ARCamera m_TagString: MainCamera @@ -909,7 +227,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: mWorldCenterMode: 0 - mWorldCenter: {fileID: 723326982} + mWorldCenter: {fileID: 0} --- !u!81 &1447995928 AudioListener: m_ObjectHideFlags: 0 @@ -974,292 +292,15 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!1001 &1590124969 -PrefabInstance: - m_ObjectHideFlags: 0 - serializedVersion: 2 - m_Modification: - m_TransformParent: {fileID: 723326983} - m_Modifications: - - target: {fileID: 100002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_Name - value: flying_skull - objectReference: {fileID: 0} - - target: {fileID: 100002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_IsActive - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 100004, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_Name - value: flying_skull_001_inv - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalPosition.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalPosition.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalPosition.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalRotation.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalRotation.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalRotation.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalRotation.w - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_RootOrder - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalEulerAnglesHint.y - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalEulerAnglesHint.z - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalScale.x - value: 20 - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalScale.y - value: 20 - objectReference: {fileID: 0} - - target: {fileID: 400002, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalScale.z - value: 20 - objectReference: {fileID: 0} - - target: {fileID: 400000, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalRotation.x - value: 0.7071068 - objectReference: {fileID: 0} - - target: {fileID: 400000, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalRotation.z - value: -0 - objectReference: {fileID: 0} - - target: {fileID: 400000, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalRotation.w - value: -0.7071068 - objectReference: {fileID: 0} - - target: {fileID: 400000, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalEulerAnglesHint.x - value: 270 - objectReference: {fileID: 0} - - target: {fileID: 400000, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_LocalRotation.y - value: -0 - objectReference: {fileID: 0} - - target: {fileID: 13700000, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} - propertyPath: m_Materials.Array.data[0] - value: - objectReference: {fileID: 2100000, guid: d07de9e9029cb4e08813867ec400ba4e, type: 2} - m_RemovedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: b07d7c0ed92004731951cc02dfe544a4, type: 3} ---- !u!43 &1736458375 -Mesh: +--- !u!114 &1447995931 +MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} - m_Name: ImageTargetMesh18214 - serializedVersion: 9 - m_SubMeshes: - - serializedVersion: 2 - firstByte: 0 - indexCount: 6 - topology: 0 - baseVertex: 0 - firstVertex: 0 - vertexCount: 4 - localAABB: - m_Center: {x: 0, y: 0, z: 0} - m_Extent: {x: 0.5, y: 0, z: 0.5} - m_Shapes: - vertices: [] - shapes: [] - channels: [] - fullWeights: [] - m_BindPose: [] - m_BoneNameHashes: - m_RootBoneNameHash: 0 - m_MeshCompression: 0 - m_IsReadable: 1 - m_KeepVertices: 1 - m_KeepIndices: 1 - m_IndexFormat: 0 - m_IndexBuffer: 000001000200020001000300 - m_VertexData: - serializedVersion: 2 - m_VertexCount: 4 - m_Channels: - - stream: 0 - offset: 0 - format: 0 - dimension: 3 - - stream: 0 - offset: 12 - format: 0 - dimension: 3 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 24 - format: 0 - dimension: 2 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - - stream: 0 - offset: 0 - format: 0 - dimension: 0 - m_DataSize: 128 - _typelessdata: 000000bf00000000000000bf000000000000803f000000000000000000000000000000bf000000000000003f000000000000803f00000000000000000000803f0000003f00000000000000bf000000000000803f000000000000803f000000000000003f000000000000003f000000000000803f000000000000803f0000803f - m_CompressedMesh: - m_Vertices: - m_NumItems: 0 - m_Range: 0 - m_Start: 0 - m_Data: - m_BitSize: 0 - m_UV: - m_NumItems: 0 - m_Range: 0 - m_Start: 0 - m_Data: - m_BitSize: 0 - m_Normals: - m_NumItems: 0 - m_Range: 0 - m_Start: 0 - m_Data: - m_BitSize: 0 - m_Tangents: - m_NumItems: 0 - m_Range: 0 - m_Start: 0 - m_Data: - m_BitSize: 0 - m_Weights: - m_NumItems: 0 - m_Data: - m_BitSize: 0 - m_NormalSigns: - m_NumItems: 0 - m_Data: - m_BitSize: 0 - m_TangentSigns: - m_NumItems: 0 - m_Data: - m_BitSize: 0 - m_FloatColors: - m_NumItems: 0 - m_Range: 0 - m_Start: 0 - m_Data: - m_BitSize: 0 - m_BoneIndices: - m_NumItems: 0 - m_Data: - m_BitSize: 0 - m_Triangles: - m_NumItems: 0 - m_Data: - m_BitSize: 0 - m_UVInfo: 0 - m_LocalAABB: - m_Center: {x: 0, y: 0, z: 0} - m_Extent: {x: 0.5, y: 0, z: 0.5} - m_MeshUsageFlags: 0 - m_BakedConvexCollisionMesh: - m_BakedTriangleCollisionMesh: - m_MeshMetrics[0]: 1 - m_MeshMetrics[1]: 1 - m_MeshOptimized: 0 - m_StreamData: - offset: 0 - size: 0 - path: ---- !u!21 &2037860783 -Material: - serializedVersion: 6 - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_Name: 'unwrapped_skullMaterial - - 18224' - m_Shader: {fileID: 4800000, guid: bd60f254bfe034e099e9f70c306d67e7, type: 3} - m_ShaderKeywords: - m_LightmapFlags: 5 - m_EnableInstancingVariants: 0 - m_DoubleSidedGI: 0 - m_CustomRenderQueue: -1 - stringTagMap: {} - disabledShaderPasses: [] - m_SavedProperties: - serializedVersion: 3 - m_TexEnvs: - - _MainTex: - m_Texture: {fileID: 2800000, guid: 172f3df370d54b7a9d705b7c2fa63bac, type: 3} - m_Scale: {x: 1, y: 1} - m_Offset: {x: 0, y: 0} - m_Floats: [] - m_Colors: - - _Color: {r: 0.9607843, g: 0.10606851, b: 0.050980415, a: 1} + m_GameObject: {fileID: 1447995925} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: adf834787ecf5449eab8e253c148730e, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/AR-2b/Assets/detection_script.cs b/AR-2b/Assets/detection_script.cs index 6aa496d..9816858 100644 --- a/AR-2b/Assets/detection_script.cs +++ b/AR-2b/Assets/detection_script.cs @@ -6,7 +6,7 @@ using OpenCVForUnity.ImgprocModule; using System.Linq; using Vuforia; -public class detection_script : MonoBehaviour +public class detection_script_2 : MonoBehaviour { Mat cameraImageMat; Mat stylizedMat = new Mat(); diff --git a/AR-2b/Assets/detection_script_2.cs b/AR-2b/Assets/detection_script_2.cs new file mode 100644 index 0000000..2645063 --- /dev/null +++ b/AR-2b/Assets/detection_script_2.cs @@ -0,0 +1,228 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using OpenCVForUnity.CoreModule; +using OpenCVForUnity.ImgprocModule; +using System.Linq; +using Vuforia; + +public class detection_script : MonoBehaviour +{ + Mat cameraImageMat; + Mat stylizedMat = new Mat(); + Mat greyMat = new Mat(); + + + int width = 100; + int height = 100; + + Texture2D outputTexture; + MatOfPoint2f dstPointsInv; + + MatOfPoint2f imagePoints; + + private Mat skullTextureMat; + + + + // Start is called before the first frame update + void Start() + { + skullTextureMat = MatDisplay.LoadRGBATexture("Resources/flying_skull_tex.png"); + + dstPointsInv = new MatOfPoint2f(); + dstPointsInv.alloc(4); + + dstPointsInv.put(2, 0, 0, height); + dstPointsInv.put(3, 0, width, height); + dstPointsInv.put(0, 0, 0, 0); + dstPointsInv.put(1, 0, width, 0); + + outputTexture = new Texture2D(width, height, TextureFormat.RGBA32, false); + + imagePoints = new MatOfPoint2f(); + imagePoints.alloc(4); + } + + // Update is called once per frame + void Update() + { + MatDisplay.SetCameraFoV(41.5f); + + Image cameraImage = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGBA8888); + + if (cameraImage != null) + { + if (cameraImageMat == null) + { + cameraImageMat = new Mat(cameraImage.Height, cameraImage.Width, CvType.CV_8UC4); + } + cameraImageMat.put(0, 0, cameraImage.Pixels); + + Imgproc.cvtColor(cameraImageMat, greyMat, Imgproc.COLOR_RGB2GRAY); + + + Imgproc.threshold(greyMat, stylizedMat, 69, 255, Imgproc.THRESH_BINARY); + + + List contourList = new List(); + Mat hierarchy = new Mat(); + Imgproc.findContours(stylizedMat, contourList, hierarchy, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE); + + //Imgproc.drawContours(cameraImageMat, contourList, -1, new Scalar(255,0,0), 2); + + List squareContours = new List(); + foreach (var contour in contourList) + { + MatOfPoint2f contour2f = new MatOfPoint2f(); + contour.convertTo(contour2f, CvType.CV_32FC2); + + double epsilon = 0.01f * Imgproc.arcLength(contour2f, true); + MatOfPoint2f approx = new MatOfPoint2f(); + Imgproc.approxPolyDP(contour2f, approx, epsilon, true); + + if (approx.toList().Count == 4) + { + Imgproc.drawContours(cameraImageMat, new List { contour }, -1, new Scalar(255,0,0), 2); + squareContours.Add(approx); + } + } + + + MatOfPoint2f square = findSquare(squareContours); + MatOfPoint greenSquare = new MatOfPoint(); + square.convertTo(greenSquare, CvType.CV_32S); + Imgproc.drawContours(cameraImageMat, new List { greenSquare }, -1, new Scalar(0, 255, 0), 2); + MatDisplay.DisplayMat(cameraImageMat, MatDisplaySettings.FULL_BACKGROUND); + + return; + + if (square != null) + { + + for (int i = 0; i < 4; i++) + { + print($"Square: {square.get(i, 0)}, idx {i}"); + imagePoints.put(i, 0, square.get(i, 0)[0], square.get(i, 0)[1]); + } + + //Debug draw points using OpenCV's drawing functions + Point imgPnt1 = new Point(imagePoints.get(0, 0)); + Point imgPnt2 = new Point(imagePoints.get(1, 0)); + Point imgPnt3 = new Point(imagePoints.get(2, 0)); + Point imgPnt4 = new Point(imagePoints.get(3, 0)); + Mat camImgCopy = cameraImageMat.clone(); + Mat outputMat = camImgCopy.clone(); + + + + Imgproc.circle(cameraImageMat, imgPnt1, 5, new Scalar(255, 0, 0, 255)); + Imgproc.circle(cameraImageMat, imgPnt2, 5, new Scalar(0, 255, 0, 255)); + Imgproc.circle(cameraImageMat, imgPnt3, 5, new Scalar(0, 0, 255, 255)); + Imgproc.circle(cameraImageMat, imgPnt4, 5, new Scalar(255, 255, 0, 255)); + + + //Imgproc.drawContours(cameraImageMat, new List { square }, -1, new Scalar(0, 255, 0), 2); + + + Mat homo = ComputeHomo(imagePoints, dstPointsInv); + + + Mat outputSkullMat = cameraImageMat.clone(); + Imgproc.warpPerspective(skullTextureMat, outputSkullMat, homo.inv(), outputSkullMat.size()); + + + Mat dstCam = cameraImageMat.clone(); + + Core.addWeighted(cameraImageMat, 0.95f, outputSkullMat, 0.7f, 0.0f, dstCam); + + //Display the Mat that includes video feed and debug points + MatDisplay.DisplayMat(dstCam, MatDisplaySettings.FULL_BACKGROUND); + + } + else + { + MatDisplay.DisplayMat(cameraImageMat, MatDisplaySettings.FULL_BACKGROUND); + } + + } + } + + MatOfPoint2f findSquare (List squareContours) + { + foreach (var outer_square in squareContours) + { + var outer_maxX = outer_square.toList().Max(point => point.x); + var outer_maxY = outer_square.toList().Max(point => point.y); + + var outer_minX = outer_square.toList().Min(point => point.x); + var outer_minY = outer_square.toList().Min(point => point.y); + + foreach (var inner_square in squareContours) + { + var inner_maxX = inner_square.toList().Max(point => point.x); + var inner_maxY = inner_square.toList().Max(point => point.y); + + var inner_minX = inner_square.toList().Min(point => point.x); + var inner_minY = inner_square.toList().Min(point => point.y); + + if (outer_minX < inner_minX && + outer_minY < inner_minY && + outer_maxX > inner_maxX && + outer_maxY > inner_maxY) + { + + List sortedOuterSquare = outer_square.toList().OrderBy(p => p.x).ThenBy(p => p.y).ToList(); + + MatOfPoint2f res = new MatOfPoint2f(); + + for (int i = 0; i < 4; i++) + { + res.put(i, 0, sortedOuterSquare[i].x, sortedOuterSquare[i].y); + } + + print("--------------------------------"); + return res; + } + } + } + return null; + } + + Mat ComputeHomo(MatOfPoint2f imgPoints, MatOfPoint2f destPoints) + { + + + Mat H = new Mat(8, 1, CvType.CV_32FC1); + Mat A = new Mat(8, 8, CvType.CV_32FC1); + Mat b = new Mat(8, 1, CvType.CV_32FC1); + + + for (int i = 0; i < 4; i++) + { + var u = destPoints.get(i, 0)[0]; + var v = destPoints.get(i, 0)[1]; + + b.put(i * 2, 0, u); + b.put((i * 2) + 1, 0, v); + + + + var x = imgPoints.get(i, 0)[0]; + var y = imgPoints.get(i, 0)[1]; + + A.put(i * 2, 0, x, y, 1, 0, 0, 0, -u * x, -u * y); + A.put((i * 2) + 1, 0, 0, 0, 0, x, y, 1, -v * x, -v * y); + + } + + Core.solve(A, b, H); + + Mat ShitsReal = new Mat(3, 3, CvType.CV_32FC1); + ShitsReal.put(0, 0, H.get(0, 0)[0], H.get(1, 0)[0], H.get(2, 0)[0]); + ShitsReal.put(1, 0, H.get(3, 0)[0], H.get(4, 0)[0], H.get(5, 0)[0]); + ShitsReal.put(2, 0, H.get(6, 0)[0], H.get(7, 0)[0], 1); + + return ShitsReal; + } +}