How to implement corner detection (C#)


/ Published in: C#
Save to your folder(s)

You can find the full source code for corner detection here. I found this solution on www.camera-sdk.com and it worked for me fine. I created a Visual C# WPF application in Visual Studio, and added two .dll files (VOIPSDK.dll and NVA.dll) to the references. The .dll files can be found on the webpage.

First, you can see the full source code for the interface of the program at Form1.Desginer.cs. On this GUI you can adjust many configurations in connection with the image of the camera, and you can have a detailed list about the detected corners.

Under Form1.cs you can find the source code for the program itself and you will see which mediahandlers, methods and configurations you should use to achieve this function.

I hope you can all use this snippet! I wish you success to build your corner detecting solutions!


Copy this code and paste it in your HTML
  1. // Form1.Designer.cs
  2.  
  3. namespace CornerDetection
  4. {
  5. partial class Form1
  6. {
  7. /// <summary>
  8. /// Required designer variable.
  9. /// </summary>
  10. private System.ComponentModel.IContainer components = null;
  11.  
  12. /// <summary>
  13. /// Clean up any resources being used.
  14. /// </summary>
  15. /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  16. protected override void Dispose(bool disposing)
  17. {
  18. if (disposing && (components != null))
  19. {
  20. components.Dispose();
  21. }
  22. base.Dispose(disposing);
  23. }
  24.  
  25. #region Windows Form Designer generated code
  26.  
  27. /// <summary>
  28. /// Required method for Designer support - do not modify
  29. /// the contents of this method with the code editor.
  30. /// </summary>
  31. private void InitializeComponent()
  32. {
  33. this.label1 = new System.Windows.Forms.Label();
  34. this.label2 = new System.Windows.Forms.Label();
  35. this.btn_Set = new System.Windows.Forms.Button();
  36. this.tb_BlockSize = new System.Windows.Forms.TextBox();
  37. this.tb_Epsilon = new System.Windows.Forms.TextBox();
  38. this.tb_MaxDetectedObjects = new System.Windows.Forms.TextBox();
  39. this.tb_MaxIteration = new System.Windows.Forms.TextBox();
  40. this.tb_MinDistance = new System.Windows.Forms.TextBox();
  41. this.groupBox1 = new System.Windows.Forms.GroupBox();
  42. this.tb_ZeroZoneSizeY = new System.Windows.Forms.TextBox();
  43. this.tb_SearchWindowSizeY = new System.Windows.Forms.TextBox();
  44. this.label14 = new System.Windows.Forms.Label();
  45. this.tb_ZeroZoneSizeX = new System.Windows.Forms.TextBox();
  46. this.label13 = new System.Windows.Forms.Label();
  47. this.tb_SearchWindowSizeX = new System.Windows.Forms.TextBox();
  48. this.label9 = new System.Windows.Forms.Label();
  49. this.tb_QualityLevel = new System.Windows.Forms.TextBox();
  50. this.label6 = new System.Windows.Forms.Label();
  51. this.label5 = new System.Windows.Forms.Label();
  52. this.label8 = new System.Windows.Forms.Label();
  53. this.label3 = new System.Windows.Forms.Label();
  54. this.label7 = new System.Windows.Forms.Label();
  55. this.groupBox2 = new System.Windows.Forms.GroupBox();
  56. this.btn_HighlightSet = new System.Windows.Forms.Button();
  57. this.label11 = new System.Windows.Forms.Label();
  58. this.label10 = new System.Windows.Forms.Label();
  59. this.tb_DrawThickness = new System.Windows.Forms.TextBox();
  60. this.tb_Blue = new System.Windows.Forms.TextBox();
  61. this.chk_ShowImage = new System.Windows.Forms.CheckBox();
  62. this.tb_Green = new System.Windows.Forms.TextBox();
  63. this.tb_Red = new System.Windows.Forms.TextBox();
  64. this.lb_Detection = new System.Windows.Forms.ListBox();
  65. this.label12 = new System.Windows.Forms.Label();
  66. this.label4 = new System.Windows.Forms.Label();
  67. this.tb_DrawSize = new System.Windows.Forms.TextBox();
  68. this.groupBox1.SuspendLayout();
  69. this.groupBox2.SuspendLayout();
  70. this.SuspendLayout();
  71. //
  72. // label1
  73. //
  74. this.label1.AutoSize = true;
  75. this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
  76. this.label1.Location = new System.Drawing.Point(30, 265);
  77. this.label1.Name = "label1";
  78. this.label1.Size = new System.Drawing.Size(87, 13);
  79. this.label1.TabIndex = 0;
  80. this.label1.Text = "Original image";
  81. //
  82. // label2
  83. //
  84. this.label2.AutoSize = true;
  85. this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
  86. this.label2.Location = new System.Drawing.Point(370, 265);
  87. this.label2.Name = "label2";
  88. this.label2.Size = new System.Drawing.Size(103, 13);
  89. this.label2.TabIndex = 1;
  90. this.label2.Text = "Processed image";
  91. //
  92. // btn_Set
  93. //
  94. this.btn_Set.Location = new System.Drawing.Point(189, 319);
  95. this.btn_Set.Name = "btn_Set";
  96. this.btn_Set.Size = new System.Drawing.Size(58, 23);
  97. this.btn_Set.TabIndex = 2;
  98. this.btn_Set.Text = "Set";
  99. this.btn_Set.UseVisualStyleBackColor = true;
  100. this.btn_Set.Click += new System.EventHandler(this.btn_Set_Click);
  101. //
  102. // tb_BlockSize
  103. //
  104. this.tb_BlockSize.Location = new System.Drawing.Point(153, 26);
  105. this.tb_BlockSize.Name = "tb_BlockSize";
  106. this.tb_BlockSize.Size = new System.Drawing.Size(87, 20);
  107. this.tb_BlockSize.TabIndex = 3;
  108. //
  109. // tb_Epsilon
  110. //
  111. this.tb_Epsilon.Location = new System.Drawing.Point(153, 62);
  112. this.tb_Epsilon.Name = "tb_Epsilon";
  113. this.tb_Epsilon.Size = new System.Drawing.Size(87, 20);
  114. this.tb_Epsilon.TabIndex = 5;
  115. //
  116. // tb_MaxDetectedObjects
  117. //
  118. this.tb_MaxDetectedObjects.Location = new System.Drawing.Point(153, 98);
  119. this.tb_MaxDetectedObjects.Name = "tb_MaxDetectedObjects";
  120. this.tb_MaxDetectedObjects.Size = new System.Drawing.Size(87, 20);
  121. this.tb_MaxDetectedObjects.TabIndex = 6;
  122. //
  123. // tb_MaxIteration
  124. //
  125. this.tb_MaxIteration.Location = new System.Drawing.Point(153, 134);
  126. this.tb_MaxIteration.Name = "tb_MaxIteration";
  127. this.tb_MaxIteration.Size = new System.Drawing.Size(87, 20);
  128. this.tb_MaxIteration.TabIndex = 7;
  129. //
  130. // tb_MinDistance
  131. //
  132. this.tb_MinDistance.Location = new System.Drawing.Point(153, 170);
  133. this.tb_MinDistance.Name = "tb_MinDistance";
  134. this.tb_MinDistance.Size = new System.Drawing.Size(87, 20);
  135. this.tb_MinDistance.TabIndex = 8;
  136. //
  137. // groupBox1
  138. //
  139. this.groupBox1.Controls.Add(this.tb_ZeroZoneSizeY);
  140. this.groupBox1.Controls.Add(this.tb_SearchWindowSizeY);
  141. this.groupBox1.Controls.Add(this.label14);
  142. this.groupBox1.Controls.Add(this.tb_ZeroZoneSizeX);
  143. this.groupBox1.Controls.Add(this.label13);
  144. this.groupBox1.Controls.Add(this.tb_SearchWindowSizeX);
  145. this.groupBox1.Controls.Add(this.label9);
  146. this.groupBox1.Controls.Add(this.tb_QualityLevel);
  147. this.groupBox1.Controls.Add(this.label6);
  148. this.groupBox1.Controls.Add(this.label5);
  149. this.groupBox1.Controls.Add(this.label8);
  150. this.groupBox1.Controls.Add(this.label3);
  151. this.groupBox1.Controls.Add(this.label7);
  152. this.groupBox1.Controls.Add(this.tb_MaxDetectedObjects);
  153. this.groupBox1.Controls.Add(this.btn_Set);
  154. this.groupBox1.Controls.Add(this.tb_BlockSize);
  155. this.groupBox1.Controls.Add(this.tb_MaxIteration);
  156. this.groupBox1.Controls.Add(this.tb_MinDistance);
  157. this.groupBox1.Controls.Add(this.tb_Epsilon);
  158. this.groupBox1.Location = new System.Drawing.Point(676, 225);
  159. this.groupBox1.Name = "groupBox1";
  160. this.groupBox1.Size = new System.Drawing.Size(258, 348);
  161. this.groupBox1.TabIndex = 12;
  162. this.groupBox1.TabStop = false;
  163. this.groupBox1.Text = "Settings";
  164. //
  165. // tb_ZeroZoneSizeY
  166. //
  167. this.tb_ZeroZoneSizeY.Location = new System.Drawing.Point(198, 278);
  168. this.tb_ZeroZoneSizeY.Name = "tb_ZeroZoneSizeY";
  169. this.tb_ZeroZoneSizeY.Size = new System.Drawing.Size(42, 20);
  170. this.tb_ZeroZoneSizeY.TabIndex = 23;
  171. //
  172. // tb_SearchWindowSizeY
  173. //
  174. this.tb_SearchWindowSizeY.Location = new System.Drawing.Point(198, 242);
  175. this.tb_SearchWindowSizeY.Name = "tb_SearchWindowSizeY";
  176. this.tb_SearchWindowSizeY.Size = new System.Drawing.Size(42, 20);
  177. this.tb_SearchWindowSizeY.TabIndex = 22;
  178. //
  179. // label14
  180. //
  181. this.label14.AutoSize = true;
  182. this.label14.Location = new System.Drawing.Point(70, 281);
  183. this.label14.Name = "label14";
  184. this.label14.Size = new System.Drawing.Size(77, 13);
  185. this.label14.TabIndex = 21;
  186. this.label14.Text = "ZeroZoneSize:";
  187. //
  188. // tb_ZeroZoneSizeX
  189. //
  190. this.tb_ZeroZoneSizeX.Location = new System.Drawing.Point(153, 278);
  191. this.tb_ZeroZoneSizeX.Name = "tb_ZeroZoneSizeX";
  192. this.tb_ZeroZoneSizeX.Size = new System.Drawing.Size(42, 20);
  193. this.tb_ZeroZoneSizeX.TabIndex = 20;
  194. //
  195. // label13
  196. //
  197. this.label13.AutoSize = true;
  198. this.label13.Location = new System.Drawing.Point(44, 245);
  199. this.label13.Name = "label13";
  200. this.label13.Size = new System.Drawing.Size(103, 13);
  201. this.label13.TabIndex = 19;
  202. this.label13.Text = "SearchWindowSize:";
  203. //
  204. // tb_SearchWindowSizeX
  205. //
  206. this.tb_SearchWindowSizeX.Location = new System.Drawing.Point(153, 242);
  207. this.tb_SearchWindowSizeX.Name = "tb_SearchWindowSizeX";
  208. this.tb_SearchWindowSizeX.Size = new System.Drawing.Size(42, 20);
  209. this.tb_SearchWindowSizeX.TabIndex = 18;
  210. //
  211. // label9
  212. //
  213. this.label9.AutoSize = true;
  214. this.label9.Location = new System.Drawing.Point(79, 209);
  215. this.label9.Name = "label9";
  216. this.label9.Size = new System.Drawing.Size(68, 13);
  217. this.label9.TabIndex = 17;
  218. this.label9.Text = "QualityLevel:";
  219. //
  220. // tb_QualityLevel
  221. //
  222. this.tb_QualityLevel.Location = new System.Drawing.Point(153, 206);
  223. this.tb_QualityLevel.Name = "tb_QualityLevel";
  224. this.tb_QualityLevel.Size = new System.Drawing.Size(87, 20);
  225. this.tb_QualityLevel.TabIndex = 16;
  226. //
  227. // label6
  228. //
  229. this.label6.AutoSize = true;
  230. this.label6.Location = new System.Drawing.Point(37, 101);
  231. this.label6.Name = "label6";
  232. this.label6.Size = new System.Drawing.Size(110, 13);
  233. this.label6.TabIndex = 13;
  234. this.label6.Text = "MaxDetectedObjects:";
  235. //
  236. // label5
  237. //
  238. this.label5.AutoSize = true;
  239. this.label5.Location = new System.Drawing.Point(103, 65);
  240. this.label5.Name = "label5";
  241. this.label5.Size = new System.Drawing.Size(44, 13);
  242. this.label5.TabIndex = 12;
  243. this.label5.Text = "Epsilon:";
  244. //
  245. // label8
  246. //
  247. this.label8.AutoSize = true;
  248. this.label8.Location = new System.Drawing.Point(78, 173);
  249. this.label8.Name = "label8";
  250. this.label8.Size = new System.Drawing.Size(69, 13);
  251. this.label8.TabIndex = 15;
  252. this.label8.Text = "MinDistance:";
  253. //
  254. // label3
  255. //
  256. this.label3.AutoSize = true;
  257. this.label3.Location = new System.Drawing.Point(90, 29);
  258. this.label3.Name = "label3";
  259. this.label3.Size = new System.Drawing.Size(57, 13);
  260. this.label3.TabIndex = 10;
  261. this.label3.Text = "BlockSize:";
  262. //
  263. // label7
  264. //
  265. this.label7.AutoSize = true;
  266. this.label7.Location = new System.Drawing.Point(79, 137);
  267. this.label7.Name = "label7";
  268. this.label7.Size = new System.Drawing.Size(68, 13);
  269. this.label7.TabIndex = 14;
  270. this.label7.Text = "MaxIteration:";
  271. //
  272. // groupBox2
  273. //
  274. this.groupBox2.Controls.Add(this.label4);
  275. this.groupBox2.Controls.Add(this.tb_DrawSize);
  276. this.groupBox2.Controls.Add(this.btn_HighlightSet);
  277. this.groupBox2.Controls.Add(this.label11);
  278. this.groupBox2.Controls.Add(this.label10);
  279. this.groupBox2.Controls.Add(this.tb_DrawThickness);
  280. this.groupBox2.Controls.Add(this.tb_Blue);
  281. this.groupBox2.Controls.Add(this.chk_ShowImage);
  282. this.groupBox2.Controls.Add(this.tb_Green);
  283. this.groupBox2.Controls.Add(this.tb_Red);
  284. this.groupBox2.Location = new System.Drawing.Point(679, 12);
  285. this.groupBox2.Name = "groupBox2";
  286. this.groupBox2.Size = new System.Drawing.Size(258, 207);
  287. this.groupBox2.TabIndex = 13;
  288. this.groupBox2.TabStop = false;
  289. this.groupBox2.Text = "Highlight";
  290. //
  291. // btn_HighlightSet
  292. //
  293. this.btn_HighlightSet.Location = new System.Drawing.Point(186, 178);
  294. this.btn_HighlightSet.Name = "btn_HighlightSet";
  295. this.btn_HighlightSet.Size = new System.Drawing.Size(58, 23);
  296. this.btn_HighlightSet.TabIndex = 19;
  297. this.btn_HighlightSet.Text = "Set";
  298. this.btn_HighlightSet.UseVisualStyleBackColor = true;
  299. this.btn_HighlightSet.Click += new System.EventHandler(this.btn_HighlightSet_Click);
  300. //
  301. // label11
  302. //
  303. this.label11.AutoSize = true;
  304. this.label11.Location = new System.Drawing.Point(64, 97);
  305. this.label11.Name = "label11";
  306. this.label11.Size = new System.Drawing.Size(84, 13);
  307. this.label11.TabIndex = 18;
  308. this.label11.Text = "DrawThickness:";
  309. //
  310. // label10
  311. //
  312. this.label10.AutoSize = true;
  313. this.label10.Location = new System.Drawing.Point(74, 63);
  314. this.label10.Name = "label10";
  315. this.label10.Size = new System.Drawing.Size(33, 13);
  316. this.label10.TabIndex = 17;
  317. this.label10.Text = "RGB:";
  318. //
  319. // tb_DrawThickness
  320. //
  321. this.tb_DrawThickness.Location = new System.Drawing.Point(153, 95);
  322. this.tb_DrawThickness.Name = "tb_DrawThickness";
  323. this.tb_DrawThickness.Size = new System.Drawing.Size(87, 20);
  324. this.tb_DrawThickness.TabIndex = 17;
  325. //
  326. // tb_Blue
  327. //
  328. this.tb_Blue.Location = new System.Drawing.Point(198, 59);
  329. this.tb_Blue.Name = "tb_Blue";
  330. this.tb_Blue.Size = new System.Drawing.Size(42, 20);
  331. this.tb_Blue.TabIndex = 16;
  332. //
  333. // chk_ShowImage
  334. //
  335. this.chk_ShowImage.AutoSize = true;
  336. this.chk_ShowImage.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
  337. this.chk_ShowImage.Location = new System.Drawing.Point(37, 25);
  338. this.chk_ShowImage.Name = "chk_ShowImage";
  339. this.chk_ShowImage.Size = new System.Drawing.Size(85, 17);
  340. this.chk_ShowImage.TabIndex = 14;
  341. this.chk_ShowImage.Text = "ShowImage:";
  342. this.chk_ShowImage.UseVisualStyleBackColor = true;
  343. //
  344. // tb_Green
  345. //
  346. this.tb_Green.Location = new System.Drawing.Point(153, 59);
  347. this.tb_Green.Name = "tb_Green";
  348. this.tb_Green.Size = new System.Drawing.Size(42, 20);
  349. this.tb_Green.TabIndex = 15;
  350. //
  351. // tb_Red
  352. //
  353. this.tb_Red.Location = new System.Drawing.Point(108, 59);
  354. this.tb_Red.Name = "tb_Red";
  355. this.tb_Red.Size = new System.Drawing.Size(42, 20);
  356. this.tb_Red.TabIndex = 14;
  357. //
  358. // lb_Detection
  359. //
  360. this.lb_Detection.FormattingEnabled = true;
  361. this.lb_Detection.Location = new System.Drawing.Point(10, 322);
  362. this.lb_Detection.Name = "lb_Detection";
  363. this.lb_Detection.Size = new System.Drawing.Size(660, 251);
  364. this.lb_Detection.TabIndex = 14;
  365. //
  366. // label12
  367. //
  368. this.label12.AutoSize = true;
  369. this.label12.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
  370. this.label12.Location = new System.Drawing.Point(12, 305);
  371. this.label12.Name = "label12";
  372. this.label12.Size = new System.Drawing.Size(91, 13);
  373. this.label12.TabIndex = 15;
  374. this.label12.Text = "Detection info:";
  375. //
  376. // label4
  377. //
  378. this.label4.AutoSize = true;
  379. this.label4.Location = new System.Drawing.Point(92, 135);
  380. this.label4.Name = "label4";
  381. this.label4.Size = new System.Drawing.Size(55, 13);
  382. this.label4.TabIndex = 21;
  383. this.label4.Text = "DrawSize:";
  384. //
  385. // tb_DrawSize
  386. //
  387. this.tb_DrawSize.Location = new System.Drawing.Point(153, 131);
  388. this.tb_DrawSize.Name = "tb_DrawSize";
  389. this.tb_DrawSize.Size = new System.Drawing.Size(87, 20);
  390. this.tb_DrawSize.TabIndex = 20;
  391. //
  392. // MainForm
  393. //
  394. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  395. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  396. this.ClientSize = new System.Drawing.Size(947, 581);
  397. this.Controls.Add(this.label12);
  398. this.Controls.Add(this.lb_Detection);
  399. this.Controls.Add(this.groupBox2);
  400. this.Controls.Add(this.groupBox1);
  401. this.Controls.Add(this.label2);
  402. this.Controls.Add(this.label1);
  403. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  404. this.MaximizeBox = false;
  405. this.Name = "MainForm";
  406. this.Text = "Corner Detection";
  407. this.Load += new System.EventHandler(this.MainForm_Load);
  408. this.groupBox1.ResumeLayout(false);
  409. this.groupBox1.PerformLayout();
  410. this.groupBox2.ResumeLayout(false);
  411. this.groupBox2.PerformLayout();
  412. this.ResumeLayout(false);
  413. this.PerformLayout();
  414.  
  415. }
  416.  
  417. #endregion
  418.  
  419. private System.Windows.Forms.Label label1;
  420. private System.Windows.Forms.Label label2;
  421. private System.Windows.Forms.Button btn_Set;
  422. private System.Windows.Forms.TextBox tb_BlockSize;
  423. private System.Windows.Forms.TextBox tb_Epsilon;
  424. private System.Windows.Forms.TextBox tb_MaxDetectedObjects;
  425. private System.Windows.Forms.TextBox tb_MaxIteration;
  426. private System.Windows.Forms.TextBox tb_MinDistance;
  427. private System.Windows.Forms.GroupBox groupBox1;
  428. private System.Windows.Forms.Label label8;
  429. private System.Windows.Forms.Label label7;
  430. private System.Windows.Forms.Label label6;
  431. private System.Windows.Forms.Label label5;
  432. private System.Windows.Forms.Label label3;
  433. private System.Windows.Forms.GroupBox groupBox2;
  434. private System.Windows.Forms.CheckBox chk_ShowImage;
  435. private System.Windows.Forms.TextBox tb_Blue;
  436. private System.Windows.Forms.TextBox tb_Green;
  437. private System.Windows.Forms.TextBox tb_Red;
  438. private System.Windows.Forms.Label label11;
  439. private System.Windows.Forms.Label label10;
  440. private System.Windows.Forms.TextBox tb_DrawThickness;
  441. private System.Windows.Forms.ListBox lb_Detection;
  442. private System.Windows.Forms.Button btn_HighlightSet;
  443. private System.Windows.Forms.Label label12;
  444. private System.Windows.Forms.Label label14;
  445. private System.Windows.Forms.TextBox tb_ZeroZoneSizeX;
  446. private System.Windows.Forms.Label label13;
  447. private System.Windows.Forms.TextBox tb_SearchWindowSizeX;
  448. private System.Windows.Forms.Label label9;
  449. private System.Windows.Forms.TextBox tb_QualityLevel;
  450. private System.Windows.Forms.TextBox tb_ZeroZoneSizeY;
  451. private System.Windows.Forms.TextBox tb_SearchWindowSizeY;
  452. private System.Windows.Forms.Label label4;
  453. private System.Windows.Forms.TextBox tb_DrawSize;
  454. }
  455. }
  456.  
  457.  
  458. // Form1.cs
  459.  
  460. using System;
  461. using System.Drawing;
  462. using System.Windows.Forms;
  463. using Ozeki.Media.MediaHandlers;
  464. using Ozeki.Media.MediaHandlers.Video;
  465. using Ozeki.Media.MediaHandlers.Video.CV;
  466. using Ozeki.Media.MediaHandlers.Video.CV.Data;
  467. using Ozeki.Media.MediaHandlers.Video.CV.Processer;
  468. using Ozeki.Media.Video.Controls;
  469.  
  470. namespace CornerDetection
  471. {
  472. public partial class Form1 : Form
  473. {
  474. WebCamera _webCamera;
  475. MediaConnector _connector;
  476.  
  477. ImageProcesserHandler _imageProcesserHandler;
  478. ICornerDetector _cornerDetector;
  479. FrameCapture _frameCapture;
  480.  
  481. VideoViewerWF _originalView;
  482. VideoViewerWF _processedView;
  483. DrawingImageProvider _originalImageProvider;
  484. DrawingImageProvider _processedImageProvider;
  485.  
  486. public Form1()
  487. {
  488. InitializeComponent();
  489. }
  490.  
  491. void MainForm_Load(object sender, EventArgs e)
  492. {
  493. Init();
  494.  
  495. SetVideoViewers();
  496.  
  497. InitDetectorFields();
  498.  
  499. ConnectWebcam();
  500.  
  501. Start();
  502. }
  503.  
  504. void Init()
  505. {
  506. _frameCapture = new FrameCapture();
  507. _frameCapture.SetInterval(5);
  508.  
  509. _webCamera = WebCamera.GetDefaultDevice();
  510. _connector = new MediaConnector();
  511. _originalImageProvider = new DrawingImageProvider();
  512. _processedImageProvider = new DrawingImageProvider();
  513.  
  514. _cornerDetector = ImageProcesserFactory.CreateCornerDetector();
  515. _cornerDetector.DetectionOccurred += _cornerDetector_DetectionOccurred;
  516.  
  517. _imageProcesserHandler = new ImageProcesserHandler();
  518. _imageProcesserHandler.AddProcesser(_cornerDetector);
  519. }
  520.  
  521. void SetVideoViewers()
  522. {
  523. _originalView = new VideoViewerWF
  524. {
  525. BackColor = Color.Black,
  526. Location = new Point(10, 20),
  527. Size = new Size(320, 240)
  528. };
  529.  
  530. _originalView.SetImageProvider(_originalImageProvider);
  531. Controls.Add(_originalView);
  532.  
  533. _processedView = new VideoViewerWF
  534. {
  535. BackColor = Color.Black,
  536. Location = new Point(350, 20),
  537. Size = new Size(320, 240)
  538. };
  539.  
  540. _processedView.SetImageProvider(_processedImageProvider);
  541. Controls.Add(_processedView);
  542. }
  543.  
  544. void InitDetectorFields()
  545. {
  546. InvokeGUIThread(() =>
  547. {
  548. chk_ShowImage.Checked = _cornerDetector.ShowImage;
  549. tb_Red.Text = _cornerDetector.DrawColor.R.ToString();
  550. tb_Green.Text = _cornerDetector.DrawColor.G.ToString();
  551. tb_Blue.Text = _cornerDetector.DrawColor.B.ToString();
  552. tb_DrawThickness.Text = _cornerDetector.DrawThickness.ToString();
  553.  
  554. tb_BlockSize.Text = _cornerDetector.BlockSize.ToString();
  555. tb_DrawSize.Text = _cornerDetector.DrawSize.ToString();
  556. tb_Epsilon.Text = _cornerDetector.Epsilon.ToString();
  557. tb_MaxDetectedObjects.Text = _cornerDetector.MaxDetectedObjects.ToString();
  558. tb_MaxIteration.Text = _cornerDetector.MaxIteration.ToString();
  559. tb_MinDistance.Text = _cornerDetector.MinDistance.ToString();
  560. tb_QualityLevel.Text = _cornerDetector.QualityLevel.ToString();
  561. tb_SearchWindowSizeX.Text = _cornerDetector.SearchWindowSize.Width.ToString();
  562. tb_SearchWindowSizeY.Text = _cornerDetector.SearchWindowSize.Height.ToString();
  563. tb_ZeroZoneSizeX.Text = _cornerDetector.ZeroZoneSize.Width.ToString();
  564. tb_ZeroZoneSizeY.Text = _cornerDetector.ZeroZoneSize.Height.ToString();
  565. });
  566. }
  567.  
  568. void ConnectWebcam()
  569. {
  570. _connector.Connect(_webCamera, _originalImageProvider);
  571.  
  572. _connector.Connect(_webCamera, _frameCapture);
  573. _connector.Connect(_frameCapture, _imageProcesserHandler);
  574. _connector.Connect(_imageProcesserHandler, _processedImageProvider);
  575. }
  576.  
  577. void Start()
  578. {
  579. _originalView.Start();
  580. _processedView.Start();
  581.  
  582. _frameCapture.Start();
  583. _webCamera.Start();
  584. }
  585.  
  586. void btn_HighlightSet_Click(object sender, EventArgs e)
  587. {
  588. InvokeGUIThread(() =>
  589. {
  590. _cornerDetector.ShowImage = chk_ShowImage.Checked;
  591. _cornerDetector.DrawColor = Color.FromArgb(Int32.Parse(tb_Red.Text), Int32.Parse(tb_Green.Text), Int32.Parse(tb_Blue.Text));
  592. _cornerDetector.DrawSize = Int32.Parse(tb_DrawSize.Text);
  593. _cornerDetector.DrawThickness = Int32.Parse(tb_DrawThickness.Text);
  594. });
  595. }
  596.  
  597. void btn_Set_Click(object sender, EventArgs e)
  598. {
  599. InvokeGUIThread(() =>
  600. {
  601. _cornerDetector.BlockSize = Int32.Parse(tb_BlockSize.Text);
  602. _cornerDetector.Epsilon = Double.Parse(tb_Epsilon.Text);
  603. _cornerDetector.MaxDetectedObjects = Int32.Parse(tb_MaxDetectedObjects.Text);
  604. _cornerDetector.MaxIteration = Int32.Parse(tb_MaxIteration.Text);
  605. _cornerDetector.MinDistance = Int32.Parse(tb_MinDistance.Text);
  606. _cornerDetector.QualityLevel = Double.Parse(tb_QualityLevel.Text);
  607. _cornerDetector.SearchWindowSize = new Size(Int32.Parse(tb_SearchWindowSizeX.Text), Int32.Parse(tb_SearchWindowSizeY.Text));
  608. _cornerDetector.ZeroZoneSize = new Size(Int32.Parse(tb_ZeroZoneSizeX.Text), Int32.Parse(tb_ZeroZoneSizeY.Text));
  609. });
  610. }
  611.  
  612. void _cornerDetector_DetectionOccurred(object sender, CornerDetectedEventArgs e)
  613. {
  614. InvokeGUIThread(() =>
  615. {
  616. lb_Detection.Items.Clear();
  617.  
  618. foreach (var info in e.Info)
  619. {
  620. lb_Detection.Items.Add(info);
  621. }
  622. });
  623. }
  624.  
  625. void InvokeGUIThread(Action action)
  626. {
  627. BeginInvoke(action);
  628. }
  629.  
  630. }
  631. }

URL: http://www.camera-sdk.com/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.