/ Published in: C#
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!
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!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// Form1.Designer.cs namespace CornerDetection { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); this.label1.Name = "label1"; this.label1.TabIndex = 0; this.label1.Text = "Original image"; // // label2 // this.label2.AutoSize = true; this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); this.label2.Name = "label2"; this.label2.TabIndex = 1; this.label2.Text = "Processed image"; // // btn_Set // this.btn_Set.Name = "btn_Set"; this.btn_Set.TabIndex = 2; this.btn_Set.Text = "Set"; this.btn_Set.UseVisualStyleBackColor = true; // // tb_BlockSize // this.tb_BlockSize.Name = "tb_BlockSize"; this.tb_BlockSize.TabIndex = 3; // // tb_Epsilon // this.tb_Epsilon.Name = "tb_Epsilon"; this.tb_Epsilon.TabIndex = 5; // // tb_MaxDetectedObjects // this.tb_MaxDetectedObjects.Name = "tb_MaxDetectedObjects"; this.tb_MaxDetectedObjects.TabIndex = 6; // // tb_MaxIteration // this.tb_MaxIteration.Name = "tb_MaxIteration"; this.tb_MaxIteration.TabIndex = 7; // // tb_MinDistance // this.tb_MinDistance.Name = "tb_MinDistance"; this.tb_MinDistance.TabIndex = 8; // // groupBox1 // this.groupBox1.Controls.Add(this.tb_ZeroZoneSizeY); this.groupBox1.Controls.Add(this.tb_SearchWindowSizeY); this.groupBox1.Controls.Add(this.label14); this.groupBox1.Controls.Add(this.tb_ZeroZoneSizeX); this.groupBox1.Controls.Add(this.label13); this.groupBox1.Controls.Add(this.tb_SearchWindowSizeX); this.groupBox1.Controls.Add(this.label9); this.groupBox1.Controls.Add(this.tb_QualityLevel); this.groupBox1.Controls.Add(this.label6); this.groupBox1.Controls.Add(this.label5); this.groupBox1.Controls.Add(this.label8); this.groupBox1.Controls.Add(this.label3); this.groupBox1.Controls.Add(this.label7); this.groupBox1.Controls.Add(this.tb_MaxDetectedObjects); this.groupBox1.Controls.Add(this.btn_Set); this.groupBox1.Controls.Add(this.tb_BlockSize); this.groupBox1.Controls.Add(this.tb_MaxIteration); this.groupBox1.Controls.Add(this.tb_MinDistance); this.groupBox1.Controls.Add(this.tb_Epsilon); this.groupBox1.Name = "groupBox1"; this.groupBox1.TabIndex = 12; this.groupBox1.TabStop = false; this.groupBox1.Text = "Settings"; // // tb_ZeroZoneSizeY // this.tb_ZeroZoneSizeY.Name = "tb_ZeroZoneSizeY"; this.tb_ZeroZoneSizeY.TabIndex = 23; // // tb_SearchWindowSizeY // this.tb_SearchWindowSizeY.Name = "tb_SearchWindowSizeY"; this.tb_SearchWindowSizeY.TabIndex = 22; // // label14 // this.label14.AutoSize = true; this.label14.Name = "label14"; this.label14.TabIndex = 21; this.label14.Text = "ZeroZoneSize:"; // // tb_ZeroZoneSizeX // this.tb_ZeroZoneSizeX.Name = "tb_ZeroZoneSizeX"; this.tb_ZeroZoneSizeX.TabIndex = 20; // // label13 // this.label13.AutoSize = true; this.label13.Name = "label13"; this.label13.TabIndex = 19; this.label13.Text = "SearchWindowSize:"; // // tb_SearchWindowSizeX // this.tb_SearchWindowSizeX.Name = "tb_SearchWindowSizeX"; this.tb_SearchWindowSizeX.TabIndex = 18; // // label9 // this.label9.AutoSize = true; this.label9.Name = "label9"; this.label9.TabIndex = 17; this.label9.Text = "QualityLevel:"; // // tb_QualityLevel // this.tb_QualityLevel.Name = "tb_QualityLevel"; this.tb_QualityLevel.TabIndex = 16; // // label6 // this.label6.AutoSize = true; this.label6.Name = "label6"; this.label6.TabIndex = 13; this.label6.Text = "MaxDetectedObjects:"; // // label5 // this.label5.AutoSize = true; this.label5.Name = "label5"; this.label5.TabIndex = 12; this.label5.Text = "Epsilon:"; // // label8 // this.label8.AutoSize = true; this.label8.Name = "label8"; this.label8.TabIndex = 15; this.label8.Text = "MinDistance:"; // // label3 // this.label3.AutoSize = true; this.label3.Name = "label3"; this.label3.TabIndex = 10; this.label3.Text = "BlockSize:"; // // label7 // this.label7.AutoSize = true; this.label7.Name = "label7"; this.label7.TabIndex = 14; this.label7.Text = "MaxIteration:"; // // groupBox2 // this.groupBox2.Controls.Add(this.label4); this.groupBox2.Controls.Add(this.tb_DrawSize); this.groupBox2.Controls.Add(this.btn_HighlightSet); this.groupBox2.Controls.Add(this.label11); this.groupBox2.Controls.Add(this.label10); this.groupBox2.Controls.Add(this.tb_DrawThickness); this.groupBox2.Controls.Add(this.tb_Blue); this.groupBox2.Controls.Add(this.chk_ShowImage); this.groupBox2.Controls.Add(this.tb_Green); this.groupBox2.Controls.Add(this.tb_Red); this.groupBox2.Name = "groupBox2"; this.groupBox2.TabIndex = 13; this.groupBox2.TabStop = false; this.groupBox2.Text = "Highlight"; // // btn_HighlightSet // this.btn_HighlightSet.Name = "btn_HighlightSet"; this.btn_HighlightSet.TabIndex = 19; this.btn_HighlightSet.Text = "Set"; this.btn_HighlightSet.UseVisualStyleBackColor = true; // // label11 // this.label11.AutoSize = true; this.label11.Name = "label11"; this.label11.TabIndex = 18; this.label11.Text = "DrawThickness:"; // // label10 // this.label10.AutoSize = true; this.label10.Name = "label10"; this.label10.TabIndex = 17; this.label10.Text = "RGB:"; // // tb_DrawThickness // this.tb_DrawThickness.Name = "tb_DrawThickness"; this.tb_DrawThickness.TabIndex = 17; // // tb_Blue // this.tb_Blue.Name = "tb_Blue"; this.tb_Blue.TabIndex = 16; // // chk_ShowImage // this.chk_ShowImage.AutoSize = true; this.chk_ShowImage.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; this.chk_ShowImage.Name = "chk_ShowImage"; this.chk_ShowImage.TabIndex = 14; this.chk_ShowImage.Text = "ShowImage:"; this.chk_ShowImage.UseVisualStyleBackColor = true; // // tb_Green // this.tb_Green.Name = "tb_Green"; this.tb_Green.TabIndex = 15; // // tb_Red // this.tb_Red.Name = "tb_Red"; this.tb_Red.TabIndex = 14; // // lb_Detection // this.lb_Detection.FormattingEnabled = true; this.lb_Detection.Name = "lb_Detection"; this.lb_Detection.TabIndex = 14; // // label12 // this.label12.AutoSize = true; this.label12.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238))); this.label12.Name = "label12"; this.label12.TabIndex = 15; this.label12.Text = "Detection info:"; // // label4 // this.label4.AutoSize = true; this.label4.Name = "label4"; this.label4.TabIndex = 21; this.label4.Text = "DrawSize:"; // // tb_DrawSize // this.tb_DrawSize.Name = "tb_DrawSize"; this.tb_DrawSize.TabIndex = 20; // // MainForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.Controls.Add(this.label12); this.Controls.Add(this.lb_Detection); this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox1); this.Controls.Add(this.label2); this.Controls.Add(this.label1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.MaximizeBox = false; this.Name = "MainForm"; this.Text = "Corner Detection"; this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button btn_Set; private System.Windows.Forms.TextBox tb_BlockSize; private System.Windows.Forms.TextBox tb_Epsilon; private System.Windows.Forms.TextBox tb_MaxDetectedObjects; private System.Windows.Forms.TextBox tb_MaxIteration; private System.Windows.Forms.TextBox tb_MinDistance; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Label label8; private System.Windows.Forms.Label label7; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label3; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.CheckBox chk_ShowImage; private System.Windows.Forms.TextBox tb_Blue; private System.Windows.Forms.TextBox tb_Green; private System.Windows.Forms.TextBox tb_Red; private System.Windows.Forms.Label label11; private System.Windows.Forms.Label label10; private System.Windows.Forms.TextBox tb_DrawThickness; private System.Windows.Forms.ListBox lb_Detection; private System.Windows.Forms.Button btn_HighlightSet; private System.Windows.Forms.Label label12; private System.Windows.Forms.Label label14; private System.Windows.Forms.TextBox tb_ZeroZoneSizeX; private System.Windows.Forms.Label label13; private System.Windows.Forms.TextBox tb_SearchWindowSizeX; private System.Windows.Forms.Label label9; private System.Windows.Forms.TextBox tb_QualityLevel; private System.Windows.Forms.TextBox tb_ZeroZoneSizeY; private System.Windows.Forms.TextBox tb_SearchWindowSizeY; private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox tb_DrawSize; } } // Form1.cs using System; using System.Drawing; using System.Windows.Forms; using Ozeki.Media.MediaHandlers; using Ozeki.Media.MediaHandlers.Video; using Ozeki.Media.MediaHandlers.Video.CV; using Ozeki.Media.MediaHandlers.Video.CV.Data; using Ozeki.Media.MediaHandlers.Video.CV.Processer; using Ozeki.Media.Video.Controls; namespace CornerDetection { public partial class Form1 : Form { WebCamera _webCamera; MediaConnector _connector; ImageProcesserHandler _imageProcesserHandler; ICornerDetector _cornerDetector; FrameCapture _frameCapture; VideoViewerWF _originalView; VideoViewerWF _processedView; DrawingImageProvider _originalImageProvider; DrawingImageProvider _processedImageProvider; public Form1() { InitializeComponent(); } void MainForm_Load(object sender, EventArgs e) { Init(); SetVideoViewers(); InitDetectorFields(); ConnectWebcam(); Start(); } void Init() { _frameCapture.SetInterval(5); _webCamera = WebCamera.GetDefaultDevice(); _cornerDetector = ImageProcesserFactory.CreateCornerDetector(); _cornerDetector.DetectionOccurred += _cornerDetector_DetectionOccurred; _imageProcesserHandler.AddProcesser(_cornerDetector); } void SetVideoViewers() { _originalView = new VideoViewerWF { BackColor = Color.Black, }; _originalView.SetImageProvider(_originalImageProvider); Controls.Add(_originalView); _processedView = new VideoViewerWF { BackColor = Color.Black, }; _processedView.SetImageProvider(_processedImageProvider); Controls.Add(_processedView); } void InitDetectorFields() { InvokeGUIThread(() => { tb_Red.Text = _cornerDetector.DrawColor.R.ToString(); tb_Green.Text = _cornerDetector.DrawColor.G.ToString(); tb_Blue.Text = _cornerDetector.DrawColor.B.ToString(); tb_DrawThickness.Text = _cornerDetector.DrawThickness.ToString(); tb_BlockSize.Text = _cornerDetector.BlockSize.ToString(); tb_DrawSize.Text = _cornerDetector.DrawSize.ToString(); tb_Epsilon.Text = _cornerDetector.Epsilon.ToString(); tb_MaxDetectedObjects.Text = _cornerDetector.MaxDetectedObjects.ToString(); tb_MaxIteration.Text = _cornerDetector.MaxIteration.ToString(); tb_MinDistance.Text = _cornerDetector.MinDistance.ToString(); tb_QualityLevel.Text = _cornerDetector.QualityLevel.ToString(); tb_SearchWindowSizeX.Text = _cornerDetector.SearchWindowSize.Width.ToString(); tb_SearchWindowSizeY.Text = _cornerDetector.SearchWindowSize.Height.ToString(); tb_ZeroZoneSizeX.Text = _cornerDetector.ZeroZoneSize.Width.ToString(); tb_ZeroZoneSizeY.Text = _cornerDetector.ZeroZoneSize.Height.ToString(); }); } void ConnectWebcam() { _connector.Connect(_webCamera, _originalImageProvider); _connector.Connect(_webCamera, _frameCapture); _connector.Connect(_frameCapture, _imageProcesserHandler); _connector.Connect(_imageProcesserHandler, _processedImageProvider); } void Start() { _originalView.Start(); _processedView.Start(); _frameCapture.Start(); _webCamera.Start(); } void btn_HighlightSet_Click(object sender, EventArgs e) { InvokeGUIThread(() => { _cornerDetector.DrawColor = Color.FromArgb(Int32.Parse(tb_Red.Text), Int32.Parse(tb_Green.Text), Int32.Parse(tb_Blue.Text)); _cornerDetector.DrawSize = Int32.Parse(tb_DrawSize.Text); _cornerDetector.DrawThickness = Int32.Parse(tb_DrawThickness.Text); }); } void btn_Set_Click(object sender, EventArgs e) { InvokeGUIThread(() => { _cornerDetector.BlockSize = Int32.Parse(tb_BlockSize.Text); _cornerDetector.Epsilon = Double.Parse(tb_Epsilon.Text); _cornerDetector.MaxDetectedObjects = Int32.Parse(tb_MaxDetectedObjects.Text); _cornerDetector.MaxIteration = Int32.Parse(tb_MaxIteration.Text); _cornerDetector.MinDistance = Int32.Parse(tb_MinDistance.Text); _cornerDetector.QualityLevel = Double.Parse(tb_QualityLevel.Text); _cornerDetector.SearchWindowSize = new Size(Int32.Parse(tb_SearchWindowSizeX.Text), Int32.Parse(tb_SearchWindowSizeY.Text)); _cornerDetector.ZeroZoneSize = new Size(Int32.Parse(tb_ZeroZoneSizeX.Text), Int32.Parse(tb_ZeroZoneSizeY.Text)); }); } void _cornerDetector_DetectionOccurred(object sender, CornerDetectedEventArgs e) { InvokeGUIThread(() => { lb_Detection.Items.Clear(); foreach (var info in e.Info) { lb_Detection.Items.Add(info); } }); } void InvokeGUIThread(Action action) { BeginInvoke(action); } } }
URL: http://www.camera-sdk.com/