Parameters.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Net;
  8. using bbiwarg.Utility;
  9. namespace bbiwarg
  10. {
  11. /// <summary>
  12. /// type of input source
  13. /// </summary>
  14. public enum InputType
  15. {
  16. Camera,
  17. Movie
  18. }
  19. /// <summary>
  20. /// Defines all parameters used in the whole program.
  21. /// </summary>
  22. static class Parameters
  23. {
  24. #region console
  25. /// <summary>
  26. /// with of the console in monospace characters
  27. /// </summary>
  28. public static readonly int ConsoleWidth = 90;
  29. /// <summary>
  30. /// height of the console in monospace characters
  31. /// </summary>
  32. public static readonly int ConsoleHeight = 30;
  33. #endregion
  34. #region input
  35. /// <summary>
  36. /// the input source type
  37. /// </summary>
  38. public static readonly InputType InputSource = InputType.Camera;
  39. /// <summary>
  40. /// path to the movie file used as input source
  41. /// </summary>
  42. public static readonly String InputMoviePath = "..\\..\\videos\\touch\\4.skv";
  43. #endregion
  44. #region Logger
  45. /// <summary>
  46. /// true iff the timer output should be shown
  47. /// </summary>
  48. public static readonly bool LoggerTimerOutputEnabled = true;
  49. /// <summary>
  50. /// bitfield which specifies which subjects should be logged
  51. /// </summary>
  52. public static readonly LogSubject LoggerEnabledSubjects = LogSubject.None;
  53. #endregion
  54. #region DebugWindow
  55. /// <summary>
  56. /// true iff the debug window is enabled
  57. /// </summary>
  58. public static readonly bool DebugWindowEnabled = true;
  59. /// <summary>
  60. /// the update interval for the debug window
  61. /// </summary>
  62. public static readonly int DebugWindowUpdateIntervall = 1000 / 30; // 30fps
  63. /// <summary>
  64. /// the title of the debug window
  65. /// </summary>
  66. public static readonly String DebugWindowTitle = "BBIWARG - DebugOutput";
  67. #endregion
  68. #region GlassesWindow
  69. /// <summary>
  70. /// true iff the glasses window is enabled
  71. /// </summary>
  72. public static readonly bool GlassesWindowEnabled = false;
  73. /// <summary>
  74. /// the update interval for the glasses window
  75. /// </summary>
  76. public static readonly int GlassesWindowUpdateInterval = 1000 / 30; // 30fps
  77. /// <summary>
  78. /// the titel of the debug window
  79. /// </summary>
  80. public static readonly String GlassesWindowTitle = "BBIWARG - GlassesOutput";
  81. /// <summary>
  82. /// number of calibration points
  83. /// </summary>
  84. public static readonly int GlassesWindowNumCalibrationPoints = 20;
  85. #endregion
  86. #region tuio
  87. /// <summary>
  88. /// true iff the tuio server is enabled
  89. /// </summary>
  90. public static readonly bool TuioEnabledByDefault = true;
  91. /// <summary>
  92. /// the default ip address of the tuio server
  93. /// </summary>
  94. public static readonly String TuioDefaultIP = "127.0.0.1";
  95. /// <summary>
  96. /// the default port of the tuio server
  97. /// </summary>
  98. public static readonly Int16 TuioDefaultPort = 3333;
  99. #endregion
  100. #region ConfidenceImage
  101. /// <summary>
  102. /// the minimum confidence threshold for pixel values to be considered correct
  103. /// </summary>
  104. public static readonly int ConfidenceImageMinThreshold = 500;
  105. #endregion
  106. #region DepthImage
  107. /// <summary>
  108. /// the size of the median filter used to filter the depth image
  109. /// </summary>
  110. public static readonly int DepthImageMedianSize = 5;
  111. /// <summary>
  112. /// the depth range which is considered important (in mm)
  113. /// </summary>
  114. public static readonly int DepthImageDepthRange = 200; // <255
  115. #endregion
  116. #region EdgeImage
  117. /// <summary>
  118. /// start threshold for the canny edge detector used to detect edges in the depth image
  119. /// </summary>
  120. public static readonly int EdgeImageCannyStartThreshold = 80;
  121. /// <summary>
  122. /// linking threshold for the canny edge detector used to detect edges in the depth image
  123. /// </summary>
  124. public static readonly int EdgeImageCannyLinkingThreshold = 60;
  125. /// <summary>
  126. /// filter size for the canny edge detector used to detect edges in the depth image
  127. /// </summary>
  128. public static readonly int EdgeImageCannySize = 3;
  129. /// <summary>
  130. /// number of dilation iterations to generate the rough edge image from the edge image
  131. /// </summary>
  132. public static readonly int EdgeImageRoughNumDilationIterations = 1;
  133. #endregion
  134. #region general tracking
  135. /// <summary>
  136. /// if a tracked object moves this relative amount it will have a similarity of 0 to itself at the previous position
  137. /// </summary>
  138. public static readonly float TrackerMaxRelativeMove = 0.25f;
  139. #endregion
  140. #region finger detection
  141. public static readonly int FingerStepSize = 1;
  142. public static readonly int FingerMaxGapCounter = 3;
  143. public static readonly int FingerMaxSliceDifferencePerStep = 5;
  144. public static readonly int FingerMinNumSlices = 20;
  145. public static readonly float FingerMaxWidth3D = 35f;
  146. public static readonly int FingerMaxWidth2D = 30; // TODO remove and replace with 3Dwidth
  147. public static readonly int FingerMinWidth2D = 2;
  148. public static readonly int FingerRemoveNumSlicesForCorrection = 10;
  149. public static readonly int FingerNumSlicesForRelativeDirection = FingerRemoveNumSlicesForCorrection;
  150. public static readonly int FingerOutMargin = 6;
  151. public static readonly int FingerMaxCrippleDifference = 20;
  152. public static readonly int FingerContourMargin = 4;
  153. #endregion
  154. #region finger tracking
  155. /// <summary>
  156. /// number of frames a finger needs to be detected before it is tracked
  157. /// </summary>
  158. public static readonly int FingerTrackerNumFramesDetectedUntilTracked = 5;
  159. /// <summary>
  160. /// number of frames a finger needs to be lost before it is deleted
  161. /// </summary>
  162. public static readonly int FingerTrackerNumFramesLostUntilDeleted = 10;
  163. /// <summary>
  164. /// xx entry for the measurement noise covariance matrix for the kalman filter used to smooth the finger hand and tip points
  165. /// </summary>
  166. public static readonly float FingermXX = 0.000005f;
  167. /// <summary>
  168. /// xy and yx entry for the measurement noise covariance matrix for the kalman filter used to smooth the finger hand and tip points
  169. /// </summary>
  170. public static readonly float FingermXY = 0.0f;
  171. /// <summary>
  172. /// yy entry for the measurement noise covariance matrix for the kalman filter used to smooth the finger hand and tip points
  173. /// </summary>
  174. public static readonly float FingermYY = 0.000005f;
  175. /// <summary>
  176. /// number of finger slice directions used to compute the mean finger direction
  177. /// </summary>
  178. public static readonly int FingerTrackerNumDirectionsForMeanDirection = 10;
  179. /// <summary>
  180. /// if the tip point of a finger moves this relative amount it will have a similarity of 0 to itself at the previous position
  181. /// </summary>
  182. public static readonly float FingerTrackerMaxTipPointRelativeMove = TrackerMaxRelativeMove;
  183. /// <summary>
  184. /// if the hand point of a finger moves this relative amount it will have a similarity of 0 to itself at the previous position
  185. /// </summary>
  186. public static readonly float FingerTrackerMaxHandPointRelativeMove = TrackerMaxRelativeMove;
  187. #endregion
  188. #region hand detection
  189. /// <summary>
  190. /// number of colors used to draw hands
  191. /// </summary>
  192. public static readonly int HandNumColors = 3;
  193. /// <summary>
  194. /// maximum downwards depth difference between a pixel and a neighboring pixel belonging to the same hand
  195. /// </summary>
  196. public static readonly int HandFloodFillDownDiff = 2;
  197. /// <summary>
  198. /// maximum upwards depth difference between a pixel and a neighboring pixel belonging to the same hand
  199. /// </summary>
  200. public static readonly int HandFloodFillUpDiff = 2;
  201. /// <summary>
  202. /// maximum size of a hand relative to the whole image
  203. /// </summary>
  204. public static readonly float HandMaxSize = 0.6f;
  205. /// <summary>
  206. /// minimum size of a hand realtive to the whole image
  207. /// </summary>
  208. public static readonly float HandMinSize = 0.01f;
  209. /// <summary>
  210. /// maximum size of a hand extension mask relative to the whole image
  211. /// </summary>
  212. public static readonly float HandExtensionMaxRelativeSize = 0.5f * HandMaxSize;
  213. /// <summary>
  214. /// maximum depth difference below which two sections of a hand which are seperated by a finger are considered to belong to the same hand
  215. /// </summary>
  216. public static readonly int HandExtendMaxDifference = 40;
  217. /// <summary>
  218. /// the maximum distance of the thumb tip point to the outer short point of a convexity defect for possible thumb defects
  219. /// </summary>
  220. public static readonly float HandThumbDefectMaxDistanceToThumb = Parameters.FingerMaxWidth2D;
  221. /// <summary>
  222. /// the minumum ratio of the thumb length to the length from the depth point to the outer short point of a convexity defect for possible thumb defects
  223. /// </summary>
  224. public static readonly float HandThumbDefectMinThumbShortLengthRatio = 0.75f;
  225. /// <summary>
  226. /// the maximum ratio of the thumb length to the length from the depth point to the outer short point of a convexity defect for possible thumb defects
  227. /// </summary>
  228. public static readonly float HandThumbDefectMaxThumbShortLengthRatio = 1.1f;
  229. /// <summary>
  230. /// the minimum ratio of the length from the depth point to the outer short point to
  231. /// the length from the depth point to the outer long point of a convexity defect for possible thumb defects
  232. /// </summary>
  233. public static readonly float HandThumbDefectMinShortLongLengthRatio = 0.3f;
  234. /// <summary>
  235. /// the maximum ratio of the length from the depth point to the outer short point to
  236. /// the length from the depth point to the outer long point of a convexity defect for possible thumb defects
  237. /// </summary>
  238. public static readonly float HandThumbDefectMaxShortLongLengthRatio = 0.7f;
  239. #endregion
  240. #region hand tracker
  241. /// <summary>
  242. /// number of frames a hand needs to be detected before it is tracked
  243. /// </summary>
  244. public static readonly int HandTrackerNumFramesDetectedUntilTracked = 5;
  245. /// <summary>
  246. /// number of frames a hand needs to be lost before it is deleted
  247. /// </summary>
  248. public static readonly int HandTrackerNumFramesLostUntilDeleted = 5;
  249. /// <summary>
  250. /// if the centroid of a hand moves this relative amount it will have a similarity of 0 to itself at the previous position
  251. /// </summary>
  252. public static readonly float HandTrackerMaxCentroidRelativeMove = TrackerMaxRelativeMove;
  253. /// <summary>
  254. /// xx entry for the measurement noise covariance matrix for the kalman filter used to smooth the hand centroid
  255. /// </summary>
  256. public static readonly float HandmXX = 0.0005f;
  257. /// <summary>
  258. /// xy and yx entry for the measurement noise covariance matrix for the kalman filter used to smooth the hand centroid
  259. /// </summary>
  260. public static readonly float HandmXY = 0.0f;
  261. /// <summary>
  262. /// yy entry for the measurement noise covariance matrix for the kalman filter used to smooth the hand centroid
  263. /// </summary>
  264. public static readonly float HandmYY = 0.0005f;
  265. #endregion
  266. #region palm detection
  267. /// <summary>
  268. /// number of positions along the forefinger used as starting points to detect the palm width
  269. /// </summary>
  270. public static readonly int PalmNumPositionsForPalmWidth = 5;
  271. /// <summary>
  272. /// relative tolerance which specifies when a point is considered to be in the palm grid
  273. /// </summary>
  274. public static readonly float PalmInsideTolerance = 0.1f;
  275. #endregion
  276. #region palm tracker
  277. /// <summary>
  278. /// number of frames a palm needs to be detected before it is tracked
  279. /// </summary>
  280. public static readonly int PalmTrackerNumFramesDetectedUntilTracked = 5;
  281. /// <summary>
  282. /// number of frames a palm needs to be lost before it is deleted
  283. /// </summary>
  284. public static readonly int PalmTrackerNumFramesLostUntilDeleted = 5;
  285. /// <summary>
  286. /// if the upper wrist point of the palm grid moves this relative amount it will have a similarity of 0 to itself at the previous position
  287. /// </summary>
  288. public static readonly float PalmTrackerMaxWristUpperRelativeMove = TrackerMaxRelativeMove;
  289. /// <summary>
  290. /// if the lower wrist point of the palm grid moves this relative amount it will have a similarity of 0 to itself at the previous position
  291. /// </summary>
  292. public static readonly float PalmTrackerMaxWristLowerRelativeMove = TrackerMaxRelativeMove;
  293. /// <summary>
  294. /// if the upper finger point of the palm grid moves this relative amount it will have a similarity of 0 to itself at the previous position
  295. /// </summary>
  296. public static readonly float PalmTrackerMaxFingersUpperRelativeMove = TrackerMaxRelativeMove;
  297. /// <summary>
  298. /// if the lower finger point of the palm grid moves this relative amount it will have a similarity of 0 to itself at the previous position
  299. /// </summary>
  300. public static readonly float PalmTrackerMaxFingersLowerRelativeMove = TrackerMaxRelativeMove;
  301. /// <summary>
  302. /// xx entry for the measurement noise covariance matrix for the kalman filter used to smooth the palm grid points
  303. /// </summary>
  304. public static readonly float PalmmXX = 0.00005f;
  305. /// <summary>
  306. /// xy and yx entry for the measurement noise covariance matrix for the kalman filter used to smooth the palm grid points
  307. /// </summary>
  308. public static readonly float PalmmXY = 0.0f;
  309. /// <summary>
  310. /// yy entry for the measurement noise covariance matrix for the kalman filter used to smooth the palm grid points
  311. /// </summary>
  312. public static readonly float PalmmYY = 0.00005f;
  313. #endregion
  314. #region palm grid
  315. /// <summary>
  316. /// default number of palm grid rows
  317. /// </summary>
  318. public static readonly int PalmGridDefaultNumRows = 3;
  319. /// <summary>
  320. /// default number of palm grid columns
  321. /// </summary>
  322. public static readonly int PalmGridDefaultNumColumns = 4;
  323. #endregion
  324. #region touch detection
  325. public static readonly float TouchMinTouchValue = 0.3f;
  326. public static readonly int TouchAreaSize = 30;
  327. public static readonly int TouchFloodfillDownDiff = 1;
  328. public static readonly int TouchFloodfillUpDiff = 3;
  329. public static readonly int TouchTipInsideFactor = 2;
  330. public static readonly int TouchTipOutsideFactor = 7;
  331. #endregion
  332. #region touch tracking
  333. /// <summary>
  334. /// number of frames an object needs to be detected before it is tracked
  335. /// </summary>
  336. public static readonly int TouchTrackerNumFramesDetectedUntilTracked = 1;
  337. /// <summary>
  338. /// number of frames an object needs to be lost before it is deleted
  339. /// </summary>
  340. public static readonly int TouchTrackerNumFramesLostUntilDeleted = 5;
  341. /// <summary>
  342. /// if the absolute position of a tracked touch event moves this relative amount it will have a similarity of 0 to itself at the previous position
  343. /// </summary>
  344. public static readonly float TouchTrackerMaxAbsolutePositionRelativeMove = TrackerMaxRelativeMove;
  345. /// <summary>
  346. /// xx entry for the measurement noise covariance matrix for the kalman filter used to smooth touch events
  347. /// </summary>
  348. public static readonly float TouchmXX = 0.003f;
  349. /// <summary>
  350. /// xy and yx entry for the measurement noise covariance matrix for the kalman filter used to smooth touch events
  351. /// </summary>
  352. public static readonly float TouchmXY = 0.0f;
  353. /// <summary>
  354. /// yy entry for the measurement noise covariance matrix for the kalman filter used to smooth touch events
  355. /// </summary>
  356. public static readonly float TouchmYY = 0.00165f;
  357. /// <summary>
  358. /// value used for all entries in the process noise covariance matrix for the kalman filter used to smooth touch events
  359. /// </summary>
  360. public static readonly float TouchProcessNoise = 3.0e-4f;
  361. #endregion
  362. #region TouchEventVisualizer
  363. /// <summary>
  364. /// time in ms after which old touch events are removed from the touch event visualizer
  365. /// </summary>
  366. public static readonly int TouchEventVisualizerFadeOutTime = 1500;
  367. #endregion
  368. #region homographyExport
  369. /// <summary>
  370. /// file name of the file to which the homography is written
  371. /// </summary>
  372. public static readonly String HomographyFileName = "homography.txt";
  373. #endregion
  374. #region colors
  375. #region general
  376. /// <summary>
  377. /// color used to draw detected objects
  378. /// </summary>
  379. public static readonly Color ColorDetected = Color.Turquoise;
  380. /// <summary>
  381. /// color used to draw tracked objects
  382. /// </summary>
  383. public static readonly Color ColorTracked = Color.Yellow;
  384. #endregion
  385. #region images
  386. /// <summary>
  387. /// color used to specify which color channels the depth image is drawn to
  388. /// </summary>
  389. public static readonly Color DepthImageColor = Color.White;
  390. /// <summary>
  391. /// color used to specify which color channels the edge image is drawn to
  392. /// </summary>
  393. public static readonly Color EdgeImageColor = Color.Blue;
  394. /// <summary>
  395. /// color used to draw the borders of the output images
  396. /// </summary>
  397. public static readonly Color OutputImageBorderColor = Color.White;
  398. #endregion
  399. #region finger
  400. /// <summary>
  401. /// color used to draw the finger slices
  402. /// </summary>
  403. public static readonly Color FingerSliceColor = Color.Magenta;
  404. /// <summary>
  405. /// color used to draw the detected fingers
  406. /// </summary>
  407. public static readonly Color FingerDetectedColor = ColorDetected;
  408. /// <summary>
  409. /// color used to draw the tracked fingers
  410. /// </summary>
  411. public static readonly Color FingerTrackedColor = ColorTracked;
  412. /// <summary>
  413. /// color used to draw the finger tip point
  414. /// </summary>
  415. public static readonly Color FingerTipColor = Color.Blue;
  416. /// <summary>
  417. /// color used to draw the finger hand point
  418. /// </summary>
  419. public static readonly Color FingerHandColor = Color.Yellow;
  420. /// <summary>
  421. /// color used to draw the finger contour
  422. /// </summary>
  423. public static readonly Color FingerContourColor = Color.Red;
  424. /// <summary>
  425. /// color used to draw the text for the finger id
  426. /// </summary>
  427. public static readonly Color FingerIDColor = Color.White;
  428. #endregion
  429. #region touch
  430. /// <summary>
  431. /// color used to draw detected touch events
  432. /// </summary>
  433. public static readonly Color TouchEventDetectedColor = ColorDetected;
  434. /// <summary>
  435. /// color used to draw tracked touch events
  436. /// </summary>
  437. public static readonly Color TouchEventTrackedColor = ColorTracked;
  438. #endregion
  439. #region TouchEventVisualizer
  440. /// <summary>
  441. /// color used to draw the lines between touch events in the touch event visualizer
  442. /// </summary>
  443. public static readonly Color TouchEventVisualizerLineColor = Color.Yellow;
  444. /// <summary>
  445. /// color used to draw the touch event points in the touch event visualizer
  446. /// </summary>
  447. public static readonly Color TouchEventVisualizerPointColor = Color.Red;
  448. /// <summary>
  449. /// color used to draw the grid in the touch event visualizer
  450. /// </summary>
  451. public static readonly Color TouchEventVisualizerGridColor = Color.White;
  452. /// <summary>
  453. /// color used to draw the text in the touch event visualizer
  454. /// </summary>
  455. public static readonly Color TouchEventVisualizerTextColor = Color.White;
  456. /// <summary>
  457. /// color used to highlight the active block in the touch event visualizer
  458. /// </summary>
  459. public static readonly Color TouchEventVisualizerActiveBlockColor = Color.DarkSlateGray;
  460. #endregion
  461. #region palm
  462. /// <summary>
  463. /// color used to draw the plam quadrangle
  464. /// </summary>
  465. public static readonly Color PalmQuadColor = Color.Blue;
  466. /// <summary>
  467. /// color used to draw the palm grid in the palm
  468. /// </summary>
  469. public static readonly Color PalmGridColor = Color.CornflowerBlue;
  470. #endregion
  471. #region hand
  472. /// <summary>
  473. /// colors used to draw the hands (ith element is a color which specifies the color channels used to draw the ith hand)
  474. /// </summary>
  475. public static readonly Color[] HandColors = new Color[3] { Color.Red, Color.Blue, Color.Green };
  476. /// <summary>
  477. /// color used to draw the hand centroid
  478. /// </summary>
  479. public static readonly Color HandCentroidColor = Color.Yellow;
  480. /// <summary>
  481. /// color used to draw the hand id text
  482. /// </summary>
  483. public static readonly Color HandIDColor = Color.White;
  484. /// <summary>
  485. /// color used to draw the points of the thumb defects
  486. /// </summary>
  487. public static readonly Color HandThumbDefectPointColor = Color.Lime;
  488. /// <summary>
  489. /// color used to draw the lines of the thumb defects
  490. /// </summary>
  491. public static readonly Color HandThumbDefectLineColor = Color.CornflowerBlue;
  492. #endregion
  493. #region calibration
  494. /// <summary>
  495. /// color used to draw the calibration points in the glasses window
  496. /// </summary>
  497. public static readonly Color CalibrationPointColor = Color.Yellow;
  498. #endregion
  499. #endregion
  500. }
  501. }