Rotate Filter
If you use this filter, you will be able to rotate an image by any degrees. You can also change the background color behind the rotated image using the RGB sliders given below the "Angle" trackbar.
Important: you should study this article in order to find out how to setup your Windows Forms Application correctly.
Properties
Angle: A float type value which represents the value of the angle, which is used to rotate the picture of a camera or video.You are allowed to set any negative or positive value, because this function can handle every value. It divides the current value with 360 degree in order to get the real angle.
FillColor: This method sets the background color of the video image to a specified color given to it. It is composed from 3 integers representing the value of the red, green and blue color coordinates.
Windows Form |
Windows forms version
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 OzRotate _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 OzRotate(); } 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 angle_TrackScroll(object sender, EventArgs e) { { var trackBar_angle = sender as TrackBar; if (trackBar_angle != null) { var value = trackBar_angle.Value; _filter.Angle = value; lb_angle.Text = @"Angle : " + value; } } } private int r, g, b; private void red_TrackScroll(object sender, EventArgs e) { var trackBar_red = sender as TrackBar; if (trackBar_red != null) { var value = trackBar_red.Value; r = value; _filter.FillColor = System.Drawing.Color.FromArgb(r, g, b); lb_red.Text = @"Red : " + value; } } private void green_TrackScroll(object sender, EventArgs e) { var trackBar_green = sender as TrackBar; if (trackBar_green != null) { var value = trackBar_green.Value; g = value; _filter.FillColor = System.Drawing.Color.FromArgb(r, g, b); lb_green.Text = @"Green : " + value; } } private void blue_TrackScroll(object sender, EventArgs e) { var trackBar_blue = sender as TrackBar; if (trackBar_blue != null) { var value = trackBar_blue.Value; b = value; _filter.FillColor = System.Drawing.Color.FromArgb(r, g, b); lb_blue.Text = @"Blue : " + value; } } } }
Windows forms version
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_red = new System.Windows.Forms.TrackBar(); this.trackBar_green = new System.Windows.Forms.TrackBar(); this.lb_red = new System.Windows.Forms.Label(); this.lb_green = 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.lb_blue = new System.Windows.Forms.Label(); this.trackBar_blue = new System.Windows.Forms.TrackBar(); this.lb_vwa = new System.Windows.Forms.Label(); this.trackBar_vwa = new System.Windows.Forms.TrackBar(); this.trackBar_angle = new System.Windows.Forms.TrackBar(); this.lb_angle = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.trackBar_red)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBar_green)).BeginInit(); this.groupBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.trackBar_blue)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBar_vwa)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBar_angle)).BeginInit(); 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_red // this.trackBar_red.Location = new System.Drawing.Point(127, 19); this.trackBar_red.Maximum = 255; this.trackBar_red.Name = "trackBar_red"; this.trackBar_red.Size = new System.Drawing.Size(347, 45); this.trackBar_red.TabIndex = 16; this.trackBar_red.Value = 2; this.trackBar_red.Scroll += new System.EventHandler(this.red_TrackScroll); // // trackBar_green // this.trackBar_green.Location = new System.Drawing.Point(127, 70); this.trackBar_green.Maximum = 255; this.trackBar_green.Name = "trackBar_green"; this.trackBar_green.Size = new System.Drawing.Size(347, 45); this.trackBar_green.TabIndex = 17; this.trackBar_green.Value = 2; this.trackBar_green.Scroll += new System.EventHandler(this.green_TrackScroll); // // lb_red // this.lb_red.AutoSize = true; this.lb_red.Location = new System.Drawing.Point(47, 19); this.lb_red.Name = "lb_red"; this.lb_red.Size = new System.Drawing.Size(30, 13); this.lb_red.TabIndex = 19; this.lb_red.Text = "Red:"; // // lb_green // this.lb_green.AutoSize = true; this.lb_green.Location = new System.Drawing.Point(46, 70); this.lb_green.Name = "lb_green"; this.lb_green.Size = new System.Drawing.Size(39, 13); this.lb_green.TabIndex = 20; this.lb_green.Text = "Green:"; // // 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.lb_blue); this.groupBox.Controls.Add(this.trackBar_blue); this.groupBox.Controls.Add(this.lb_vwa); this.groupBox.Controls.Add(this.trackBar_vwa); this.groupBox.Controls.Add(this.lb_green); this.groupBox.Controls.Add(this.lb_red); this.groupBox.Controls.Add(this.trackBar_green); this.groupBox.Controls.Add(this.trackBar_red); this.groupBox.Location = new System.Drawing.Point(-1, 477); this.groupBox.Name = "groupBox"; this.groupBox.Size = new System.Drawing.Size(493, 174); this.groupBox.TabIndex = 23; this.groupBox.TabStop = false; this.groupBox.Text = "RGB settings:"; // // lb_blue // this.lb_blue.AutoSize = true; this.lb_blue.Location = new System.Drawing.Point(46, 121); this.lb_blue.Name = "lb_blue"; this.lb_blue.Size = new System.Drawing.Size(31, 13); this.lb_blue.TabIndex = 24; this.lb_blue.Text = "Blue:"; // // trackBar_blue // this.trackBar_blue.Location = new System.Drawing.Point(127, 121); this.trackBar_blue.Maximum = 255; this.trackBar_blue.Name = "trackBar_blue"; this.trackBar_blue.Size = new System.Drawing.Size(347, 45); this.trackBar_blue.TabIndex = 23; this.trackBar_blue.Value = 1; this.trackBar_blue.Scroll += new System.EventHandler(this.blue_TrackScroll); // // lb_vwa // this.lb_vwa.AutoSize = true; this.lb_vwa.Location = new System.Drawing.Point(9, 186); this.lb_vwa.Name = "lb_vwa"; this.lb_vwa.Size = new System.Drawing.Size(127, 13); this.lb_vwa.TabIndex = 22; this.lb_vwa.Text = "Vertical waves amplitude:"; // // trackBar_vwa // this.trackBar_vwa.Location = new System.Drawing.Point(159, 186); this.trackBar_vwa.Maximum = 255; this.trackBar_vwa.Minimum = 1; this.trackBar_vwa.Name = "trackBar_vwa"; this.trackBar_vwa.Size = new System.Drawing.Size(315, 45); this.trackBar_vwa.TabIndex = 21; this.trackBar_vwa.Value = 1; // // trackBar_angle // this.trackBar_angle.Location = new System.Drawing.Point(126, 423); this.trackBar_angle.Maximum = 360; this.trackBar_angle.Minimum = -360; this.trackBar_angle.Name = "trackBar_angle"; this.trackBar_angle.Size = new System.Drawing.Size(357, 45); this.trackBar_angle.TabIndex = 24; this.trackBar_angle.Scroll += new System.EventHandler(this.angle_TrackScroll); // // lb_angle // this.lb_angle.AutoSize = true; this.lb_angle.Location = new System.Drawing.Point(45, 423); this.lb_angle.Name = "lb_angle"; this.lb_angle.Size = new System.Drawing.Size(37, 13); this.lb_angle.TabIndex = 25; this.lb_angle.Text = "Angle:"; // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(501, 662); this.Controls.Add(this.lb_angle); this.Controls.Add(this.trackBar_angle); 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 = "Rotate"; ((System.ComponentModel.ISupportInitialize)(this.trackBar_red)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBar_green)).EndInit(); this.groupBox.ResumeLayout(false); this.groupBox.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.trackBar_blue)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBar_vwa)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.trackBar_angle)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private Ozeki.Media.VideoViewerWF videoViewer; private System.Windows.Forms.Button btn_Connect; private System.Windows.Forms.TrackBar trackBar_red; private System.Windows.Forms.TrackBar trackBar_green; private System.Windows.Forms.Label lb_red; private System.Windows.Forms.Label lb_green; private System.Windows.Forms.Button btn_add; private System.Windows.Forms.Button btn_remove; private System.Windows.Forms.GroupBox groupBox; private System.Windows.Forms.Label lb_vwa; private System.Windows.Forms.TrackBar trackBar_vwa; private System.Windows.Forms.TrackBar trackBar_blue; private System.Windows.Forms.TrackBar trackBar_angle; private System.Windows.Forms.Label lb_angle; private System.Windows.Forms.Label lb_blue; } }
Related Pages
Conclusion
With the help of this lecture you can successfully implement rotate filter with your C# camera application using the Ozeki Camera SDK.
FAQ
Below you can find the answers for the most frequently asked questions related to this topic:
-
What kind of developer environment is needed?
- Microsoft Visual Studio 2010
- Microsoft .Net Framework 4.0
- Internet connection
-
How can I get the URL of the camera?
You can get the URL from the producer of the camera.
-
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
- Introduction to image manipulation
- How to implement brightness filter in C#
- How to create channel filtering in C#
- How to create contrast correction in C#
- How to implement gamma correction in C#
- How to implement greyscale effect in C#
- How to implement histogram equalization in C#
- How to accomplish rotate filter in C#
- How to accomplish invert colors in C#
- How to accomplish jitter in C#
- How to create mirror effect in C#
- How to accomplish pixellate in C#
- How to implement rotate channels in C#
- How to implement hue modifier in C#
- How to implement salt and pepper noise in C#
- How to create saturation correction in C#
- How to create sepia effect in C#
- How to implement sharpen in C#
- How to implement simple posterization in C#
- How to create water wave in C#
- How to implement YCbCr in C#