Ozeki Camera Recorder Stat

Sharpen

By using this method you can clarify your pictures. Sometimes it can happen that the captured image looks out of focus. Where darker tones meet lighter ones sharpening increases the contrast, makes light tones lightened and dark tones even darker. Sharpening makes your photo clearer and sharper, it increases the level of quality.

Important: you should study this article in order to find out how to setup your Windows Forms Application correctly.

Properties

In addition to the previously used functions the Sharpen filter has it's own functions.

Divisor: Lowers the brightness of the image to make it easier to recognize boundaries for objects.

Treshold: Specifies the light treshold where the sharpening will take place.

DynamicDivisorForEdges: This function is responsible for processing the checkbox values to trigger the DynamicDivisorForEdges and the ProcessAlpha transformations if required.

original#
Figure 1 - Original image

original#
Figure 2 - Modified image with sharpen effect

Windows Form  

MainForm.cs

using System;
using System.Windows.Forms;
using Ozeki.Camera;
using Ozeki.Media;

namespace ImageManipulation_WF
{
    public partial class MainForm : Form
    {
        private ICamera _camera;
        private DrawingImageProvider _imageProvider;
        private MediaConnector _connector;

        #region Initialize manipulation and filter
        private ImageManipulation _manipulation;
        private OzSharpen _filter;
        #endregion

        public MainForm()
        {
            InitializeComponent();

            _connector = new MediaConnector();
            _imageProvider = new DrawingImageProvider();
            // Create video viewer UI control

            // Bind the camera image to the UI control
            videoViewer.SetImageProvider(_imageProvider);

            _manipulation = new ImageManipulation();
            _manipulation.Start();

            _filter = new OzSharpen();
        }

        private void btn_Connect_Click(object sender, EventArgs e)
        {
            _camera = new WebCamera();

            if (_camera == null) return;

            _connector.Connect(_camera.VideoChannel, _manipulation);
            _connector.Connect(_manipulation, _imageProvider);

            _camera.Start();
            videoViewer.Start();
        }

        private void btn_Add_Click(object sender, EventArgs e)
        {
            _manipulation.Add(_filter);
        }

        private void btn_Remove_Click(object sender, EventArgs e)
        {
            _manipulation.Remove(_filter);
        }

        private void div_TrackScroll(object sender, EventArgs e)
        {
            {
                var trackBar_div = sender as TrackBar;
                if (trackBar_div != null)
                {
                    var value = trackBar_div.Value;
                    _filter.Divisor = value;
                    lb_div.Text = @"Divisor : " + value;
                }
            }
        }

        private void th_TrackScroll(object sender, EventArgs e)
        {
            {
                var trackBar_th = sender as TrackBar;
                if (trackBar_th != null)
                {
                    var value = trackBar_th.Value;
                    _filter.Treshold = value;
                    lb_th.Text = @"Treshold : " + value;
                }
            }
        }

        private void chk_Event_dde(object sender, EventArgs e)
        {
            var checkBox_dde = sender as CheckBox;
            var isDde = (bool)checkBox_dde.Checked;
            _filter.DynamicDivisorForEdges = isDde;
        }

        private void chk_Event_pa(object sender, EventArgs e)
        {
            var checkBox_pa = sender as CheckBox;
            var isPa = (bool)checkBox_pa.Checked;
            _filter.DynamicDivisorForEdges = isPa;
        }
    }
}
		

Code 1 Sharpen in C#

GUI

MainForm.Designer.cs

			namespace ImageManipulation_WF
{
    partial class MainForm
    {
        /// 
        /// 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.videoViewer = new Ozeki.Media.VideoViewerWF();
            this.btn_Connect = new System.Windows.Forms.Button();
            this.trackBar_div = new System.Windows.Forms.TrackBar();
            this.trackBar_th = new System.Windows.Forms.TrackBar();
            this.lb_div = new System.Windows.Forms.Label();
            this.lb_th = new System.Windows.Forms.Label();
            this.btn_add = new System.Windows.Forms.Button();
            this.btn_remove = new System.Windows.Forms.Button();
            this.groupBox = new System.Windows.Forms.GroupBox();
            this.chk_dde = new System.Windows.Forms.CheckBox();
            this.chk_pa = new System.Windows.Forms.CheckBox();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_div)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_th)).BeginInit();
            this.groupBox.SuspendLayout();
            this.SuspendLayout();
            // 
            // videoViewer
            // 
            this.videoViewer.BackColor = System.Drawing.Color.Black;
            this.videoViewer.FlipMode = Ozeki.Media.FlipMode.None;
            this.videoViewer.FrameStretch = Ozeki.Media.FrameStretch.Uniform;
            this.videoViewer.FullScreenEnabled = true;
            this.videoViewer.Location = new System.Drawing.Point(12, 57);
            this.videoViewer.Name = "videoViewer";
            this.videoViewer.RotateAngle = 0;
            this.videoViewer.Size = new System.Drawing.Size(471, 334);
            this.videoViewer.TabIndex = 0;
            this.videoViewer.Text = "videoViewerWF1";
            // 
            // btn_Connect
            // 
            this.btn_Connect.Location = new System.Drawing.Point(12, 12);
            this.btn_Connect.Name = "btn_Connect";
            this.btn_Connect.Size = new System.Drawing.Size(152, 26);
            this.btn_Connect.TabIndex = 14;
            this.btn_Connect.Text = "Connect to WebCamera";
            this.btn_Connect.UseVisualStyleBackColor = true;
            this.btn_Connect.Click += new System.EventHandler(this.btn_Connect_Click);
            // 
            // trackBar_div
            // 
            this.trackBar_div.Location = new System.Drawing.Point(127, 19);
            this.trackBar_div.Minimum = 1;
            this.trackBar_div.Name = "trackBar_div";
            this.trackBar_div.Size = new System.Drawing.Size(347, 45);
            this.trackBar_div.TabIndex = 16;
            this.trackBar_div.Value = 1;
            this.trackBar_div.Scroll += new System.EventHandler(this.div_TrackScroll);
            // 
            // trackBar_th
            // 
            this.trackBar_th.Location = new System.Drawing.Point(127, 70);
            this.trackBar_th.Maximum = 200;
            this.trackBar_th.Minimum = -280;
            this.trackBar_th.Name = "trackBar_th";
            this.trackBar_th.Size = new System.Drawing.Size(347, 45);
            this.trackBar_th.TabIndex = 17;
            this.trackBar_th.Scroll += new System.EventHandler(this.th_TrackScroll);
            // 
            // lb_div
            // 
            this.lb_div.AutoSize = true;
            this.lb_div.Location = new System.Drawing.Point(47, 19);
            this.lb_div.Name = "lb_div";
            this.lb_div.Size = new System.Drawing.Size(42, 13);
            this.lb_div.TabIndex = 19;
            this.lb_div.Text = "Divisor:";
            // 
            // lb_th
            // 
            this.lb_th.AutoSize = true;
            this.lb_th.Location = new System.Drawing.Point(46, 70);
            this.lb_th.Name = "lb_th";
            this.lb_th.Size = new System.Drawing.Size(51, 13);
            this.lb_th.TabIndex = 20;
            this.lb_th.Text = "Treshold:";
            // 
            // btn_add
            // 
            this.btn_add.Location = new System.Drawing.Point(315, 14);
            this.btn_add.Name = "btn_add";
            this.btn_add.Size = new System.Drawing.Size(75, 23);
            this.btn_add.TabIndex = 21;
            this.btn_add.Text = "Add";
            this.btn_add.UseVisualStyleBackColor = true;
            this.btn_add.Click += new System.EventHandler(this.btn_Add_Click);
            // 
            // btn_remove
            // 
            this.btn_remove.Location = new System.Drawing.Point(408, 14);
            this.btn_remove.Name = "btn_remove";
            this.btn_remove.Size = new System.Drawing.Size(75, 23);
            this.btn_remove.TabIndex = 22;
            this.btn_remove.Text = "Remove";
            this.btn_remove.UseVisualStyleBackColor = true;
            this.btn_remove.Click += new System.EventHandler(this.btn_Remove_Click);
            // 
            // groupBox
            // 
            this.groupBox.Controls.Add(this.chk_dde);
            this.groupBox.Controls.Add(this.chk_pa);
            this.groupBox.Controls.Add(this.lb_th);
            this.groupBox.Controls.Add(this.lb_div);
            this.groupBox.Controls.Add(this.trackBar_th);
            this.groupBox.Controls.Add(this.trackBar_div);
            this.groupBox.Location = new System.Drawing.Point(-1, 411);
            this.groupBox.Name = "groupBox";
            this.groupBox.Size = new System.Drawing.Size(493, 149);
            this.groupBox.TabIndex = 23;
            this.groupBox.TabStop = false;
            this.groupBox.Text = "Sharpen settings:";
            // 
            // chk_dde
            // 
            this.chk_dde.AutoSize = true;
            this.chk_dde.Location = new System.Drawing.Point(49, 110);
            this.chk_dde.Name = "chk_dde";
            this.chk_dde.Size = new System.Drawing.Size(147, 17);
            this.chk_dde.TabIndex = 24;
            this.chk_dde.Text = "Dynamic divisor for edges";
            this.chk_dde.UseVisualStyleBackColor = true;
            this.chk_dde.CheckedChanged += new System.EventHandler(this.chk_Event_dde);
            // 
            // chk_pa
            // 
            this.chk_pa.AutoSize = true;
            this.chk_pa.Location = new System.Drawing.Point(216, 110);
            this.chk_pa.Name = "chk_pa";
            this.chk_pa.Size = new System.Drawing.Size(93, 17);
            this.chk_pa.TabIndex = 25;
            this.chk_pa.Text = "Process alpha";
            this.chk_pa.UseVisualStyleBackColor = true;
            this.chk_pa.CheckedChanged += new System.EventHandler(this.chk_Event_pa);
            // 
            // MainForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(501, 574);
            this.Controls.Add(this.groupBox);
            this.Controls.Add(this.btn_remove);
            this.Controls.Add(this.btn_add);
            this.Controls.Add(this.btn_Connect);
            this.Controls.Add(this.videoViewer);
            this.Name = "MainForm";
            this.Text = "Sharpen";
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_div)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.trackBar_th)).EndInit();
            this.groupBox.ResumeLayout(false);
            this.groupBox.PerformLayout();
            this.ResumeLayout(false);

        }

        #endregion

        private Ozeki.Media.VideoViewerWF videoViewer;
        private System.Windows.Forms.Button btn_Connect;
        private System.Windows.Forms.TrackBar trackBar_div;
        private System.Windows.Forms.TrackBar trackBar_th;
        private System.Windows.Forms.Label lb_div;
        private System.Windows.Forms.Label lb_th;
        private System.Windows.Forms.Button btn_add;
        private System.Windows.Forms.Button btn_remove;
        private System.Windows.Forms.GroupBox groupBox;
        private System.Windows.Forms.CheckBox chk_dde;
        private System.Windows.Forms.CheckBox chk_pa;
    }
}
		

Code 2 Sharpen GUI in C#

Conclusion

With the help of this lecture you can successfully implement sharpen effect with your C# camera application using the Ozeki Camera SDK.

Related Pages

FAQ

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

  1. What kind of developer environment is needed?

    • Microsoft Visual Studio 2010
    • Microsoft .Net Framework 4.0
    • Internet connection
  2. How can I get the URL of the camera?

    You can get the URL from the producer of the camera.

  3. 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.