Mat image = new Mat("image.jpg", ImreadModes.Color); Mat gray = new Mat(); CvInvoke.CvtColor(image, gray, ColorConversion.Bgr2Gray); //convert to grayscale CvInvoke.GaussianBlur(gray, gray, new Size(3, 3), 0); //apply Gaussian blur Rectangle rect = CvInvoke.BoundingRectangle(gray); //get the bounding rectangle CvInvoke.Rectangle(image, rect, new MCvScalar(0, 0, 255), 2); //draw the rectangle on the original image CvInvoke.Imshow("Result", image);
using (var capture = new VideoCapture("video.mp4")) { while (true) { Mat frame = capture.QueryFrame(); if (frame == null) break; Mat gray = new Mat(); CvInvoke.CvtColor(frame, gray, ColorConversion.Bgr2Gray); //convert to grayscale CvInvoke.GaussianBlur(gray, gray, new Size(3, 3), 0); //apply Gaussian blur Rectangle rect = CvInvoke.BoundingRectangle(gray); //get the bounding rectangle CvInvoke.Rectangle(frame, rect, new MCvScalar(0, 0, 255), 2); //draw the rectangle on the frame CvInvoke.Imshow("Result", frame); CvInvoke.WaitKey(20); } }This example loads a video and processes each frame to get the bounding rectangle around the object in the frame. It then draws the rectangle on the frame and displays the result. Package: Emgu CV.