Browse Source

More functions added for Operation Menu in Image Viewer

git-svn-id: https://emgucv.svn.sourceforge.net/svnroot/emgucv/trunk@70 d7f09016-e345-0410-b530-edf29a71df78
UWP10
canming 17 years ago
parent
commit
bfe1e0ff54
  1. 4
      Emgu.CV.Test/Face.cs
  2. 8
      Emgu.CV/Contour.cs
  3. 9
      Emgu.CV/ExposableMethodAttribute.cs
  4. 142
      Emgu.CV/IImage.cs
  5. BIN
      Emgu.CV/Image.cs
  6. BIN
      Emgu.CV/PInvoke/CvInvoke.cs
  7. 14
      Emgu.CV/UI/ImageBox.cs
  8. 3
      Emgu.CV/UI/ImageProperty.Designer.cs
  9. 24
      Emgu.CV/UI/ImageProperty.cs
  10. 12
      Emgu.CV/UI/ImageViewer.cs
  11. 121
      Emgu.CV/UI/ParamInputDlg.cs
  12. 9
      Emgu.Utils/Operation.cs

4
Emgu.CV.Test/Face.cs

@ -63,7 +63,7 @@ namespace Emgu.CV.Test
private Image<Gray, D> _s;
private Image<Gray, D> _v;
private Histogram _hueHtg;
private Seq<MCvContour> _skinContour;
//private Seq<MCvContour> _skinContour;
private Rectangle<double> _rect;
private HaarCascade _eyeCascade;
@ -231,7 +231,7 @@ namespace Emgu.CV.Test
if (_h != null) _h.Dispose();
if (_s != null) _s.Dispose();
if (_v != null) _v.Dispose();
if (_skinContour != null) _skinContour.Dispose();
//if (_skinContour != null) _skinContour.Dispose();
}
}
}

8
Emgu.CV/Contour.cs

@ -4,8 +4,16 @@ using System.Text;
namespace Emgu.CV
{
/// <summary>
/// Wrapped class for Contour
/// </summary>
public class Contour : Seq<MCvPoint>
{
/// <summary>
/// Craete a contour from the specific IntPtr and storage
/// </summary>
/// <param name="ptr"></param>
/// <param name="storage"></param>
public Contour(IntPtr ptr, MemStorage storage)
: base(ptr, storage)
{

9
Emgu.CV/ExposableMethodAttribute.cs

@ -4,11 +4,17 @@ using System.Text;
namespace Emgu.CV
{
/// <summary>
/// Attribute used by ImageBox to generate Operation Menu
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class ExposableMethodAttribute : System.Attribute
{
private bool _exposable;
/// <summary>
/// Get or Set the Exposable value, if true, this function will be displayed in Operation Menu of ImageBox
/// </summary>
public bool Exposable
{
get
@ -21,6 +27,9 @@ namespace Emgu.CV
}
}
/// <summary>
/// Constructor
/// </summary>
public ExposableMethodAttribute()
{
_exposable = true;

142
Emgu.CV/IImage.cs

@ -5,39 +5,168 @@ using System.Drawing;
namespace Emgu.CV
{
/// <summary>
/// IImage interface
/// </summary>
public interface IImage
{
/// <summary>
/// Convert this image into Bitmap
/// </summary>
/// <returns></returns>
[ExposableMethod(Exposable=false)]
Bitmap AsBitmap();
/// <summary>
/// The width of this image
/// </summary>
int Width
{
[ExposableMethod(Exposable = false)]
get;
}
/// <summary>
/// The height of this image
/// </summary>
int Height
{
[ExposableMethod(Exposable = false)]
get;
}
/// <summary>
/// Inplace compute the complement image
/// </summary>
void _Not();
/// <summary>
/// Inplace compute the minimum of the image pixel with the specific value
/// </summary>
/// <param name="value">the minimun value</param>
void _Min(double value);
/// <summary>
/// Inplace compute the maximum of the image pixel with the specific value
/// </summary>
/// <param name="value"></param>
void _Max(double value);
/// <summary>
/// Inplace perform Erode function for <paramref name="iterations"/>
/// </summary>
/// <param name="iterations">the number of iterations for erode</param>
void _Erode(int iterations);
/// <summary>
/// Inplace perform Dilate function for <paramref name="iterations"/>
/// </summary>
/// <param name="iterations">the number of iterations for dilate</param>
void _Dilate(int iterations);
///<summary>
///The function cvPyrUp performs up-sampling step of Gaussian pyramid decomposition.
///First it upsamples <i>this</i> image by injecting even zero rows and columns and then convolves
///result with the specified filter multiplied by 4 for interpolation.
///So the resulting image is four times larger than the source image.
///</summary>
///<returns> The upsampled image</returns>
IImage PyrUp();
///<summary>
///The function PyrDown performs downsampling step of Gaussian pyramid decomposition.
///First it convolves <i>this</i> image with the specified filter and then downsamples the image
///by rejecting even rows and columns.
///</summary>
///<returns> The downsampled image</returns>
IImage PyrDown();
/// <summary>
/// The function cvLaplace calculates Laplacian of the source image by summing second x- and y- derivatives calculated using Sobel operator:
/// dst(x,y) = d2src/dx2 + d2src/dy2
/// Specifying aperture_size=1 gives the fastest variant that is equal to convolving the image with the following kernel:
///
/// |0 1 0|
/// |1 -4 1|
/// |0 1 0|
/// </summary>
/// <param name="apertureSize">Aperture size </param>
/// <returns>The Laplacian of the image</returns>
IImage Laplace(int apertureSize);
///<summary>
/// Scale the image to the specific size
/// </summary>
///<param name="width">The width of the returned image.</param>
///<param name="height">The height of the returned image.</param>
///<returns>The resized image</returns>
IImage Resize(int width, int height);
///<summary>
/// Scale the image to the specific size: width *= scale; height *= scale
/// </summary>
/// <returns>The scaled image</returns>
IImage Resize(double scale);
///<summary>
/// Find the edges on this image and marked them in the returned image.
///</summary>
///<param name="thresh"> The threshhold to find initial segments of strong edges</param>
///<param name="threshLinking"> The threshold used for edge Linking</param>
///<returns> The edges found by the Canny edge detector</returns>
IImage Canny(MCvScalar thresh, MCvScalar threshLinking);
///<summary> Return a filpped copy of the current image</summary>
///<param name="flipType">The type of the flipping</param>
///<returns> The flipped copy of <i>this</i> image </returns>
IImage Flip(CvEnum.FLIP flipType);
/// <summary>
/// Rotate the image the specified angle
/// </summary>
/// <param name="angle">The angle of rotation in degrees.</param>
/// <param name="background">The color with wich to fill the background</param>
/// <param name="crop">If set to true the image is cropped to its original size, possibly losing corners information. If set to false the result image has different size than original and all rotation information is preserved</param>
/// <returns>The rotated image</returns>
IImage Rotate(double angle, MCvScalar background, bool crop);
/// <summary>
/// performs forward or inverse transform of 1D or 2D floating-point array
/// </summary>
/// <param name="type">Transformation flags</param>
/// <param name="nonzeroRows">Number of nonzero rows to in the source array (in case of forward 2d transform), or a number of rows of interest in the destination array (in case of inverse 2d transform). If the value is negative, zero, or greater than the total number of rows, it is ignored. The parameter can be used to speed up 2d convolution/correlation when computing them via DFT</param>
/// <returns>The result of DFT</returns>
IImage DFT(CvEnum.CV_DXT type, int nonzeroRows);
/// <summary>
/// performs forward or inverse transform of 2D floating-point image
/// </summary>
/// <param name="type">Transformation flags</param>
/// <returns>The result of DCT</returns>
IImage DCT(CvEnum.CV_DCT_TYPE type);
/// <summary>
/// Convert the current image to grayscale image
/// </summary>
/// <returns>The Grayscale image</returns>
IImage ToGray();
IImage Resize(int width, int height);
/// <summary>
/// Convert the current image to depth of Single
/// </summary>
/// <returns>The Single(floating point) image </returns>
IImage ToSingle();
/// <summary>
/// Convert the current image to depth of Byte
/// </summary>
/// <returns>The Byte image </returns>
IImage ToByte();
/// <summary>
/// The type of color for this image
/// </summary>
System.Type TypeOfColor
Type TypeOfColor
{
[ExposableMethod(Exposable = false)]
get;
@ -52,9 +181,18 @@ namespace Emgu.CV
get;
}
/// <summary>
/// Obtain the color from the specific location on the image
/// </summary>
/// <param name="position">The location of the pixel</param>
/// <returns>The color value on the specific <paramref name="position"/></returns>
[ExposableMethod(Exposable = false)]
ColorType GetColor(Point2D<int> position);
/// <summary>
/// Save the image to the specific <paramref name="fileName"/>
/// </summary>
/// <param name="fileName">The file name of the image</param>
[ExposableMethod(Exposable = false)]
void Save(String fileName);
}

BIN
Emgu.CV/Image.cs

BIN
Emgu.CV/PInvoke/CvInvoke.cs

14
Emgu.CV/UI/ImageBox.cs

@ -52,14 +52,22 @@ namespace Emgu.CV.UI
private String OperationStackToString()
{
String CSharpFunction = "public static IImage Function(IImage image)\r\n{{\r\n\t{0}\r\n\treturn image;\r\n}}";
List<String> opStr = new List<string>();
foreach (Operation<IImage> op in _operationStack)
{
opStr.Add(op.ToString());
if (op.Method.ReturnType == typeof(void))
{
opStr.Add(op.ToCode("image")+";");
}
else
{
opStr.Add("image = " + op.ToCode("image")+";");
}
}
String[] sArray = opStr.ToArray();
System.Array.Reverse(sArray);
return String.Join("->", sArray);
return String.Format(CSharpFunction, String.Join("\r\n\t", sArray));
}
private void AddOperationMenuItem()
@ -152,7 +160,7 @@ namespace Emgu.CV.UI
imageProperty1.ImageHeight = _displayedImage.Height;
#region display the color type
System.Type colorType = _displayedImage.TypeOfColor;
Type colorType = _displayedImage.TypeOfColor;
Object[] colorAttributes = colorType.GetCustomAttributes(typeof(ColorInfo), true);
if (colorAttributes.Length > 0)
{

3
Emgu.CV/UI/ImageProperty.Designer.cs

@ -1,5 +1,8 @@
namespace Emgu.CV.UI
{
/// <summary>
/// The control to display image properties
/// </summary>
partial class ImageProperty
{
/// <summary>

24
Emgu.CV/UI/ImageProperty.cs

@ -11,11 +11,17 @@ namespace Emgu.CV.UI
{
public partial class ImageProperty : UserControl
{
/// <summary>
/// Create a ImageProperty control
/// </summary>
public ImageProperty()
{
InitializeComponent();
}
/// <summary>
/// Set the width of the image
/// </summary>
public int ImageWidth
{
set
@ -24,6 +30,9 @@ namespace Emgu.CV.UI
}
}
/// <summary>
/// Set the height of the image
/// </summary>
public int ImageHeight
{
set
@ -32,6 +41,9 @@ namespace Emgu.CV.UI
}
}
/// <summary>
/// Set the Type of the color
/// </summary>
public String ColorType
{
set
@ -40,6 +52,9 @@ namespace Emgu.CV.UI
}
}
/// <summary>
/// Set the mouse position over the image
/// </summary>
public Point2D<int> MousePositionOnImage
{
set
@ -48,6 +63,9 @@ namespace Emgu.CV.UI
}
}
/// <summary>
/// Set the color intensity of the pixel on the image where is mouse is at
/// </summary>
public ColorType ColorIntensity
{
set
@ -57,6 +75,9 @@ namespace Emgu.CV.UI
}
}
/// <summary>
/// Set the Depth of the image
/// </summary>
public System.Type ColorDepth
{
set
@ -65,6 +86,9 @@ namespace Emgu.CV.UI
}
}
/// <summary>
/// Set the description of the operation stack
/// </summary>
public String OperationStackText
{
set

12
Emgu.CV/UI/ImageViewer.cs

@ -8,14 +8,26 @@ using System.Windows.Forms;
namespace Emgu.CV.UI
{
/// <summary>
/// The Image viewer that display IImage
/// </summary>
public partial class ImageViewer : Form
{
/// <summary>
/// Create a ImageViewer from the specific <paramref name="img"/>
/// </summary>
/// <param name="img">The image to be displayed in this viewer</param>
public ImageViewer(IImage img)
{
InitializeComponent();
imageBox1.Image = img;
}
/// <summary>
/// Create a ImageViewer from the specific <paramref name="img"/>, using <paramref name="windowName"/> as window name
/// </summary>
/// <param name="img">The image to be displayed</param>
/// <param name="windowName">The name of the window</param>
public ImageViewer(IImage img, string windowName)
: this(img)
{

121
Emgu.CV/UI/ParamInputDlg.cs

@ -9,6 +9,9 @@ using System.Reflection;
namespace Emgu.CV.UI
{
/// <summary>
/// The dialog to ask user for parameters to the specific method
/// </summary>
public partial class ParamInputDlg : Form
{
private bool _sucessed = false;
@ -104,6 +107,29 @@ namespace Emgu.CV.UI
}
}
private static String ParseParameterName(ParameterInfo param)
{
String name = param.Name;
#region Add space before every upper case character
Char[] nameChars = name.ToCharArray();
List<Char> charList = new List<char>();
foreach (Char c in nameChars)
{
if (c.CompareTo('A') >= 0 && c.CompareTo('Z') <= 0)
{ //upper case char
charList.Add(' ');
}
charList.Add(c);
}
name = new string(charList.ToArray());
#endregion
//convert the first letter to upper case
name = name.Substring(0, 1).ToUpper() + name.Substring(1);
return name;
}
/// <summary>
/// Create a panel for the specific parameter
/// </summary>
@ -116,26 +142,109 @@ namespace Emgu.CV.UI
ParamInputPanel panel = new ParamInputPanel();
panel.Height = 50;
panel.Width = 400;
int textBoxStartX = 100, textBoxStartY = 10;
#region add the label for the parameter
Label paramNameLabel = new Label();
paramNameLabel.Text = param.Name;
paramNameLabel.Text = ParseParameterName(param) + ":" ;
paramNameLabel.AutoSize = true;
panel.Controls.Add(paramNameLabel);
paramNameLabel.Location = new System.Drawing.Point(10, 10);
paramNameLabel.Location = new System.Drawing.Point(10, textBoxStartY);
#endregion
if (paramType.IsEnum)
{
ComboBox combo = new ComboBox();
panel.Controls.Add(combo);
combo.Location = new System.Drawing.Point(textBoxStartX, textBoxStartY);
combo.Items.AddRange(Enum.GetNames(paramType));
combo.SelectedIndex = 0;
if (paramType == typeof(int))
panel.GetParamFunction =
delegate()
{
Object o = null;
try
{
o = Enum.Parse(paramType, combo.SelectedItem.ToString(), true);
}
catch (Exception)
{
return null;
}
return o;
};
} else if (paramType == typeof(bool))
{
//Do something here
ComboBox combo = new ComboBox();
panel.Controls.Add(combo);
combo.Location = new System.Drawing.Point(textBoxStartX, textBoxStartY);
combo.Items.AddRange(new String[] { "True", "False" });
combo.SelectedIndex = 0;
panel.GetParamFunction =
delegate()
{
Object o = null;
try
{
o = combo.SelectedItem.ToString().Equals("True");
}
catch (Exception)
{
return null;
}
return o;
};
}
else if (paramType == typeof(int) || paramType == typeof(double))
{
//Create inpout box for the int paramater
TextBox inputTextBox = new TextBox();
panel.Controls.Add(inputTextBox);
inputTextBox.Location = new System.Drawing.Point(100, 10);
inputTextBox.Location = new System.Drawing.Point(textBoxStartX, textBoxStartY);
inputTextBox.Text = "0";
panel.GetParamFunction =
delegate()
{
Object o = null;
try
{
o = System.Convert.ChangeType(inputTextBox.Text, paramType);
}
catch (Exception)
{
return null;
}
return o;
};
}
else if (paramType == typeof(MCvScalar))
{
TextBox[] inputBoxes = new TextBox[4];
int boxWidth = 40;
//Create input boxes for the scalar value
for (int i = 0; i < inputBoxes.Length; i++)
{
inputBoxes[i] = new TextBox();
panel.Controls.Add(inputBoxes[i]);
inputBoxes[i].Location = new System.Drawing.Point(textBoxStartX + i * (boxWidth + 5), textBoxStartY);
inputBoxes[i].Width = boxWidth;
inputBoxes[i].Text = "0.0";
}
panel.GetParamFunction =
delegate()
{
Object o = null;
try
{
o = System.Convert.ToInt32(inputTextBox.Text);
double[] values = new double[4];
for (int i = 0; i < inputBoxes.Length; i++)
{
values[i] = System.Convert.ToDouble(inputBoxes[i].Text);
}
o = new MCvScalar(values[0], values[1], values[2], values[3]);
}
catch (Exception)
{

9
Emgu.Utils/Operation.cs

@ -41,5 +41,14 @@ namespace Emgu.Reflection
Method.Name,
String.Join(", ", System.Array.ConvertAll<Object, String>(Parameters, System.Convert.ToString)));
}
public String ToCode(String instanceName)
{
String res = String.Format("{0}.{1}({2})",
instanceName,
Method.Name,
String.Join(", ", System.Array.ConvertAll<Object, String>(Parameters, System.Convert.ToString)));
return res;
}
}
}
Loading…
Cancel
Save