How to measure the width of an object in C#

This lecture demonstrates how you can measure the width of an object (e.g. on a conveyor belt) in C# by using a USB camera. To implement this example, you need to have Ozeki Camera SDK installed, and a reference to OzekiSDK.dll and OzekiComputerVision.dll should be added to your Visual Studio project.

How to measure the width of an object using a USB camera

To establish the connection properly between your application and a USB camera you should apply the same code snippet what you have used in the example (How to connect to an USB camera and display the picture in C#?).

Important:

You should study this article in order to find out how to setup your Windows Forms Application correctly

Getting started

To get started it is recomended to Download and Install the latest version of Ozeki Camera SDK. After installation you can find the example code discussed in this page with full source code in the following location on your harddisk:

Download Ozeki Camera SDK: https://www.camera-sdk.com/https://camera-sdk.com/p_6513-download-onvif-ozeki-camera-sdk-for-c-sharp.html
Windows forms version: C:\Program Files\Ozeki\Ozeki SDK\examples.zip\Examples\Other\WidthMeasurement.zip

To compile this example you will need Microsoft Visual Studio installed on your computer.

To find the implementation of creating the connection between your USB camera device and your application, please visit this site.

In the consrtuctor of the Form1 class you need to initialize the object those you created. These are:

  • the VideoViewerWF _originalView object to manage the video of your camera,
  • the VideoViewerWF _processedView object to display the video of your camera and to mark the object you wish to measure,
  • the IWebCamera _webCamera object to manage your USB camera device,
  • the MediaConnector _connector to create a connection between media objects,
  • the ImageProcesserHandler _imageProcesserHandler to be able to detect an object,
  • the IRectangleDetector _rectangleDetector object to detect a rectangle,

How to use the application:

  1. First, download the SDK and open the example in Visual Studio.
  2. Build your application and it will automatically connect to the default camera of your system.
  3. Then place the webcamera to somewhere (important: during the measurement do not change its distance from the objects you wish to measure).
  4. Take an object to a specific distance from the webcamera, and wait until the application will detect that object.

    Figure 1 - The GUI of the application in C#


  5. Now, press Space button on your keyboard and provide the width of the object (repeat this step 2 or 3 times).
  6. Place an other object to the same place and the application will calculate the width of the object based on the width of the previous object. If the application detects the new object, you can see its size in the Calculated object width (mm) textbox.

    Figure 2 - The GUI of the application in C#

Form1.cs

using System;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Ozeki.Camera;
using Ozeki.Media;
using Ozeki.Vision;

namespace WidthMeasurement
{
    public partial class Form1 : Form
    {
        IWebCamera _webCamera;
        MediaConnector _connector;

        ImageProcesserHandler _imageProcesserHandler;
        IRectangleDetector _rectangleDetector;
        FrameCapture _frameCapture;

        VideoViewerWF _originalView;
        VideoViewerWF _processedView;
        DrawingImageProvider _originalImageProvider;
        DrawingImageProvider _processedImageProvider;

        String _objectName;
        String _widthPixel;
        String _widthMM;
        int _objectCounter;

        public Form1()
        {
            InitializeComponent();            
        }

        void Form1_Load_1(object sender, EventArgs e)
        {
            KeyPreview = true;

            Init();

            SetVideoViewers();

            ConnectWebcam();

            Start();
        }

        void Init()
        {
            _frameCapture = new FrameCapture();
            _frameCapture.SetInterval(5);

            _webCamera = WebCameraFactory.GetDefaultDevice();  
            _connector = new MediaConnector();
            _originalImageProvider = new DrawingImageProvider();
            _processedImageProvider = new DrawingImageProvider();

            _rectangleDetector = ImageProcesserFactory.CreateRectangleDetector();
            _rectangleDetector.DetectionOccurred += _rectangleDetector_DetectionOccurred;

            _imageProcesserHandler = new ImageProcesserHandler();
            _imageProcesserHandler.AddProcesser(_rectangleDetector);
        }

        void SetVideoViewers()
        {
            _originalView = new VideoViewerWF
            {
                BackColor = Color.Black,
                Location = new Point(10, 20),
                Size = new Size(320, 240)
            };

            _originalView.SetImageProvider(_originalImageProvider);
            Controls.Add(_originalView);

            _processedView = new VideoViewerWF
            {
                BackColor = Color.Black,
                Location = new Point(350, 20),
                Size = new Size(320, 240)
            };

            _processedView.SetImageProvider(_processedImageProvider);
            Controls.Add(_processedView);
        }

        void ConnectWebcam()
        {
            _connector.Connect(_webCamera.VideoChannel, _originalImageProvider);

            _connector.Connect(_webCamera.VideoChannel, _frameCapture);
            _connector.Connect(_frameCapture, _imageProcesserHandler);
            _connector.Connect(_imageProcesserHandler, _processedImageProvider);
        }

        void Start()
        {
            _originalView.Start();
            _processedView.Start();

            _frameCapture.Start();
            _webCamera.Start();
        }

        void _rectangleDetector_DetectionOccurred(object sender, RectangleDetectedEventArgs e)
        {
            if (e.Info.Count == 0)
                return;

            InvokeGUIThread(() =>
            {
                var rectangle = e.Info.Last();
                tb_Pixels.Text = Math.Round(rectangle.Size.Width).ToString();

                _widthPixel = Math.Round(rectangle.Size.Width).ToString();

                tb_MeasuredPixels.Text = _widthPixel;

                try
                {
                    var calculated = float.Parse(tb_Average.Text)*float.Parse(_widthPixel);
                    tb_MeasuredMM.Text = calculated.ToString();
                }
                catch(Exception ex){}
            });
        }

        void InvokeGUIThread(Action action)
        {
            BeginInvoke(action);
        }

        void Form1_KeyPress(object sender, KeyPressEventArgs e)
        {
            var keychar = e.KeyChar;

            if (Char.IsWhiteSpace(keychar))
            {
                var videoData = _originalImageProvider.CurrentVideoData;

                _connector.Disconnect(_frameCapture, _imageProcesserHandler);

                _imageProcesserHandler.ProcessImage(videoData);

                InvokeGUIThread(() =>
                {
                    tb_MM.Enabled = true;
                    bt_Save.Enabled = true;
                    bt_Cancel.Enabled = true;
                });
            }
        }

        void bt_Save_Click(object sender, EventArgs e)
        {
            float isFloat;
            if (float.TryParse(tb_MM.Text, out isFloat) && float.TryParse(_widthPixel, out isFloat))
            {
                InvokeGUIThread(() =>
                {
                    tb_MM.Enabled = false;
                    bt_Save.Enabled = false;
                    bt_Cancel.Enabled = false;
                });

                _objectCounter++;
                _objectName = "Object" + _objectCounter;

                _widthMM = tb_MM.Text;
                dataGridView1.Rows.Add(_objectName, _widthPixel, _widthMM, "Delete");

                tb_MM.Text = String.Empty;

                CalculateAverage();

                _connector.Connect(_frameCapture, _imageProcesserHandler);
            }           
        }

        void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                int selectedIndex = dataGridView1.CurrentCell.RowIndex;
                if (selectedIndex > -1)
                {
                    dataGridView1.Rows.RemoveAt(selectedIndex);
                    dataGridView1.Refresh();
                    CalculateAverage();
                }
            }
        }

        void CalculateAverage()
        {
            int divisor = 0;
            float sum = 0;

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                var mm = float.Parse(row.Cells[2].Value.ToString());
                var pixel = float.Parse(row.Cells[1].Value.ToString());

                sum += mm / pixel;

                divisor++;
            }

            float average = sum / divisor;
            InvokeGUIThread(() =>
            {
                tb_Average.Text = Math.Round(average, 2).ToString(); 
            });
        }

        void LinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            var link = new LinkLabel.Link { LinkData = "http://www.camera-sdk.com/" };

            if (link.LinkData != null) Process.Start(link.LinkData as string);
        }

        void bt_Cancel_Click(object sender, EventArgs e)
        {
            InvokeGUIThread(() =>
            {
                bt_Cancel.Enabled = false;
                bt_Save.Enabled = false;
                tb_MM.Enabled = false;
                tb_MM.Text = String.Empty;
            });

            _connector.Connect(_frameCapture, _imageProcesserHandler);
        }
    }
}
	

Code 1 - Code example for width measurement in C#

Form1.Designer.cs

namespace WidthMeasurement
{
    partial class Form1
    {
        /// 
        /// Required designer variable.
        /// 
        private System.ComponentModel.IContainer components = null;

        /// 
        /// Clean up any resources being used.
        /// 
        /// true if managed resources should be disposed; otherwise, false.
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// 
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// 
        private void InitializeComponent()
        {
            this.label2 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.gb_Calibrate = new System.Windows.Forms.GroupBox();
            this.bt_Save = new System.Windows.Forms.Button();
            this.tb_MM = new System.Windows.Forms.TextBox();
            this.tb_Pixels = new System.Windows.Forms.TextBox();
            this.label8 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.panel1 = new System.Windows.Forms.Panel();
            this.label10 = new System.Windows.Forms.Label();
            this.tb_Average = new System.Windows.Forms.TextBox();
            this.label5 = new System.Windows.Forms.Label();
            this.label4 = new System.Windows.Forms.Label();
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.ObjectName = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.InPixel = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.InMM = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Delete = new System.Windows.Forms.DataGridViewButtonColumn();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.tb_MeasuredMM = new System.Windows.Forms.TextBox();
            this.tb_MeasuredPixels = new System.Windows.Forms.TextBox();
            this.label9 = new System.Windows.Forms.Label();
            this.label7 = new System.Windows.Forms.Label();
            this.label11 = new System.Windows.Forms.Label();
            this.LinkLabel = new System.Windows.Forms.LinkLabel();
            this.label12 = new System.Windows.Forms.Label();
            this.bt_Cancel = new System.Windows.Forms.Button();
            this.gb_Calibrate.SuspendLayout();
            this.groupBox1.SuspendLayout();
            this.panel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.groupBox2.SuspendLayout();
            this.SuspendLayout();
            // 
            // 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.Location = new System.Drawing.Point(372, 259);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(103, 13);
            this.label2.TabIndex = 31;
            this.label2.Text = "Processed image";
            // 
            // 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.Location = new System.Drawing.Point(32, 259);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(87, 13);
            this.label1.TabIndex = 30;
            this.label1.Text = "Original image";
            // 
            // gb_Calibrate
            // 
            this.gb_Calibrate.Controls.Add(this.bt_Cancel);
            this.gb_Calibrate.Controls.Add(this.bt_Save);
            this.gb_Calibrate.Controls.Add(this.tb_MM);
            this.gb_Calibrate.Controls.Add(this.tb_Pixels);
            this.gb_Calibrate.Controls.Add(this.label8);
            this.gb_Calibrate.Controls.Add(this.label6);
            this.gb_Calibrate.Controls.Add(this.label3);
            this.gb_Calibrate.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.gb_Calibrate.Location = new System.Drawing.Point(24, 294);
            this.gb_Calibrate.Name = "gb_Calibrate";
            this.gb_Calibrate.Size = new System.Drawing.Size(648, 159);
            this.gb_Calibrate.TabIndex = 36;
            this.gb_Calibrate.TabStop = false;
            this.gb_Calibrate.Text = "Calibrate";
            // 
            // bt_Save
            // 
            this.bt_Save.Enabled = false;
            this.bt_Save.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.bt_Save.Location = new System.Drawing.Point(11, 116);
            this.bt_Save.Name = "bt_Save";
            this.bt_Save.Size = new System.Drawing.Size(75, 23);
            this.bt_Save.TabIndex = 5;
            this.bt_Save.Text = "Save";
            this.bt_Save.UseVisualStyleBackColor = true;
            this.bt_Save.Click += new System.EventHandler(this.bt_Save_Click);
            // 
            // tb_MM
            // 
            this.tb_MM.Enabled = false;
            this.tb_MM.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.tb_MM.Location = new System.Drawing.Point(281, 85);
            this.tb_MM.Name = "tb_MM";
            this.tb_MM.Size = new System.Drawing.Size(100, 24);
            this.tb_MM.TabIndex = 4;
            // 
            // tb_Pixels
            // 
            this.tb_Pixels.Enabled = false;
            this.tb_Pixels.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.tb_Pixels.Location = new System.Drawing.Point(281, 56);
            this.tb_Pixels.Name = "tb_Pixels";
            this.tb_Pixels.Size = new System.Drawing.Size(100, 24);
            this.tb_Pixels.TabIndex = 3;
            // 
            // label8
            // 
            this.label8.AutoSize = true;
            this.label8.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.label8.Location = new System.Drawing.Point(8, 85);
            this.label8.Name = "label8";
            this.label8.Size = new System.Drawing.Size(241, 18);
            this.label8.TabIndex = 2;
            this.label8.Text = "(3) Enter width in millimetres (mm): ";
            // 
            // label6
            // 
            this.label6.AutoSize = true;
            this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.label6.Location = new System.Drawing.Point(6, 56);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(189, 18);
            this.label6.TabIndex = 1;
            this.label6.Text = "(2) Measured width (pixels):";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.label3.Location = new System.Drawing.Point(6, 24);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(245, 18);
            this.label3.TabIndex = 0;
            this.label3.Text = "(1) Press [SPACE] to take snapshot";
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.panel1);
            this.groupBox1.Controls.Add(this.dataGridView1);
            this.groupBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.groupBox1.Location = new System.Drawing.Point(678, 297);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(450, 329);
            this.groupBox1.TabIndex = 37;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Reference objects";
            // 
            // panel1
            // 
            this.panel1.BackColor = System.Drawing.SystemColors.AppWorkspace;
            this.panel1.Controls.Add(this.label10);
            this.panel1.Controls.Add(this.tb_Average);
            this.panel1.Controls.Add(this.label5);
            this.panel1.Controls.Add(this.label4);
            this.panel1.Location = new System.Drawing.Point(3, 195);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(444, 128);
            this.panel1.TabIndex = 1;
            // 
            // label10
            // 
            this.label10.AutoSize = true;
            this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.label10.Location = new System.Drawing.Point(154, 39);
            this.label10.Name = "label10";
            this.label10.Size = new System.Drawing.Size(38, 16);
            this.label10.TabIndex = 3;
            this.label10.Text = "(mm)";
            // 
            // tb_Avarage
            // 
            this.tb_Average.BackColor = System.Drawing.Color.White;
            this.tb_Average.Enabled = false;
            this.tb_Average.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.tb_Average.Location = new System.Drawing.Point(61, 36);
            this.tb_Average.Name = "tb_Avarage";
            this.tb_Average.Size = new System.Drawing.Size(87, 22);
            this.tb_Average.TabIndex = 2;
            // 
            // label5
            // 
            this.label5.AutoSize = true;
            this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.label5.Location = new System.Drawing.Point(5, 39);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(59, 16);
            this.label5.TabIndex = 1;
            this.label5.Text = "1 pixel = ";
            // 
            // label4
            // 
            this.label4.AutoSize = true;
            this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Underline, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.label4.Location = new System.Drawing.Point(4, 4);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(144, 20);
            this.label4.TabIndex = 0;
            this.label4.Text = "Avarage pixel width";
            // 
            // dataGridView1
            // 
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.AllowUserToDeleteRows = false;
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.ObjectName,
            this.InPixel,
            this.InMM,
            this.Delete});
            this.dataGridView1.Location = new System.Drawing.Point(3, 16);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.Size = new System.Drawing.Size(444, 176);
            this.dataGridView1.TabIndex = 0;
            this.dataGridView1.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellContentClick_1);
            // 
            // ObjectName
            // 
            this.ObjectName.HeaderText = "Name";
            this.ObjectName.Name = "ObjectName";
            this.ObjectName.ReadOnly = true;
            // 
            // InPixel
            // 
            this.InPixel.HeaderText = "Width in pixel";
            this.InPixel.Name = "InPixel";
            this.InPixel.ReadOnly = true;
            // 
            // InMM
            // 
            this.InMM.HeaderText = "Width in mm";
            this.InMM.Name = "InMM";
            this.InMM.ReadOnly = true;
            // 
            // Delete
            // 
            this.Delete.HeaderText = "Delete";
            this.Delete.Name = "Delete";
            this.Delete.ReadOnly = true;
            this.Delete.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.Delete.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.tb_MeasuredMM);
            this.groupBox2.Controls.Add(this.tb_MeasuredPixels);
            this.groupBox2.Controls.Add(this.label9);
            this.groupBox2.Controls.Add(this.label7);
            this.groupBox2.Location = new System.Drawing.Point(24, 460);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(648, 166);
            this.groupBox2.TabIndex = 38;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Measure";
            // 
            // tb_MeasuredMM
            // 
            this.tb_MeasuredMM.Enabled = false;
            this.tb_MeasuredMM.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.tb_MeasuredMM.Location = new System.Drawing.Point(281, 49);
            this.tb_MeasuredMM.Name = "tb_MeasuredMM";
            this.tb_MeasuredMM.Size = new System.Drawing.Size(100, 24);
            this.tb_MeasuredMM.TabIndex = 4;
            this.tb_MeasuredMM.Text = "-";
            // 
            // tb_MeasuredPixels
            // 
            this.tb_MeasuredPixels.Enabled = false;
            this.tb_MeasuredPixels.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.tb_MeasuredPixels.Location = new System.Drawing.Point(281, 18);
            this.tb_MeasuredPixels.Name = "tb_MeasuredPixels";
            this.tb_MeasuredPixels.Size = new System.Drawing.Size(100, 24);
            this.tb_MeasuredPixels.TabIndex = 3;
            this.tb_MeasuredPixels.Text = "-";
            // 
            // label9
            // 
            this.label9.AutoSize = true;
            this.label9.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.label9.Location = new System.Drawing.Point(7, 47);
            this.label9.Name = "label9";
            this.label9.Size = new System.Drawing.Size(229, 18);
            this.label9.TabIndex = 2;
            this.label9.Text = "(2) Calculated object width (mm): ";
            // 
            // label7
            // 
            this.label7.AutoSize = true;
            this.label7.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.label7.Location = new System.Drawing.Point(6, 16);
            this.label7.Name = "label7";
            this.label7.Size = new System.Drawing.Size(230, 18);
            this.label7.TabIndex = 1;
            this.label7.Text = "(1) Detected object width (pixels): ";
            // 
            // label11
            // 
            this.label11.AutoSize = true;
            this.label11.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.label11.Location = new System.Drawing.Point(685, 80);
            this.label11.Name = "label11";
            this.label11.Size = new System.Drawing.Size(215, 20);
            this.label11.TabIndex = 41;
            this.label11.Text = "Width measurement example";
            // 
            // LinkLabel
            // 
            this.LinkLabel.AutoSize = true;
            this.LinkLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.LinkLabel.Location = new System.Drawing.Point(685, 51);
            this.LinkLabel.Name = "LinkLabel";
            this.LinkLabel.Size = new System.Drawing.Size(163, 20);
            this.LinkLabel.TabIndex = 40;
            this.LinkLabel.TabStop = true;
            this.LinkLabel.Text = "www.camera-sdk.com";
            this.LinkLabel.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.LinkLabel_LinkClicked);
            // 
            // label12
            // 
            this.label12.AutoSize = true;
            this.label12.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.label12.Location = new System.Drawing.Point(685, 20);
            this.label12.Name = "label12";
            this.label12.Size = new System.Drawing.Size(179, 24);
            this.label12.TabIndex = 39;
            this.label12.Text = "OZEKI Camera SDK";
            // 
            // bt_Cancel
            // 
            this.bt_Cancel.Enabled = false;
            this.bt_Cancel.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
            this.bt_Cancel.Location = new System.Drawing.Point(92, 116);
            this.bt_Cancel.Name = "bt_Cancel";
            this.bt_Cancel.Size = new System.Drawing.Size(75, 23);
            this.bt_Cancel.TabIndex = 6;
            this.bt_Cancel.Text = "Cancel";
            this.bt_Cancel.UseVisualStyleBackColor = true;
            this.bt_Cancel.Click += new System.EventHandler(this.bt_Cancel_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(1143, 641);
            this.Controls.Add(this.label11);
            this.Controls.Add(this.LinkLabel);
            this.Controls.Add(this.label12);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.gb_Calibrate);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Name = "Form1";
            this.Text = "Width measurement";
            this.Load += new System.EventHandler(this.Form1_Load_1);
            this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Form1_KeyPress);
            this.gb_Calibrate.ResumeLayout(false);
            this.gb_Calibrate.PerformLayout();
            this.groupBox1.ResumeLayout(false);
            this.panel1.ResumeLayout(false);
            this.panel1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.GroupBox gb_Calibrate;
        private System.Windows.Forms.Button bt_Save;
        private System.Windows.Forms.TextBox tb_MM;
        private System.Windows.Forms.TextBox tb_Pixels;
        private System.Windows.Forms.Label label8;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.DataGridView dataGridView1;
        private System.Windows.Forms.DataGridViewTextBoxColumn ObjectName;
        private System.Windows.Forms.DataGridViewTextBoxColumn InPixel;
        private System.Windows.Forms.DataGridViewTextBoxColumn InMM;
        private System.Windows.Forms.DataGridViewButtonColumn Delete;
        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.TextBox tb_Average;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.TextBox tb_MeasuredMM;
        private System.Windows.Forms.TextBox tb_MeasuredPixels;
        private System.Windows.Forms.Label label9;
        private System.Windows.Forms.Label label7;
        private System.Windows.Forms.Label label10;
        private System.Windows.Forms.Label label11;
        private System.Windows.Forms.LinkLabel LinkLabel;
        private System.Windows.Forms.Label label12;
        private System.Windows.Forms.Button bt_Cancel;
    }
}
	

Code 2 - GUI example in C#

Related Pages

FAQ

Below you can find the answers for the most frequently asked questions related to this topic:

  1. How can I get the URL of the camera?

    You can get the URL from the producer of the camera. (In the 10th tutorial you can find information on how to create an own IP camera discoverer program.)

  2. I have not managed to build the solution. How to solve it?

    • Please set the Target framework property of the project to .NET 4.0.
    • You should add the OzekiSDK.dll to the references of the solution.
    • Please import the missing classes.

More information