本文整理汇总了C#中Emgu.CV.MemStorage.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# MemStorage.Clear方法的具体用法?C# MemStorage.Clear怎么用?C# MemStorage.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Emgu.CV.MemStorage
的用法示例。
在下文中一共展示了MemStorage.Clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessFrame
private void ProcessFrame(object sender, EventArgs e)
{
using (MemStorage storage = new MemStorage()) //create storage for motion components
{
Image<Bgr, Byte> image = _capture.QuerySmallFrame().PyrUp(); //reduce noise from the image
capturedImageBox.Image = image;
//update the motion history
_motionHistory.Update(image.Convert<Gray, Byte>());
#region get a copy of the motion mask and enhance its color
Image<Gray, Byte> motionMask = _motionHistory.Mask;
double[] minValues, maxValues;
System.Drawing.Point[] minLoc, maxLoc;
motionMask.MinMax(out minValues, out maxValues, out minLoc, out maxLoc);
motionMask._Mul(255.0 / maxValues[0]);
#endregion
//create the motion image
Image<Bgr, Byte> motionImage = new Image<Bgr, byte>(motionMask.Size);
//display the motion pixels in blue (first channel)
motionImage[0] = motionMask;
//Threshold to define a motion area, reduce the value to detect smaller motion
double minArea = 100;
storage.Clear(); //clear the storage
Seq<MCvConnectedComp> motionComponents = _motionHistory.GetMotionComponents(storage);
//iterate through each of the motion component
foreach (MCvConnectedComp comp in motionComponents)
{
//reject the components that have small area;
if (comp.area < minArea) continue;
// find the angle and motion pixel count of the specific area
double angle, motionPixelCount;
_motionHistory.MotionInfo(comp.rect, out angle, out motionPixelCount);
//reject the area that contains too few motion
if (motionPixelCount < comp.area * 0.05) continue;
//Draw each individual motion in red
DrawMotion(motionImage, comp.rect, angle, new Bgr(Color.Red));
}
// find and draw the overall motion angle
double overallAngle, overallMotionPixelCount;
_motionHistory.MotionInfo(motionMask.ROI, out overallAngle, out overallMotionPixelCount);
DrawMotion(motionImage, motionMask.ROI, overallAngle, new Bgr(Color.Green));
//Display the amount of motions found on the current image
UpdateText(String.Format("Total Motions found: {0}; Motion Pixel count: {1}", motionComponents.Total, overallMotionPixelCount));
//Display the image of the motion
motionImageBox.Image = motionImage;
}
}
示例2: ProcessFrame
private void ProcessFrame( object sender, EventArgs e)
{
using (MemStorage storage = new MemStorage()) //create storage for motion components
{
Image<Bgr, Byte> image = _capture.QuerySmallFrame().PyrUp();//capturing a frame.
Image<Bgr, Byte> cloned = image.Clone();//creating a copy of orginal image
cloned = image.Resize(320, 240);//setting the resolution to 320 x 240
capturedImageBox.Image = image;
//Setting of region of interest
//x1=get point x1
// y1=get point y1
//x2=get point x2
// y2=get point y2
//height=y1-y2
//width=x1-x2
//arg of rectangle are (x1,y1,width,height)
image.ROI = new System.Drawing.Rectangle(10, 20, 300, 200);
_motionHistory.Update(image.Convert<Gray, Byte>());//update the motion history
#region get a copy of the motion mask and enhance its color
Image<Gray, Byte> motionMask = _motionHistory.Mask;
double[] minValues, maxValues;
System.Drawing.Point[] minLoc, maxLoc;
motionMask.MinMax(out minValues, out maxValues, out minLoc, out maxLoc);
motionMask._Mul(255.0 / maxValues[0]);
#endregion
//create the motion image
Image<Bgr, Byte> motionImage = new Image<Bgr, byte>(motionMask.Size);
//display the motion pixels in blue (first channel)
motionImage[0] = motionMask;
//Threshold to define a motion area, reduce the value to detect smaller motion
double minArea = 100;
storage.Clear(); //clear the storage
Seq<MCvConnectedComp> motionComponents = _motionHistory.GetMotionComponents(storage);
//iterate through each of the motion component
foreach (MCvConnectedComp comp in motionComponents)
{
//reject the components that have small area;
if (comp.area < minArea) continue;
// find the angle and motion pixel count of the specific area
double angle, motionPixelCount;
_motionHistory.MotionInfo(comp.rect, out angle, out motionPixelCount);
//reject the area that contains too few motion
if (motionPixelCount < comp.area * 0.05) continue;
//Draw each individual motion in red
DrawMotion(motionImage, comp.rect, angle, new Bgr(Color.Red));
}
// find and draw the overall motion angle
double overallAngle, overallMotionPixelCount;
_motionHistory.MotionInfo(motionMask.ROI, out overallAngle, out overallMotionPixelCount);
DrawMotion(motionImage, motionMask.ROI, overallAngle, new Bgr(Color.Green));
//Display the amount of motions found on the current image
UpdateText(String.Format("Total Motions found: {0}; Motion Pixel count: {1}", motionComponents.Total, overallMotionPixelCount));
string s1;
string s2;
//creating folder--single folder is created with name-motion.you can change name of folder according to you.
string activeDir = @"d:\";
//Create a new subfolder under the current active folder
string newPath = System.IO.Path.Combine(activeDir, "intro123");
activeDir = @newPath;
string newPath1 = System.IO.Path.Combine(activeDir, "video");
string newPath2 = System.IO.Path.Combine(activeDir, "streaming");
// Create the subfolder
System.IO.Directory.CreateDirectory(newPath1);
System.IO.Directory.CreateDirectory(newPath2);
thershold = 1000;
if (overallMotionPixelCount>thershold)//check minimium threshold for consider motion.
{
s1 = String.Format("d:/intro123/video/{0}.jpg", i);
s2 = String.Format("d:/intro123/streaming/{0}.jpg", i);//formatting the string as e:/images/1.jpg etc
CvInvoke.cvSaveImage(s1, cloned.Ptr );
CvInvoke.cvSaveImage(s2, cloned.Ptr);//saving the image
i++;//incrementing the pic counter
}
//Display the image of the motion
motionImageBox.Image = motionImage;
}
}
示例3: ProcessFrame
//motion detection processing
private Image<Bgr, Byte> ProcessFrame(Image<Bgr, Byte> image)
{
// using (Image<Bgr, Byte> image = grabber.QueryFrame().Resize(320, 240, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC))
using (MemStorage storage = new MemStorage()) //create storage for motion components
{
if (_forgroundDetector == null)
{
//_forgroundDetector = new BGCodeBookModel<Bgr>();
// _forgroundDetector = new FGDetector<Bgr>(Emgu.CV.CvEnum.FORGROUND_DETECTOR_TYPE.FGD);
_forgroundDetector = new BGStatModel<Bgr>(image, Emgu.CV.CvEnum.BG_STAT_TYPE.FGD_STAT_MODEL);
}
_forgroundDetector.Update(image);
// imageBoxFrameGrabber.Image = image;
//update the motion history
_motionHistory.Update(_forgroundDetector.ForgroundMask);
#region get a copy of the motion mask and enhance its color
double[] minValues, maxValues;
Point[] minLoc, maxLoc;
_motionHistory.Mask.MinMax(out minValues, out maxValues, out minLoc, out maxLoc);
Image<Gray, Byte> motionMask = _motionHistory.Mask.Mul(255.0 / maxValues[0]);
#endregion
//create the motion image
Image<Bgr, Byte> motionImage = new Image<Bgr, byte>(motionMask.Size);
//display the motion pixels in blue (first channel)
motionImage[0] = motionMask;
//Threshold to define a motion area, reduce the value to detect smaller motion
double minArea = 100;
storage.Clear(); //clear the storage
Seq<MCvConnectedComp> motionComponents = _motionHistory.GetMotionComponents(storage);
if (showGridLines)
{
LineSegment2D line = new LineSegment2D(new Point(0, 169), new Point(520, 169));
LineSegment2D line2 = new LineSegment2D(new Point(259, 0), new Point(259, 340));
image.Draw(line, new Bgr(Color.White), 2);
image.Draw(line2, new Bgr(Color.White), 2);
}
if (displayPosNum)
{
for (int i = 0; i < dsPos.Tables[0].Rows.Count; i++)
{
if (showPos)
image.Draw("# " + dsPos.Tables[0].Rows[i][0].ToString(), ref font, new Point(int.Parse(dsPos.Tables[0].Rows[i][1].ToString()) - 120, int.Parse(dsPos.Tables[0].Rows[i][2].ToString()) - 50), new Bgr(Color.Yellow));
if (showNames)
image.Draw(dsPos.Tables[0].Rows[i][3].ToString(), ref font, new Point(int.Parse(dsPos.Tables[0].Rows[i][1].ToString()) - 120, int.Parse(dsPos.Tables[0].Rows[i][2].ToString()) - 70), new Bgr(Color.Yellow));
}
}
if (red1 && red1cnt < 100)
{
red1cnt++;
image.Draw(new Rectangle(0, 0, 255, 165), new Bgr(Color.Red), 3);
if (red1cnt == 99)
{
red1 = false;
red1cnt = 0;
}
}
if (red2 && red2cnt < 100)
{
red2cnt++;
image.Draw(new Rectangle(262, 0, 257, 167), new Bgr(Color.Red), 3);
if (red2cnt == 99)
{
red2 = false;
red2cnt = 0;
}
}
if (red3 && red3cnt < 100)
{
red3cnt++;
image.Draw(new Rectangle(0, 170, 260, 170), new Bgr(Color.Red), 3);
if (red3cnt == 99)
{
red3 = false;
red3cnt = 0;
}
}
if (red4 && red4cnt < 100)
{
red4cnt++;
image.Draw(new Rectangle(260, 170, 260, 170), new Bgr(Color.Red), 3);
if (red4cnt == 99)
//.........这里部分代码省略.........