Browse Source

git-svn-id: https://emgucv.svn.sourceforge.net/svnroot/emgucv/trunk@241 d7f09016-e345-0410-b530-edf29a71df78

UWP10
canming 17 years ago
parent
commit
57ed70720b
  1. 13
      Emgu.CV.Test/AutoTestImage.cs
  2. 38
      Emgu.CV.Test/AutoTestVarious.cs
  3. 4
      Emgu.CV/Image.cs
  4. 91
      Emgu.CV/PInvoke/CvInvoke.cs

13
Emgu.CV.Test/AutoTestImage.cs

@ -235,6 +235,19 @@ namespace Emgu.CV.Test
img1.SetValue(new Bgr(255, 0, 0));
Image<Bgr, Byte> img = new Image<Bgr, byte>(800, 800);
img.SetValue(255);
Image<Bgr, Byte> mask = new Image<Bgr, byte>(img.Width, img.Height);
mask.SetRandUniform(new MCvScalar(0, 0, 0), new MCvScalar(255, 255, 255)); //file the mask with random color
DateTime startTime = DateTime.Now;
Image<Bgr, Byte> imgMasked = img.Convert<Byte, Byte>(mask,
delegate(Byte byteFromImg, Byte byteFromMask)
{
return byteFromMask > (Byte) 120 ? byteFromImg : (Byte) 0;
});
Trace.WriteLine(String.Format("Time used: {0} milliseconds", DateTime.Now.Subtract(startTime).TotalMilliseconds));
Assert.IsTrue(img1.Equals(img2));
}

38
Emgu.CV.Test/AutoTestVarious.cs

@ -407,6 +407,35 @@ namespace Emgu.CV.Test
Assert.IsTrue(new Point3D<float>(0.0f, 0.0f, 1.0f).Equals(p3));
}
[Test]
public void TestMatchTemplate()
{
#region prepare synthetic image for testing
int templWidth = 50;
int templHeight = 50;
Point2D<double> templCenter = new Point2D<double>(120, 100);
//Create a random object
Image<Bgr, Byte> randomObj = new Image<Bgr, byte>(templWidth, templHeight);
randomObj.SetRandUniform(new MCvScalar(), new MCvScalar(255, 255, 255));
//Draw the object in image1 center at templCenter;
Image<Bgr, Byte> img = new Image<Bgr, byte>(300, 200);
Rectangle<double> objectLocation = new Rectangle<double>(templCenter, 50, 50);
img.ROI = objectLocation;
randomObj.Copy(img, null);
img.ROI = null;
#endregion
Image<Gray, Single> match = img.MatchTemplate(randomObj, Emgu.CV.CvEnum.TM_TYPE.CV_TM_SQDIFF);
double[] minVal, maxVal;
MCvPoint[] minLoc, maxLoc;
match.MinMax(out minVal, out maxVal, out minLoc, out maxLoc);
Assert.AreEqual(minLoc[0].x, templCenter.X - templWidth / 2);
Assert.AreEqual(minLoc[0].y, templCenter.Y - templHeight / 2);
}
[Test]
public void TestOpticalFlow()
{
@ -474,6 +503,15 @@ namespace Emgu.CV.Test
//Application.Run(new ImageViewer(chessboardImage));
}
[Test]
public void TestFillConvexPolygon()
{
Image<Bgr, Byte> img = new Image<Bgr, byte>(200, 200);
Rectangle<double> rect = new Rectangle<double>(new Point2D<double>(100, 100), 50, 50);
img.Draw((IConvexPolygon<double>)rect, new Bgr(Color.Blue), 0);
//Application.Run(new ImageViewer(img));
}
[Test]
public void TestVideoWriter()
{

4
Emgu.CV/Image.cs

@ -1337,9 +1337,9 @@ namespace Emgu.CV
/// <param name="template">Searched template; must be not greater than the source image and the same data type as the image</param>
/// <param name="method">Specifies the way the template must be compared with image regions </param>
/// <returns>The comparison result: width = this.Width - template.Width + 1; height = this.Height - template.Height + 1 </returns>
public Image<TColor, TDepth> MatchTemplate(Image<TColor, TDepth> template, CvEnum.TM_TYPE method)
public Image<Gray, Single> MatchTemplate(Image<TColor, TDepth> template, CvEnum.TM_TYPE method)
{
Image<TColor, TDepth> res = new Image<TColor, TDepth>(Width - template.Width + 1, Height - template.Height + 1);
Image<Gray, Single> res = new Image<Gray, Single>(Width - template.Width + 1, Height - template.Height + 1);
CvInvoke.cvMatchTemplate(Ptr, template.Ptr, res.Ptr, method);
return res;
}

91
Emgu.CV/PInvoke/CvInvoke.cs

@ -2182,25 +2182,6 @@ namespace Emgu.CV
[DllImport(CV_LIBRARY)]
public static extern MCvBox2D cvFitEllipse2(IntPtr points);
/// <summary>
/// Finds a circumscribed rectangle of the minimal area for 2D point set by building convex hull for the set and applying rotating calipers technique to the hull.
/// </summary>
/// <param name="points">Sequence or array of points</param>
/// <param name="storage">temporary memory storage</param>
/// <returns>a circumscribed rectangle of the minimal area for 2D point set</returns>
[DllImport(CV_LIBRARY)]
public static extern MCvBox2D cvMinAreaRect2(IntPtr points, IntPtr storage);
/// <summary>
/// Finds the minimal circumscribed circle for 2D point set using iterative algorithm. It returns nonzero if the resultant circle contains all the input points and zero otherwise (i.e. algorithm failed)
/// </summary>
/// <param name="points">Sequence or array of 2D points</param>
/// <param name="center">Output parameter. The center of the enclosing circle</param>
/// <param name="radius">Output parameter. The radius of the enclosing circle.</param>
/// <returns>Nonzero if the resultant circle contains all the input points and zero otherwise (i.e. algorithm failed)</returns>
[DllImport(CV_LIBRARY)]
public static extern int cvMinEnclosingCircle(IntPtr points, out MCvPoint2D32f center, out float radius);
/// <summary>
/// The function cvConvexHull2 finds convex hull of 2D point set using Sklansky's algorithm.
/// </summary>
@ -2338,18 +2319,6 @@ namespace Emgu.CV
[DllImport(CV_LIBRARY)]
public static extern void cvInpaint(IntPtr src, IntPtr mask, IntPtr dst, CvEnum.INPAINT_TYPE flags, double inpaintRadius);
/// <summary>
/// Calculates weighted sum of input image image and the accumulator acc so that acc becomes a running average of frame sequence:
/// acc(x,y)=(1-<paramref name="alpha"/>) * acc(x,y) + <paramref name="alpha"/> * image(x,y) if mask(x,y)!=0
/// where <paramref name="alpha"/> regulates update speed (how fast accumulator forgets about previous frames).
/// </summary>
/// <param name="image">Input image, 1- or 3-channel, 8-bit or 32-bit floating point (each channel of multi-channel image is processed independently). </param>
/// <param name="acc">Accumulator of the same number of channels as input image, 32-bit or 64-bit floating-point. </param>
/// <param name="alpha">Weight of input image</param>
/// <param name="mask">Optional operation mask</param>
[DllImport(CV_LIBRARY)]
public static extern void cvRunningAvg(IntPtr image, IntPtr acc, double alpha, IntPtr mask);
/// <summary>
/// Smooths image using one of several methods. Every of the methods has some features and restrictions listed below
/// Blur with no scaling works with single-channel images only and supports accumulation of 8-bit to 16-bit format (similar to cvSobel and cvLaplace) and 32-bit floating point to 32-bit floating-point format.
@ -2493,6 +2462,33 @@ namespace Emgu.CV
return cvPointPolygonTest(contour, pt, measureDist ? 1 : 0);
}
/// <summary>
/// Finds a circumscribed rectangle of the minimal area for 2D point set by building convex hull for the set and applying rotating calipers technique to the hull.
/// </summary>
/// <param name="points">Sequence or array of points</param>
/// <param name="storage">temporary memory storage</param>
/// <returns>a circumscribed rectangle of the minimal area for 2D point set</returns>
[DllImport(CV_LIBRARY)]
public static extern MCvBox2D cvMinAreaRect2(IntPtr points, IntPtr storage);
/// <summary>
/// Finds the minimal circumscribed circle for 2D point set using iterative algorithm. It returns nonzero if the resultant circle contains all the input points and zero otherwise (i.e. algorithm failed)
/// </summary>
/// <param name="points">Sequence or array of 2D points</param>
/// <param name="center">Output parameter. The center of the enclosing circle</param>
/// <param name="radius">Output parameter. The radius of the enclosing circle.</param>
/// <returns>Nonzero if the resultant circle contains all the input points and zero otherwise (i.e. algorithm failed)</returns>
[DllImport(CV_LIBRARY)]
public static extern int cvMinEnclosingCircle(IntPtr points, out MCvPoint2D32f center, out float radius);
/// <summary>
/// Calculates 2D pair-wise geometrical histogram (PGH), described in [Iivarinen97], for the contour. The algorithm considers every pair of the contour edges. The angle between the edges and the minimum/maximum distances are determined for every pair. To do this each of the edges in turn is taken as the base, while the function loops through all the other edges. When the base edge and any other edge are considered, the minimum and maximum distances from the points on the non-base edge and line of the base edge are selected. The angle between the edges defines the row of the histogram in which all the bins that correspond to the distance between the calculated minimum and maximum distances are incremented (that is, the histogram is transposed relatively to [Iivarninen97] definition). The histogram can be used for contour matching
/// </summary>
/// <param name="contour">Input contour. Currently, only integer point coordinates are allowed</param>
/// <param name="hist">Calculated histogram; must be two-dimensional</param>
[DllImport(CV_LIBRARY)]
public static extern void cvCalcPGH(IntPtr contour, IntPtr hist);
/// <summary>
/// Calculates area of the whole contour or contour section.
/// </summary>
@ -3328,6 +3324,7 @@ namespace Emgu.CV
int xOrder,
int yOrder);
#region Accumulation of Background Statistics
/// <summary>
/// Adds the whole image or its selected region to accumulator sum
/// </summary>
@ -3337,6 +3334,38 @@ namespace Emgu.CV
[DllImport(CV_LIBRARY)]
public static extern void cvAcc(IntPtr image, IntPtr sum, IntPtr mask);
/// <summary>
/// Adds the input image image or its selected region, raised to power 2, to the accumulator sqsum
/// </summary>
/// <param name="image">Input image, 1- or 3-channel, 8-bit or 32-bit floating point (each channel of multi-channel image is processed independently)</param>
/// <param name="sqsum">Accumulator of the same number of channels as input image, 32-bit or 64-bit floating-point</param>
/// <param name="mask">Optional operation mask</param>
[DllImport(CV_LIBRARY)]
public static extern void cvSquareAcc(IntPtr image, IntPtr sqsum, IntPtr mask);
/// <summary>
/// Adds product of 2 images or thier selected regions to accumulator acc
/// </summary>
/// <param name="image1">First input image, 1- or 3-channel, 8-bit or 32-bit floating point (each channel of multi-channel image is processed independently)</param>
/// <param name="image2">Second input image, the same format as the first one</param>
/// <param name="acc">Accumulator of the same number of channels as input images, 32-bit or 64-bit floating-point</param>
/// <param name="mask">Optional operation mask</param>
[DllImport(CV_LIBRARY)]
public static extern void cvMultiplyAcc(IntPtr image1, IntPtr image2, IntPtr acc, IntPtr mask);
/// <summary>
/// Calculates weighted sum of input image image and the accumulator acc so that acc becomes a running average of frame sequence:
/// acc(x,y)=(1-<paramref name="alpha"/>) * acc(x,y) + <paramref name="alpha"/> * image(x,y) if mask(x,y)!=0
/// where <paramref name="alpha"/> regulates update speed (how fast accumulator forgets about previous frames).
/// </summary>
/// <param name="image">Input image, 1- or 3-channel, 8-bit or 32-bit floating point (each channel of multi-channel image is processed independently). </param>
/// <param name="acc">Accumulator of the same number of channels as input image, 32-bit or 64-bit floating-point. </param>
/// <param name="alpha">Weight of input image</param>
/// <param name="mask">Optional operation mask</param>
[DllImport(CV_LIBRARY)]
public static extern void cvRunningAvg(IntPtr image, IntPtr acc, double alpha, IntPtr mask);
#endregion
/// <summary>
/// Converts a rotation vector to rotation matrix or vice versa. Rotation vector is a compact representation of rotation matrix. Direction of the rotation vector is the rotation axis and the length of the vector is the rotation angle around the axis. The rotation matrix R, corresponding to the rotation vector r.
/// </summary>

Loading…
Cancel
Save