├── .gitignore ├── Assets ├── Editor.meta ├── Editor │ ├── PostProcessBuilder │ └── PostProcessBuilder.meta ├── Materials.meta ├── Materials │ ├── Ar Object.mat │ ├── Ar Object.mat.meta │ ├── Background Camera.mat │ └── Background Camera.mat.meta ├── Plugins.meta ├── Plugins │ ├── Android.meta │ ├── Android │ │ ├── AndroidManifest.xml │ │ ├── AndroidManifest.xml.meta │ │ ├── libcheck_texture.so │ │ ├── libcheck_texture.so.meta │ │ ├── libopencv_sample.so │ │ └── libopencv_sample.so.meta │ ├── x86_64.meta │ └── x86_64 │ │ ├── check_texture.bundle.meta │ │ ├── check_texture.bundle │ │ ├── Contents.meta │ │ └── Contents │ │ │ ├── Info.plist │ │ │ ├── Info.plist.meta │ │ │ ├── MacOS.meta │ │ │ ├── MacOS │ │ │ ├── check_texture │ │ │ └── check_texture.meta │ │ │ ├── Resources.meta │ │ │ └── Resources │ │ │ ├── Android.mk │ │ │ ├── Android.mk.meta │ │ │ ├── Application.mk │ │ │ └── Application.mk.meta │ │ ├── opencv_sample.bundle.meta │ │ └── opencv_sample.bundle │ │ ├── Contents.meta │ │ └── Contents │ │ ├── Info.plist │ │ ├── Info.plist.meta │ │ ├── MacOS.meta │ │ └── MacOS │ │ ├── opencv_sample │ │ └── opencv_sample.meta ├── Prefabs.meta ├── Prefabs │ ├── Ar Object.prefab │ └── Ar Object.prefab.meta ├── Scenes.meta ├── Scenes │ ├── Aruco.unity │ ├── Aruco.unity.meta │ ├── Aruco_AR.unity │ ├── Aruco_AR.unity.meta │ ├── CannyCamera.unity │ ├── CannyCamera.unity.meta │ ├── CheckTexture.unity │ ├── CheckTexture.unity.meta │ ├── NativeCamera.unity │ ├── NativeCamera.unity.meta │ ├── ReadTexture.unity │ └── ReadTexture.unity.meta ├── Scripts.meta ├── Scripts │ ├── ArPlane.cs │ ├── ArPlane.cs.meta │ ├── CannyCamera.cs │ ├── CannyCamera.cs.meta │ ├── CheckTexture.cs │ ├── CheckTexture.cs.meta │ ├── DetectArucoMarker.cs │ ├── DetectArucoMarker.cs.meta │ ├── NativeCamera.cs │ ├── NativeCamera.cs.meta │ ├── ReadTexture.cs │ └── ReadTexture.cs.meta ├── StreamingAssets.meta └── StreamingAssets │ ├── intrinsics.yml │ ├── intrinsics.yml.meta │ ├── zzz.png │ └── zzz.png.meta ├── LICENSE ├── Plugins ├── check_texture │ ├── jni │ │ ├── Android.mk │ │ ├── Application.mk │ │ └── check_texture.cpp │ └── mac │ │ ├── check_texture.xcodeproj │ │ ├── project.pbxproj │ │ ├── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcuserdata │ │ │ │ └── hecomi.xcuserdatad │ │ │ │ └── UserInterfaceState.xcuserstate │ │ └── xcuserdata │ │ │ └── hecomi.xcuserdatad │ │ │ └── xcschemes │ │ │ ├── check_texture.xcscheme │ │ │ └── xcschememanagement.plist │ │ └── check_texture │ │ └── Info.plist └── opencv_sample │ ├── jni │ ├── Android.mk │ ├── Application.mk │ ├── aruco.cpp │ ├── aruco │ │ ├── AUTHORS │ │ ├── COPYING │ │ ├── ChangeLog │ │ ├── INSTALL │ │ ├── LICENSE │ │ ├── NEWS │ │ ├── README │ │ ├── TODO │ │ └── jni │ │ │ ├── Aruco.mk │ │ │ ├── ar_omp.cpp │ │ │ ├── ar_omp.h │ │ │ ├── aruco.h │ │ │ ├── arucofidmarkers.cpp │ │ │ ├── arucofidmarkers.h │ │ │ ├── board.cpp │ │ │ ├── board.h │ │ │ ├── boarddetector.cpp │ │ │ ├── boarddetector.h │ │ │ ├── cameraparameters.cpp │ │ │ ├── cameraparameters.h │ │ │ ├── cvdrawingutils.cpp │ │ │ ├── cvdrawingutils.h │ │ │ ├── exports.h │ │ │ ├── marker.cpp │ │ │ ├── marker.h │ │ │ ├── markerdetector.cpp │ │ │ ├── markerdetector.h │ │ │ ├── subpixelcorner.cpp │ │ │ └── subpixelcorner.h │ ├── camera_image.cpp │ ├── log.h │ └── read_image.cpp │ └── mac │ ├── opencv_sample.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── hecomi.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── hecomi.xcuserdatad │ │ └── xcschemes │ │ ├── opencv_sample.xcscheme │ │ └── xcschememanagement.plist │ └── opencv_sample │ └── Info.plist └── ProjectSettings ├── AudioManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset └── TimeManager.asset /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | 6 | # Autogenerated VS/MD solution and project files 7 | *.csproj 8 | *.unityproj 9 | *.sln 10 | *.suo 11 | *.tmp 12 | *.user 13 | *.userprefs 14 | *.pidb 15 | *.booproj 16 | 17 | # Unity3D generated meta files 18 | *.pidb.meta 19 | 20 | # Unity3D Generated File On Crash Reports 21 | sysinfo.txt 22 | 23 | # Mac 24 | *.DS_Store 25 | 26 | # Libraries 27 | Plugins/opencv_sample/jni/opencv/ 28 | 29 | # Intermediates 30 | obj/ 31 | *.o 32 | *.d 33 | -------------------------------------------------------------------------------- /Assets/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7560c65437e2045db819562d8f984e81 3 | folderAsset: yes 4 | timeCreated: 1442042622 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Editor/PostProcessBuilder: -------------------------------------------------------------------------------- 1 | adb shell mkdir /sdcard/AndroidOpenCvSample 2 | ls -1 ../../Assets/StreamingAssets/ | \ 3 | grep -v .meta | \ 4 | xargs -ILOCALFILE \ 5 | adb push ../../Assets/StreamingAssets/LOCALFILE /sdcard/AndroidOpenCvSample/ 6 | 7 | -------------------------------------------------------------------------------- /Assets/Editor/PostProcessBuilder.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 09698e83f40ed413290e64fa8f588d06 3 | timeCreated: 1442044955 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d6738ccfcb6e743cda8ac6524c9f6d2b 3 | folderAsset: yes 4 | timeCreated: 1442073215 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Materials/Ar Object.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/Materials/Ar Object.mat -------------------------------------------------------------------------------- /Assets/Materials/Ar Object.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c85ef11189a8424692a9e4e6f7d07ce 3 | timeCreated: 1442249374 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Materials/Background Camera.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/Materials/Background Camera.mat -------------------------------------------------------------------------------- /Assets/Materials/Background Camera.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0a44ba7a32962495a8c88e17b442af20 3 | timeCreated: 1442073222 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1639f6557f9344fbbbae4783e2426f5e 3 | folderAsset: yes 4 | timeCreated: 1441435743 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/Android.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e4950e0ec02af45ac93b298cabf4ed17 3 | folderAsset: yes 4 | timeCreated: 1441435750 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/Android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Assets/Plugins/Android/AndroidManifest.xml.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b221f2b5a85db4c98a61002b991bb86e 3 | timeCreated: 1441470055 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/Android/libcheck_texture.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/Plugins/Android/libcheck_texture.so -------------------------------------------------------------------------------- /Assets/Plugins/Android/libcheck_texture.so.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ffa9b912168364ec7b2b84f9aa882dbf 3 | timeCreated: 1441438816 4 | licenseType: Pro 5 | PluginImporter: 6 | serializedVersion: 1 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | platformData: 11 | Any: 12 | enabled: 1 13 | settings: {} 14 | userData: 15 | assetBundleName: 16 | assetBundleVariant: 17 | -------------------------------------------------------------------------------- /Assets/Plugins/Android/libopencv_sample.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/Plugins/Android/libopencv_sample.so -------------------------------------------------------------------------------- /Assets/Plugins/Android/libopencv_sample.so.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f0fe2dd41aebf4ecc8b20efaed6e4d58 3 | timeCreated: 1441471741 4 | licenseType: Pro 5 | PluginImporter: 6 | serializedVersion: 1 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | platformData: 11 | Any: 12 | enabled: 1 13 | settings: {} 14 | userData: 15 | assetBundleName: 16 | assetBundleVariant: 17 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: af310b8f47e7e4ec78c06bdc725f95a6 3 | folderAsset: yes 4 | timeCreated: 1441455539 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/check_texture.bundle.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: add4a79973b964af9a4d750ed0f35da0 3 | folderAsset: yes 4 | timeCreated: 1441456551 5 | licenseType: Pro 6 | PluginImporter: 7 | serializedVersion: 1 8 | iconMap: {} 9 | executionOrder: {} 10 | isPreloaded: 0 11 | platformData: 12 | Any: 13 | enabled: 1 14 | settings: {} 15 | userData: 16 | assetBundleName: 17 | assetBundleVariant: 18 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/check_texture.bundle/Contents.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a5a9db835a4454e5cbd89f07f38e572b 3 | folderAsset: yes 4 | timeCreated: 1441456551 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/check_texture.bundle/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 14F27 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | check_texture 11 | CFBundleIdentifier 12 | com.hecomi.check-texture.check-texture 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | check_texture 17 | CFBundlePackageType 18 | BNDL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | DTCompiler 26 | com.apple.compilers.llvm.clang.1_0 27 | DTPlatformBuild 28 | 6E35b 29 | DTPlatformVersion 30 | GM 31 | DTSDKBuild 32 | 14D125 33 | DTSDKName 34 | macosx10.10 35 | DTXcode 36 | 0640 37 | DTXcodeBuild 38 | 6E35b 39 | NSHumanReadableCopyright 40 | Copyright © 2015年 hecomi. All rights reserved. 41 | 42 | 43 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/check_texture.bundle/Contents/Info.plist.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1b4042144b3c64f9ea47f37886ab141c 3 | timeCreated: 1441456551 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/check_texture.bundle/Contents/MacOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c84f79a40cc884515b8c5fcecbfdc245 3 | folderAsset: yes 4 | timeCreated: 1441456551 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/check_texture.bundle/Contents/MacOS/check_texture: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/Plugins/x86_64/check_texture.bundle/Contents/MacOS/check_texture -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/check_texture.bundle/Contents/MacOS/check_texture.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b82a959f522fa4f7aa235ebaf61dd645 3 | timeCreated: 1441456551 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/check_texture.bundle/Contents/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aa77821adeef24ec2a259462facd9b72 3 | folderAsset: yes 4 | timeCreated: 1441456551 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/check_texture.bundle/Contents/Resources/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | NDK_APP_DST_DIR := ../../../Assets/Plugins/ 6 | LOCAL_MODULE := libcheck_texture 7 | LOCAL_SRC_FILES := check_texture.cpp 8 | 9 | include $(BUILD_SHARED_LIBRARY) 10 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/check_texture.bundle/Contents/Resources/Android.mk.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f306bbf19d6c64a5dab0ebc0a0ffc32d 3 | timeCreated: 1441456551 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/check_texture.bundle/Contents/Resources/Application.mk: -------------------------------------------------------------------------------- 1 | APP_STL := gnustl_static 2 | APP_CPPFLAGS := -frtti -fexceptions 3 | APP_ABI := x86_64 4 | APP_PLATFORM := android-9 5 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/check_texture.bundle/Contents/Resources/Application.mk.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 49d199c36cb3d4025b1b0bc32ac8b9fb 3 | timeCreated: 1441456551 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/opencv_sample.bundle.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c64adae2eb263448b8e09d558f9ab1d7 3 | folderAsset: yes 4 | timeCreated: 1441471601 5 | licenseType: Pro 6 | PluginImporter: 7 | serializedVersion: 1 8 | iconMap: {} 9 | executionOrder: {} 10 | isPreloaded: 0 11 | platformData: 12 | Any: 13 | enabled: 1 14 | settings: {} 15 | userData: 16 | assetBundleName: 17 | assetBundleVariant: 18 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/opencv_sample.bundle/Contents.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f7529a499a8f742dfaf8df9fb1193d8d 3 | folderAsset: yes 4 | timeCreated: 1441471601 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/opencv_sample.bundle/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 14F27 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | opencv_sample 11 | CFBundleIdentifier 12 | com.hecomi.opencv-sample.opencv-sample 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | opencv_sample 17 | CFBundlePackageType 18 | BNDL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | DTCompiler 26 | com.apple.compilers.llvm.clang.1_0 27 | DTPlatformBuild 28 | 6E35b 29 | DTPlatformVersion 30 | GM 31 | DTSDKBuild 32 | 14D125 33 | DTSDKName 34 | macosx10.10 35 | DTXcode 36 | 0640 37 | DTXcodeBuild 38 | 6E35b 39 | NSHumanReadableCopyright 40 | Copyright © 2015年 hecomi. All rights reserved. 41 | 42 | 43 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/opencv_sample.bundle/Contents/Info.plist.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2f4471388331148e48f4d812968bf1a6 3 | timeCreated: 1441471601 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/opencv_sample.bundle/Contents/MacOS.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ac23fc4e9092d4e1fbc833fce7751844 3 | folderAsset: yes 4 | timeCreated: 1441471601 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/opencv_sample.bundle/Contents/MacOS/opencv_sample: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/Plugins/x86_64/opencv_sample.bundle/Contents/MacOS/opencv_sample -------------------------------------------------------------------------------- /Assets/Plugins/x86_64/opencv_sample.bundle/Contents/MacOS/opencv_sample.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed22f0335ec6647708be369c4380d4c5 3 | timeCreated: 1441471601 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Prefabs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e326a9a0006ea4557a51d4c77cd0438d 3 | folderAsset: yes 4 | timeCreated: 1442122229 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Prefabs/Ar Object.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/Prefabs/Ar Object.prefab -------------------------------------------------------------------------------- /Assets/Prefabs/Ar Object.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7b4a76d6b165f444ca941c5129252e0e 3 | timeCreated: 1442248002 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e5dfcdae5072b467a9d1a5c6ee2db695 3 | folderAsset: yes 4 | timeCreated: 1441471767 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scenes/Aruco.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/Scenes/Aruco.unity -------------------------------------------------------------------------------- /Assets/Scenes/Aruco.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d923beaef1bcc436bb07d497ff267cfc 3 | timeCreated: 1442050900 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/Aruco_AR.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/Scenes/Aruco_AR.unity -------------------------------------------------------------------------------- /Assets/Scenes/Aruco_AR.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3082c982291ba4217b0a19a0cc253eba 3 | timeCreated: 1442073245 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/CannyCamera.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/Scenes/CannyCamera.unity -------------------------------------------------------------------------------- /Assets/Scenes/CannyCamera.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f9231528547214cebb1a9d57435b0f6d 3 | timeCreated: 1441535730 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/CheckTexture.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/Scenes/CheckTexture.unity -------------------------------------------------------------------------------- /Assets/Scenes/CheckTexture.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a48fa4e0e90204668bc929c7eed3c65d 3 | timeCreated: 1441435737 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/NativeCamera.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/Scenes/NativeCamera.unity -------------------------------------------------------------------------------- /Assets/Scenes/NativeCamera.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eeeee09680b6d4117aeb348b51706e14 3 | timeCreated: 1442054588 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/ReadTexture.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/Scenes/ReadTexture.unity -------------------------------------------------------------------------------- /Assets/Scenes/ReadTexture.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: da04fa949a6914693bc4e1e5ddb9258f 3 | timeCreated: 1441471786 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5873b2188d57b4020ab813345af95b24 3 | folderAsset: yes 4 | timeCreated: 1441437151 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts/ArPlane.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Runtime.InteropServices; 5 | using System.Threading; 6 | 7 | public class ArPlane : MonoBehaviour 8 | { 9 | [DllImport("opencv_sample")] 10 | private static extern IntPtr aruco_initialize(int width, int height, float markerSize, string cameraParamsFilePath); 11 | [DllImport("opencv_sample")] 12 | private static extern void aruco_finalize(IntPtr instance); 13 | [DllImport("opencv_sample")] 14 | private static extern void aruco_set_image(IntPtr instance, IntPtr src); 15 | [DllImport("opencv_sample")] 16 | private static extern void aruco_get_image(IntPtr instance, IntPtr dest); 17 | [DllImport("opencv_sample")] 18 | private static extern int aruco_detect(IntPtr instance, bool drawOutputImage); 19 | [DllImport("opencv_sample")] 20 | private static extern IntPtr aruco_get_markers(IntPtr instance); 21 | 22 | private WebCamTexture webcamTexture_; 23 | private bool isWebCamInitialized_ = false; 24 | private int width_; 25 | private int height_; 26 | 27 | private IntPtr aruco_ = IntPtr.Zero; 28 | private bool isArucoUpdated_ = false; 29 | public float unityMarkerSize = 1f; 30 | public float markerSize = 0.1f; 31 | public string cameraParamsFileName = "intrinsics.yml"; 32 | private List markers_ = new List(); 33 | private int markerNum_; 34 | 35 | private Thread thread_; 36 | private Mutex mutex_; 37 | 38 | public GameObject prefab; 39 | private Dictionary arObjects_ = new Dictionary(); 40 | 41 | [StructLayout(LayoutKind.Sequential)] 42 | struct MarkerResult 43 | { 44 | [MarshalAs(UnmanagedType.I4)] 45 | public int id; 46 | [MarshalAs(UnmanagedType.ByValArray, SizeConst=3)] 47 | public double[] position; 48 | [MarshalAs(UnmanagedType.ByValArray, SizeConst=4)] 49 | public double[] orientation; 50 | } 51 | 52 | public int cameraWidth = 800; 53 | public int cameraHeight = 450; 54 | public int cameraFrameRate = 15; 55 | public float cameraFov = 38f; 56 | 57 | string GetFilePath(string fileName) 58 | { 59 | #if UNITY_EDITOR 60 | return Application.streamingAssetsPath + "/" + fileName; 61 | #elif UNITY_ANDROID 62 | return "/sdcard/AndroidOpenCvSample/" + fileName; 63 | #endif 64 | } 65 | 66 | void Awake() 67 | { 68 | SetupWebCamTexture(); 69 | InitializeAruco(); 70 | 71 | mutex_ = new Mutex(); 72 | thread_ = new Thread(() => { 73 | try { 74 | for (;;) { 75 | Thread.Sleep(0); 76 | if (!isArucoUpdated_) { 77 | mutex_.WaitOne(); 78 | var num = aruco_detect(aruco_, false); 79 | GetMarkers(num); 80 | mutex_.ReleaseMutex(); 81 | isArucoUpdated_ = true; 82 | } 83 | } 84 | } catch (Exception e) { 85 | if (!(e is ThreadAbortException)) { 86 | Debug.LogError("Unexpected Death: " + e.ToString()); 87 | } 88 | } 89 | }); 90 | 91 | thread_.Start(); 92 | } 93 | 94 | void OnDestroy() 95 | { 96 | thread_.Abort(); 97 | FinalizeAruco(); 98 | } 99 | 100 | void SetupWebCamTexture() 101 | { 102 | var devices = WebCamTexture.devices; 103 | if (devices.Length > 0) { 104 | webcamTexture_ = new WebCamTexture(devices[0].name, cameraWidth, cameraHeight, cameraFrameRate); 105 | webcamTexture_.Play(); 106 | GetComponent().material.mainTexture = webcamTexture_; 107 | width_ = webcamTexture_.width; 108 | height_ = webcamTexture_.height; 109 | isWebCamInitialized_ = true; 110 | } else { 111 | Debug.Log("no camera"); 112 | } 113 | } 114 | 115 | void InitializeAruco() 116 | { 117 | if (!isWebCamInitialized_) return; 118 | 119 | var path = GetFilePath(cameraParamsFileName); 120 | aruco_ = aruco_initialize(width_, height_, markerSize, path); 121 | } 122 | 123 | void FinalizeAruco() 124 | { 125 | aruco_finalize(aruco_); 126 | } 127 | 128 | void GetMarkers(int num) 129 | { 130 | markers_.Clear(); 131 | var ptr = aruco_get_markers(aruco_); 132 | var size = Marshal.SizeOf(typeof(MarkerResult)); 133 | for (int i = 0; i < num; ++i) { 134 | var data = new IntPtr(ptr.ToInt64() + size * i); 135 | var marker = (MarkerResult)Marshal.PtrToStructure(data, typeof(MarkerResult)); 136 | markers_.Add(marker); 137 | } 138 | Debug.Log(num); 139 | } 140 | 141 | void OnMarkerDetected(int id, Vector3 pos, Quaternion rot) 142 | { 143 | if (arObjects_.ContainsKey(id)) { 144 | var obj = arObjects_[id].transform; 145 | obj.localPosition = pos; 146 | obj.localRotation = rot; 147 | } else { 148 | var obj = Instantiate(prefab) as GameObject; 149 | obj.transform.parent = Camera.main.transform; 150 | obj.transform.localPosition = pos; 151 | obj.transform.localRotation = rot; 152 | arObjects_.Add(id, obj); 153 | } 154 | } 155 | 156 | Vector3 GetMarkerPos(double[] p) 157 | { 158 | var unityFov = Camera.main.fieldOfView; 159 | // should be 1f 160 | var xyScaleFactor = Mathf.Tan(Mathf.Deg2Rad * unityFov) / Mathf.Tan(Mathf.Deg2Rad * cameraFov); 161 | var realToUnityScale = unityMarkerSize / markerSize; 162 | var x = -(float)p[0] * xyScaleFactor; 163 | var y = -(float)p[1] * xyScaleFactor; 164 | var z = (float)p[2]; 165 | return new Vector3(x, y, z) * realToUnityScale; 166 | } 167 | 168 | Quaternion GetMarkerRot(double[] q) 169 | { 170 | var x = -(float)q[2]; 171 | var y = (float)q[1]; 172 | var z = (float)q[0]; 173 | var w = -(float)q[3]; 174 | return new Quaternion(x, y, z, w); 175 | } 176 | 177 | void FullScreen() 178 | { 179 | var fov = Camera.main.fieldOfView; 180 | var farPos = 1000f; 181 | var scaleY = farPos * Mathf.Tan(Mathf.Deg2Rad * fov / 2) * 2 * 0.1f; 182 | var scaleX = scaleY * width_ / height_; 183 | transform.localPosition = Vector3.forward * farPos; 184 | transform.localScale = new Vector3(scaleX, 1f, scaleY); 185 | } 186 | 187 | void SetObjectsVisibility() 188 | { 189 | var detectedIds = new List(); 190 | foreach (var marker in markers_) { 191 | detectedIds.Add(marker.id); 192 | } 193 | foreach (var kvp in arObjects_) { 194 | var id = kvp.Key; 195 | var obj = kvp.Value; 196 | bool isDetected = false; 197 | foreach (var detectedId in detectedIds) { 198 | if (id == detectedId) { 199 | isDetected = true; 200 | break; 201 | } 202 | } 203 | obj.SetActive(isDetected); 204 | } 205 | } 206 | 207 | void Update() 208 | { 209 | if (isWebCamInitialized_ && webcamTexture_.didUpdateThisFrame) return; 210 | 211 | while (!isArucoUpdated_) Thread.Sleep(1); 212 | 213 | var pixels = webcamTexture_.GetPixels32(); 214 | var handle = GCHandle.Alloc(pixels, GCHandleType.Pinned); 215 | var ptr = handle.AddrOfPinnedObject(); 216 | aruco_set_image(aruco_, ptr); 217 | handle.Free(); 218 | 219 | mutex_.WaitOne(); 220 | foreach (var marker in markers_) { 221 | var pos = GetMarkerPos(marker.position); 222 | var rot = GetMarkerRot(marker.orientation); 223 | OnMarkerDetected(marker.id, pos, rot); 224 | } 225 | SetObjectsVisibility(); 226 | isArucoUpdated_ = false; 227 | mutex_.ReleaseMutex(); 228 | 229 | FullScreen(); 230 | } 231 | 232 | void OnGUI() 233 | { 234 | Rect rect = new Rect(20, 50, 400, 30); 235 | cameraFov = GUI.HorizontalSlider(rect, cameraFov, 0, 100); 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /Assets/Scripts/ArPlane.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c49b76cae1332455788558c69873335d 3 | timeCreated: 1442073355 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/CannyCamera.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | public class CannyCamera : MonoBehaviour 6 | { 7 | [DllImport("opencv_sample")] 8 | private static extern int to_canny(IntPtr src, IntPtr dest, int width, int height, int thresh1, int thresh2); 9 | 10 | private WebCamTexture webcamTexture_; 11 | private Texture2D cannyTexture_; 12 | 13 | private bool isWebCamInitialized_ = false; 14 | private int width_; 15 | private int height_; 16 | 17 | [Range(0, 255)] 18 | public int thresh1 = 50; 19 | [Range(0, 255)] 20 | public int thresh2 = 200; 21 | 22 | void Start() 23 | { 24 | SetupWebCamTexture(); 25 | SetupCannyTexture(); 26 | } 27 | 28 | void SetupWebCamTexture() 29 | { 30 | var devices = WebCamTexture.devices; 31 | if (devices.Length > 0) { 32 | webcamTexture_ = new WebCamTexture(devices[0].name, 640, 480); 33 | webcamTexture_.Play(); 34 | width_ = webcamTexture_.width; 35 | height_ = webcamTexture_.height; 36 | isWebCamInitialized_ = true; 37 | } else { 38 | Debug.Log("no camera"); 39 | } 40 | } 41 | 42 | void SetupCannyTexture() 43 | { 44 | if (!isWebCamInitialized_) return; 45 | cannyTexture_ = new Texture2D(width_, height_); 46 | } 47 | 48 | void Update() 49 | { 50 | if (!isWebCamInitialized_) return; 51 | 52 | var pixels = webcamTexture_.GetPixels32(); 53 | var handle = GCHandle.Alloc(pixels, GCHandleType.Pinned); 54 | var ptr = handle.AddrOfPinnedObject(); 55 | to_canny(ptr, ptr, width_, height_, thresh1, thresh2); 56 | 57 | cannyTexture_.SetPixels32(pixels); 58 | cannyTexture_.Apply(); 59 | GetComponent().material.mainTexture = cannyTexture_; 60 | } 61 | } -------------------------------------------------------------------------------- /Assets/Scripts/CannyCamera.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 33ba32a428f90483280a7dc35ee52adc 3 | timeCreated: 1441535702 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/CheckTexture.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | public class CheckTexture : MonoBehaviour 6 | { 7 | [DllImport("check_texture")] 8 | private static extern void create_check_texture(IntPtr data, int w, int h, int ch); 9 | 10 | private Texture2D texture_; 11 | private Color32[] pixels_; 12 | private GCHandle pixels_handle_; 13 | private IntPtr pixels_ptr_ = IntPtr.Zero; 14 | 15 | void Start() 16 | { 17 | // テクスチャを生成 18 | texture_ = new Texture2D(10, 10, TextureFormat.RGB24, false); 19 | // テクスチャの拡大方法をニアレストネイバーに変更 20 | texture_.filterMode = FilterMode.Point; 21 | // Color32 型の配列としてテクスチャの参照をもらう 22 | pixels_ = texture_.GetPixels32(); 23 | // GC されないようにする 24 | pixels_handle_ = GCHandle.Alloc(pixels_, GCHandleType.Pinned); 25 | // そのテクスチャのアドレスをもらう 26 | pixels_ptr_ = pixels_handle_.AddrOfPinnedObject(); 27 | // スクリプトがアタッチされたオブジェクトのテクスチャをコレにする 28 | GetComponent().material.mainTexture = texture_; 29 | // ネイティブ側でテクスチャを生成 30 | create_check_texture(pixels_ptr_, texture_.width, texture_.height, 4); 31 | // セットして反映させる 32 | texture_.SetPixels32(pixels_); 33 | texture_.Apply(false, true); 34 | // GC 対象にする 35 | pixels_handle_.Free(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Assets/Scripts/CheckTexture.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9a26a95cff1f044b2b03483fc26bd25b 3 | timeCreated: 1441437158 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/DetectArucoMarker.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections; 4 | using System.Runtime.InteropServices; 5 | using System.Threading; 6 | 7 | public class DetectArucoMarker : MonoBehaviour 8 | { 9 | [DllImport("opencv_sample")] 10 | private static extern IntPtr aruco_initialize(int width, int height, float markerSize, string cameraParamsFilePath); 11 | [DllImport("opencv_sample")] 12 | private static extern void aruco_finalize(IntPtr instance); 13 | [DllImport("opencv_sample")] 14 | private static extern void aruco_set_image(IntPtr instance, IntPtr src); 15 | [DllImport("opencv_sample")] 16 | private static extern void aruco_get_image(IntPtr instance, IntPtr dest); 17 | [DllImport("opencv_sample")] 18 | private static extern int aruco_detect(IntPtr instance); 19 | 20 | private WebCamTexture webcamTexture_; 21 | private bool isWebCamInitialized_ = false; 22 | private int width_; 23 | private int height_; 24 | 25 | private IntPtr aruco_ = IntPtr.Zero; 26 | private bool isArucoUpdated_ = false; 27 | public float markerSize = 0.04f; 28 | public string cameraParamsFileName = "intrinsics.yml"; 29 | 30 | public Thread thread_; 31 | 32 | string GetFilePath(string fileName) 33 | { 34 | #if UNITY_EDITOR 35 | return Application.streamingAssetsPath + "/" + fileName; 36 | #elif UNITY_ANDROID 37 | return "/sdcard/AndroidOpenCvSample/" + fileName; 38 | #endif 39 | } 40 | 41 | void Awake() 42 | { 43 | SetupWebCamTexture(); 44 | InitializeAruco(); 45 | 46 | thread_ = new Thread(() => { 47 | try { 48 | for (;;) { 49 | Thread.Sleep(0); 50 | if (!isArucoUpdated_) { 51 | aruco_detect(aruco_); 52 | isArucoUpdated_ = true; 53 | } 54 | } 55 | } catch (Exception e) { 56 | if (!(e is ThreadAbortException)) { 57 | Debug.LogError("Unexpected Death: " + e.ToString()); 58 | } 59 | } 60 | }); 61 | thread_.Start(); 62 | } 63 | 64 | void OnDestroy() 65 | { 66 | thread_.Abort(); 67 | FinalizeAruco(); 68 | } 69 | 70 | void SetupWebCamTexture() 71 | { 72 | var devices = WebCamTexture.devices; 73 | if (devices.Length > 0) { 74 | webcamTexture_ = new WebCamTexture(devices[0].name, 640, 480); 75 | webcamTexture_.Play(); 76 | width_ = webcamTexture_.width; 77 | height_ = webcamTexture_.height; 78 | isWebCamInitialized_ = true; 79 | } else { 80 | Debug.Log("no camera"); 81 | } 82 | } 83 | 84 | void InitializeAruco() 85 | { 86 | if (!isWebCamInitialized_) return; 87 | 88 | var path = GetFilePath(cameraParamsFileName); 89 | aruco_ = aruco_initialize(width_, height_, markerSize, path); 90 | } 91 | 92 | void FinalizeAruco() 93 | { 94 | aruco_finalize(aruco_); 95 | } 96 | 97 | void Update() 98 | { 99 | if (isWebCamInitialized_ && webcamTexture_.didUpdateThisFrame) return; 100 | 101 | if (isArucoUpdated_) { 102 | { 103 | var pixels = webcamTexture_.GetPixels32(); 104 | var handle = GCHandle.Alloc(pixels, GCHandleType.Pinned); 105 | var ptr = handle.AddrOfPinnedObject(); 106 | aruco_set_image(aruco_, ptr); 107 | handle.Free(); 108 | } 109 | { 110 | var tex = new Texture2D(width_, height_, TextureFormat.RGBA32, false, false); 111 | var pixels = tex.GetPixels32(); 112 | var handle = GCHandle.Alloc(pixels, GCHandleType.Pinned); 113 | var ptr = handle.AddrOfPinnedObject(); 114 | aruco_get_image(aruco_, ptr); 115 | handle.Free(); 116 | tex.SetPixels32(pixels); 117 | tex.Apply(false, false); 118 | GetComponent().material.mainTexture = tex; 119 | } 120 | isArucoUpdated_ = false; 121 | } 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Assets/Scripts/DetectArucoMarker.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 57c5db7386db546ba96330bdb3b9d959 3 | timeCreated: 1442050525 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/NativeCamera.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Collections; 4 | using System.Runtime.InteropServices; 5 | 6 | public class NativeCamera : MonoBehaviour 7 | { 8 | [DllImport("opencv_sample")] 9 | private static extern IntPtr get_camera(); 10 | [DllImport("opencv_sample")] 11 | private static extern void release_camera(IntPtr camera); 12 | [DllImport("opencv_sample")] 13 | private static extern bool fetch_image(IntPtr camera, IntPtr dest, int width, int height); 14 | 15 | private IntPtr camera_ = IntPtr.Zero; 16 | private Texture2D texture_; 17 | private Color32[] pixels_; 18 | private GCHandle handle_; 19 | private IntPtr ptr_; 20 | 21 | void Start() 22 | { 23 | camera_ = get_camera(); 24 | if (camera_ == IntPtr.Zero) { 25 | Debug.LogError("camera cannot be opened."); 26 | return; 27 | } 28 | 29 | texture_ = new Texture2D(640, 480, TextureFormat.RGBA32, false); 30 | pixels_ = texture_.GetPixels32(); 31 | handle_ = GCHandle.Alloc(pixels_, GCHandleType.Pinned); 32 | ptr_ = handle_.AddrOfPinnedObject(); 33 | GetComponent().material.mainTexture = texture_; 34 | } 35 | 36 | void OnDestroy() 37 | { 38 | if (handle_.IsAllocated) { 39 | handle_.Free(); 40 | } 41 | if (camera_ != IntPtr.Zero) { 42 | release_camera(camera_); 43 | } 44 | } 45 | 46 | void Update() 47 | { 48 | if (fetch_image(camera_, ptr_, 640, 480)) { 49 | texture_.SetPixels32(pixels_); 50 | texture_.Apply(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Assets/Scripts/NativeCamera.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7861511937867461cbea9ea454e22d70 3 | timeCreated: 1441646733 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/ReadTexture.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.Runtime.InteropServices; 4 | 5 | public class ReadTexture : MonoBehaviour 6 | { 7 | [DllImport("opencv_sample")] 8 | private static extern bool get_image_size(string path, out int width, out int height); 9 | [DllImport("opencv_sample")] 10 | private static extern bool read_image(string path, IntPtr ptr); 11 | 12 | private Texture2D texture_; 13 | private Color32[] pixels_; 14 | private GCHandle pixels_handle_; 15 | private IntPtr pixels_ptr_ = IntPtr.Zero; 16 | 17 | public string imagePath = "zzz.png"; 18 | 19 | string GetFilePath(string fileName) 20 | { 21 | #if UNITY_EDITOR 22 | return Application.streamingAssetsPath + "/" + fileName; 23 | #elif UNITY_ANDROID 24 | return "/sdcard/AndroidOpenCvSample/" + fileName; 25 | #endif 26 | } 27 | 28 | void Start() 29 | { 30 | var path = GetFilePath(imagePath); 31 | int width, height; 32 | if (!get_image_size(path, out width, out height)) { 33 | Debug.LogFormat("{0} was not found", path); 34 | return; 35 | } 36 | 37 | texture_ = new Texture2D(width, height, TextureFormat.RGB24, false); 38 | texture_.filterMode = FilterMode.Point; 39 | pixels_ = texture_.GetPixels32(); 40 | pixels_handle_ = GCHandle.Alloc(pixels_, GCHandleType.Pinned); 41 | pixels_ptr_ = pixels_handle_.AddrOfPinnedObject(); 42 | GetComponent().material.mainTexture = texture_; 43 | 44 | read_image(path, pixels_ptr_); 45 | 46 | texture_.SetPixels32(pixels_); 47 | texture_.Apply(); 48 | pixels_handle_.Free(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Assets/Scripts/ReadTexture.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 77e27492df3bb484e87b301420b0f46b 3 | timeCreated: 1441470202 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/StreamingAssets.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5eab5263fe9e340a981267fafd28b4b9 3 | folderAsset: yes 4 | timeCreated: 1441469756 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/intrinsics.yml: -------------------------------------------------------------------------------- 1 | %YAML:1.0 2 | calibration_time: "dom 27 feb 2011 17:16:27 CET" 3 | nframes: 5 4 | image_width: 2560 5 | image_height: 1440 6 | # image_width: 1280 7 | # image_height: 720 8 | # image_width: 720 9 | # image_height: 480 10 | board_width: 8 11 | board_height: 6 12 | square_size: 2.8999999165534973e-02 13 | flags: 0 14 | camera_matrix: !!opencv-matrix 15 | rows: 3 16 | cols: 3 17 | dt: d 18 | data: [ 19 | 1955.84, 0, 1262.76, 20 | 0, 1955.72, 749.30, 21 | 0, 0, 1] 22 | # data: [ 23 | # 1021.03, 0, 634.81, 24 | # 0, 1019.98, 359.26, 25 | # 0, 0, 1] 26 | # data: [ 27 | # 1053.57, 0, 633.09, 28 | # 0, 1053.30, 354.51, 29 | # 0, 0, 1] 30 | distortion_coefficients: !!opencv-matrix 31 | rows: 5 32 | cols: 1 33 | dt: d 34 | data: [ 0.0995485, -0.206384, 35 | 0.00754589, 0.00336531, 36 | 0 ] 37 | avg_reprojection_error: 8.4719362981201396e-01 38 | per_view_reprojection_errors: !!opencv-matrix 39 | rows: 5 40 | cols: 1 41 | dt: f 42 | data: [ 4.28777784e-01, 9.05612946e-01, 1.08689988e+00, 43 | 6.98072255e-01, 9.57101762e-01 ] 44 | # a set of 6-tuples (rotation vector + translation vector) for each view 45 | extrinsic_parameters: !!opencv-matrix 46 | rows: 5 47 | cols: 6 48 | dt: f 49 | data: [ 6.47093183e-33, 6.47093183e-33, 0., 0., 0., 0., 0., 0., 0., 50 | 0., 0., 6.47067322e-33, .Nan, 2.80259693e-45, 3.73649902e+02, 51 | 128., 6.47104938e-33, .Nan, .Nan, 1.44968018e+02, 6.47105820e-33, 52 | 0., 1.52838165e+02, 2.27430847e+02, .Nan, 2.21454285e+02, 53 | 2.61589783e+02, 2.16458176e+02, 3.19432526e+02, 2.12284958e+02 ] 54 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/intrinsics.yml.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1d84492ab0dc4af49ffa6fd8d342eb8 3 | timeCreated: 1442041844 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/StreamingAssets/zzz.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Assets/StreamingAssets/zzz.png -------------------------------------------------------------------------------- /Assets/StreamingAssets/zzz.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 184b0bc23e92445ed92f600171273347 3 | timeCreated: 1441469783 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | This sample 3 | ================================================================================ 4 | 5 | The MIT License (MIT) 6 | 7 | Copyright (c) 2015 hecomi 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of 10 | this software and associated documentation files (the "Software"), to deal in 11 | the Software without restriction, including without limitation the rights to 12 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 13 | the Software, and to permit persons to whom the Software is furnished to do so, 14 | subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 21 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 22 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 23 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | 26 | 27 | ================================================================================ 28 | Aruco 29 | ================================================================================ 30 | 31 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 32 | 33 | Redistribution and use in source and binary forms, with or without modification, are 34 | permitted provided that the following conditions are met: 35 | 36 | 1. Redistributions of source code must retain the above copyright notice, this list of 37 | conditions and the following disclaimer. 38 | 39 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 40 | of conditions and the following disclaimer in the documentation and/or other materials 41 | provided with the distribution. 42 | 43 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 44 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 45 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 46 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 47 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 48 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 49 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 50 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 51 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 52 | 53 | The views and conclusions contained in the software and documentation are those of the 54 | authors and should not be interpreted as representing official policies, either expressed 55 | or implied, of Rafael Muñoz Salinas. 56 | -------------------------------------------------------------------------------- /Plugins/check_texture/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | NDK_APP_DST_DIR := ../../../Assets/Plugins/Android 6 | LOCAL_MODULE := libcheck_texture 7 | LOCAL_SRC_FILES := check_texture.cpp 8 | LOCAL_CFLAGS := -std=c++11 9 | 10 | include $(BUILD_SHARED_LIBRARY) 11 | -------------------------------------------------------------------------------- /Plugins/check_texture/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_STL := gnustl_static 2 | APP_CPPFLAGS := -frtti -fexceptions 3 | APP_ABI := x86_64 4 | APP_PLATFORM := android-9 5 | -------------------------------------------------------------------------------- /Plugins/check_texture/jni/check_texture.cpp: -------------------------------------------------------------------------------- 1 | extern "C" 2 | { 3 | 4 | void create_check_texture(unsigned char* arr, int w, int h, int ch) 5 | { 6 | int n = 0; 7 | for (int i = 0; i < w; ++i) { 8 | for (int j = 0; j < h; ++j) { 9 | for (int k = 0; k < ch; ++k) { 10 | arr[n++] = ( (i + j) % 2 == 0 ) ? 255 : 0; 11 | } 12 | } 13 | } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Plugins/check_texture/mac/check_texture.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 585CFE321B9B17BC006B9286 /* check_texture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 585CFE2F1B9B17BC006B9286 /* check_texture.cpp */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXFileReference section */ 14 | 585CFE261B9B1799006B9286 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 15 | 585CFE2F1B9B17BC006B9286 /* check_texture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = check_texture.cpp; sourceTree = ""; }; 16 | 585CFE331B9B1910006B9286 /* check_texture.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; name = check_texture.bundle; path = /Users/hecomi/ProgramLocal/Unity/UnityAndroidOpenCvSample/Plugins/check_texture/mac/../../../Assets/Plugins/x86_64/check_texture.bundle; sourceTree = ""; }; 17 | /* End PBXFileReference section */ 18 | 19 | /* Begin PBXFrameworksBuildPhase section */ 20 | 585CFE1F1B9B1799006B9286 /* Frameworks */ = { 21 | isa = PBXFrameworksBuildPhase; 22 | buildActionMask = 2147483647; 23 | files = ( 24 | ); 25 | runOnlyForDeploymentPostprocessing = 0; 26 | }; 27 | /* End PBXFrameworksBuildPhase section */ 28 | 29 | /* Begin PBXGroup section */ 30 | 585CFE191B9B1799006B9286 = { 31 | isa = PBXGroup; 32 | children = ( 33 | 585CFE2C1B9B17BC006B9286 /* jni */, 34 | 585CFE241B9B1799006B9286 /* check_texture */, 35 | ); 36 | sourceTree = ""; 37 | }; 38 | 585CFE241B9B1799006B9286 /* check_texture */ = { 39 | isa = PBXGroup; 40 | children = ( 41 | 585CFE251B9B1799006B9286 /* Supporting Files */, 42 | ); 43 | path = check_texture; 44 | sourceTree = ""; 45 | }; 46 | 585CFE251B9B1799006B9286 /* Supporting Files */ = { 47 | isa = PBXGroup; 48 | children = ( 49 | 585CFE261B9B1799006B9286 /* Info.plist */, 50 | ); 51 | name = "Supporting Files"; 52 | sourceTree = ""; 53 | }; 54 | 585CFE2C1B9B17BC006B9286 /* jni */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 585CFE2F1B9B17BC006B9286 /* check_texture.cpp */, 58 | ); 59 | name = jni; 60 | path = ../jni; 61 | sourceTree = ""; 62 | }; 63 | /* End PBXGroup section */ 64 | 65 | /* Begin PBXNativeTarget section */ 66 | 585CFE211B9B1799006B9286 /* check_texture */ = { 67 | isa = PBXNativeTarget; 68 | buildConfigurationList = 585CFE291B9B1799006B9286 /* Build configuration list for PBXNativeTarget "check_texture" */; 69 | buildPhases = ( 70 | 585CFE1E1B9B1799006B9286 /* Sources */, 71 | 585CFE1F1B9B1799006B9286 /* Frameworks */, 72 | 585CFE201B9B1799006B9286 /* Resources */, 73 | ); 74 | buildRules = ( 75 | ); 76 | dependencies = ( 77 | ); 78 | name = check_texture; 79 | productName = check_texture; 80 | productReference = 585CFE331B9B1910006B9286 /* check_texture.bundle */; 81 | productType = "com.apple.product-type.bundle"; 82 | }; 83 | /* End PBXNativeTarget section */ 84 | 85 | /* Begin PBXProject section */ 86 | 585CFE1A1B9B1799006B9286 /* Project object */ = { 87 | isa = PBXProject; 88 | attributes = { 89 | LastUpgradeCheck = 0640; 90 | ORGANIZATIONNAME = hecomi; 91 | TargetAttributes = { 92 | 585CFE211B9B1799006B9286 = { 93 | CreatedOnToolsVersion = 6.4; 94 | }; 95 | }; 96 | }; 97 | buildConfigurationList = 585CFE1D1B9B1799006B9286 /* Build configuration list for PBXProject "check_texture" */; 98 | compatibilityVersion = "Xcode 3.2"; 99 | developmentRegion = English; 100 | hasScannedForEncodings = 0; 101 | knownRegions = ( 102 | en, 103 | ); 104 | mainGroup = 585CFE191B9B1799006B9286; 105 | productRefGroup = 585CFE191B9B1799006B9286; 106 | projectDirPath = ""; 107 | projectRoot = ""; 108 | targets = ( 109 | 585CFE211B9B1799006B9286 /* check_texture */, 110 | ); 111 | }; 112 | /* End PBXProject section */ 113 | 114 | /* Begin PBXResourcesBuildPhase section */ 115 | 585CFE201B9B1799006B9286 /* Resources */ = { 116 | isa = PBXResourcesBuildPhase; 117 | buildActionMask = 2147483647; 118 | files = ( 119 | ); 120 | runOnlyForDeploymentPostprocessing = 0; 121 | }; 122 | /* End PBXResourcesBuildPhase section */ 123 | 124 | /* Begin PBXSourcesBuildPhase section */ 125 | 585CFE1E1B9B1799006B9286 /* Sources */ = { 126 | isa = PBXSourcesBuildPhase; 127 | buildActionMask = 2147483647; 128 | files = ( 129 | 585CFE321B9B17BC006B9286 /* check_texture.cpp in Sources */, 130 | ); 131 | runOnlyForDeploymentPostprocessing = 0; 132 | }; 133 | /* End PBXSourcesBuildPhase section */ 134 | 135 | /* Begin XCBuildConfiguration section */ 136 | 585CFE271B9B1799006B9286 /* Debug */ = { 137 | isa = XCBuildConfiguration; 138 | buildSettings = { 139 | ALWAYS_SEARCH_USER_PATHS = NO; 140 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 141 | CLANG_CXX_LIBRARY = "libc++"; 142 | CLANG_ENABLE_MODULES = YES; 143 | CLANG_ENABLE_OBJC_ARC = YES; 144 | CLANG_WARN_BOOL_CONVERSION = YES; 145 | CLANG_WARN_CONSTANT_CONVERSION = YES; 146 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 147 | CLANG_WARN_EMPTY_BODY = YES; 148 | CLANG_WARN_ENUM_CONVERSION = YES; 149 | CLANG_WARN_INT_CONVERSION = YES; 150 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 151 | CLANG_WARN_UNREACHABLE_CODE = YES; 152 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 153 | CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)"; 154 | COPY_PHASE_STRIP = NO; 155 | DEBUG_INFORMATION_FORMAT = dwarf; 156 | ENABLE_STRICT_OBJC_MSGSEND = YES; 157 | GCC_C_LANGUAGE_STANDARD = gnu99; 158 | GCC_DYNAMIC_NO_PIC = NO; 159 | GCC_NO_COMMON_BLOCKS = YES; 160 | GCC_OPTIMIZATION_LEVEL = 0; 161 | GCC_PREPROCESSOR_DEFINITIONS = ( 162 | "DEBUG=1", 163 | "$(inherited)", 164 | ); 165 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 166 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 167 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 168 | GCC_WARN_UNDECLARED_SELECTOR = YES; 169 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 170 | GCC_WARN_UNUSED_FUNCTION = YES; 171 | GCC_WARN_UNUSED_VARIABLE = YES; 172 | MACOSX_DEPLOYMENT_TARGET = 10.10; 173 | MTL_ENABLE_DEBUG_INFO = YES; 174 | ONLY_ACTIVE_ARCH = YES; 175 | SDKROOT = macosx; 176 | }; 177 | name = Debug; 178 | }; 179 | 585CFE281B9B1799006B9286 /* Release */ = { 180 | isa = XCBuildConfiguration; 181 | buildSettings = { 182 | ALWAYS_SEARCH_USER_PATHS = NO; 183 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 184 | CLANG_CXX_LIBRARY = "libc++"; 185 | CLANG_ENABLE_MODULES = YES; 186 | CLANG_ENABLE_OBJC_ARC = YES; 187 | CLANG_WARN_BOOL_CONVERSION = YES; 188 | CLANG_WARN_CONSTANT_CONVERSION = YES; 189 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 190 | CLANG_WARN_EMPTY_BODY = YES; 191 | CLANG_WARN_ENUM_CONVERSION = YES; 192 | CLANG_WARN_INT_CONVERSION = YES; 193 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 194 | CLANG_WARN_UNREACHABLE_CODE = YES; 195 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 196 | COPY_PHASE_STRIP = NO; 197 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 198 | ENABLE_NS_ASSERTIONS = NO; 199 | ENABLE_STRICT_OBJC_MSGSEND = YES; 200 | GCC_C_LANGUAGE_STANDARD = gnu99; 201 | GCC_NO_COMMON_BLOCKS = YES; 202 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 203 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 204 | GCC_WARN_UNDECLARED_SELECTOR = YES; 205 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 206 | GCC_WARN_UNUSED_FUNCTION = YES; 207 | GCC_WARN_UNUSED_VARIABLE = YES; 208 | MACOSX_DEPLOYMENT_TARGET = 10.10; 209 | MTL_ENABLE_DEBUG_INFO = NO; 210 | SDKROOT = macosx; 211 | }; 212 | name = Release; 213 | }; 214 | 585CFE2A1B9B1799006B9286 /* Debug */ = { 215 | isa = XCBuildConfiguration; 216 | buildSettings = { 217 | COMBINE_HIDPI_IMAGES = YES; 218 | CONFIGURATION_BUILD_DIR = ../../../Assets/Plugins/x86_64; 219 | INFOPLIST_FILE = check_texture/Info.plist; 220 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; 221 | PRODUCT_NAME = "$(TARGET_NAME)"; 222 | SKIP_INSTALL = YES; 223 | WRAPPER_EXTENSION = bundle; 224 | }; 225 | name = Debug; 226 | }; 227 | 585CFE2B1B9B1799006B9286 /* Release */ = { 228 | isa = XCBuildConfiguration; 229 | buildSettings = { 230 | COMBINE_HIDPI_IMAGES = YES; 231 | CONFIGURATION_BUILD_DIR = ../../../Assets/Plugins/x86_64; 232 | INFOPLIST_FILE = check_texture/Info.plist; 233 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; 234 | PRODUCT_NAME = "$(TARGET_NAME)"; 235 | SKIP_INSTALL = YES; 236 | WRAPPER_EXTENSION = bundle; 237 | }; 238 | name = Release; 239 | }; 240 | /* End XCBuildConfiguration section */ 241 | 242 | /* Begin XCConfigurationList section */ 243 | 585CFE1D1B9B1799006B9286 /* Build configuration list for PBXProject "check_texture" */ = { 244 | isa = XCConfigurationList; 245 | buildConfigurations = ( 246 | 585CFE271B9B1799006B9286 /* Debug */, 247 | 585CFE281B9B1799006B9286 /* Release */, 248 | ); 249 | defaultConfigurationIsVisible = 0; 250 | defaultConfigurationName = Release; 251 | }; 252 | 585CFE291B9B1799006B9286 /* Build configuration list for PBXNativeTarget "check_texture" */ = { 253 | isa = XCConfigurationList; 254 | buildConfigurations = ( 255 | 585CFE2A1B9B1799006B9286 /* Debug */, 256 | 585CFE2B1B9B1799006B9286 /* Release */, 257 | ); 258 | defaultConfigurationIsVisible = 0; 259 | defaultConfigurationName = Release; 260 | }; 261 | /* End XCConfigurationList section */ 262 | }; 263 | rootObject = 585CFE1A1B9B1799006B9286 /* Project object */; 264 | } 265 | -------------------------------------------------------------------------------- /Plugins/check_texture/mac/check_texture.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Plugins/check_texture/mac/check_texture.xcodeproj/project.xcworkspace/xcuserdata/hecomi.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Plugins/check_texture/mac/check_texture.xcodeproj/project.xcworkspace/xcuserdata/hecomi.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Plugins/check_texture/mac/check_texture.xcodeproj/xcuserdata/hecomi.xcuserdatad/xcschemes/check_texture.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 60 | 61 | 67 | 68 | 69 | 70 | 72 | 73 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /Plugins/check_texture/mac/check_texture.xcodeproj/xcuserdata/hecomi.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | check_texture.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 585CFE211B9B1799006B9286 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Plugins/check_texture/mac/check_texture/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.hecomi.check-texture.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | NSHumanReadableCopyright 24 | Copyright © 2015年 hecomi. All rights reserved. 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | OPENCV_CAMERA_MODULES:=on 6 | OPENCV_INSTALL_MODULES:=on 7 | OPENCV_LIB_TYPE := STATIC 8 | include opencv/jni/OpenCV.mk 9 | include aruco/jni/Aruco.mk 10 | 11 | NDK_APP_DST_DIR := ../../../Assets/Plugins/Android 12 | LOCAL_MODULE := opencv_sample 13 | LOCAL_SRC_FILES += $(shell ls -1 *.cpp) 14 | LOCAL_CFLAGS += -std=c++11 15 | 16 | include $(BUILD_SHARED_LIBRARY) 17 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_STL := gnustl_static 2 | APP_CPPFLAGS := -frtti -fexceptions 3 | APP_ABI := armeabi-v7a 4 | APP_PLATFORM := android-15 5 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "log.h" 5 | 6 | 7 | class aruco_manager 8 | { 9 | public: 10 | struct marker_result 11 | { 12 | int id; 13 | double position[3]; 14 | double orientation[4]; 15 | }; 16 | 17 | aruco_manager() 18 | { 19 | } 20 | 21 | void set_image_size(int width, int height) 22 | { 23 | width_ = width; 24 | height_ = height; 25 | input_ = cv::Mat(height, width, CV_8UC4); 26 | } 27 | 28 | void set_marker_size(float marker_size) 29 | { 30 | marker_size_ = marker_size; 31 | } 32 | 33 | void set_params(const char* camera_params_file_path) 34 | { 35 | params_.readFromXMLFile(camera_params_file_path); 36 | params_.resize(cv::Size(width_, height_)); 37 | } 38 | 39 | void set_image(unsigned char* src) 40 | { 41 | if (src != nullptr) { 42 | input_ = cv::Mat(height_, width_, CV_8UC4, src).clone(); 43 | } 44 | } 45 | 46 | void get_image(unsigned char* dest) const 47 | { 48 | if (dest != nullptr) { 49 | memcpy(dest, output_.data, output_.total() * output_.elemSize()); 50 | } 51 | } 52 | 53 | size_t detect(bool drawOutputImage = true) 54 | { 55 | if (input_.empty()) return -1; 56 | 57 | cv::Mat bgr; 58 | cv::cvtColor(input_, bgr, cv::COLOR_BGRA2BGR); 59 | 60 | cv::Mat resized; 61 | cv::resize(bgr, resized, cv::Size(), 0.4f, 0.4f); 62 | 63 | std::vector markers; 64 | detector_.detect(bgr, markers, params_, marker_size_, true); 65 | 66 | markers_.clear(); 67 | 68 | for (auto&& marker : markers) { 69 | marker.draw(bgr, cv::Scalar(0, 0, 255), 2); 70 | aruco::CvDrawingUtils::draw3dCube(bgr, marker, params_); 71 | 72 | marker_result result; 73 | result.id = marker.id; 74 | marker.OgreGetPoseParameters(result.position, result.orientation); 75 | 76 | markers_.push_back(result); 77 | } 78 | 79 | if (drawOutputImage) { 80 | cv::cvtColor(bgr, output_, cv::COLOR_BGR2BGRA); 81 | } 82 | 83 | input_.release(); 84 | 85 | return markers_.size(); 86 | } 87 | 88 | void* get_markers() 89 | { 90 | return &markers_[0]; 91 | } 92 | 93 | private: 94 | aruco::CameraParameters params_; 95 | aruco::MarkerDetector detector_; 96 | cv::Mat input_; 97 | cv::Mat output_; 98 | int width_ = 0; 99 | int height_ = 0; 100 | float marker_size_ = 0.1f; 101 | int marker_num_ = 10; 102 | std::vector markers_; 103 | }; 104 | 105 | 106 | extern "C" 107 | { 108 | 109 | void* aruco_initialize( 110 | int width, 111 | int height, 112 | float marker_size, 113 | const char* camera_params_file_path) 114 | { 115 | auto manager = new aruco_manager(); 116 | manager->set_image_size(width, height); 117 | manager->set_marker_size(marker_size); 118 | manager->set_params(camera_params_file_path); 119 | return manager; 120 | } 121 | 122 | void aruco_finalize(void* instance) 123 | { 124 | auto manager = static_cast(instance); 125 | delete manager; 126 | instance = nullptr; 127 | } 128 | 129 | void aruco_set_image(void* instance, unsigned char* src) 130 | { 131 | auto manager = static_cast(instance); 132 | if (manager == nullptr) return; 133 | manager->set_image(src); 134 | } 135 | 136 | void aruco_get_image(void* instance, unsigned char* dest) 137 | { 138 | auto manager = static_cast(instance); 139 | if (manager == nullptr) return; 140 | manager->get_image(dest); 141 | } 142 | 143 | int aruco_detect(void* instance) 144 | { 145 | auto manager = static_cast(instance); 146 | if (manager == nullptr) return -1; 147 | return static_cast(manager->detect()); 148 | } 149 | 150 | void* aruco_get_markers(void* instance) 151 | { 152 | auto manager = static_cast(instance); 153 | if (manager == nullptr) return nullptr; 154 | return manager->get_markers(); 155 | } 156 | 157 | } 158 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/AUTHORS: -------------------------------------------------------------------------------- 1 | The ARUCO Library has been developed by the Ava group of the Univeristy of Cordoba(Spain) 2 | Contact to Rafael Muñoz Salinas 3 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/COPYING: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Plugins/opencv_sample/jni/aruco/COPYING -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/ChangeLog: -------------------------------------------------------------------------------- 1 | VERSION 1.3 2 | - Compatibility with OpenCV 3 3 | - In Marker Detector: 4 | - Paralelization using OpenMP 5 | - Marked as deprecated enableErosion and pyrDown 6 | - Added functionality for markers with "locked corners". We refer to marker whose corners are connected 7 | either to another marker (formaing a chessboard pattern), or to another black square. In this mode, 8 | the use of subcorner refinement methods is expected to be more precise. See enableLockedCornersMethod() 9 | - Added funcionality to search for the first threshold parameter simultaneously in several 10 | values. The process is parallelized in multiple threads. See setMultiThresholdSearch() 11 | - In HRM markers: 12 | - Speed up marker identification process 13 | - Improve performance of dictionary generation process. 14 | - Added LICENSE file 15 | 16 | VERSION 1.2.5 17 | - New type of markers: highly reliable markers (hrm) including utils to use them 18 | - Added chromaticmask class to create occlusion mask based on chromatic boards 19 | - Added watermark with the id to the markers to allow easy identification of printed markers 20 | - Now, by default, setYPerpendicular=false. So, Z is now pointing out of the board. 21 | - Added a reprjection test in boardetector see BoardDetector::set_repj_err_thres() and BoardDetector::get_repj_err_thres () 22 | - Added support for 5 distortion parameters in CameraParameters class 23 | - Removed experimental code for removing the deformation that occurs when a marker is in a cylinder 24 | - Omp support in linux (in markerdetector) 25 | - Added an static function in BoardDetector::detect to do everything in a single line. 26 | - New BoardConfiguration constructor receving a path with the configuration to be read. 27 | - Revised opencv #includes to include just the necessary modules 28 | - Added aruco_calibration.cpp to perform camera calibration using aruco boards 29 | - Changes in LINES refinement to perform undistortion automatically 30 | - Method setYPerperdicular in BoardDetector changed to setYPerpendicular (spelling error) 31 | - Added getWarpSize() and setWarpSize methods in MarkerDetector to allow changing the canonical image size 32 | - Bug fixed in aruco_create_board 33 | 34 | VERSION 1.2.4 35 | - Bugs fixed for MSVC2010 36 | 37 | VERSION 1.2.3 38 | - Changes in boardconfiguration and boardetector to allow arbitrary located markers. No API changes involved, except for the config files that have changed their format. 39 | - Changes in arucofidmarkers to allow the creation of chessboard like boards (FiducidalMarkers::createBoardImage_ChessBoard). 40 | Added the corresponding change in aruco_create_board to support such feature 41 | - Added experimental code for removing the deformation that occurs when a marker is in a cylinder 42 | - Added the corner refinement method LINES. It is based on intersecting the lines of the marker's sides using the contour points. 43 | We believe this is the best refinement method of the library so far. 44 | - Added functionality in aruco::BoarDetector to perform the whole detection process in it if desired 45 | - Changed aruco_test_board to use the new functionality described above 46 | - Changed old way of obtaining extrinsics FindExtrinsicParam2 for the new one solvePnp in BoardDetector and in Marker 47 | 48 | VERSION 1.1.0 49 | - Ogre integration ( Board::OgreGetPoseParameters and Marker::OgreGetPoseParameters). 50 | - Changes to make it compile with MSVC 2010 51 | - Remove getopt.h dependency. Command line are simpler now 52 | - MarkerDetector: Externalization of the marker detector to allow using user-defined markers. The function setMakerDetectorFunction allows to define this function 53 | - Added class FiducidalMarkers to detect the original aruco markers 54 | - MarkerDetector: function glGetProjectionMatrix is moved to the CameraParameters class. Sorry, but it is more logical. 55 | - MarkerDetector: Clear separation between the detection phases into separated functions that can be externally called (thresHold and detectRectangles) for more sohpisticated user needs 56 | - MarkerDetector: new corner refinement method based on harris detector. Also, added the possibility of not refining corners at all. 57 | - Added an option to work on a reduced version of the images (pyrDown). 58 | - Changes the adaptive threshold method. Now we employ the MEAN. As a consequence, the process is faster and do not depen on the window size. 59 | - Initial tests with android 60 | - Bugs fixed 61 | 62 | VERSION 1.0.0 63 | - New names for the main classes Marker,MarkerDector... etc. Sorry, but I needed to clear up things. It wont be difficult to adapt. 64 | - A new class for the camera parameters. It can be readed from the calibration.cpp application in OpenCv2.2 65 | - Refactorization of code to make it more maintainable 66 | - Better support for Windows (Cmake) and OpenGL 67 | - Improved documentation. Windows users should read the README file that explains how to build the library 68 | - A new class for drawing markers and boards in opencv images 69 | - A couple of new very simple examples to teach the use of the library(aruco_simple and aruco_simple_board) 70 | 71 | VERSION 0.9.5 72 | Added support for Boards 73 | Added cmake support 74 | Bugs fixed 75 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/INSTALL: -------------------------------------------------------------------------------- 1 | read the README file -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Rafael Muñoz Salinas. 27 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Plugins/opencv_sample/jni/aruco/NEWS -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/README: -------------------------------------------------------------------------------- 1 | ArUco: Augmented Reality library from the University of Cordoba 2 | ------------------------------------------------------------------- 3 | 4 | ArUco is a minimal C++ library for detection of Augmented Reality markers based on OpenCv exclusively. 5 | 6 | It is an educational project to show student how to detect augmented reality markers and it is provided under BSD license. 7 | 8 | 9 | CONTACT: Rafael Munoz-Salinas: rmsalinas@uco.es 10 | 11 | \section INTRODUCTION 12 | 13 | The library relies on the use of coded markers. Each marker has an unique code indicated by the black and white colors in it. The libary detect borders, and analyzes into the rectangular regions which of them are likely to be markers. Then, a decoding is performed and if the code is valid, it is considered that the rectangle is a marker. 14 | 15 | The codification included into the marker is a slighly modified version of the Hamming Code. It has a total a 25 bits didived in 5 rows of 5 bits each. So, we have 5 words of 5 bits. Each word, contains only 2 bits of real information, the rest is for and error detection/correction (error correction is yet to be done). As a conclusion, a marker contains 10 bits of real information wich allows 1024 different markers. 16 | 17 | 18 | 19 | 20 | \section LIBRARY DESCRIPTION: 21 | 22 | The ArUco library contents are divided in two main directories. The src directory, which contains the library itself. And the utils directory which contains the applications. 23 | 24 | The library main classes are: 25 | 26 | - aruco::Marker: which represent a marker detected in the image 27 | - aruco::MarkerDetector: that is in charge of deteting the markers in a image Detection is done by simple calling the member funcion ArMarkerDetector::detect(). Additionally, the classes contain members to create the required matrices for rendering using OpenGL. See aruco_test_gl for details 28 | - aruco::BoardConfiguration: A board is an array of markers in a known order. BoardConfiguracion is the class that defines a board by indicating the id of its markers. In addition, it has informacion about the distance between the markers so that extrinsica camera computations can be done. 29 | - aruco::Board: This class defines a board detected in a image. The board has the extrinsic camera parameters as public atributes. In addition, it has a method that allows obtain the matrix for getting its position in OpenGL (see aruco_test_board_gl for details). 30 | - aruco::BoardDetector : This is the class in charge of detecting a board in a image. You must pass to it the set of markers detected by ArMarkerDetector and the BoardConfiguracion of the board you want to detect. This class will do the rest for you, even calculating the camera extrinsics. 31 | 32 | \subsection BOARDS 33 | 34 | Aruco allows the possibility to employ board. Boards are markers composed by an array of markers arranged in a known order. The advantages of using boards instead of simple markers are: 35 | - More robusteness. The misdetection of several markers of the board is not a problem as long as a minimum set of them are detected. 36 | - More precision. Since there are a larger number of corners, camera pose estimation becomes more precise. 37 | 38 | 39 | A Board contains several markers so that they are more robustly detected. In general, a board is a set of markers. So BoardConfiguration is only 40 | a list of the id of the markers along with the position of their corners. 41 | 42 | The position of the corners can be specified either in pixels (in a non-specific size) or in meters. The first is the 43 | typical case in which you generate the image of board and the print it. Since you do not know in advance the real 44 | size of the markers, their corners are specified in pixels, and then, the translation to meters can be made once you 45 | know the real size. On the other hand, you may want to have the information of your boards in meters in your 46 | configuration file once you have created it. The BoardConfiguration allows you to do so. 47 | 48 | Creating boards in managed by two applications. First, use aruco_create_board to create the image of the board. 49 | Print it and use your measurer to know the real size of the markers. Then, you can use aruco_board_pix2meters to create 50 | new configuration file that expresses the board in meters. So, you no longer need to remember the size of your markers. 51 | 52 | Since version 1.2, aruco allows to create boards with chessboard configuration. To support the detection of chessboards, we need to apply an erosion in the image when detecting markers. 53 | This is an option that can be disabled in MarkerDetector::enableErosion. By default, it is enabled. However, disabling it can speed up the process up to a 10%. So if you 54 | do not want to use chessboards, disable it. 55 | 56 | \subsection APPLICATIONS 57 | 58 | - The library comes with several applications that will help you to learn how to use the library: 59 | -# aruco_create_marker: which creates marker and saves it in a jpg file you can print. 60 | -# aruco_simple : simple test aplication that detects the markers in an image 61 | -# aruco_test: this is the main application for detection. It reads images either from the camera of from a video and detect markers. Additionally, if you provide the intrinsics of the camera(obtained by OpenCv calibration) and the size of the marker in meters, the library calculates the marker intrinsics so that you can easily create your AR applications. 62 | -# aruco_test_gl: shows how to use the library AR applications using OpenGL for rendering 63 | -# aruco_create_board: application that helps you to create a board 64 | -# aruco_board_pix2meters: application that helps you to convert a board configuration file from pixels(as provided by aruco_create_board) to meters. 65 | -# aruco_test_board: application that detects boards 66 | -# aruco_simple_board: simple application that detects boards in an image 67 | -# aruco_test_board_gl: application that detects boards and uses OpenGL to draw 68 | 69 | 70 | \subsection HIGHLY RELIABLE MARKERS 71 | After version 1.2.5, ArUco includes a new type of marker codification know as Highly Reliable Markers (hrm). The main benefits are: (i) number of markers and marker size is customizable by the user and (ii) error correction can be applied. 72 | For more details, see "S. Garrido-Jurado, R. Muñoz-Salinas, F.J. Madrid-Cuevas, M.J. Marín-Jiménez, Automatic generation and detection of highly reliable fiducial markers under occlusion, Pattern Recognition, Volume 47, Issue 6, June 2014" 73 | The 'utils_hrm' folder contains some applications to test these markers 74 | -# aruco_hrm_create_dictionary: creates customized dictionary of highly reliable markers 75 | -# aruco_hrm_test: basic application for single marker detection 76 | -# aruco_hrm_create_board: create a board of hrm markers, it can also create chromatic boards for occlusion map (see paper for more information) 77 | -# aruco_hrm_test_board: detect board. If use chromatic board it can also generate occlusion mask 78 | 79 | 80 | 81 | \section COMPILING THE LIBRARY: 82 | 83 | REQUIREMENTS: OpenCv >= 2.4.9, cmake >= 2.8 84 | OPTIONAL: OpenGL for aruco_test_gl and aruco_test_board_gl 85 | 86 | \subsection LINUX: 87 | 88 | Go to the aruco library and do 89 | >mkdir build 90 | >cd build 91 | >cmake .. 92 | >make 93 | >make install (optional) 94 | 95 | NOTE ON OPENGL: The library supports eaily the integration with OpenGL. In order to compile with support for OpenGL, you just have installed in your system the develop packages for GL and glut (or freeglut). 96 | 97 | \subsection WINDOWS 98 | 99 | We have successfully compiled in in two compilers: MSVC2010 and MinGW. 100 | In both cases cmake and OpenCv are required first. So install them 101 | 102 | 103 | \subsubsection Microsoft Visual C++ (Express Edition 2010) 104 | 105 | a) Downdload MSVC 2010 (http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express). 106 | b) Use cmake to create the project. Compile and run! 107 | 108 | \subsubsection MinGW and codeblocks 109 | 110 | The library has been compiled using MinGW and codeblocks. Below I describe the best way to compile it that I know. If you know better, please let me know. 111 | 112 | step 1) codeblocks 113 | -# Download codeblocks. I recommend to download the version 10.5 with mingw included (codeblocks-10.05mingw-setup.exe) 114 | -# Install and set the PATH variable so that the codeblock/mingw/bin directory is included. In my case "c:\codeblocks\mingw\bin". This will allow cmake to find the compiler. 115 | -# The codeblock program will not find the mingw path by deafult. So, run codeblocks and go to setting->Compuiler debugger and set the correct path to the MinGW dir. 116 | 117 | step 2) aruco 118 | -# download and decompress. 119 | -# Open cmake gui application and set the path to the main library directory and also set a path where the project is going to be built. Generate the codeblock project. 120 | -# Open the project with codeblock and compile then, install. The programs will be probably generated into the bin directory 121 | 122 | 123 | OpenGL: by default, the mingw version installed has not the glut library. SO, the opengl programs are not compiled. If you want to compile with OpenGL support, you must install glut, or prefereably freeglut. 124 | So, download the library (http://www.martinpayne.me.uk/software/development/GLUT/freeglut-MinGW.zip) for mingw. Decompress in a directory X. Then, rerun cmake setting the variable GLU_PATH to that directory 125 | >cmake .. -DGLUT_PATH="C:\x" 126 | Finally, recompile and test. Indeed, you should move the freeglut.dll to the directory with the binaries or to any other place in the PATH. 127 | 128 | \section Testing 129 | 130 | For testing the applications, the library provides videos and the corresponding camera parameters of these videos. Into the directories you will find information on how to run the examples. 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/TODO: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/Aruco.mk: -------------------------------------------------------------------------------- 1 | ARUCO_PATH := $(call my-dir) 2 | LOCAL_SRC_FILES += $(shell ls -1 $(ARUCO_PATH)/*.cpp) 3 | LOCAL_C_INCLUDES += $(ARUCO_PATH) 4 | 5 | 6 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/ar_omp.cpp: -------------------------------------------------------------------------------- 1 | #ifndef USE_OMP 2 | int omp_get_max_threads() { return 1; } 3 | int omp_get_thread_num() { return 0; } 4 | #endif 5 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/ar_omp.h: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are 6 | permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | of conditions and the following disclaimer in the documentation and/or other materials 13 | provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 16 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 17 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 18 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 22 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | The views and conclusions contained in the software and documentation are those of the 26 | authors and should not be interpreted as representing official policies, either expressed 27 | or implied, of Rafael Muñoz Salinas. 28 | */ 29 | 30 | #ifdef USE_OMP 31 | #include 32 | #else 33 | int omp_get_max_threads(); 34 | int omp_get_thread_num(); 35 | #endif 36 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/aruco.h: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are 6 | permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this list of 9 | conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | of conditions and the following disclaimer in the documentation and/or other materials 13 | provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 16 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 17 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 18 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 22 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 23 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | The views and conclusions contained in the software and documentation are those of the 26 | authors and should not be interpreted as representing official policies, either expressed 27 | or implied, of Rafael Muñoz Salinas. 28 | 29 | 30 | 31 | \mainpage ArUco: Augmented Reality library from the University of Cordoba 32 | 33 | 34 | ArUco is a minimal C++ library for detection of Augmented Reality markers based on OpenCv exclusively. 35 | 36 | It is an educational project to show student how to detect augmented reality markers and it is provided under BSD license. 37 | 38 | 39 | \section INTRODUCTION INTRODUCTION 40 | 41 | The library relies on the use of coded markers. Each marker has an unique code indicated by the black and white colors in it. The libary detect borders, and 42 | analyzes into the rectangular regions which of them are likely to be markers. Then, a decoding is performed and if the code is valid, it is considered that the 43 | rectangle is a marker. 44 | 45 | The codification included into the marker is a slighly modified version of the Hamming Code. It has a total a 25 bits didived in 5 rows of 5 bits each. So, we 46 | have 5 words of 5 bits. Each word, contains only 2 bits of real information, the rest is for and error detection/correction (error correction is yet to be 47 | done). As a conclusion, a marker contains 10 bits of real information wich allows 1024 different markers. 48 | 49 | 50 | \section BOARDS BOARDS 51 | 52 | Aruco allows the possibility to employ board. Boards are markers composed by an array of markers arranged in a known order. The advantages of using boards 53 | instead of simple markers are: 54 | - More robusteness. The misdetection of several markers of the board is not a problem as long as a minimum set of them are detected. 55 | - More precision. Since there are a larger number of corners, camera pose estimation becomes more precise. 56 | 57 | 58 | \section APPLICATIONS APPLICATIONS 59 | 60 | The library comes with five applications that will help you to learn how to use the library: 61 | - aruco_create_marker: which creates marker and saves it in a jpg file you can print. 62 | - aruco_simple : simple test aplication that detects the markers in a image 63 | - aruco_test: this is the main application for detection. It reads images either from the camera of from a video and detect markers. Additionally, if you 64 | provide the intrinsics of the camera(obtained by OpenCv calibration) and the size of the marker in meters, the library calculates the marker intrinsics so that 65 | you can easily create your AR applications. 66 | - aruco_test_gl: shows how to use the library AR applications using OpenGL for rendering 67 | - aruco_create_board: application that helps you to create a board 68 | - aruco_simple_board: simple test aplication that detects a board of markers in a image 69 | - aruco_test_board: application that detects boards 70 | - aruco_test_board_gl: application that detects boards and uses OpenGL to draw 71 | 72 | \section LIBRARY LIBRARY DESCRIPTION: 73 | 74 | The ArUco library contents are divided in two main directories. The src directory, which contains the library itself. And the utils directory which contains the 75 | applications. 76 | 77 | The library main classes are: 78 | - aruco::CameraParameters: represent the information of the camera that captures the images. Here you must set the calibration info. 79 | - aruco::Marker: which represent a marker detected in the image 80 | - aruco::MarkerDetector: that is in charge of deteting the markers in a image Detection is done by simple calling the member funcion 81 | ArMarkerDetector::detect(). Additionally, the classes contain members to create the required matrices for rendering using OpenGL. See aruco_test_gl for details 82 | - aruco::BoardConfiguration: A board is an array of markers in a known order. BoardConfiguracion is the class that defines a board by indicating the id of 83 | its markers. In addition, it has informacion about the distance between the markers so that extrinsica camera computations can be done. 84 | - aruco::Board: This class defines a board detected in a image. The board has the extrinsic camera parameters as public atributes. In addition, it has a 85 | method that allows obtain the matrix for getting its position in OpenGL (see aruco_test_board_gl for details). 86 | - aruco::BoardDetector : This is the class in charge of detecting a board in a image. You must pass to it the set of markers detected by ArMarkerDetector and 87 | the BoardConfiguracion of the board you want to detect. This class will do the rest for you, even calculating the camera extrinsics. 88 | 89 | 90 | \section COMPILING COMPILING THE LIBRARY: 91 | \subsection Linux 92 | Go to the aruco library and do 93 | \verbatim 94 | >mkdir build 95 | >cd build 96 | >cmake .. 97 | >make 98 | >make install (optional) 99 | \endverbatim 100 | 101 | NOTE ON OPENGL: The library supports eaily the integration with OpenGL. In order to compile with support for OpenGL, you just have installed in your system the 102 | develop packages for GL and glut (or freeglut). 103 | 104 | \subsection WINDOWS 105 | 106 | The library has been compiled using MinGW and codeblocks. Below I describe the best way to compile it that I know. If you know better, please let me know. 107 | - step 1) codeblocks 108 | -# Download codeblocks. I recommend to download the version 10.5 with mingw included (codeblocks-10.05mingw-setup.exe) 109 | -# Install and set the PATH variable so that the codeblock/mingw/bin directory is included. In my case c:/codeblocks/mingw/bin. This will allow cmake to 110 | find the compiler. 111 | -# The codeblock program will not find the mingw path by deafult. So, run codeblocks and go to setting->Compuiler debugger and set the correct path to the 112 | MinGW dir. 113 | - step 2) cmake 114 | -# Download and install the last version of cmake. 115 | - step 3) OpenCv 116 | -# Download the source code and compile it using cmake and codeblocks. Note: install the library in C:\ if you want it to be easily detected by cmake 117 | afterwards 118 | - step 4) aruco 119 | -# Download and decompress. 120 | -# Open cmake gui application and set the path to the main library directory and also set a path where the project is going to be built. 121 | -# Generate the codeblock project. 122 | -# Open the project with codeblock and compile then, install. The programs will be probably generated into the bin directory 123 | 124 | OpenGL: by default, the mingw version installed has not the glut library. So, the opengl programs are not compiled. If you want to compile with OpenGL support, 125 | you must install glut, or prefereably freeglut. 126 | Thus, 127 | - Download the library (http://www.martinpayne.me.uk/software/development/GLUT/freeglut-MinGW.zip) for mingw. 128 | - Decompress in a directory X. 129 | - Then, rerun cmake setting the variable GLU_PATH to that directory (>cmake .. -DGLUT_PATH="C:\X") 130 | - Finally, recompile and test. Indeed, you should move the freeglut.dll to the directory with the binaries or to any other place in the PATH. 131 | 132 | 133 | CONCLUSION: Move to Linux, things are simpler :P 134 | 135 | 136 | \section Testing 137 | 138 | For testing the applications, the library provides videos and the corresponding camera parameters of these videos. Into the directories you will find 139 | information on how to run the examples. 140 | 141 | \section Final Notes 142 | 143 | - REQUIREMENTS: OpenCv >= 2.1.0. and OpenGL for (aruco_test_gl and aruco_test_board_gl) 144 | - CONTACT: Rafael Munoz-Salinas: rmsalinas@uco.es 145 | - This libary is free software and come with no guaratee! 146 | 147 | */ 148 | 149 | #include "markerdetector.h" 150 | #include "boarddetector.h" 151 | #include "cvdrawingutils.h" 152 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/arucofidmarkers.h: -------------------------------------------------------------------------------- 1 | /***************************** 2 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Rafael Muñoz Salinas. 27 | ********************************/ 28 | 29 | #ifndef ArucoFiducicalMarkerDetector_H 30 | #define ArucoFiducicalMarkerDetector_H 31 | #include 32 | #include "exports.h" 33 | #include "marker.h" 34 | #include "board.h" 35 | namespace aruco { 36 | 37 | class ARUCO_EXPORTS FiducidalMarkers { 38 | public: 39 | /** 40 | * \brief Creates an ar marker with the id specified using a modified version of the hamming code. 41 | * There are two type of markers: a) These of 10 bits b) these of 3 bits. The latter are employed for applications 42 | * that need few marker but they must be small. The two type of markers are distinguished by their ids. While the first type 43 | * of markers have ids in the interval [0-1023], the second type ids in the interval [2000-2006]. 44 | * 45 | * 46 | * 10 bits markers 47 | * ----------------------- 48 | * There are a total of 5 rows of 5 cols. Each row encodes a total of 2 bits, so there are 2^10 bits:(0-1023). 49 | * 50 | * The least significative bytes are first (from left-up to to right-bottom) 51 | * 52 | * Example: the id = 110 (decimal) is be represented in binary as : 00 01 10 11 10. 53 | * 54 | * Then, it will generate the following marker: 55 | * 56 | * -# 1st row encodes 00: 1 0 0 0 0 : hex 0x10 57 | * -# 2nd row encodes 01: 1 0 1 1 1 : hex 0x17 58 | * -# 3nd row encodes 10: 0 1 0 0 1 : hex 0x09 59 | * -# 4th row encodes 11: 0 1 1 1 0 : hex 0x0e 60 | * -# 5th row encodes 10: 0 1 0 0 1 : hex 0x09 61 | * 62 | * Note that : The first bit, is the inverse of the hamming parity. This avoids the 0 0 0 0 0 to be valid 63 | * These marker are detected by the function getFiduciadlMarker_Aruco_Type1 64 | * @param writeIdWaterMark if true, writes a watermark with the marker id 65 | * @param locked if true, creates etra rectangles lcoking the corners of the marker (new in version 1.2.6) 66 | */ 67 | static cv::Mat createMarkerImage(int id, int size, bool writeIdWaterMark = true, bool locked = false) throw(cv::Exception); 68 | 69 | /** Detection of fiducidal aruco markers (10 bits) 70 | * @param in input image with the patch that contains the possible marker 71 | * @param nRotations number of 90deg rotations in clockwise direction needed to set the marker in correct position 72 | * @return -1 if the image passed is a not a valid marker, and its id in case it really is a marker 73 | */ 74 | static int detect(const cv::Mat &in, int &nRotations); 75 | 76 | /**Similar to createMarkerImage. Instead of returning a visible image, returns a 8UC1 matrix of 0s and 1s with the marker info 77 | */ 78 | static cv::Mat getMarkerMat(int id) throw(cv::Exception); 79 | 80 | 81 | /**Creates a printable image of a board 82 | * @param gridSize grid layout (numer of sqaures in x and Y) 83 | * @param MarkerSize size of markers sides in pixels 84 | * @param MarkerDistance distance between the markers 85 | * @param TInfo output 86 | * @param excludedIds set of ids excluded from the board 87 | */ 88 | static cv::Mat createBoardImage(cv::Size gridSize, int MarkerSize, int MarkerDistance, BoardConfiguration &TInfo, 89 | vector< int > *excludedIds = NULL) throw(cv::Exception); 90 | 91 | 92 | /**Creates a printable image of a board in chessboard_like manner 93 | * @param gridSize grid layout (numer of sqaures in x and Y) 94 | * @param MarkerSize size of markers sides in pixels 95 | * @param TInfo output 96 | * @param setDataCentered indicates if the center is set at the center of the board. Otherwise it is the left-upper corner 97 | * 98 | */ 99 | static cv::Mat createBoardImage_ChessBoard(cv::Size gridSize, int MarkerSize, BoardConfiguration &TInfo, bool setDataCentered = true, 100 | vector< int > *excludedIds = NULL) throw(cv::Exception); 101 | 102 | /**Creates a printable image of a board in a frame fashion 103 | * @param gridSize grid layout (numer of sqaures in x and Y) 104 | * @param MarkerSize size of markers sides in pixels 105 | * @param MarkerDistance distance between the markers 106 | * @param TInfo output 107 | * @param setDataCentered indicates if the center is set at the center of the board. Otherwise it is the left-upper corner 108 | * 109 | */ 110 | static cv::Mat createBoardImage_Frame(cv::Size gridSize, int MarkerSize, int MarkerDistance, BoardConfiguration &TInfo, bool setDataCentered = true, 111 | vector< int > *excludedIds = NULL) throw(cv::Exception); 112 | 113 | private: 114 | static vector< int > getListOfValidMarkersIds_random(int nMarkers, vector< int > *excluded) throw(cv::Exception); 115 | static cv::Mat rotate(const cv::Mat &in); 116 | static int hammDistMarker(cv::Mat bits); 117 | static int analyzeMarkerImage(cv::Mat &grey, int &nRotations); 118 | static bool correctHammMarker(cv::Mat &bits); 119 | }; 120 | } 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/board.cpp: -------------------------------------------------------------------------------- 1 | /***************************** 2 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Rafael Muñoz Salinas. 27 | ********************************/ 28 | #include "board.h" 29 | #include 30 | #include 31 | using namespace std; 32 | using namespace cv; 33 | namespace aruco { 34 | 35 | /** 36 | * 37 | * 38 | */ 39 | BoardConfiguration::BoardConfiguration() { mInfoType = NONE; } 40 | /** 41 | * 42 | * 43 | */ 44 | BoardConfiguration::BoardConfiguration(string filePath) throw(cv::Exception) { 45 | mInfoType = NONE; 46 | readFromFile(filePath); 47 | } 48 | /** 49 | * 50 | * 51 | */ 52 | BoardConfiguration::BoardConfiguration(const BoardConfiguration &T) : vector< MarkerInfo >(T) { 53 | // MarkersInfo=T.MarkersInfo; 54 | mInfoType = T.mInfoType; 55 | } 56 | 57 | /** 58 | * 59 | * 60 | */ 61 | BoardConfiguration &BoardConfiguration::operator=(const BoardConfiguration &T) { 62 | // MarkersInfo=T.MarkersInfo; 63 | vector< MarkerInfo >::operator=(T); 64 | mInfoType = T.mInfoType; 65 | return *this; 66 | } 67 | /** 68 | * 69 | * 70 | */ 71 | void BoardConfiguration::saveToFile(string sfile) throw(cv::Exception) { 72 | 73 | cv::FileStorage fs(sfile, cv::FileStorage::WRITE); 74 | saveToFile(fs); 75 | } 76 | /**Saves the board info to a file 77 | */ 78 | void BoardConfiguration::saveToFile(cv::FileStorage &fs) throw(cv::Exception) { 79 | fs << "aruco_bc_nmarkers" << (int)size(); 80 | fs << "aruco_bc_mInfoType" << (int)mInfoType; 81 | fs << "aruco_bc_markers" 82 | << "["; 83 | for (size_t i = 0; i < size(); i++) { 84 | fs << "{:" 85 | << "id" << at(i).id; 86 | 87 | fs << "corners" 88 | << "[:"; 89 | for (int c = 0; c < at(i).size(); c++) 90 | fs << at(i)[c]; 91 | fs << "]"; 92 | fs << "}"; 93 | } 94 | fs << "]"; 95 | } 96 | 97 | /** 98 | * 99 | * 100 | */ 101 | void BoardConfiguration::readFromFile(string sfile) throw(cv::Exception) { 102 | try { 103 | cv::FileStorage fs(sfile, cv::FileStorage::READ); 104 | readFromFile(fs); 105 | } catch (std::exception &ex) { 106 | throw cv::Exception(81818, "BoardConfiguration::readFromFile", ex.what() + string(" file=)") + sfile, __FILE__, __LINE__); 107 | } 108 | } 109 | 110 | 111 | /**Reads board info from a file 112 | */ 113 | void BoardConfiguration::readFromFile(cv::FileStorage &fs) throw(cv::Exception) { 114 | int aux = 0; 115 | // look for the nmarkers 116 | if (fs["aruco_bc_nmarkers"].name() != "aruco_bc_nmarkers") 117 | throw cv::Exception(81818, "BoardConfiguration::readFromFile", "invalid file type", __FILE__, __LINE__); 118 | fs["aruco_bc_nmarkers"] >> aux; 119 | resize(aux); 120 | fs["aruco_bc_mInfoType"] >> mInfoType; 121 | cv::FileNode markers = fs["aruco_bc_markers"]; 122 | int i = 0; 123 | for (FileNodeIterator it = markers.begin(); it != markers.end(); ++it, i++) { 124 | at(i).id = (*it)["id"]; 125 | FileNode FnCorners = (*it)["corners"]; 126 | for (FileNodeIterator itc = FnCorners.begin(); itc != FnCorners.end(); ++itc) { 127 | vector< float > coordinates3d; 128 | (*itc) >> coordinates3d; 129 | if (coordinates3d.size() != 3) 130 | throw cv::Exception(81818, "BoardConfiguration::readFromFile", "invalid file type 3", __FILE__, __LINE__); 131 | cv::Point3f point(coordinates3d[0], coordinates3d[1], coordinates3d[2]); 132 | at(i).push_back(point); 133 | } 134 | } 135 | } 136 | 137 | /** 138 | */ 139 | int BoardConfiguration::getIndexOfMarkerId(int id) const { 140 | 141 | for (size_t i = 0; i < size(); i++) 142 | if (at(i).id == id) 143 | return i; 144 | return -1; 145 | } 146 | 147 | /** 148 | */ 149 | const MarkerInfo &BoardConfiguration::getMarkerInfo(int id) const throw(cv::Exception) { 150 | for (size_t i = 0; i < size(); i++) 151 | if (at(i).id == id) 152 | return at(i); 153 | throw cv::Exception(111, "BoardConfiguration::getMarkerInfo", "Marker with the id given is not found", __FILE__, __LINE__); 154 | } 155 | 156 | 157 | /** 158 | */ 159 | void Board::glGetModelViewMatrix(double modelview_matrix[16]) throw(cv::Exception) { 160 | // check if paremeters are valid 161 | bool invalid = false; 162 | for (int i = 0; i < 3 && !invalid; i++) { 163 | if (Tvec.at< float >(i, 0) != -999999) 164 | invalid |= false; 165 | if (Rvec.at< float >(i, 0) != -999999) 166 | invalid |= false; 167 | } 168 | if (invalid) 169 | throw cv::Exception(9002, "extrinsic parameters are not set", "Marker::getModelViewMatrix", __FILE__, __LINE__); 170 | Mat Rot(3, 3, CV_32FC1), Jacob; 171 | Rodrigues(Rvec, Rot, Jacob); 172 | 173 | double para[3][4]; 174 | for (int i = 0; i < 3; i++) 175 | for (int j = 0; j < 3; j++) 176 | para[i][j] = Rot.at< float >(i, j); 177 | // now, add the translation 178 | para[0][3] = Tvec.at< float >(0, 0); 179 | para[1][3] = Tvec.at< float >(1, 0); 180 | para[2][3] = Tvec.at< float >(2, 0); 181 | double scale = 1; 182 | 183 | modelview_matrix[0 + 0 * 4] = para[0][0]; 184 | // R1C2 185 | modelview_matrix[0 + 1 * 4] = para[0][1]; 186 | modelview_matrix[0 + 2 * 4] = para[0][2]; 187 | modelview_matrix[0 + 3 * 4] = para[0][3]; 188 | // R2 189 | modelview_matrix[1 + 0 * 4] = para[1][0]; 190 | modelview_matrix[1 + 1 * 4] = para[1][1]; 191 | modelview_matrix[1 + 2 * 4] = para[1][2]; 192 | modelview_matrix[1 + 3 * 4] = para[1][3]; 193 | // R3 194 | modelview_matrix[2 + 0 * 4] = -para[2][0]; 195 | modelview_matrix[2 + 1 * 4] = -para[2][1]; 196 | modelview_matrix[2 + 2 * 4] = -para[2][2]; 197 | modelview_matrix[2 + 3 * 4] = -para[2][3]; 198 | modelview_matrix[3 + 0 * 4] = 0.0; 199 | modelview_matrix[3 + 1 * 4] = 0.0; 200 | modelview_matrix[3 + 2 * 4] = 0.0; 201 | modelview_matrix[3 + 3 * 4] = 1.0; 202 | if (scale != 0.0) { 203 | modelview_matrix[12] *= scale; 204 | modelview_matrix[13] *= scale; 205 | modelview_matrix[14] *= scale; 206 | } 207 | } 208 | 209 | 210 | /**** 211 | * 212 | */ 213 | void Board::OgreGetPoseParameters(double position[3], double orientation[4]) throw(cv::Exception) { 214 | // check if paremeters are valid 215 | bool invalid = false; 216 | for (int i = 0; i < 3 && !invalid; i++) { 217 | if (Tvec.at< float >(i, 0) != -999999) 218 | invalid |= false; 219 | if (Rvec.at< float >(i, 0) != -999999) 220 | invalid |= false; 221 | } 222 | if (invalid) 223 | throw cv::Exception(9003, "extrinsic parameters are not set", "Marker::getModelViewMatrix", __FILE__, __LINE__); 224 | 225 | // calculate position vector 226 | position[0] = -Tvec.ptr< float >(0)[0]; 227 | position[1] = -Tvec.ptr< float >(0)[1]; 228 | position[2] = +Tvec.ptr< float >(0)[2]; 229 | 230 | // now calculare orientation quaternion 231 | cv::Mat Rot(3, 3, CV_32FC1); 232 | cv::Rodrigues(Rvec, Rot); 233 | 234 | // calculate axes for quaternion 235 | double stAxes[3][3]; 236 | // x axis 237 | stAxes[0][0] = -Rot.at< float >(0, 0); 238 | stAxes[0][1] = -Rot.at< float >(1, 0); 239 | stAxes[0][2] = +Rot.at< float >(2, 0); 240 | // y axis 241 | stAxes[1][0] = -Rot.at< float >(0, 1); 242 | stAxes[1][1] = -Rot.at< float >(1, 1); 243 | stAxes[1][2] = +Rot.at< float >(2, 1); 244 | // for z axis, we use cross product 245 | stAxes[2][0] = stAxes[0][1] * stAxes[1][2] - stAxes[0][2] * stAxes[1][1]; 246 | stAxes[2][1] = -stAxes[0][0] * stAxes[1][2] + stAxes[0][2] * stAxes[1][0]; 247 | stAxes[2][2] = stAxes[0][0] * stAxes[1][1] - stAxes[0][1] * stAxes[1][0]; 248 | 249 | // transposed matrix 250 | double axes[3][3]; 251 | axes[0][0] = stAxes[0][0]; 252 | axes[1][0] = stAxes[0][1]; 253 | axes[2][0] = stAxes[0][2]; 254 | 255 | axes[0][1] = stAxes[1][0]; 256 | axes[1][1] = stAxes[1][1]; 257 | axes[2][1] = stAxes[1][2]; 258 | 259 | axes[0][2] = stAxes[2][0]; 260 | axes[1][2] = stAxes[2][1]; 261 | axes[2][2] = stAxes[2][2]; 262 | 263 | // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes 264 | // article "Quaternion Calculus and Fast Animation". 265 | double fTrace = axes[0][0] + axes[1][1] + axes[2][2]; 266 | double fRoot; 267 | 268 | if (fTrace > 0.0) { 269 | // |w| > 1/2, may as well choose w > 1/2 270 | fRoot = sqrt(fTrace + 1.0); // 2w 271 | orientation[0] = 0.5 * fRoot; 272 | fRoot = 0.5 / fRoot; // 1/(4w) 273 | orientation[1] = (axes[2][1] - axes[1][2]) * fRoot; 274 | orientation[2] = (axes[0][2] - axes[2][0]) * fRoot; 275 | orientation[3] = (axes[1][0] - axes[0][1]) * fRoot; 276 | } else { 277 | // |w| <= 1/2 278 | static unsigned int s_iNext[3] = {1, 2, 0}; 279 | unsigned int i = 0; 280 | if (axes[1][1] > axes[0][0]) 281 | i = 1; 282 | if (axes[2][2] > axes[i][i]) 283 | i = 2; 284 | unsigned int j = s_iNext[i]; 285 | unsigned int k = s_iNext[j]; 286 | 287 | fRoot = sqrt(axes[i][i] - axes[j][j] - axes[k][k] + 1.0); 288 | double *apkQuat[3] = {&orientation[1], &orientation[2], &orientation[3]}; 289 | *apkQuat[i] = 0.5 * fRoot; 290 | fRoot = 0.5 / fRoot; 291 | orientation[0] = (axes[k][j] - axes[j][k]) * fRoot; 292 | *apkQuat[j] = (axes[j][i] + axes[i][j]) * fRoot; 293 | *apkQuat[k] = (axes[k][i] + axes[i][k]) * fRoot; 294 | } 295 | } 296 | 297 | /** 298 | */ 299 | void Board::draw(cv::Mat &im, cv::Scalar color, int lineWidth, bool writeId) { 300 | for (size_t i = 0; i < size(); i++) { 301 | at(i).draw(im, color, lineWidth, writeId); 302 | } 303 | } 304 | 305 | /**Save this from a file 306 | */ 307 | void Board::saveToFile(string filePath) throw(cv::Exception) { 308 | cv::FileStorage fs(filePath, cv::FileStorage::WRITE); 309 | 310 | fs << "aruco_bo_rvec" << Rvec; 311 | fs << "aruco_bo_tvec" << Tvec; 312 | // now, the markers 313 | fs << "aruco_bo_nmarkers" << (int)size(); 314 | fs << "aruco_bo_markers" 315 | << "["; 316 | for (size_t i = 0; i < size(); i++) { 317 | fs << "{:" 318 | << "id" << at(i).id; 319 | fs << "corners" 320 | << "[:"; 321 | for (int c = 0; c < at(i).size(); c++) 322 | fs << at(i)[c]; 323 | fs << "]"; 324 | fs << "}"; 325 | } 326 | fs << "]"; 327 | // save configuration file 328 | conf.saveToFile(fs); 329 | 330 | 331 | 332 | // readFromFile(fs); 333 | } 334 | /**Read this from a file 335 | */ 336 | void Board::readFromFile(string filePath) throw(cv::Exception) { 337 | cv::FileStorage fs(filePath, cv::FileStorage::READ); 338 | if (fs["aruco_bo_nmarkers"].name() != "aruco_bo_nmarkers") 339 | throw cv::Exception(81818, "Board::readFromFile", "invalid file type:", __FILE__, __LINE__); 340 | 341 | 342 | 343 | int aux = 0; 344 | // look for the nmarkers 345 | fs["aruco_bo_nmarkers"] >> aux; 346 | resize(aux); 347 | fs["aruco_bo_rvec"] >> Rvec; 348 | fs["aruco_bo_tvec"] >> Tvec; 349 | 350 | cv::FileNode markers = fs["aruco_bo_markers"]; 351 | int i = 0; 352 | for (FileNodeIterator it = markers.begin(); it != markers.end(); ++it, i++) { 353 | at(i).id = (*it)["id"]; 354 | int ncorners = (*it)["ncorners"]; 355 | at(i).resize(ncorners); 356 | FileNode FnCorners = (*it)["corners"]; 357 | int c = 0; 358 | for (FileNodeIterator itc = FnCorners.begin(); itc != FnCorners.end(); ++itc, c++) { 359 | vector< float > coordinates2d; 360 | (*itc) >> coordinates2d; 361 | if (coordinates2d.size() != 2) 362 | throw cv::Exception(81818, "Board::readFromFile", "invalid file type 2", __FILE__, __LINE__); 363 | cv::Point2f point; 364 | point.x = coordinates2d[0]; 365 | point.y = coordinates2d[1]; 366 | at(i).push_back(point); 367 | } 368 | } 369 | 370 | conf.readFromFile(fs); 371 | } 372 | 373 | /** 374 | */ 375 | void BoardConfiguration::getIdList(std::vector< int > &ids, bool append) const { 376 | if (!append) 377 | ids.clear(); 378 | for (size_t i = 0; i < size(); i++) 379 | ids.push_back(at(i).id); 380 | } 381 | }; 382 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/board.h: -------------------------------------------------------------------------------- 1 | /***************************** 2 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Rafael Muñoz Salinas. 27 | ********************************/ 28 | #ifndef _Aruco_board_h 29 | #define _Aruco_board_h 30 | #include 31 | #include 32 | #include 33 | #include "exports.h" 34 | #include "marker.h" 35 | using namespace std; 36 | namespace aruco { 37 | /** 38 | * 3d representation of a marker 39 | */ 40 | struct ARUCO_EXPORTS MarkerInfo : public vector< cv::Point3f > { 41 | MarkerInfo() {} 42 | MarkerInfo(int _id) { id = _id; } 43 | MarkerInfo(const MarkerInfo &MI) : vector< cv::Point3f >(MI) { id = MI.id; } 44 | MarkerInfo &operator=(const MarkerInfo &MI) { 45 | vector< cv::Point3f >::operator=(MI); 46 | id = MI.id; 47 | return *this; 48 | } 49 | int id; // maker id 50 | }; 51 | 52 | /**\brief This class defines a board with several markers. 53 | * A Board contains several markers so that they are more robustly detected. 54 | * 55 | * In general, a board is a set of markers. So BoardConfiguration is only a list 56 | * of the id of the markers along with the position of their corners. 57 | * 58 | * The position of the corners can be specified either in pixels (in a non-specific size) or in meters. 59 | * The first is the typical case in which you generate the image of board and the print it. Since you do not know in advance the real 60 | * size of the markers, their corners are specified in pixels, and then, the translation to meters can be made once you know the real size. 61 | * 62 | * On the other hand, you may want to have the information of your boards in meters. The BoardConfiguration allows you to do so. 63 | * 64 | * The point is in the mInfoType variable. It can be either PIX or METERS according to your needs. 65 | * 66 | */ 67 | 68 | 69 | class ARUCO_EXPORTS BoardConfiguration : public vector< MarkerInfo > { 70 | friend class Board; 71 | 72 | public: 73 | enum MarkerInfoType { 74 | NONE = -1, 75 | PIX = 0, 76 | METERS = 1 77 | }; // indicates if the data in MakersInfo is expressed in meters or in pixels so as to do conversion internally 78 | // variable indicates if the data in MakersInfo is expressed in meters or in pixels so as to do conversion internally 79 | int mInfoType; 80 | /** 81 | */ 82 | BoardConfiguration(); 83 | /**Loads from file 84 | * @param filePath to the config file 85 | */ 86 | BoardConfiguration(string filePath) throw(cv::Exception); 87 | 88 | /** 89 | */ 90 | BoardConfiguration(const BoardConfiguration &T); 91 | 92 | /** 93 | */ 94 | BoardConfiguration &operator=(const BoardConfiguration &T); 95 | /**Saves the board info to a file 96 | */ 97 | void saveToFile(string sfile) throw(cv::Exception); 98 | /**Reads board info from a file 99 | */ 100 | void readFromFile(string sfile) throw(cv::Exception); 101 | /**Indicates if the corners are expressed in meters 102 | */ 103 | bool isExpressedInMeters() const { return mInfoType == METERS; } 104 | /**Indicates if the corners are expressed in meters 105 | */ 106 | bool isExpressedInPixels() const { return mInfoType == PIX; } 107 | /**Returns the index of the marker with id indicated, if is in the list 108 | */ 109 | int getIndexOfMarkerId(int id) const; 110 | /**Returns the Info of the marker with id specified. If not in the set, throws exception 111 | */ 112 | const MarkerInfo &getMarkerInfo(int id) const throw(cv::Exception); 113 | /**Set in the list passed the set of the ids 114 | */ 115 | void getIdList(vector< int > &ids, bool append = true) const; 116 | 117 | private: 118 | /**Saves the board info to a file 119 | */ 120 | void saveToFile(cv::FileStorage &fs) throw(cv::Exception); 121 | /**Reads board info from a file 122 | */ 123 | void readFromFile(cv::FileStorage &fs) throw(cv::Exception); 124 | }; 125 | 126 | /** 127 | */ 128 | class ARUCO_EXPORTS Board : public vector< Marker > { 129 | 130 | public: 131 | BoardConfiguration conf; 132 | // matrices of rotation and translation respect to the camera 133 | cv::Mat Rvec, Tvec; 134 | /** 135 | */ 136 | Board() { 137 | Rvec.create(3, 1, CV_32FC1); 138 | Tvec.create(3, 1, CV_32FC1); 139 | for (int i = 0; i < 3; i++) 140 | Tvec.at< float >(i, 0) = Rvec.at< float >(i, 0) = -999999; 141 | } 142 | 143 | /**Given the extrinsic camera parameters returns the GL_MODELVIEW matrix for opengl. 144 | * Setting this matrix, the reference corrdinate system will be set in this board 145 | */ 146 | void glGetModelViewMatrix(double modelview_matrix[16]) throw(cv::Exception); 147 | 148 | /** 149 | * Returns position vector and orientation quaternion for an Ogre scene node or entity. 150 | * Use: 151 | * ... 152 | * Ogre::Vector3 ogrePos (position[0], position[1], position[2]); 153 | * Ogre::Quaternion ogreOrient (orientation[0], orientation[1], orientation[2], orientation[3]); 154 | * mySceneNode->setPosition( ogrePos ); 155 | * mySceneNode->setOrientation( ogreOrient ); 156 | * ... 157 | */ 158 | void OgreGetPoseParameters(double position[3], double orientation[4]) throw(cv::Exception); 159 | 160 | 161 | /**Save this from a file 162 | */ 163 | void saveToFile(string filePath) throw(cv::Exception); 164 | /**Read this from a file 165 | */ 166 | void readFromFile(string filePath) throw(cv::Exception); 167 | 168 | /**Draws the detected markers 169 | */ 170 | void draw(cv::Mat &im, cv::Scalar color, int lineWidth = 1, bool writeId = true); 171 | }; 172 | } 173 | 174 | #endif 175 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/boarddetector.cpp: -------------------------------------------------------------------------------- 1 | /***************************** 2 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Rafael Muñoz Salinas. 27 | ********************************/ 28 | #include "boarddetector.h" 29 | #define _USE_MATH_DEFINES 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | using namespace std; 37 | using namespace cv; 38 | namespace aruco { 39 | /** 40 | */ 41 | BoardDetector::BoardDetector(bool setYPerpendicular) { 42 | _setYPerpendicular = setYPerpendicular; 43 | _areParamsSet = false; 44 | repj_err_thres = -1; 45 | } 46 | /** 47 | * Use if you plan to let this class to perform marker detection too 48 | */ 49 | void BoardDetector::setParams(const BoardConfiguration &bc, const CameraParameters &cp, float markerSizeMeters) { 50 | _camParams = cp; 51 | _markerSize = markerSizeMeters; 52 | _bconf = bc; 53 | _areParamsSet = true; 54 | } 55 | /** 56 | * 57 | * 58 | */ 59 | void BoardDetector::setParams(const BoardConfiguration &bc) { 60 | _bconf = bc; 61 | _areParamsSet = true; 62 | } 63 | 64 | /** 65 | * 66 | * 67 | */ 68 | float BoardDetector::detect(const cv::Mat &im) throw(cv::Exception) { 69 | _mdetector.detect(im, _vmarkers); 70 | 71 | float res; 72 | 73 | if (_camParams.isValid()) 74 | res = detect(_vmarkers, _bconf, _boardDetected, _camParams.CameraMatrix, _camParams.Distorsion, _markerSize); 75 | else 76 | res = detect(_vmarkers, _bconf, _boardDetected); 77 | return res; 78 | } 79 | /** 80 | * 81 | * 82 | */ 83 | float BoardDetector::detect(const vector< Marker > &detectedMarkers, const BoardConfiguration &BConf, Board &Bdetected, const CameraParameters &cp, 84 | float markerSizeMeters) throw(cv::Exception) { 85 | return detect(detectedMarkers, BConf, Bdetected, cp.CameraMatrix, cp.Distorsion, markerSizeMeters); 86 | } 87 | /** 88 | * 89 | * 90 | */ 91 | float BoardDetector::detect(const vector< Marker > &detectedMarkers, const BoardConfiguration &BConf, Board &Bdetected, Mat camMatrix, Mat distCoeff, 92 | float markerSizeMeters) throw(cv::Exception) { 93 | if (BConf.size() == 0) 94 | throw cv::Exception(8881, "BoardDetector::detect", "Invalid BoardConfig that is empty", __FILE__, __LINE__); 95 | if (BConf[0].size() < 2) 96 | throw cv::Exception(8881, "BoardDetector::detect", "Invalid BoardConfig that is empty 2", __FILE__, __LINE__); 97 | // compute the size of the markers in meters, which is used for some routines(mostly drawing) 98 | float ssize; 99 | if (BConf.mInfoType == BoardConfiguration::PIX && markerSizeMeters > 0) 100 | ssize = markerSizeMeters; 101 | else if (BConf.mInfoType == BoardConfiguration::METERS) { 102 | ssize = cv::norm(BConf[0][0] - BConf[0][1]); 103 | } 104 | 105 | // cout<<"markerSizeMeters="<= 1) { 121 | if (camMatrix.rows != 0) { 122 | if (markerSizeMeters > 0 && BConf.mInfoType == BoardConfiguration::PIX) 123 | hasEnoughInfoForRTvecCalculation = true; 124 | else if (BConf.mInfoType == BoardConfiguration::METERS) 125 | hasEnoughInfoForRTvecCalculation = true; 126 | } 127 | } 128 | 129 | // calculate extrinsic if there is information for that 130 | if (hasEnoughInfoForRTvecCalculation) { 131 | 132 | // calculate the size of the markers in meters if expressed in pixels 133 | double marker_meter_per_pix = 0; 134 | if (BConf.mInfoType == BoardConfiguration::PIX) 135 | marker_meter_per_pix = markerSizeMeters / cv::norm(BConf[0][0] - BConf[0][1]); 136 | else 137 | marker_meter_per_pix = 1; // to avoind interferring the process below 138 | 139 | // now, create the matrices for finding the extrinsics 140 | vector< cv::Point3f > objPoints; 141 | vector< cv::Point2f > imagePoints; 142 | for (size_t i = 0; i < Bdetected.size(); i++) { 143 | int idx = Bdetected.conf.getIndexOfMarkerId(Bdetected[i].id); 144 | assert(idx != -1); 145 | for (int p = 0; p < 4; p++) { 146 | imagePoints.push_back(Bdetected[i][p]); 147 | const aruco::MarkerInfo &Minfo = Bdetected.conf.getMarkerInfo(Bdetected[i].id); 148 | objPoints.push_back(Minfo[p] * marker_meter_per_pix); 149 | // cout< objPoints_filtered; 190 | vector< cv::Point2f > imagePoints_filtered; 191 | for (size_t i = 0; i < pointsThatPassTest.size(); i++) { 192 | objPoints_filtered.push_back(objPoints[pointsThatPassTest[i]]); 193 | imagePoints_filtered.push_back(imagePoints[pointsThatPassTest[i]]); 194 | } 195 | 196 | cv::solvePnP(objPoints_filtered, imagePoints_filtered, camMatrix, distCoeff, rvec, tvec); 197 | rvec.convertTo(Bdetected.Rvec, CV_32FC1); 198 | tvec.convertTo(Bdetected.Tvec, CV_32FC1); 199 | } 200 | 201 | 202 | // now, rotate 90 deg in X so that Y axis points up 203 | if (_setYPerpendicular) 204 | rotateXAxis(Bdetected.Rvec); 205 | // cout<(0,0)<<" "<(1,0)<<" "<(2,0)<(0,0)<<" "<(1,0)<<" "<(2,0)<(1, 1) = cos(angleRad); 220 | RX.at< float >(1, 2) = -sin(angleRad); 221 | RX.at< float >(2, 1) = sin(angleRad); 222 | RX.at< float >(2, 2) = cos(angleRad); 223 | // now multiply 224 | R = R * RX; 225 | // finally, the the rodrigues back 226 | Rodrigues(R, rotation); 227 | } 228 | 229 | /**Static version (all in one) 230 | */ 231 | Board BoardDetector::detect(const cv::Mat &Image, const BoardConfiguration &bc, const CameraParameters &cp, float markerSizeMeters) { 232 | BoardDetector BD; 233 | BD.setParams(bc, cp, markerSizeMeters); 234 | BD.detect(Image); 235 | return BD.getDetectedBoard(); 236 | } 237 | }; 238 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/boarddetector.h: -------------------------------------------------------------------------------- 1 | /***************************** 2 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Rafael Muñoz Salinas. 27 | ********************************/ 28 | #ifndef _Aruco_BoardDetector_H 29 | #define _Aruco_BoardDetector_H 30 | #include 31 | #include "exports.h" 32 | #include "board.h" 33 | #include "cameraparameters.h" 34 | #include "markerdetector.h" 35 | using namespace std; 36 | 37 | namespace aruco { 38 | 39 | /**\brief This class detects AR boards 40 | * Version 1.2 41 | * There are two modes for board detection. 42 | * First, the old way. (You first detect markers with MarkerDetector and then call to detect in this class. 43 | * 44 | * Second: New mode, marker detection is included in the class 45 | * \code 46 | 47 | CameraParameters CP; 48 | CP.readFromFile(path_cp) 49 | BoardConfiguration BC; 50 | BC.readFromFile(path_bc); 51 | BoardDetector BD; 52 | BD.setParams(BC,CP); //or only BD.setParams(BC) 53 | //capture image 54 | cv::Mat im; 55 | capture_image(im); 56 | 57 | float prob=BD.detect(im); 58 | if (prob>0.3) 59 | CvDrawingUtils::draw3DAxis(im,BD.getDetectedBoard(),CP); 60 | 61 | \endcode 62 | * 63 | */ 64 | class ARUCO_EXPORTS BoardDetector { 65 | public: 66 | /** See discussion in @see enableRotateXAxis. 67 | * Do not change unless you know what you are doing 68 | */ 69 | BoardDetector(bool setYPerpendicular = false); 70 | 71 | 72 | /** 73 | * Use if you plan to let this class to perform marker detection too 74 | */ 75 | void setParams(const BoardConfiguration &bc, const CameraParameters &cp, float markerSizeMeters = -1); 76 | void setParams(const BoardConfiguration &bc); 77 | /** 78 | * Detect markers, and then, look for the board indicated in setParams() 79 | * @return value indicating the likelihood of having found the marker 80 | */ 81 | float detect(const cv::Mat &im) throw(cv::Exception); 82 | /**Returns a reference to the board detected 83 | */ 84 | Board &getDetectedBoard() { return _boardDetected; } 85 | /**Returns a reference to the internal marker detector 86 | */ 87 | MarkerDetector &getMarkerDetector() { return _mdetector; } 88 | /**Returns the vector of markers detected 89 | */ 90 | vector< Marker > &getDetectedMarkers() { return _vmarkers; } 91 | 92 | 93 | // ALTERNATIVE DETECTION METHOD, BASED ON MARKERS PREVIOUSLY DETECTED 94 | 95 | /** Given the markers detected, determines if there is the board passed 96 | * @param detectedMarkers result provided by aruco::ArMarkerDetector 97 | * @param BConf the board you want to see if is present 98 | * @param Bdetected output information of the detected board 99 | * @param camMatrix camera matrix with intrinsics 100 | * @param distCoeff camera distorsion coeff 101 | * @param camMatrix intrinsic camera information. 102 | * @param distCoeff camera distorsion coefficient. If set Mat() if is assumed no camera distorion 103 | * @param markerSizeMeters size of the marker sides expressed in meters 104 | * @return value indicating the likelihood of having found the marker 105 | */ 106 | float detect(const vector< Marker > &detectedMarkers, const BoardConfiguration &BConf, Board &Bdetected, cv::Mat camMatrix = cv::Mat(), 107 | cv::Mat distCoeff = cv::Mat(), float markerSizeMeters = -1) throw(cv::Exception); 108 | float detect(const vector< Marker > &detectedMarkers, const BoardConfiguration &BConf, Board &Bdetected, const CameraParameters &cp, 109 | float markerSizeMeters = -1) throw(cv::Exception); 110 | 111 | /**Static version (all in one). Detects the board indicated 112 | * @param Image input image 113 | * @param bc the board you want to see if is present 114 | * @param cp camera parameters 115 | * @param markerSizeMeters size of the marker sides expressed in meters (not needed in the board is expressed in meters) 116 | * @return Board detected 117 | */ 118 | static Board detect(const cv::Mat &Image, const BoardConfiguration &bc, const CameraParameters &cp, float markerSizeMeters = -1); 119 | 120 | /** 121 | * By default, the Y axis is set to point up. However this is not the default 122 | * operation mode of opencv, which produces the Z axis pointing up instead. 123 | * So, to achieve this change, we have to rotate the X axis. 124 | */ 125 | void setYPerpendicular(bool enable) { _setYPerpendicular = enable; } 126 | void setYPerperdicular(bool enable) { setYPerpendicular(enable); } // TODO mark as deprecated 127 | bool isYPerpendicular() { return _setYPerpendicular; } 128 | 129 | /**Sets the threshold for reprjection test. Pixels that after estimating the camera location 130 | * projects 'repj_err_thres' pixels farther from its original location are discarded as outliers. 131 | * By default it is set to -1, meaning that not reprojection test is performed 132 | */ 133 | void set_repj_err_thres(float Repj_err_thres) { repj_err_thres = Repj_err_thres; } 134 | float get_repj_err_thres() const { return repj_err_thres; } 135 | 136 | 137 | private: 138 | void rotateXAxis(cv::Mat &rotation); 139 | bool _setYPerpendicular; 140 | 141 | //-- Functionality to detect markers inside 142 | bool _areParamsSet; 143 | BoardConfiguration _bconf; 144 | Board _boardDetected; 145 | float _markerSize, repj_err_thres; 146 | CameraParameters _camParams; 147 | MarkerDetector _mdetector; // internal markerdetector 148 | vector< Marker > _vmarkers; // markers detected in the call to : float detect(const cv::Mat &im); 149 | }; 150 | }; 151 | #endif 152 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/cameraparameters.h: -------------------------------------------------------------------------------- 1 | /***************************** 2 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Rafael Muñoz Salinas. 27 | ********************************/ 28 | #ifndef _Aruco_CameraParameters_H 29 | #define _Aruco_CameraParameters_H 30 | #include "exports.h" 31 | #include 32 | #include 33 | using namespace std; 34 | namespace aruco { 35 | /**\brief Parameters of the camera 36 | */ 37 | 38 | class ARUCO_EXPORTS CameraParameters { 39 | public: 40 | // 3x3 matrix (fx 0 cx, 0 fy cy, 0 0 1) 41 | cv::Mat CameraMatrix; 42 | // 4x1 matrix (k1,k2,p1,p2) 43 | cv::Mat Distorsion; 44 | // size of the image 45 | cv::Size CamSize; 46 | 47 | /**Empty constructor 48 | */ 49 | CameraParameters(); 50 | /**Creates the object from the info passed 51 | * @param cameraMatrix 3x3 matrix (fx 0 cx, 0 fy cy, 0 0 1) 52 | * @param distorsionCoeff 4x1 matrix (k1,k2,p1,p2) 53 | * @param size image size 54 | */ 55 | CameraParameters(cv::Mat cameraMatrix, cv::Mat distorsionCoeff, cv::Size size) throw(cv::Exception); 56 | /**Sets the parameters 57 | * @param cameraMatrix 3x3 matrix (fx 0 cx, 0 fy cy, 0 0 1) 58 | * @param distorsionCoeff 4x1 matrix (k1,k2,p1,p2) 59 | * @param size image size 60 | */ 61 | void setParams(cv::Mat cameraMatrix, cv::Mat distorsionCoeff, cv::Size size) throw(cv::Exception); 62 | /**Copy constructor 63 | */ 64 | CameraParameters(const CameraParameters &CI); 65 | 66 | /**Indicates whether this object is valid 67 | */ 68 | bool isValid() const { 69 | return CameraMatrix.rows != 0 && CameraMatrix.cols != 0 && Distorsion.rows != 0 && Distorsion.cols != 0 && CamSize.width != -1 && CamSize.height != -1; 70 | } 71 | /**Assign operator 72 | */ 73 | CameraParameters &operator=(const CameraParameters &CI); 74 | /**Reads the camera parameters from a file generated using saveToFile. 75 | */ 76 | void readFromFile(string path) throw(cv::Exception); 77 | /**Saves this to a file 78 | */ 79 | void saveToFile(string path, bool inXML = true) throw(cv::Exception); 80 | 81 | /**Reads from a YAML file generated with the opencv2.2 calibration utility 82 | */ 83 | void readFromXMLFile(string filePath) throw(cv::Exception); 84 | 85 | /**Adjust the parameters to the size of the image indicated 86 | */ 87 | void resize(cv::Size size) throw(cv::Exception); 88 | 89 | /**Returns the location of the camera in the reference system given by the rotation and translation vectors passed 90 | * NOT TESTED 91 | */ 92 | static cv::Point3f getCameraLocation(cv::Mat Rvec, cv::Mat Tvec); 93 | 94 | /**Given the intrinsic camera parameters returns the GL_PROJECTION matrix for opengl. 95 | * PLease NOTE that when using OpenGL, it is assumed no camera distorsion! So, if it is not true, you should have 96 | * undistor image 97 | * 98 | * @param orgImgSize size of the original image 99 | * @param size of the image/window where to render (can be different from the real camera image). Please not that it must be related to CamMatrix 100 | * @param proj_matrix output projection matrix to give to opengl 101 | * @param gnear,gfar: visible rendering range 102 | * @param invert: indicates if the output projection matrix has to yield a horizontally inverted image because image data has not been stored in the order of 103 | *glDrawPixels: bottom-to-top. 104 | */ 105 | void glGetProjectionMatrix(cv::Size orgImgSize, cv::Size size, double proj_matrix[16], double gnear, double gfar, bool invert = false) throw(cv::Exception); 106 | 107 | /** 108 | * setup camera for an Ogre project. 109 | * Use: 110 | * ... 111 | * Ogre::Matrix4 PM(proj_matrix[0], proj_matrix[1], ... , proj_matrix[15]); 112 | * yourCamera->setCustomProjectionMatrix(true, PM); 113 | * yourCamera->setCustomViewMatrix(true, Ogre::Matrix4::IDENTITY); 114 | * ... 115 | * As in OpenGL, it assumes no camera distorsion 116 | */ 117 | void OgreGetProjectionMatrix(cv::Size orgImgSize, cv::Size size, double proj_matrix[16], double gnear, double gfar, 118 | bool invert = false) throw(cv::Exception); 119 | 120 | 121 | /**Returns the 4x4 homogeneous transform matrix from the R and T vectors computed 122 | */ 123 | static cv::Mat getRTMatrix(const cv::Mat &R_, const cv::Mat &T_, int forceType); 124 | 125 | private: 126 | // GL routines 127 | 128 | static void argConvGLcpara2(double cparam[3][4], int width, int height, double gnear, double gfar, double m[16], bool invert) throw(cv::Exception); 129 | static int arParamDecompMat(double source[3][4], double cpara[3][4], double trans[3][4]) throw(cv::Exception); 130 | static double norm(double a, double b, double c); 131 | static double dot(double a1, double a2, double a3, double b1, double b2, double b3); 132 | }; 133 | } 134 | #endif 135 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/cvdrawingutils.cpp: -------------------------------------------------------------------------------- 1 | /***************************** 2 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Rafael Muñoz Salinas. 27 | ********************************/ 28 | #include "cvdrawingutils.h" 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace cv; 34 | namespace aruco { 35 | /**** 36 | * 37 | * 38 | * 39 | ****/ 40 | void CvDrawingUtils::draw3dAxis(cv::Mat &Image, Marker &m, const CameraParameters &CP) { 41 | 42 | float size = m.ssize * 3; 43 | Mat objectPoints(4, 3, CV_32FC1); 44 | objectPoints.at< float >(0, 0) = 0; 45 | objectPoints.at< float >(0, 1) = 0; 46 | objectPoints.at< float >(0, 2) = 0; 47 | objectPoints.at< float >(1, 0) = size; 48 | objectPoints.at< float >(1, 1) = 0; 49 | objectPoints.at< float >(1, 2) = 0; 50 | objectPoints.at< float >(2, 0) = 0; 51 | objectPoints.at< float >(2, 1) = size; 52 | objectPoints.at< float >(2, 2) = 0; 53 | objectPoints.at< float >(3, 0) = 0; 54 | objectPoints.at< float >(3, 1) = 0; 55 | objectPoints.at< float >(3, 2) = size; 56 | 57 | vector< Point2f > imagePoints; 58 | cv::projectPoints(objectPoints, m.Rvec, m.Tvec, CP.CameraMatrix, CP.Distorsion, imagePoints); 59 | // draw lines of different colours 60 | cv::line(Image, imagePoints[0], imagePoints[1], Scalar(0, 0, 255, 255), 1, CV_AA); 61 | cv::line(Image, imagePoints[0], imagePoints[2], Scalar(0, 255, 0, 255), 1, CV_AA); 62 | cv::line(Image, imagePoints[0], imagePoints[3], Scalar(255, 0, 0, 255), 1, CV_AA); 63 | putText(Image, "x", imagePoints[1], FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0, 0, 255, 255), 2); 64 | putText(Image, "y", imagePoints[2], FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0, 255, 0, 255), 2); 65 | putText(Image, "z", imagePoints[3], FONT_HERSHEY_SIMPLEX, 0.6, Scalar(255, 0, 0, 255), 2); 66 | } 67 | 68 | /**** 69 | * 70 | * 71 | * 72 | ****/ 73 | void CvDrawingUtils::draw3dCube(cv::Mat &Image, Marker &m, const CameraParameters &CP, bool setYperpendicular) { 74 | Mat objectPoints(8, 3, CV_32FC1); 75 | double halfSize = m.ssize / 2; 76 | 77 | if (setYperpendicular) { 78 | objectPoints.at< float >(0, 0) = -halfSize; 79 | objectPoints.at< float >(0, 1) = 0; 80 | objectPoints.at< float >(0, 2) = -halfSize; 81 | objectPoints.at< float >(1, 0) = halfSize; 82 | objectPoints.at< float >(1, 1) = 0; 83 | objectPoints.at< float >(1, 2) = -halfSize; 84 | objectPoints.at< float >(2, 0) = halfSize; 85 | objectPoints.at< float >(2, 1) = 0; 86 | objectPoints.at< float >(2, 2) = halfSize; 87 | objectPoints.at< float >(3, 0) = -halfSize; 88 | objectPoints.at< float >(3, 1) = 0; 89 | objectPoints.at< float >(3, 2) = halfSize; 90 | 91 | objectPoints.at< float >(4, 0) = -halfSize; 92 | objectPoints.at< float >(4, 1) = m.ssize; 93 | objectPoints.at< float >(4, 2) = -halfSize; 94 | objectPoints.at< float >(5, 0) = halfSize; 95 | objectPoints.at< float >(5, 1) = m.ssize; 96 | objectPoints.at< float >(5, 2) = -halfSize; 97 | objectPoints.at< float >(6, 0) = halfSize; 98 | objectPoints.at< float >(6, 1) = m.ssize; 99 | objectPoints.at< float >(6, 2) = halfSize; 100 | objectPoints.at< float >(7, 0) = -halfSize; 101 | objectPoints.at< float >(7, 1) = m.ssize; 102 | objectPoints.at< float >(7, 2) = halfSize; 103 | } else { 104 | objectPoints.at< float >(0, 0) = -halfSize; 105 | objectPoints.at< float >(0, 1) = -halfSize; 106 | objectPoints.at< float >(0, 2) = 0; 107 | objectPoints.at< float >(1, 0) = halfSize; 108 | objectPoints.at< float >(1, 1) = -halfSize; 109 | objectPoints.at< float >(1, 2) = 0; 110 | objectPoints.at< float >(2, 0) = halfSize; 111 | objectPoints.at< float >(2, 1) = halfSize; 112 | objectPoints.at< float >(2, 2) = 0; 113 | objectPoints.at< float >(3, 0) = -halfSize; 114 | objectPoints.at< float >(3, 1) = halfSize; 115 | objectPoints.at< float >(3, 2) = 0; 116 | 117 | objectPoints.at< float >(4, 0) = -halfSize; 118 | objectPoints.at< float >(4, 1) = -halfSize; 119 | objectPoints.at< float >(4, 2) = m.ssize; 120 | objectPoints.at< float >(5, 0) = halfSize; 121 | objectPoints.at< float >(5, 1) = -halfSize; 122 | objectPoints.at< float >(5, 2) = m.ssize; 123 | objectPoints.at< float >(6, 0) = halfSize; 124 | objectPoints.at< float >(6, 1) = halfSize; 125 | objectPoints.at< float >(6, 2) = m.ssize; 126 | objectPoints.at< float >(7, 0) = -halfSize; 127 | objectPoints.at< float >(7, 1) = halfSize; 128 | objectPoints.at< float >(7, 2) = m.ssize; 129 | } 130 | 131 | vector< Point2f > imagePoints; 132 | projectPoints(objectPoints, m.Rvec, m.Tvec, CP.CameraMatrix, CP.Distorsion, imagePoints); 133 | // draw lines of different colours 134 | for (int i = 0; i < 4; i++) 135 | cv::line(Image, imagePoints[i], imagePoints[(i + 1) % 4], Scalar(0, 0, 255, 255), 1, CV_AA); 136 | 137 | for (int i = 0; i < 4; i++) 138 | cv::line(Image, imagePoints[i + 4], imagePoints[4 + (i + 1) % 4], Scalar(0, 0, 255, 255), 1, CV_AA); 139 | 140 | for (int i = 0; i < 4; i++) 141 | cv::line(Image, imagePoints[i], imagePoints[i + 4], Scalar(0, 0, 255, 255), 1, CV_AA); 142 | } 143 | 144 | 145 | /**** 146 | * 147 | * 148 | * 149 | ****/ 150 | void CvDrawingUtils::draw3dAxis(cv::Mat &Image, Board &B, const CameraParameters &CP) { 151 | Mat objectPoints(4, 3, CV_32FC1); 152 | objectPoints.at< float >(0, 0) = 0; 153 | objectPoints.at< float >(0, 1) = 0; 154 | objectPoints.at< float >(0, 2) = 0; 155 | objectPoints.at< float >(1, 0) = 2 * B[0].ssize; 156 | objectPoints.at< float >(1, 1) = 0; 157 | objectPoints.at< float >(1, 2) = 0; 158 | objectPoints.at< float >(2, 0) = 0; 159 | objectPoints.at< float >(2, 1) = 2 * B[0].ssize; 160 | objectPoints.at< float >(2, 2) = 0; 161 | objectPoints.at< float >(3, 0) = 0; 162 | objectPoints.at< float >(3, 1) = 0; 163 | objectPoints.at< float >(3, 2) = 2 * B[0].ssize; 164 | 165 | vector< Point2f > imagePoints; 166 | projectPoints(objectPoints, B.Rvec, B.Tvec, CP.CameraMatrix, CP.Distorsion, imagePoints); 167 | // draw lines of different colours 168 | cv::line(Image, imagePoints[0], imagePoints[1], Scalar(0, 0, 255, 255), 2, CV_AA); 169 | cv::line(Image, imagePoints[0], imagePoints[2], Scalar(0, 255, 0, 255), 2, CV_AA); 170 | cv::line(Image, imagePoints[0], imagePoints[3], Scalar(255, 0, 0, 255), 2, CV_AA); 171 | 172 | putText(Image, "X", imagePoints[1], FONT_HERSHEY_SIMPLEX, 1, Scalar(0, 0, 255, 255), 2); 173 | putText(Image, "Y", imagePoints[2], FONT_HERSHEY_SIMPLEX, 1, Scalar(0, 255, 0, 255), 2); 174 | putText(Image, "Z", imagePoints[3], FONT_HERSHEY_SIMPLEX, 1, Scalar(255, 0, 0, 255), 2); 175 | } 176 | 177 | 178 | /**** 179 | * 180 | * 181 | * 182 | ****/ 183 | void CvDrawingUtils::draw3dCube(cv::Mat &Image, Board &B, const CameraParameters &CP, bool setYperpendicular) { 184 | 185 | float cubeSize = B[0].ssize; 186 | float txz = -cubeSize / 2; 187 | Mat objectPoints(8, 3, CV_32FC1); 188 | 189 | if (setYperpendicular) { 190 | objectPoints.at< float >(0, 0) = txz; 191 | objectPoints.at< float >(0, 1) = 0; 192 | objectPoints.at< float >(0, 2) = txz; 193 | objectPoints.at< float >(1, 0) = txz + cubeSize; 194 | objectPoints.at< float >(1, 1) = 0; 195 | objectPoints.at< float >(1, 2) = txz; 196 | objectPoints.at< float >(2, 0) = txz + cubeSize; 197 | objectPoints.at< float >(2, 1) = cubeSize; 198 | objectPoints.at< float >(2, 2) = txz; 199 | objectPoints.at< float >(3, 0) = txz; 200 | objectPoints.at< float >(3, 1) = cubeSize; 201 | objectPoints.at< float >(3, 2) = txz; 202 | 203 | objectPoints.at< float >(4, 0) = txz; 204 | objectPoints.at< float >(4, 1) = 0; 205 | objectPoints.at< float >(4, 2) = txz + cubeSize; 206 | objectPoints.at< float >(5, 0) = txz + cubeSize; 207 | objectPoints.at< float >(5, 1) = 0; 208 | objectPoints.at< float >(5, 2) = txz + cubeSize; 209 | objectPoints.at< float >(6, 0) = txz + cubeSize; 210 | objectPoints.at< float >(6, 1) = cubeSize; 211 | objectPoints.at< float >(6, 2) = txz + cubeSize; 212 | objectPoints.at< float >(7, 0) = txz; 213 | objectPoints.at< float >(7, 1) = cubeSize; 214 | objectPoints.at< float >(7, 2) = txz + cubeSize; 215 | } else { 216 | objectPoints.at< float >(0, 0) = txz; 217 | objectPoints.at< float >(0, 2) = 0; 218 | objectPoints.at< float >(0, 1) = txz; 219 | objectPoints.at< float >(1, 0) = txz + cubeSize; 220 | objectPoints.at< float >(1, 2) = 0; 221 | objectPoints.at< float >(1, 1) = txz; 222 | objectPoints.at< float >(2, 0) = txz + cubeSize; 223 | objectPoints.at< float >(2, 2) = -cubeSize; 224 | objectPoints.at< float >(2, 1) = txz; 225 | objectPoints.at< float >(3, 0) = txz; 226 | objectPoints.at< float >(3, 2) = -cubeSize; 227 | objectPoints.at< float >(3, 1) = txz; 228 | 229 | objectPoints.at< float >(4, 0) = txz; 230 | objectPoints.at< float >(4, 2) = 0; 231 | objectPoints.at< float >(4, 1) = txz + cubeSize; 232 | objectPoints.at< float >(5, 0) = txz + cubeSize; 233 | objectPoints.at< float >(5, 2) = 0; 234 | objectPoints.at< float >(5, 1) = txz + cubeSize; 235 | objectPoints.at< float >(6, 0) = txz + cubeSize; 236 | objectPoints.at< float >(6, 2) = -cubeSize; 237 | objectPoints.at< float >(6, 1) = txz + cubeSize; 238 | objectPoints.at< float >(7, 0) = txz; 239 | objectPoints.at< float >(7, 2) = -cubeSize; 240 | objectPoints.at< float >(7, 1) = txz + cubeSize; 241 | } 242 | 243 | vector< Point2f > imagePoints; 244 | projectPoints(objectPoints, B.Rvec, B.Tvec, CP.CameraMatrix, CP.Distorsion, imagePoints); 245 | // draw lines of different colours 246 | for (int i = 0; i < 4; i++) 247 | cv::line(Image, imagePoints[i], imagePoints[(i + 1) % 4], Scalar(0, 0, 255, 255), 1, CV_AA); 248 | 249 | for (int i = 0; i < 4; i++) 250 | cv::line(Image, imagePoints[i + 4], imagePoints[4 + (i + 1) % 4], Scalar(0, 0, 255, 255), 1, CV_AA); 251 | 252 | for (int i = 0; i < 4; i++) 253 | cv::line(Image, imagePoints[i], imagePoints[i + 4], Scalar(0, 0, 255, 255), 1, CV_AA); 254 | } 255 | } 256 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/cvdrawingutils.h: -------------------------------------------------------------------------------- 1 | /***************************** 2 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Rafael Muñoz Salinas. 27 | ********************************/ 28 | #ifndef _ArUco_DrawUtils_H_ 29 | #define _ArUco_DrawUtils_H_ 30 | #include "exports.h" 31 | #include "aruco.h" 32 | namespace aruco { 33 | /**\brief A set of functions to draw in opencv images 34 | */ 35 | class ARUCO_EXPORTS CvDrawingUtils { 36 | public: 37 | static void draw3dAxis(cv::Mat &Image, Marker &m, const CameraParameters &CP); 38 | 39 | static void draw3dCube(cv::Mat &Image, Marker &m, const CameraParameters &CP, bool setYperpendicular = false); 40 | 41 | static void draw3dAxis(cv::Mat &Image, Board &m, const CameraParameters &CP); 42 | 43 | static void draw3dCube(cv::Mat &Image, Board &m, const CameraParameters &CP, bool setYperpendicular = false); 44 | }; 45 | }; 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/exports.h: -------------------------------------------------------------------------------- 1 | /***************************** 2 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Rafael Muñoz Salinas. 27 | ********************************/ 28 | 29 | 30 | 31 | #ifndef __OPENARUCO_CORE_TYPES_H__ 32 | #define __OPENARUCO_CORE_TYPES_H__ 33 | 34 | #if !defined _CRT_SECURE_NO_DEPRECATE && _MSC_VER > 1300 35 | #define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */ 36 | #endif 37 | 38 | 39 | #if (defined WIN32 || defined _WIN32 || defined WINCE) && defined DSO_EXPORTS 40 | #define ARUCO_EXPORTS __declspec(dllexport) 41 | #else 42 | #define ARUCO_EXPORTS 43 | #endif 44 | 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/marker.cpp: -------------------------------------------------------------------------------- 1 | /***************************** 2 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Rafael Muñoz Salinas. 27 | ********************************/ 28 | #include "marker.h" 29 | #define _USE_MATH_DEFINES 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | using namespace cv; 36 | namespace aruco { 37 | /** 38 | * 39 | */ 40 | Marker::Marker() { 41 | id = -1; 42 | ssize = -1; 43 | Rvec.create(3, 1, CV_32FC1); 44 | Tvec.create(3, 1, CV_32FC1); 45 | for (int i = 0; i < 3; i++) 46 | Tvec.at< float >(i, 0) = Rvec.at< float >(i, 0) = -999999; 47 | } 48 | /** 49 | * 50 | */ 51 | Marker::Marker(const Marker &M) : std::vector< cv::Point2f >(M) { 52 | M.Rvec.copyTo(Rvec); 53 | M.Tvec.copyTo(Tvec); 54 | id = M.id; 55 | ssize = M.ssize; 56 | } 57 | 58 | /** 59 | * 60 | */ 61 | Marker::Marker(const std::vector< cv::Point2f > &corners, int _id) : std::vector< cv::Point2f >(corners) { 62 | id = _id; 63 | ssize = -1; 64 | Rvec.create(3, 1, CV_32FC1); 65 | Tvec.create(3, 1, CV_32FC1); 66 | for (int i = 0; i < 3; i++) 67 | Tvec.at< float >(i, 0) = Rvec.at< float >(i, 0) = -999999; 68 | } 69 | 70 | /** 71 | * 72 | */ 73 | void Marker::glGetModelViewMatrix(double modelview_matrix[16]) throw(cv::Exception) { 74 | // check if paremeters are valid 75 | bool invalid = false; 76 | for (int i = 0; i < 3 && !invalid; i++) { 77 | if (Tvec.at< float >(i, 0) != -999999) 78 | invalid |= false; 79 | if (Rvec.at< float >(i, 0) != -999999) 80 | invalid |= false; 81 | } 82 | if (invalid) 83 | throw cv::Exception(9003, "extrinsic parameters are not set", "Marker::getModelViewMatrix", __FILE__, __LINE__); 84 | Mat Rot(3, 3, CV_32FC1), Jacob; 85 | Rodrigues(Rvec, Rot, Jacob); 86 | 87 | double para[3][4]; 88 | for (int i = 0; i < 3; i++) 89 | for (int j = 0; j < 3; j++) 90 | para[i][j] = Rot.at< float >(i, j); 91 | // now, add the translation 92 | para[0][3] = Tvec.at< float >(0, 0); 93 | para[1][3] = Tvec.at< float >(1, 0); 94 | para[2][3] = Tvec.at< float >(2, 0); 95 | double scale = 1; 96 | 97 | modelview_matrix[0 + 0 * 4] = para[0][0]; 98 | // R1C2 99 | modelview_matrix[0 + 1 * 4] = para[0][1]; 100 | modelview_matrix[0 + 2 * 4] = para[0][2]; 101 | modelview_matrix[0 + 3 * 4] = para[0][3]; 102 | // R2 103 | modelview_matrix[1 + 0 * 4] = para[1][0]; 104 | modelview_matrix[1 + 1 * 4] = para[1][1]; 105 | modelview_matrix[1 + 2 * 4] = para[1][2]; 106 | modelview_matrix[1 + 3 * 4] = para[1][3]; 107 | // R3 108 | modelview_matrix[2 + 0 * 4] = -para[2][0]; 109 | modelview_matrix[2 + 1 * 4] = -para[2][1]; 110 | modelview_matrix[2 + 2 * 4] = -para[2][2]; 111 | modelview_matrix[2 + 3 * 4] = -para[2][3]; 112 | modelview_matrix[3 + 0 * 4] = 0.0; 113 | modelview_matrix[3 + 1 * 4] = 0.0; 114 | modelview_matrix[3 + 2 * 4] = 0.0; 115 | modelview_matrix[3 + 3 * 4] = 1.0; 116 | if (scale != 0.0) { 117 | modelview_matrix[12] *= scale; 118 | modelview_matrix[13] *= scale; 119 | modelview_matrix[14] *= scale; 120 | } 121 | } 122 | 123 | 124 | 125 | /**** 126 | * 127 | */ 128 | void Marker::OgreGetPoseParameters(double position[3], double orientation[4]) throw(cv::Exception) { 129 | 130 | // check if paremeters are valid 131 | bool invalid = false; 132 | for (int i = 0; i < 3 && !invalid; i++) { 133 | if (Tvec.at< float >(i, 0) != -999999) 134 | invalid |= false; 135 | if (Rvec.at< float >(i, 0) != -999999) 136 | invalid |= false; 137 | } 138 | if (invalid) 139 | throw cv::Exception(9003, "extrinsic parameters are not set", "Marker::getModelViewMatrix", __FILE__, __LINE__); 140 | 141 | // calculate position vector 142 | position[0] = -Tvec.ptr< float >(0)[0]; 143 | position[1] = -Tvec.ptr< float >(0)[1]; 144 | position[2] = +Tvec.ptr< float >(0)[2]; 145 | 146 | // now calculare orientation quaternion 147 | cv::Mat Rot(3, 3, CV_32FC1); 148 | cv::Rodrigues(Rvec, Rot); 149 | 150 | // calculate axes for quaternion 151 | double stAxes[3][3]; 152 | // x axis 153 | stAxes[0][0] = -Rot.at< float >(0, 0); 154 | stAxes[0][1] = -Rot.at< float >(1, 0); 155 | stAxes[0][2] = +Rot.at< float >(2, 0); 156 | // y axis 157 | stAxes[1][0] = -Rot.at< float >(0, 1); 158 | stAxes[1][1] = -Rot.at< float >(1, 1); 159 | stAxes[1][2] = +Rot.at< float >(2, 1); 160 | // for z axis, we use cross product 161 | stAxes[2][0] = stAxes[0][1] * stAxes[1][2] - stAxes[0][2] * stAxes[1][1]; 162 | stAxes[2][1] = -stAxes[0][0] * stAxes[1][2] + stAxes[0][2] * stAxes[1][0]; 163 | stAxes[2][2] = stAxes[0][0] * stAxes[1][1] - stAxes[0][1] * stAxes[1][0]; 164 | 165 | // transposed matrix 166 | double axes[3][3]; 167 | axes[0][0] = stAxes[0][0]; 168 | axes[1][0] = stAxes[0][1]; 169 | axes[2][0] = stAxes[0][2]; 170 | 171 | axes[0][1] = stAxes[1][0]; 172 | axes[1][1] = stAxes[1][1]; 173 | axes[2][1] = stAxes[1][2]; 174 | 175 | axes[0][2] = stAxes[2][0]; 176 | axes[1][2] = stAxes[2][1]; 177 | axes[2][2] = stAxes[2][2]; 178 | 179 | // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes 180 | // article "Quaternion Calculus and Fast Animation". 181 | double fTrace = axes[0][0] + axes[1][1] + axes[2][2]; 182 | double fRoot; 183 | 184 | if (fTrace > 0.0) { 185 | // |w| > 1/2, may as well choose w > 1/2 186 | fRoot = sqrt(fTrace + 1.0); // 2w 187 | orientation[0] = 0.5 * fRoot; 188 | fRoot = 0.5 / fRoot; // 1/(4w) 189 | orientation[1] = (axes[2][1] - axes[1][2]) * fRoot; 190 | orientation[2] = (axes[0][2] - axes[2][0]) * fRoot; 191 | orientation[3] = (axes[1][0] - axes[0][1]) * fRoot; 192 | } else { 193 | // |w| <= 1/2 194 | static unsigned int s_iNext[3] = {1, 2, 0}; 195 | unsigned int i = 0; 196 | if (axes[1][1] > axes[0][0]) 197 | i = 1; 198 | if (axes[2][2] > axes[i][i]) 199 | i = 2; 200 | unsigned int j = s_iNext[i]; 201 | unsigned int k = s_iNext[j]; 202 | 203 | fRoot = sqrt(axes[i][i] - axes[j][j] - axes[k][k] + 1.0); 204 | double *apkQuat[3] = {&orientation[1], &orientation[2], &orientation[3]}; 205 | *apkQuat[i] = 0.5 * fRoot; 206 | fRoot = 0.5 / fRoot; 207 | orientation[0] = (axes[k][j] - axes[j][k]) * fRoot; 208 | *apkQuat[j] = (axes[j][i] + axes[i][j]) * fRoot; 209 | *apkQuat[k] = (axes[k][i] + axes[i][k]) * fRoot; 210 | } 211 | } 212 | 213 | 214 | 215 | void Marker::draw(Mat &in, Scalar color, int lineWidth, bool writeId) const { 216 | if (size() != 4) 217 | return; 218 | cv::line(in, (*this)[0], (*this)[1], color, lineWidth, CV_AA); 219 | cv::line(in, (*this)[1], (*this)[2], color, lineWidth, CV_AA); 220 | cv::line(in, (*this)[2], (*this)[3], color, lineWidth, CV_AA); 221 | cv::line(in, (*this)[3], (*this)[0], color, lineWidth, CV_AA); 222 | cv::rectangle(in, (*this)[0] - Point2f(2, 2), (*this)[0] + Point2f(2, 2), Scalar(0, 0, 255, 255), lineWidth, CV_AA); 223 | cv::rectangle(in, (*this)[1] - Point2f(2, 2), (*this)[1] + Point2f(2, 2), Scalar(0, 255, 0, 255), lineWidth, CV_AA); 224 | cv::rectangle(in, (*this)[2] - Point2f(2, 2), (*this)[2] + Point2f(2, 2), Scalar(255, 0, 0, 255), lineWidth, CV_AA); 225 | if (writeId) { 226 | char cad[100]; 227 | sprintf(cad, "id=%d", id); 228 | // determine the centroid 229 | Point cent(0, 0); 230 | for (int i = 0; i < 4; i++) { 231 | cent.x += (*this)[i].x; 232 | cent.y += (*this)[i].y; 233 | } 234 | cent.x /= 4.; 235 | cent.y /= 4.; 236 | putText(in, cad, cent, FONT_HERSHEY_SIMPLEX, 0.5, Scalar(255 - color[0], 255 - color[1], 255 - color[2], 255), 2); 237 | } 238 | } 239 | 240 | /** 241 | */ 242 | void Marker::calculateExtrinsics(float markerSize, const CameraParameters &CP, bool setYPerpendicular) throw(cv::Exception) { 243 | if (!CP.isValid()) 244 | throw cv::Exception(9004, "!CP.isValid(): invalid camera parameters. It is not possible to calculate extrinsics", "calculateExtrinsics", __FILE__, 245 | __LINE__); 246 | calculateExtrinsics(markerSize, CP.CameraMatrix, CP.Distorsion, setYPerpendicular); 247 | } 248 | 249 | void print(cv::Point3f p, string cad) { cout << cad << " " << p.x << " " << p.y << " " << p.z << endl; } 250 | /** 251 | */ 252 | void Marker::calculateExtrinsics(float markerSizeMeters, cv::Mat camMatrix, cv::Mat distCoeff, bool setYPerpendicular) throw(cv::Exception) { 253 | if (!isValid()) 254 | throw cv::Exception(9004, "!isValid(): invalid marker. It is not possible to calculate extrinsics", "calculateExtrinsics", __FILE__, __LINE__); 255 | if (markerSizeMeters <= 0) 256 | throw cv::Exception(9004, "markerSize<=0: invalid markerSize", "calculateExtrinsics", __FILE__, __LINE__); 257 | if (camMatrix.rows == 0 || camMatrix.cols == 0) 258 | throw cv::Exception(9004, "CameraMatrix is empty", "calculateExtrinsics", __FILE__, __LINE__); 259 | 260 | double halfSize = markerSizeMeters / 2.; 261 | cv::Mat ObjPoints(4, 3, CV_32FC1); 262 | ObjPoints.at< float >(1, 0) = -halfSize; 263 | ObjPoints.at< float >(1, 1) = halfSize; 264 | ObjPoints.at< float >(1, 2) = 0; 265 | ObjPoints.at< float >(2, 0) = halfSize; 266 | ObjPoints.at< float >(2, 1) = halfSize; 267 | ObjPoints.at< float >(2, 2) = 0; 268 | ObjPoints.at< float >(3, 0) = halfSize; 269 | ObjPoints.at< float >(3, 1) = -halfSize; 270 | ObjPoints.at< float >(3, 2) = 0; 271 | ObjPoints.at< float >(0, 0) = -halfSize; 272 | ObjPoints.at< float >(0, 1) = -halfSize; 273 | ObjPoints.at< float >(0, 2) = 0; 274 | 275 | cv::Mat ImagePoints(4, 2, CV_32FC1); 276 | 277 | // Set image points from the marker 278 | for (int c = 0; c < 4; c++) { 279 | ImagePoints.at< float >(c, 0) = ((*this)[c].x); 280 | ImagePoints.at< float >(c, 1) = ((*this)[c].y); 281 | } 282 | 283 | cv::Mat raux, taux; 284 | cv::solvePnP(ObjPoints, ImagePoints, camMatrix, distCoeff, raux, taux); 285 | raux.convertTo(Rvec, CV_32F); 286 | taux.convertTo(Tvec, CV_32F); 287 | // rotate the X axis so that Y is perpendicular to the marker plane 288 | if (setYPerpendicular) 289 | rotateXAxis(Rvec); 290 | ssize = markerSizeMeters; 291 | // cout<<(*this)<(1, 1) = cos(angleRad); 305 | RX.at< float >(1, 2) = -sin(angleRad); 306 | RX.at< float >(2, 1) = sin(angleRad); 307 | RX.at< float >(2, 2) = cos(angleRad); 308 | // now multiply 309 | R = R * RX; 310 | // finally, the the rodrigues back 311 | Rodrigues(R, rotation); 312 | } 313 | 314 | 315 | 316 | /** 317 | */ 318 | cv::Point2f Marker::getCenter() const { 319 | cv::Point2f cent(0, 0); 320 | for (size_t i = 0; i < size(); i++) { 321 | cent.x += (*this)[i].x; 322 | cent.y += (*this)[i].y; 323 | } 324 | cent.x /= float(size()); 325 | cent.y /= float(size()); 326 | return cent; 327 | } 328 | 329 | /** 330 | */ 331 | float Marker::getArea() const { 332 | assert(size() == 4); 333 | // use the cross products 334 | cv::Point2f v01 = (*this)[1] - (*this)[0]; 335 | cv::Point2f v03 = (*this)[3] - (*this)[0]; 336 | float area1 = fabs(v01.x * v03.y - v01.y * v03.x); 337 | cv::Point2f v21 = (*this)[1] - (*this)[2]; 338 | cv::Point2f v23 = (*this)[3] - (*this)[2]; 339 | float area2 = fabs(v21.x * v23.y - v21.y * v23.x); 340 | return (area2 + area1) / 2.; 341 | } 342 | /** 343 | */ 344 | float Marker::getPerimeter() const { 345 | assert(size() == 4); 346 | float sum = 0; 347 | for (int i = 0; i < 4; i++) 348 | sum += norm((*this)[i] - (*this)[(i + 1) % 4]); 349 | return sum; 350 | } 351 | } 352 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/marker.h: -------------------------------------------------------------------------------- 1 | /***************************** 2 | Copyright 2011 Rafael Muñoz Salinas. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are 5 | permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of 8 | conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | of conditions and the following disclaimer in the documentation and/or other materials 12 | provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY Rafael Muñoz Salinas ''AS IS'' AND ANY EXPRESS OR IMPLIED 15 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 16 | FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Rafael Muñoz Salinas OR 17 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 21 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 22 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those of the 25 | authors and should not be interpreted as representing official policies, either expressed 26 | or implied, of Rafael Muñoz Salinas. 27 | ********************************/ 28 | #ifndef _Aruco_Marker_H 29 | #define _Aruco_Marker_H 30 | #include 31 | #include 32 | #include 33 | #include "exports.h" 34 | #include "cameraparameters.h" 35 | using namespace std; 36 | namespace aruco { 37 | /**\brief This class represents a marker. It is a vector of the fours corners ot the marker 38 | * 39 | */ 40 | 41 | class ARUCO_EXPORTS Marker : public std::vector< cv::Point2f > { 42 | public: 43 | // id of the marker 44 | int id; 45 | // size of the markers sides in meters 46 | float ssize; 47 | // matrices of rotation and translation respect to the camera 48 | cv::Mat Rvec, Tvec; 49 | 50 | /** 51 | */ 52 | Marker(); 53 | /** 54 | */ 55 | Marker(const Marker &M); 56 | /** 57 | */ 58 | Marker(const std::vector< cv::Point2f > &corners, int _id = -1); 59 | /** 60 | */ 61 | ~Marker() {} 62 | /**Indicates if this object is valid 63 | */ 64 | bool isValid() const { return id != -1 && size() == 4; } 65 | 66 | /**Draws this marker in the input image 67 | */ 68 | void draw(cv::Mat &in, cv::Scalar color, int lineWidth = 1, bool writeId = true) const; 69 | 70 | /**Calculates the extrinsics (Rvec and Tvec) of the marker with respect to the camera 71 | * @param markerSize size of the marker side expressed in meters 72 | * @param CP parmeters of the camera 73 | * @param setYPerpendicular If set the Y axis will be perpendicular to the surface. Otherwise, it will be the Z axis 74 | */ 75 | void calculateExtrinsics(float markerSize, const CameraParameters &CP, bool setYPerpendicular = true) throw(cv::Exception); 76 | /**Calculates the extrinsics (Rvec and Tvec) of the marker with respect to the camera 77 | * @param markerSize size of the marker side expressed in meters 78 | * @param CameraMatrix matrix with camera parameters (fx,fy,cx,cy) 79 | * @param Distorsion matrix with distorsion parameters (k1,k2,p1,p2) 80 | * @param setYPerpendicular If set the Y axis will be perpendicular to the surface. Otherwise, it will be the Z axis 81 | */ 82 | void calculateExtrinsics(float markerSize, cv::Mat CameraMatrix, cv::Mat Distorsion = cv::Mat(), bool setYPerpendicular = true) throw(cv::Exception); 83 | 84 | /**Given the extrinsic camera parameters returns the GL_MODELVIEW matrix for opengl. 85 | * Setting this matrix, the reference coordinate system will be set in this marker 86 | */ 87 | void glGetModelViewMatrix(double modelview_matrix[16]) throw(cv::Exception); 88 | 89 | /** 90 | * Returns position vector and orientation quaternion for an Ogre scene node or entity. 91 | * Use: 92 | * ... 93 | * Ogre::Vector3 ogrePos (position[0], position[1], position[2]); 94 | * Ogre::Quaternion ogreOrient (orientation[0], orientation[1], orientation[2], orientation[3]); 95 | * mySceneNode->setPosition( ogrePos ); 96 | * mySceneNode->setOrientation( ogreOrient ); 97 | * ... 98 | */ 99 | void OgreGetPoseParameters(double position[3], double orientation[4]) throw(cv::Exception); 100 | 101 | /**Returns the centroid of the marker 102 | */ 103 | cv::Point2f getCenter() const; 104 | /**Returns the perimeter of the marker 105 | */ 106 | float getPerimeter() const; 107 | /**Returns the area 108 | */ 109 | float getArea() const; 110 | /** 111 | */ 112 | /** 113 | */ 114 | friend bool operator<(const Marker &M1, const Marker &M2) { return M1.id < M2.id; } 115 | /** 116 | */ 117 | friend ostream &operator<<(ostream &str, const Marker &M) { 118 | str << M.id << "="; 119 | for (int i = 0; i < 4; i++) 120 | str << "(" << M[i].x << "," << M[i].y << ") "; 121 | str << "Txyz="; 122 | for (int i = 0; i < 3; i++) 123 | str << M.Tvec.ptr< float >(0)[i] << " "; 124 | str << "Rxyz="; 125 | for (int i = 0; i < 3; i++) 126 | str << M.Rvec.ptr< float >(0)[i] << " "; 127 | 128 | return str; 129 | } 130 | 131 | 132 | private: 133 | void rotateXAxis(cv::Mat &rotation); 134 | }; 135 | } 136 | #endif 137 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/subpixelcorner.cpp: -------------------------------------------------------------------------------- 1 | #include "subpixelcorner.h" 2 | #include 3 | using namespace cv; 4 | 5 | namespace aruco { 6 | 7 | SubPixelCorner::SubPixelCorner() { 8 | _winSize = 15; 9 | _apertureSize = 3; 10 | _term.maxCount = 10; 11 | _term.epsilon = 0.1; 12 | _term.type = CV_TERMCRIT_ITER | CV_TERMCRIT_EPS; 13 | enable = true; 14 | } 15 | 16 | void SubPixelCorner::checkTerm() { 17 | switch (_term.type) { 18 | case CV_TERMCRIT_ITER: 19 | _term.epsilon = 0.f; 20 | _term.maxCount; 21 | break; 22 | case CV_TERMCRIT_EPS: 23 | _term.maxCount = _term.COUNT; 24 | break; 25 | case CV_TERMCRIT_ITER | CV_TERMCRIT_EPS: 26 | break; 27 | default: 28 | _term.maxCount = _term.COUNT; 29 | _term.epsilon = 0.1; 30 | _term.type = CV_TERMCRIT_ITER | CV_TERMCRIT_EPS; 31 | break; 32 | } 33 | 34 | eps = std::max(_term.epsilon, 0.0); 35 | eps = eps * eps; 36 | 37 | _max_iters = std::max(_term.maxCount, 1); 38 | int max1 = TermCriteria::MAX_ITER; 39 | _max_iters = std::min(_max_iters, max1); 40 | } 41 | 42 | double SubPixelCorner::pointDist(cv::Point2f estimate_corner, cv::Point2f curr_corner) { 43 | double dist = ((curr_corner.x - estimate_corner.x) * (curr_corner.x - estimate_corner.x)) + 44 | ((curr_corner.y - estimate_corner.y) * (curr_corner.y - estimate_corner.y)); 45 | return dist; 46 | } 47 | 48 | 49 | void SubPixelCorner::generateMask() { 50 | 51 | double coeff = 1. / (_winSize * _winSize); 52 | float *maskX = (float *)calloc(1, (_winSize * sizeof(float))); 53 | float *maskY = (float *)calloc(1, (_winSize * sizeof(float))); 54 | mask.create(_winSize, _winSize, CV_32FC(1)); 55 | /* calculate mask */ 56 | int k = 0; 57 | for (int i = -_winSize / 2, k = 0; i <= _winSize / 2; i++, k++) { 58 | maskX[k] = (float)exp(-i * i * coeff); 59 | } 60 | 61 | maskY = maskX; 62 | 63 | for (int i = 0; i < _winSize; i++) { 64 | float *mask_ptr = mask.ptr< float >(i); 65 | for (int j = 0; j < _winSize; j++) { 66 | mask_ptr[j] = maskX[j] * maskY[i]; 67 | } 68 | } 69 | } 70 | 71 | void SubPixelCorner::RefineCorner(cv::Mat image, std::vector< cv::Point2f > &corners) { 72 | 73 | if (enable == false) 74 | return; 75 | checkTerm(); 76 | 77 | generateMask(); 78 | // loop over all the corner points 79 | for (int k = 0; k < corners.size(); k++) { 80 | cv::Point2f curr_corner; 81 | // initial estimate 82 | cv::Point2f estimate_corner = corners[k]; 83 | 84 | // cerr << 'SSS" << corners[k].x <<":" << corners[k].y << endl; 85 | 86 | if (estimate_corner.x < 0 || estimate_corner.y < 0 || estimate_corner.y > image.rows || estimate_corner.y > image.cols) 87 | continue; 88 | int iter = 0; 89 | double dist = TermCriteria::EPS; 90 | // loop till termination criteria is met 91 | do { 92 | iter = iter + 1; 93 | curr_corner = estimate_corner; 94 | 95 | /* 96 | Point cx; 97 | cx.x=floor(curr_corner.x); 98 | cx.y=floor(curr_corner.y); 99 | double dx=curr_corner.x-cx.x; 100 | double dy=curr_corner.y-cx.y; 101 | float vIx[2]; 102 | float vIy[2]; 103 | 104 | vIx[0] = dx; 105 | vIx[1] = 1 - dx; 106 | vIy[0] = dy; 107 | vIy[1] = 1 - dy; 108 | 109 | int x1=std::max((int)(cx.x-_winSize-_apertureSize/2),0); 110 | int y1=std::max((int)(cx.y-_winSize-_apertureSize/2),0); 111 | 112 | xmin = x1<0?0:x1; 113 | xmax = x1+_winSize(i); 138 | float *dy_ptr = Dy.ptr< float >(i); 139 | ly = i - _winSize / 2 - _apertureSize / 2; 140 | 141 | float *mask_ptr = mask.ptr< float >(ly + _winSize / 2); 142 | 143 | for (int j = _apertureSize / 2; j <= _winSize; j++) { 144 | 145 | lx = j - _winSize / 2 - _apertureSize / 2; 146 | // cerr << lx+_winSize/2 << ":" ; 147 | double val = mask_ptr[lx + _winSize / 2]; 148 | double dxx = dx_ptr[j] * dx_ptr[j] * val; 149 | double dyy = dy_ptr[j] * dy_ptr[j] * val; 150 | double dxy = dx_ptr[j] * dy_ptr[j] * val; 151 | 152 | A = A + dxx; 153 | B = B + dxy; 154 | E = E + dyy; 155 | C = C + dxx * lx + dxy * ly; 156 | F = F + dxy * lx + dyy * ly; 157 | } 158 | } 159 | 160 | // computing denominator 161 | double det = (A * E - B * B); 162 | if (fabs(det) > DBL_EPSILON * DBL_EPSILON) { 163 | det = 1.0 / det; 164 | // translating back to original corner and adding new estimates 165 | estimate_corner.x = curr_corner.x + ((C * E) - (B * F)) * det; 166 | estimate_corner.y = curr_corner.y + ((A * F) - (C * D)) * det; 167 | } else { 168 | estimate_corner.x = curr_corner.x; 169 | estimate_corner.y = curr_corner.y; 170 | } 171 | 172 | dist = pointDist(estimate_corner, curr_corner); 173 | 174 | 175 | } while (iter < _max_iters && dist > eps); 176 | 177 | // double dist=pointDist(corners[k],estimate_corner); 178 | if (fabs(corners[k].x - estimate_corner.x) > _winSize || fabs(corners[k].y - estimate_corner.y) > _winSize) { 179 | estimate_corner.x = corners[k].x; 180 | estimate_corner.y = corners[k].y; 181 | } 182 | corners[k].x = estimate_corner.x; 183 | corners[k].y = estimate_corner.y; 184 | // cerr << "EEE" << corners[k].x <<":" << corners[k].y << endl; 185 | } 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/aruco/jni/subpixelcorner.h: -------------------------------------------------------------------------------- 1 | #ifndef aruco_SUBPIXELCORNER_HPP 2 | #define aruco_SUBPIXELCORNER_HPP 3 | 4 | #include // Basic OpenCV structures (cv::Mat) 5 | 6 | namespace aruco { 7 | 8 | class SubPixelCorner { 9 | private: 10 | int _winSize; 11 | int _apertureSize; 12 | cv::TermCriteria _term; 13 | double eps; 14 | cv::Mat mask; 15 | int _max_iters; 16 | 17 | public: 18 | bool enable; 19 | SubPixelCorner(); 20 | 21 | void checkTerm(); 22 | 23 | double pointDist(cv::Point2f estimate_corner, cv::Point2f curr_corner); 24 | 25 | /// method to refine the corners 26 | void RefineCorner(cv::Mat image, std::vector< cv::Point2f > &corners); 27 | 28 | // function to generate the mask 29 | void generateMask(); 30 | }; 31 | } 32 | 33 | #endif // SUBPIXELCORNER_HPP 34 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/camera_image.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "log.h" 3 | 4 | extern "C" 5 | { 6 | 7 | void* get_camera() 8 | { 9 | LOGI("get_camera"); 10 | 11 | #ifdef __APPLE__ 12 | auto camera = new cv::VideoCapture(0); 13 | #elif __ANDROID__ 14 | auto camera = new cv::VideoCapture(CV_CAP_ANDROID); 15 | #endif 16 | if (!camera->isOpened()) { 17 | delete camera; 18 | return nullptr; 19 | } 20 | return camera; 21 | } 22 | 23 | void release_camera(void* ptr) 24 | { 25 | LOGI("release_camera"); 26 | 27 | auto camera = static_cast(ptr); 28 | delete camera; 29 | } 30 | 31 | bool fetch_image(void* ptr, unsigned char* dest, int width, int height) 32 | { 33 | LOGI("fetch_image"); 34 | 35 | auto camera = static_cast(ptr); 36 | if (!camera->isOpened()) { 37 | return false; 38 | } 39 | 40 | cv::Mat rgb; 41 | (*camera) >> rgb; 42 | if (rgb.empty()) { 43 | return false; 44 | } 45 | 46 | cv::Mat resized(height, width, rgb.type()); 47 | cv::resize(rgb, resized, resized.size(), cv::INTER_LINEAR); 48 | 49 | cv::Mat rgba; 50 | cv::cvtColor(resized, rgba, CV_BGR2BGRA); 51 | memcpy(dest, rgba.data, rgba.total() * rgba.elemSize()); 52 | 53 | return true; 54 | } 55 | 56 | void to_canny(unsigned char* src, unsigned char* dest, int width, int height, int thresh1, int thresh2) 57 | { 58 | cv::Mat src_img(height, width, CV_8UC4, src); 59 | cv::Mat dest_img; 60 | cv::Canny(src_img, dest_img, thresh1, thresh2); 61 | cv::cvtColor(dest_img, dest_img, CV_GRAY2BGRA); 62 | memcpy(dest, dest_img.data, dest_img.total() * dest_img.elemSize()); 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/log.h: -------------------------------------------------------------------------------- 1 | #ifdef __ANDROID__ 2 | 3 | #include 4 | #define LOG_TAG ("UnityOpenCV") 5 | #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) 6 | #define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) 7 | #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) 8 | #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) 9 | 10 | #else 11 | 12 | #include 13 | #define LOGI(...) printf(__VA_ARGS__) 14 | #define LOGD(...) printf(__VA_ARGS__) 15 | #define LOGW(...) printf(__VA_ARGS__) 16 | #define LOGE(...) printf(__VA_ARGS__) 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/jni/read_image.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #ifdef __ANDROID__ 4 | 5 | #include 6 | #define LOG_TAG ("UnityOpenCV") 7 | #define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) 8 | #define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) 9 | #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) 10 | #define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) 11 | 12 | #else 13 | 14 | #define LOGI(...) printf(__VA_ARGS__) 15 | #define LOGD(...) printf(__VA_ARGS__) 16 | #define LOGW(...) printf(__VA_ARGS__) 17 | #define LOGE(...) printf(__VA_ARGS__) 18 | 19 | #endif 20 | 21 | extern "C" 22 | { 23 | 24 | bool get_image_size(const char* path, int* width, int* height) 25 | { 26 | const auto img = cv::imread(path); 27 | if (img.empty()) return false; 28 | *width = img.rows; 29 | *height = img.cols; 30 | return true; 31 | } 32 | 33 | bool read_image(const char* path, unsigned char* dest) 34 | { 35 | const auto rgb = cv::imread(path); 36 | if (rgb.empty()) return false; 37 | cv::Mat canny; 38 | cv::Canny(rgb, canny, 50.f, 200.f); 39 | cv::Mat rgba; 40 | cv::cvtColor(canny, rgba, cv::COLOR_GRAY2BGRA); 41 | memcpy(dest, rgba.data, rgba.total() * rgba.elemSize()); 42 | return true; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/mac/opencv_sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/mac/opencv_sample.xcodeproj/project.xcworkspace/xcuserdata/hecomi.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/Plugins/opencv_sample/mac/opencv_sample.xcodeproj/project.xcworkspace/xcuserdata/hecomi.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Plugins/opencv_sample/mac/opencv_sample.xcodeproj/xcuserdata/hecomi.xcuserdatad/xcschemes/opencv_sample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 60 | 61 | 67 | 68 | 69 | 70 | 72 | 73 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/mac/opencv_sample.xcodeproj/xcuserdata/hecomi.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | opencv_sample.xcscheme 8 | 9 | orderHint 10 | 1 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 585CFE211B9B1799006B9286 16 | 17 | primary 18 | 19 | 20 | 58F5E87A1B9B4F020097F948 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Plugins/opencv_sample/mac/opencv_sample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.hecomi.opencv-sample.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | NSHumanReadableCopyright 24 | Copyright © 2015年 hecomi. All rights reserved. 25 | NSPrincipalClass 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.1.2f1 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hecomi/unity-android-aruco-sample/ae21fcb432d878296e7d94683101cda304ba26d4/ProjectSettings/TimeManager.asset --------------------------------------------------------------------------------