OpenCVForUnityExample.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UnityUtils;
  3. using UnityEngine;
  4. using UnityEngine.SceneManagement;
  5. using UnityEngine.UI;
  6. namespace OpenCVForUnityExample
  7. {
  8. public class OpenCVForUnityExample : MonoBehaviour
  9. {
  10. public Text versionInfo;
  11. public ScrollRect scrollRect;
  12. static float verticalNormalizedPosition = 1f;
  13. // Use this for initialization
  14. void Start()
  15. {
  16. versionInfo.text = Core.NATIVE_LIBRARY_NAME + " " + Utils.getVersion() + " (" + Core.VERSION + ")";
  17. versionInfo.text += " / UnityEditor " + Application.unityVersion;
  18. versionInfo.text += " / ";
  19. #if UNITY_EDITOR
  20. versionInfo.text += "Editor";
  21. #elif UNITY_STANDALONE_WIN
  22. versionInfo.text += "Windows";
  23. #elif UNITY_STANDALONE_OSX
  24. versionInfo.text += "Mac OSX";
  25. #elif UNITY_STANDALONE_LINUX
  26. versionInfo.text += "Linux";
  27. #elif UNITY_ANDROID
  28. versionInfo.text += "Android";
  29. #elif UNITY_IOS
  30. versionInfo.text += "iOS";
  31. #elif UNITY_WSA
  32. versionInfo.text += "WSA";
  33. #elif UNITY_WEBGL
  34. versionInfo.text += "WebGL";
  35. #endif
  36. versionInfo.text += " ";
  37. #if ENABLE_MONO
  38. versionInfo.text += "Mono";
  39. #elif ENABLE_IL2CPP
  40. versionInfo.text += "IL2CPP";
  41. #elif ENABLE_DOTNET
  42. versionInfo.text += ".NET";
  43. #endif
  44. scrollRect.verticalNormalizedPosition = verticalNormalizedPosition;
  45. #if UNITY_WSA_10_0
  46. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/BarcodeDetectorExampleButton").GetComponent<Button>().interactable = false;
  47. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/BarcodeDetectorWebCamExampleButton").GetComponent<Button>().interactable = false;
  48. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/FaceDetectorYNWebCamExampleButton").GetComponent<Button>().interactable = false;
  49. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/FaceRecognizerSFExampleButton").GetComponent<Button>().interactable = false;
  50. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/ColorizationExampleButton").GetComponent<Button>().interactable = false;
  51. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/ObjectTrackingDaSiamRPNExampleButton").GetComponent<Button>().interactable = false;
  52. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/FastNeuralStyleTransferExampleButton").GetComponent<Button>().interactable = false;
  53. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/FaceDetectionResnetSSDExampleButton").GetComponent<Button>().interactable = false;
  54. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/FaceDetectionYuNetExampleButton").GetComponent<Button>().interactable = false;
  55. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/FaceDetectionYuNetV2ExampleButton").GetComponent<Button>().interactable = false;
  56. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/FacialExpressionRecognitionExampleButton").GetComponent<Button>().interactable = false;
  57. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/PoseEstimationMediaPipeExampleButton").GetComponent<Button>().interactable = false;
  58. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/HandPoseEstimationMediaPipeExampleButton").GetComponent<Button>().interactable = false;
  59. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/HumanSegmentationPPHumanSegExampleButton").GetComponent<Button>().interactable = false;
  60. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/ImageClassificationMobilenetExampleButton").GetComponent<Button>().interactable = false;
  61. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/ImageClassificationPPResnetExampleButton").GetComponent<Button>().interactable = false;
  62. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/ObjectDetectionMobileNetSSDExampleButton").GetComponent<Button>().interactable = false;
  63. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/ObjectDetectionMobileNetSSDWebCamExampleButton").GetComponent<Button>().interactable = false;
  64. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/ObjectDetectionYOLOv4ExampleButton").GetComponent<Button>().interactable = false;
  65. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/ObjectDetectionYOLOXExampleButton").GetComponent<Button>().interactable = false;
  66. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/ObjectDetectionNanoDetPlusExampleButton").GetComponent<Button>().interactable = false;
  67. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/TextRecognitionCRNNExampleButton").GetComponent<Button>().interactable = false;
  68. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/TextRecognitionCRNNWebCamExampleButton").GetComponent<Button>().interactable = false;
  69. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/ContribModulesGroup/TextDetectionExampleButton").GetComponent<Button>().interactable = false;
  70. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/ContribModulesGroup/TextRecognitionExampleButton").GetComponent<Button>().interactable = false;
  71. #endif
  72. #if !UNITY_EDITOR && !UNITY_STANDALONE_WIN && !UNITY_STANDALONE_OSX && !UNITY_LINUX && !UNITY_IOS && !UNITY_ANDROID
  73. GameObject.Find("Canvas/Panel/SceneList/ScrollView/List/MainModulesGroup/VideoCaptureCameraInputExampleButton").GetComponent<Button>().interactable = false;
  74. #endif
  75. }
  76. // Update is called once per frame
  77. void Update()
  78. {
  79. }
  80. public void OnScrollRectValueChanged()
  81. {
  82. verticalNormalizedPosition = scrollRect.verticalNormalizedPosition;
  83. }
  84. public void OnShowSystemInfoButtonClick()
  85. {
  86. SceneManager.LoadScene("ShowSystemInfo");
  87. }
  88. public void OnShowLicenseButtonClick()
  89. {
  90. SceneManager.LoadScene("ShowLicense");
  91. }
  92. #region Basic
  93. public void OnTexture2DToMatExampleButtonClick()
  94. {
  95. SceneManager.LoadScene("Texture2DToMatExample");
  96. }
  97. public void OnWebCamTextureToMatExampleButtonClick()
  98. {
  99. SceneManager.LoadScene("WebCamTextureToMatExample");
  100. }
  101. public void OnWebCamTextureToMatHelperExampleButtonClick()
  102. {
  103. SceneManager.LoadScene("WebCamTextureToMatHelperExample");
  104. }
  105. public void OnMatBasicProcessingExampleButtonClick()
  106. {
  107. SceneManager.LoadScene("MatBasicProcessingExample");
  108. }
  109. public void OnUtils_GetFilePathExampleButtonClick()
  110. {
  111. SceneManager.LoadScene("Utils_GetFilePathExample");
  112. }
  113. #endregion
  114. #region Advanced
  115. public void OnImageCorrectionExampleButtonClick()
  116. {
  117. SceneManager.LoadScene("ImageCorrectionExample");
  118. }
  119. public void OnComicFilterExampleButtonClick()
  120. {
  121. SceneManager.LoadScene("ComicFilterExample");
  122. }
  123. public void OnDocumentScannerExampleButtonClick()
  124. {
  125. SceneManager.LoadScene("DocumentScannerExample");
  126. }
  127. public void OnPhysicalGreenScreenExampleButtonClick()
  128. {
  129. SceneManager.LoadScene("PhysicalGreenScreenExample");
  130. }
  131. public void OnKeyFrameGreenScreenExampleButtonClick()
  132. {
  133. SceneManager.LoadScene("KeyFrameGreenScreenExample");
  134. }
  135. public void OnCountFingersExampleButtonClick()
  136. {
  137. SceneManager.LoadScene("CountFingersExample");
  138. }
  139. public void OnMultiObjectTrackingBasedOnColorExampleButtonClick()
  140. {
  141. SceneManager.LoadScene("MultiObjectTrackingBasedOnColorExample");
  142. }
  143. public void OnPolygonFilterExampleButtonClick()
  144. {
  145. SceneManager.LoadScene("PolygonFilterExample");
  146. }
  147. public void OnAlphaBlendingExampleButtonClick()
  148. {
  149. SceneManager.LoadScene("AlphaBlendingExample");
  150. }
  151. #endregion
  152. #region Main modules
  153. #region core
  154. public void OnKMeansClusteringExampleButtonClick()
  155. {
  156. SceneManager.LoadScene("KMeansClusteringExample");
  157. }
  158. public void OnPCAExampleButtonClick()
  159. {
  160. SceneManager.LoadScene("PCAExample");
  161. }
  162. #endregion
  163. #region imgproc
  164. public void OnCircleDetectionExampleButtonClick()
  165. {
  166. SceneManager.LoadScene("CircleDetectionExample");
  167. }
  168. public void OnConnectedComponentsExampleButtonClick()
  169. {
  170. SceneManager.LoadScene("ConnectedComponentsExample");
  171. }
  172. public void OnConvexHullExampleButtonClick()
  173. {
  174. SceneManager.LoadScene("ConvexHullExample");
  175. }
  176. public void OnDrawingExampleButtonClick()
  177. {
  178. SceneManager.LoadScene("DrawingExample");
  179. }
  180. public void OnGrabCutExampleButtonClick()
  181. {
  182. SceneManager.LoadScene("GrabCutExample");
  183. }
  184. public void OnHoughLinesPExampleButtonClick()
  185. {
  186. SceneManager.LoadScene("HoughLinesPExample");
  187. }
  188. public void OnMatchShapesExampleButtonClick()
  189. {
  190. SceneManager.LoadScene("MatchShapesExample");
  191. }
  192. public void OnMatchTemplateExampleButtonClick()
  193. {
  194. SceneManager.LoadScene("MatchTemplateExample");
  195. }
  196. public void OnThresholdExampleButtonClick()
  197. {
  198. SceneManager.LoadScene("ThresholdExample");
  199. }
  200. public void OnWrapPerspectiveExampleButtonClick()
  201. {
  202. SceneManager.LoadScene("WrapPerspectiveExample");
  203. }
  204. #endregion
  205. #region videoio
  206. public void OnVideoCaptureExampleButtonClick()
  207. {
  208. SceneManager.LoadScene("VideoCaptureExample");
  209. }
  210. public void OnVideoCaptureCameraInputExampleButtonClick()
  211. {
  212. SceneManager.LoadScene("VideoCaptureCameraInputExample");
  213. }
  214. public void OnVideoWriterExampleButtonClick()
  215. {
  216. SceneManager.LoadScene("VideoWriterExample");
  217. }
  218. public void OnVideoWriterAsyncExampleButtonClick()
  219. {
  220. SceneManager.LoadScene("VideoWriterAsyncExample");
  221. }
  222. #endregion
  223. #region video
  224. public void OnCamShiftExampleButtonClick()
  225. {
  226. SceneManager.LoadScene("CamShiftExample");
  227. }
  228. public void OnKalmanFilterExampleButtonClick()
  229. {
  230. SceneManager.LoadScene("KalmanFilterExample");
  231. }
  232. public void OnOpticalFlowExampleButtonClick()
  233. {
  234. SceneManager.LoadScene("OpticalFlowExample");
  235. }
  236. public void OnTransformECCExampleButtonClick()
  237. {
  238. SceneManager.LoadScene("TransformECCExample");
  239. }
  240. #endregion
  241. #region calib3d
  242. public void OnStereoBMExampleButtonClick()
  243. {
  244. SceneManager.LoadScene("StereoBMExample");
  245. }
  246. #endregion
  247. #region features2d
  248. public void OnFeatureMatchingExampleButtonClick()
  249. {
  250. SceneManager.LoadScene("FeatureMatchingExample");
  251. }
  252. public void OnMSERExampleButtonClick()
  253. {
  254. SceneManager.LoadScene("MSERExample");
  255. }
  256. public void OnSimpleBlobExampleButtonClick()
  257. {
  258. SceneManager.LoadScene("SimpleBlobExample");
  259. }
  260. #endregion
  261. #region imgcodecs
  262. public void OnImwriteScreenCaptureExampleButtonClick()
  263. {
  264. SceneManager.LoadScene("ImwriteScreenCaptureExample");
  265. }
  266. #endregion
  267. #region objdetect
  268. public void OnArUcoExampleButtonClick()
  269. {
  270. SceneManager.LoadScene("ArUcoExample");
  271. }
  272. public void OnArUcoWebCamExampleButtonClick()
  273. {
  274. SceneManager.LoadScene("ArUcoWebCamExample");
  275. }
  276. public void OnArUcoCreateMarkerExampleButtonClick()
  277. {
  278. SceneManager.LoadScene("ArUcoCreateMarkerExample");
  279. }
  280. public void OnArUcoCameraCalibrationExampleButtonClick()
  281. {
  282. SceneManager.LoadScene("ArUcoCameraCalibrationExample");
  283. }
  284. public void OnBarcodeDetectorExampleButtonClick()
  285. {
  286. SceneManager.LoadScene("BarcodeDetectorExample");
  287. }
  288. public void OnBarcodeDetectorWebCamExampleButtonClick()
  289. {
  290. SceneManager.LoadScene("BarcodeDetectorWebCamExample");
  291. }
  292. public void OnFaceDetectionExampleButtonClick()
  293. {
  294. SceneManager.LoadScene("FaceDetectionExample");
  295. }
  296. public void OnFaceDetectionWebCamExampleButtonClick()
  297. {
  298. SceneManager.LoadScene("FaceDetectionWebCamExample");
  299. }
  300. public void OnAsynchronousFaceDetectionWebCamExampleButtonClick()
  301. {
  302. SceneManager.LoadScene("AsynchronousFaceDetectionWebCamExample");
  303. }
  304. public void OnFaceDetectorYNWebCamExampleButtonClick()
  305. {
  306. SceneManager.LoadScene("FaceDetectorYNWebCamExample");
  307. }
  308. public void OnFaceRecognizerSFExampleButtonClick()
  309. {
  310. SceneManager.LoadScene("FaceRecognizerSFExample");
  311. }
  312. public void OnHOGDescriptorExampleButtonClick()
  313. {
  314. SceneManager.LoadScene("HOGDescriptorExample");
  315. }
  316. public void OnQRCodeDetectorExampleButtonClick()
  317. {
  318. SceneManager.LoadScene("QRCodeDetectorExample");
  319. }
  320. public void OnQRCodeDetectorWebCamExampleButtonClick()
  321. {
  322. SceneManager.LoadScene("QRCodeDetectorWebCamExample");
  323. }
  324. public void OnQRCodeEncoderExampleButtonClick()
  325. {
  326. SceneManager.LoadScene("QRCodeEncoderExample");
  327. }
  328. #endregion
  329. #region dnn
  330. public void OnColorizationExampleButtonClick()
  331. {
  332. SceneManager.LoadScene("ColorizationExample");
  333. }
  334. public void OnObjectTrackingDaSiamRPNExampleButtonClick()
  335. {
  336. SceneManager.LoadScene("ObjectTrackingDaSiamRPNExample");
  337. }
  338. public void OnFastNeuralStyleTransferExampleButtonClick()
  339. {
  340. SceneManager.LoadScene("FastNeuralStyleTransferExample");
  341. }
  342. public void OnFaceDetectionResnetSSDExampleButtonClick()
  343. {
  344. SceneManager.LoadScene("FaceDetectionResnetSSDExample");
  345. }
  346. public void OnFaceDetectionYuNetExampleButtonClick()
  347. {
  348. SceneManager.LoadScene("FaceDetectionYuNetExample");
  349. }
  350. public void OnFaceDetectionYuNetV2ExampleButtonClick()
  351. {
  352. SceneManager.LoadScene("FaceDetectionYuNetV2Example");
  353. }
  354. public void OnFacialExpressionRecognitionExampleButtonClick()
  355. {
  356. SceneManager.LoadScene("FacialExpressionRecognitionExample");
  357. }
  358. public void OnPoseEstimationMediaPipeExampleButtonClick()
  359. {
  360. SceneManager.LoadScene("PoseEstimationMediaPipeExample");
  361. }
  362. public void OnHandPoseEstimationMediaPipeExampleButtonClick()
  363. {
  364. SceneManager.LoadScene("HandPoseEstimationMediaPipeExample");
  365. }
  366. public void OnHumanSegmentationPPHumanSegExampleButtonClick()
  367. {
  368. SceneManager.LoadScene("HumanSegmentationPPHumanSegExample");
  369. }
  370. public void OnImageClassificationMobilenetExampleButtonClick()
  371. {
  372. SceneManager.LoadScene("ImageClassificationMobilenetExample");
  373. }
  374. public void OnImageClassificationPPResnetExampleButtonClick()
  375. {
  376. SceneManager.LoadScene("ImageClassificationPPResnetExample");
  377. }
  378. public void OnObjectDetectionMobileNetSSDExampleButtonClick()
  379. {
  380. SceneManager.LoadScene("ObjectDetectionMobileNetSSDExample");
  381. }
  382. public void OnObjectDetectionMobileNetSSDWebCamExampleButtonClick()
  383. {
  384. SceneManager.LoadScene("ObjectDetectionMobileNetSSDWebCamExample");
  385. }
  386. public void OnObjectDetectionYOLOv4ExampleButtonClick()
  387. {
  388. SceneManager.LoadScene("ObjectDetectionYOLOv4Example");
  389. }
  390. public void OnObjectDetectionYOLOXExampleButtonClick()
  391. {
  392. SceneManager.LoadScene("ObjectDetectionYOLOXExample");
  393. }
  394. public void OnObjectDetectionNanoDetPlusExampleButtonClick()
  395. {
  396. SceneManager.LoadScene("ObjectDetectionNanoDetPlusExample");
  397. }
  398. public void OnTextRecognitionCRNNExampleButtonClick()
  399. {
  400. SceneManager.LoadScene("TextRecognitionCRNNExample");
  401. }
  402. public void OnTextRecognitionCRNNWebCamExampleButtonClick()
  403. {
  404. SceneManager.LoadScene("TextRecognitionCRNNWebCamExample");
  405. }
  406. #endregion
  407. #region ml
  408. public void OnKNNExampleButtonClick()
  409. {
  410. SceneManager.LoadScene("KNNExample");
  411. }
  412. public void OnSVMExampleButtonClick()
  413. {
  414. SceneManager.LoadScene("SVMExample");
  415. }
  416. #endregion
  417. #region photo
  418. public void OnInpaintExampleButtonClick()
  419. {
  420. SceneManager.LoadScene("InpaintExample");
  421. }
  422. public void OnSeamlessCloneExampleButtonClick()
  423. {
  424. SceneManager.LoadScene("SeamlessCloneExample");
  425. }
  426. #endregion
  427. #endregion
  428. #region Contrib modules
  429. #region bgsegm
  430. public void OnBackgroundSubtractorExampleButtonClick()
  431. {
  432. SceneManager.LoadScene("BackgroundSubtractorExample");
  433. }
  434. #endregion
  435. #region face
  436. public void OnFaceMarkExampleButtonClick()
  437. {
  438. SceneManager.LoadScene("FaceMarkExample");
  439. }
  440. public void OnFaceRecognizerExampleButtonClick()
  441. {
  442. SceneManager.LoadScene("FaceRecognizerExample");
  443. }
  444. #endregion
  445. #region plot
  446. public void OnPlotExampleButtonClick()
  447. {
  448. SceneManager.LoadScene("PlotExample");
  449. }
  450. #endregion
  451. #region text
  452. public void OnTextDetectionExampleButtonClick()
  453. {
  454. SceneManager.LoadScene("TextDetectionExample");
  455. }
  456. public void OnTextRecognitionExampleButtonClick()
  457. {
  458. SceneManager.LoadScene("TextRecognitionExample");
  459. }
  460. #endregion
  461. #region tracking
  462. public void OnLegacyTrackingExampleButtonClick()
  463. {
  464. SceneManager.LoadScene("LegacyTrackingExample");
  465. }
  466. public void OnTrackingExampleButtonClick()
  467. {
  468. SceneManager.LoadScene("TrackingExample");
  469. }
  470. #endregion
  471. #endregion
  472. }
  473. }