Parameters.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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 / FingerStepSize;
  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 / FingerStepSize;
  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. public static readonly int HandExtendMaxDifference = 40;
  214. public static readonly float HandThumbDefectMaxDistanceToThumb = Parameters.FingerMaxWidth2D;
  215. public static readonly float HandThumbDefectMinThumbShortLengthRatio = 0.75f;
  216. public static readonly float HandThumbDefectMaxThumbShortLengthRatio = 1.1f;
  217. public static readonly float HandThumbDefectMinShortLongLengthRatio = 0.3f;
  218. public static readonly float HandThumbDefectMaxShortLongLengthRatio = 0.7f;
  219. #endregion
  220. #region hand tracker
  221. /// <summary>
  222. /// number of frames a hand needs to be detected before it is tracked
  223. /// </summary>
  224. public static readonly int HandTrackerNumFramesDetectedUntilTracked = 5;
  225. /// <summary>
  226. /// number of frames a hand needs to be lost before it is deleted
  227. /// </summary>
  228. public static readonly int HandTrackerNumFramesLostUntilDeleted = 5;
  229. /// <summary>
  230. /// if the centroid of a hand moves this relative amount it will have a similarity of 0 to itself at the previous position
  231. /// </summary>
  232. public static readonly float HandTrackerMaxCentroidRelativeMove = TrackerMaxRelativeMove;
  233. /// <summary>
  234. /// xx entry for the measurement noise covariance matrix for the kalman filter used to smooth the hand centroid
  235. /// </summary>
  236. public static readonly float HandmXX = 0.0005f;
  237. /// <summary>
  238. /// xy and yx entry for the measurement noise covariance matrix for the kalman filter used to smooth the hand centroid
  239. /// </summary>
  240. public static readonly float HandmXY = 0.0f;
  241. /// <summary>
  242. /// yy entry for the measurement noise covariance matrix for the kalman filter used to smooth the hand centroid
  243. /// </summary>
  244. public static readonly float HandmYY = 0.0005f;
  245. #endregion
  246. #region palm detection
  247. /// <summary>
  248. /// number of positions along the forefinger used as starting points to detect the palm width
  249. /// </summary>
  250. public static readonly int PalmNumPositionsForPalmWidth = 5;
  251. /// <summary>
  252. /// relative tolerance which specifies when a point is considered to be in the palm grid
  253. /// </summary>
  254. public static readonly float PalmInsideTolerance = 0.1f;
  255. #endregion
  256. #region palm tracker
  257. /// <summary>
  258. /// number of frames a palm needs to be detected before it is tracked
  259. /// </summary>
  260. public static readonly int PalmTrackerNumFramesDetectedUntilTracked = 5;
  261. /// <summary>
  262. /// number of frames a palm needs to be lost before it is deleted
  263. /// </summary>
  264. public static readonly int PalmTrackerNumFramesLostUntilDeleted = 5;
  265. /// <summary>
  266. /// 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
  267. /// </summary>
  268. public static readonly float PalmTrackerMaxWristUpperRelativeMove = TrackerMaxRelativeMove;
  269. /// <summary>
  270. /// 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
  271. /// </summary>
  272. public static readonly float PalmTrackerMaxWristLowerRelativeMove = TrackerMaxRelativeMove;
  273. /// <summary>
  274. /// 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
  275. /// </summary>
  276. public static readonly float PalmTrackerMaxFingersUpperRelativeMove = TrackerMaxRelativeMove;
  277. /// <summary>
  278. /// 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
  279. /// </summary>
  280. public static readonly float PalmTrackerMaxFingersLowerRelativeMove = TrackerMaxRelativeMove;
  281. /// <summary>
  282. /// xx entry for the measurement noise covariance matrix for the kalman filter used to smooth the palm grid points
  283. /// </summary>
  284. public static readonly float PalmmXX = 0.00005f;
  285. /// <summary>
  286. /// xy and yx entry for the measurement noise covariance matrix for the kalman filter used to smooth the palm grid points
  287. /// </summary>
  288. public static readonly float PalmmXY = 0.0f;
  289. /// <summary>
  290. /// yy entry for the measurement noise covariance matrix for the kalman filter used to smooth the palm grid points
  291. /// </summary>
  292. public static readonly float PalmmYY = 0.00005f;
  293. #endregion
  294. #region palm grid
  295. /// <summary>
  296. /// default number of palm grid rows
  297. /// </summary>
  298. public static readonly int PalmGridDefaultNumRows = 3;
  299. /// <summary>
  300. /// default number of palm grid columns
  301. /// </summary>
  302. public static readonly int PalmGridDefaultNumColumns = 4;
  303. #endregion
  304. #region touch
  305. public static readonly float TouchMinTouchValue = 0.3f;
  306. public static readonly int TouchAreaSize = 30;
  307. public static readonly int TouchFloodfillDownDiff = 1;
  308. public static readonly int TouchFloodfillUpDiff = 3;
  309. public static readonly int TouchTipInsideFactor = 2;
  310. public static readonly int TouchTipOutsideFactor = 7;
  311. #endregion
  312. #region touch tracking
  313. /// <summary>
  314. /// number of frames an object needs to be detected before it is tracked
  315. /// </summary>
  316. public static readonly int TouchTrackerNumFramesDetectedUntilTracked = 1;
  317. /// <summary>
  318. /// number of frames an object needs to be lost before it is deleted
  319. /// </summary>
  320. public static readonly int TouchTrackerNumFramesLostUntilDeleted = 5;
  321. /// <summary>
  322. /// 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
  323. /// </summary>
  324. public static readonly float TouchTrackerMaxAbsolutePositionRelativeMove = TrackerMaxRelativeMove;
  325. /// <summary>
  326. /// xx entry for the measurement noise covariance matrix for the kalman filter used to smooth touch events
  327. /// </summary>
  328. public static readonly float TouchmXX = 0.003f;
  329. /// <summary>
  330. /// xy and yx entry for the measurement noise covariance matrix for the kalman filter used to smooth touch events
  331. /// </summary>
  332. public static readonly float TouchmXY = 0.0f;
  333. /// <summary>
  334. /// yy entry for the measurement noise covariance matrix for the kalman filter used to smooth touch events
  335. /// </summary>
  336. public static readonly float TouchmYY = 0.00165f;
  337. /// <summary>
  338. /// value used for all entries in the process noise covariance matrix for the kalman filter used to smooth touch events
  339. /// </summary>
  340. public static readonly float TouchProcessNoise = 3.0e-4f;
  341. #endregion
  342. #region TouchEventVisualizer
  343. /// <summary>
  344. /// time in ms after which old touch events are removed from the touch event visualizer
  345. /// </summary>
  346. public static readonly int TouchEventVisualizerFadeOutTime = 1500;
  347. #endregion
  348. #region homographyExport
  349. /// <summary>
  350. /// file name of the file to which the homography is written
  351. /// </summary>
  352. public static readonly String HomographyFileName = "homography.txt";
  353. #endregion
  354. #region colors
  355. #region general
  356. /// <summary>
  357. /// color used to draw detected objects
  358. /// </summary>
  359. public static readonly Color ColorDetected = Color.Turquoise;
  360. /// <summary>
  361. /// color used to draw tracked objects
  362. /// </summary>
  363. public static readonly Color ColorTracked = Color.Yellow;
  364. #endregion
  365. #region images
  366. /// <summary>
  367. /// color used to specify which color channels the depth image is drawn to
  368. /// </summary>
  369. public static readonly Color DepthImageColor = Color.White;
  370. /// <summary>
  371. /// color used to specify which color channels the edge image is drawn to
  372. /// </summary>
  373. public static readonly Color EdgeImageColor = Color.Blue;
  374. /// <summary>
  375. /// color used to draw the borders of the output images
  376. /// </summary>
  377. public static readonly Color OutputImageBorderColor = Color.White;
  378. #endregion
  379. #region finger
  380. /// <summary>
  381. /// color used to draw the finger slices
  382. /// </summary>
  383. public static readonly Color FingerSliceColor = Color.Magenta;
  384. /// <summary>
  385. /// color used to draw the detected fingers
  386. /// </summary>
  387. public static readonly Color FingerDetectedColor = ColorDetected;
  388. /// <summary>
  389. /// color used to draw the tracked fingers
  390. /// </summary>
  391. public static readonly Color FingerTrackedColor = ColorTracked;
  392. /// <summary>
  393. /// color used to draw the finger tip point
  394. /// </summary>
  395. public static readonly Color FingerTipColor = Color.Blue;
  396. /// <summary>
  397. /// color used to draw the finger hand point
  398. /// </summary>
  399. public static readonly Color FingerHandColor = Color.Yellow;
  400. /// <summary>
  401. /// color used to draw the finger contour
  402. /// </summary>
  403. public static readonly Color FingerContourColor = Color.Red;
  404. /// <summary>
  405. /// color used to draw the text for the finger id
  406. /// </summary>
  407. public static readonly Color FingerIDColor = Color.White;
  408. #endregion
  409. #region touch
  410. /// <summary>
  411. /// color used to draw detected touch events
  412. /// </summary>
  413. public static readonly Color TouchEventDetectedColor = ColorDetected;
  414. /// <summary>
  415. /// color used to draw tracked touch events
  416. /// </summary>
  417. public static readonly Color TouchEventTrackedColor = ColorTracked;
  418. #endregion
  419. #region TouchEventVisualizer
  420. /// <summary>
  421. /// color used to draw the lines between touch events in the touch event visualizer
  422. /// </summary>
  423. public static readonly Color TouchEventVisualizerLineColor = Color.Yellow;
  424. /// <summary>
  425. /// color used to draw the touch event points in the touch event visualizer
  426. /// </summary>
  427. public static readonly Color TouchEventVisualizerPointColor = Color.Red;
  428. /// <summary>
  429. /// color used to draw the grid in the touch event visualizer
  430. /// </summary>
  431. public static readonly Color TouchEventVisualizerGridColor = Color.White;
  432. /// <summary>
  433. /// color used to draw the text in the touch event visualizer
  434. /// </summary>
  435. public static readonly Color TouchEventVisualizerTextColor = Color.White;
  436. /// <summary>
  437. /// color used to highlight the active block in the touch event visualizer
  438. /// </summary>
  439. public static readonly Color TouchEventVisualizerActiveBlockColor = Color.DarkSlateGray;
  440. #endregion
  441. #region palm
  442. /// <summary>
  443. /// color used to draw the plam quadrangle
  444. /// </summary>
  445. public static readonly Color PalmQuadColor = Color.Blue;
  446. /// <summary>
  447. /// color used to draw the palm grid in the palm
  448. /// </summary>
  449. public static readonly Color PalmGridColor = Color.CornflowerBlue;
  450. #endregion
  451. #region hand
  452. /// <summary>
  453. /// colors used to draw the hands (ith element is a color which specifies the color channels used to draw the ith hand)
  454. /// </summary>
  455. public static readonly Color[] HandColors = new Color[3] { Color.Red, Color.Blue, Color.Green };
  456. /// <summary>
  457. /// color used to draw the hand centroid
  458. /// </summary>
  459. public static readonly Color HandCentroidColor = Color.Yellow;
  460. /// <summary>
  461. /// color used to draw the hand id text
  462. /// </summary>
  463. public static readonly Color HandIDColor = Color.White;
  464. /// <summary>
  465. /// color used to draw the points of the thumb defects
  466. /// </summary>
  467. public static readonly Color HandThumbDefectPointColor = Color.Lime;
  468. /// <summary>
  469. /// color used to draw the lines of the thumb defects
  470. /// </summary>
  471. public static readonly Color HandThumbDefectLineColor = Color.CornflowerBlue;
  472. #endregion
  473. #region calibration
  474. /// <summary>
  475. /// color used to draw the calibration points in the glasses window
  476. /// </summary>
  477. public static readonly Color CalibrationPointColor = Color.Yellow;
  478. #endregion
  479. #endregion
  480. }
  481. }