OpenCVForUnityExample.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. using UnityEngine.UI;
  4. using System.Collections;
  5. using OpenCVForUnity.CoreModule;
  6. using OpenCVForUnity.UnityUtils;
  7. namespace OpenCVForUnityExample
  8. {
  9. public class OpenCVForUnityExample : MonoBehaviour
  10. {
  11. public Text versionInfo;
  12. public ScrollRect scrollRect;
  13. static float verticalNormalizedPosition = 1f;
  14. // Use this for initialization
  15. void Start ()
  16. {
  17. versionInfo.text = Core.NATIVE_LIBRARY_NAME + " " + Utils.getVersion () + " (" + Core.VERSION + ")";
  18. versionInfo.text += " / UnityEditor " + Application.unityVersion;
  19. versionInfo.text += " / ";
  20. #if UNITY_EDITOR
  21. versionInfo.text += "Editor";
  22. #elif UNITY_STANDALONE_WIN
  23. versionInfo.text += "Windows";
  24. #elif UNITY_STANDALONE_OSX
  25. versionInfo.text += "Mac OSX";
  26. #elif UNITY_STANDALONE_LINUX
  27. versionInfo.text += "Linux";
  28. #elif UNITY_ANDROID
  29. versionInfo.text += "Android";
  30. #elif UNITY_IOS
  31. versionInfo.text += "iOS";
  32. #elif UNITY_WSA
  33. versionInfo.text += "WSA";
  34. #elif UNITY_WEBGL
  35. versionInfo.text += "WebGL";
  36. #endif
  37. versionInfo.text += " ";
  38. #if ENABLE_MONO
  39. versionInfo.text += "Mono";
  40. #elif ENABLE_IL2CPP
  41. versionInfo.text += "IL2CPP";
  42. #elif ENABLE_DOTNET
  43. versionInfo.text += ".NET";
  44. #endif
  45. scrollRect.verticalNormalizedPosition = verticalNormalizedPosition;
  46. #if UNITY_WSA_10_0
  47. GameObject.Find ("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/MobileNetSSDExampleButton").GetComponent<Button> ().interactable = false;
  48. GameObject.Find ("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/MobileNetSSDWebCamTextureExampleButton").GetComponent<Button> ().interactable = false;
  49. GameObject.Find ("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/OpenPoseExampleButton").GetComponent<Button> ().interactable = false;
  50. GameObject.Find ("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/ResnetSSDFaceDetectionExampleButton").GetComponent<Button> ().interactable = false;
  51. GameObject.Find ("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/TensorFlowWebCamTextureExampleButton").GetComponent<Button> ().interactable = false;
  52. GameObject.Find ("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/YoloObjectDetectionExampleButton").GetComponent<Button> ().interactable = false;
  53. GameObject.Find ("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/YoloObjectDetectionWebCamTextureExampleButton").GetComponent<Button> ().interactable = false;
  54. GameObject.Find ("Canvas/Panel/SceneList/ScrollView/List/ContribModulesGroup/TextDetectionExampleButton").GetComponent<Button> ().interactable = false;
  55. GameObject.Find ("Canvas/Panel/SceneList/ScrollView/List/ContribModulesGroup/TextRecognitionExampleButton").GetComponent<Button> ().interactable = false;
  56. #endif
  57. }
  58. // Update is called once per frame
  59. void Update ()
  60. {
  61. }
  62. public void OnScrollRectValueChanged ()
  63. {
  64. verticalNormalizedPosition = scrollRect.verticalNormalizedPosition;
  65. }
  66. public void OnShowSystemInfoButtonClick ()
  67. {
  68. SceneManager.LoadScene ("ShowSystemInfo");
  69. }
  70. public void OnShowLicenseButtonClick ()
  71. {
  72. SceneManager.LoadScene ("ShowLicense");
  73. }
  74. #region Basic
  75. public void OnTexture2DToMatExampleButtonClick ()
  76. {
  77. SceneManager.LoadScene ("Texture2DToMatExample");
  78. }
  79. public void OnWebCamTextureToMatExampleButtonClick ()
  80. {
  81. SceneManager.LoadScene ("WebCamTextureToMatExample");
  82. }
  83. public void OnWebCamTextureToMatHelperExampleButtonClick ()
  84. {
  85. SceneManager.LoadScene ("WebCamTextureToMatHelperExample");
  86. }
  87. public void OnMatBasicProcessingExampleButtonClick ()
  88. {
  89. SceneManager.LoadScene ("MatBasicProcessingExample");
  90. }
  91. public void OnUtils_GetFilePathExampleButtonClick ()
  92. {
  93. SceneManager.LoadScene ("Utils_GetFilePathExample");
  94. }
  95. #endregion
  96. #region Advanced
  97. public void OnComicFilterExampleButtonClick ()
  98. {
  99. SceneManager.LoadScene ("ComicFilterExample");
  100. }
  101. public void OnGreenScreenExampleButtonClick ()
  102. {
  103. SceneManager.LoadScene ("GreenScreenExample");
  104. }
  105. public void OnHandPoseEstimationExampleButtonClick ()
  106. {
  107. SceneManager.LoadScene ("HandPoseEstimationExample");
  108. }
  109. public void OnMultiObjectTrackingBasedOnColorExampleButtonClick ()
  110. {
  111. SceneManager.LoadScene ("MultiObjectTrackingBasedOnColorExample");
  112. }
  113. public void OnPolygonFilterExampleButtonClick ()
  114. {
  115. SceneManager.LoadScene ("PolygonFilterExample");
  116. }
  117. public void OnAlphaBlendingExampleButtonClick ()
  118. {
  119. SceneManager.LoadScene ("AlphaBlendingExample");
  120. }
  121. public void OnMatToTextureInRenderThreadExampleButtonClick ()
  122. {
  123. SceneManager.LoadScene ("MatToTextureInRenderThreadExample");
  124. }
  125. #endregion
  126. #region Main modules
  127. #region core
  128. public void OnPCAExampleButtonClick ()
  129. {
  130. SceneManager.LoadScene ("PCAExample");
  131. }
  132. #endregion
  133. #region imgproc
  134. public void OnCircleDetectionExampleButtonClick ()
  135. {
  136. SceneManager.LoadScene ("CircleDetectionExample");
  137. }
  138. public void OnConnectedComponentsExampleButtonClick ()
  139. {
  140. SceneManager.LoadScene ("ConnectedComponentsExample");
  141. }
  142. public void OnConvexHullExampleButtonClick ()
  143. {
  144. SceneManager.LoadScene ("ConvexHullExample");
  145. }
  146. public void OnDrawingExampleButtonClick ()
  147. {
  148. SceneManager.LoadScene ("DrawingExample");
  149. }
  150. public void OnGrabCutExampleButtonClick ()
  151. {
  152. SceneManager.LoadScene ("GrabCutExample");
  153. }
  154. public void OnHoughLinesPExampleButtonClick ()
  155. {
  156. SceneManager.LoadScene ("HoughLinesPExample");
  157. }
  158. public void OnMatchShapesExampleButtonClick ()
  159. {
  160. SceneManager.LoadScene ("MatchShapesExample");
  161. }
  162. public void OnMatchTemplateExampleButtonClick ()
  163. {
  164. SceneManager.LoadScene ("MatchTemplateExample");
  165. }
  166. public void OnThresholdExampleButtonClick ()
  167. {
  168. SceneManager.LoadScene ("ThresholdExample");
  169. }
  170. public void OnWrapPerspectiveExampleButtonClick ()
  171. {
  172. SceneManager.LoadScene ("WrapPerspectiveExample");
  173. }
  174. #endregion
  175. #region videoio
  176. public void OnVideoCaptureExampleButtonClick ()
  177. {
  178. SceneManager.LoadScene ("VideoCaptureExample");
  179. }
  180. public void OnVideoWriterExampleButtonClick ()
  181. {
  182. SceneManager.LoadScene ("VideoWriterExample");
  183. }
  184. #endregion
  185. #region video
  186. public void OnBackgroundSubtractorMOG2ExampleButtonClick ()
  187. {
  188. SceneManager.LoadScene ("BackgroundSubtractorMOG2Example");
  189. }
  190. public void OnCamShiftExampleButtonClick ()
  191. {
  192. SceneManager.LoadScene ("CamShiftExample");
  193. }
  194. public void OnKalmanFilterExampleButtonClick ()
  195. {
  196. SceneManager.LoadScene ("KalmanFilterExample");
  197. }
  198. public void OnOpticalFlowExampleButtonClick ()
  199. {
  200. SceneManager.LoadScene ("OpticalFlowExample");
  201. }
  202. #endregion
  203. #region calib3d
  204. public void OnStereoBMExampleButtonClick ()
  205. {
  206. SceneManager.LoadScene ("StereoBMExample");
  207. }
  208. #endregion
  209. #region features2d
  210. public void OnFeature2DExampleButtonClick ()
  211. {
  212. SceneManager.LoadScene ("Feature2DExample");
  213. }
  214. public void OnMSERExampleButtonClick ()
  215. {
  216. SceneManager.LoadScene ("MSERExample");
  217. }
  218. #endregion
  219. #region imgcodecs
  220. public void OnImwriteScreenCaptureExampleButtonClick ()
  221. {
  222. SceneManager.LoadScene ("ImwriteScreenCaptureExample");
  223. }
  224. #endregion
  225. #region objdetect
  226. public void OnFaceDetectionExampleButtonClick ()
  227. {
  228. SceneManager.LoadScene ("FaceDetectionExample");
  229. }
  230. public void OnFaceDetectionWebCamTextureExampleButtonClick ()
  231. {
  232. SceneManager.LoadScene ("FaceDetectionWebCamTextureExample");
  233. }
  234. public void OnAsynchronousFaceDetectionWebCamTextureExampleButtonClick ()
  235. {
  236. SceneManager.LoadScene ("AsynchronousFaceDetectionWebCamTextureExample");
  237. }
  238. public void OnHOGDescriptorExampleButtonClick ()
  239. {
  240. SceneManager.LoadScene ("HOGDescriptorExample");
  241. }
  242. public void OnQRCodeDetectorExampleButtonClick ()
  243. {
  244. SceneManager.LoadScene ("QRCodeDetectorExample");
  245. }
  246. public void OnQRCodeDetectorWebCamTextureExampleButtonClick ()
  247. {
  248. SceneManager.LoadScene ("QRCodeDetectorWebCamTextureExample");
  249. }
  250. #endregion
  251. #region dnn
  252. public void OnMobileNetSSDExampleButtonClick ()
  253. {
  254. SceneManager.LoadScene ("MobileNetSSDExample");
  255. }
  256. public void OnMobileNetSSDWebCamTextureExampleButtonClick ()
  257. {
  258. SceneManager.LoadScene ("MobileNetSSDWebCamTextureExample");
  259. }
  260. public void OnOpenPoseExampleButtonClick ()
  261. {
  262. SceneManager.LoadScene ("OpenPoseExample");
  263. }
  264. public void OnResnetSSDFaceDetectionExampleButtonClick ()
  265. {
  266. SceneManager.LoadScene ("ResnetSSDFaceDetectionExample");
  267. }
  268. public void OnTensorFlowWebCamTextureExampleButtonClick ()
  269. {
  270. SceneManager.LoadScene ("TensorFlowWebCamTextureExample");
  271. }
  272. public void OnYoloObjectDetectionExampleButtonClick ()
  273. {
  274. SceneManager.LoadScene ("YoloObjectDetectionExample");
  275. }
  276. public void OnYoloObjectDetectionWebCamTextureExampleButtonClick ()
  277. {
  278. SceneManager.LoadScene ("YoloObjectDetectionWebCamTextureExample");
  279. }
  280. #endregion
  281. #region ml
  282. public void OnSVMExampleButtonClick ()
  283. {
  284. SceneManager.LoadScene ("SVMExample");
  285. }
  286. #endregion
  287. #region photo
  288. public void OnInpaintExampleButtonClick ()
  289. {
  290. SceneManager.LoadScene ("InpaintExample");
  291. }
  292. public void OnSeamlessCloneExampleButtonClick ()
  293. {
  294. SceneManager.LoadScene ("SeamlessCloneExample");
  295. }
  296. #endregion
  297. #region shape
  298. public void OnThinPlateSplineShapeTransformerExampleButtonClick ()
  299. {
  300. SceneManager.LoadScene ("ThinPlateSplineShapeTransformerExample");
  301. }
  302. #endregion
  303. #endregion
  304. #region Contrib modules
  305. #region aruco
  306. public void OnArUcoExampleButtonClick ()
  307. {
  308. SceneManager.LoadScene ("ArUcoExample");
  309. }
  310. public void OnArUcoWebCamTextureExampleButtonClick ()
  311. {
  312. SceneManager.LoadScene ("ArUcoWebCamTextureExample");
  313. }
  314. public void OnArUcoCreateMarkerExampleButtonClick ()
  315. {
  316. SceneManager.LoadScene ("ArUcoCreateMarkerExample");
  317. }
  318. public void OnArUcoCameraCalibrationExampleButtonClick ()
  319. {
  320. SceneManager.LoadScene ("ArUcoCameraCalibrationExample");
  321. }
  322. #endregion
  323. #region face
  324. public void OnFaceMarkExampleButtonClick ()
  325. {
  326. SceneManager.LoadScene ("FaceMarkExample");
  327. }
  328. public void OnFaceRecognizerExampleButtonClick ()
  329. {
  330. SceneManager.LoadScene ("FaceRecognizerExample");
  331. }
  332. #endregion
  333. #region plot
  334. public void OnPlotExampleButtonClick ()
  335. {
  336. SceneManager.LoadScene ("PlotExample");
  337. }
  338. #endregion
  339. #region text
  340. public void OnTextDetectionExampleButtonClick ()
  341. {
  342. SceneManager.LoadScene ("TextDetectionExample");
  343. }
  344. public void OnTextRecognitionExampleButtonClick ()
  345. {
  346. SceneManager.LoadScene ("TextRecognitionExample");
  347. }
  348. #endregion
  349. #region tracking
  350. public void OnTrackingExampleButtonClick ()
  351. {
  352. SceneManager.LoadScene ("TrackingExample");
  353. }
  354. #endregion
  355. #endregion
  356. }
  357. }