private PointF[] ProcessFrame(Image <Bgr, Byte> image, AutomatedRodentTracker.Services.RBSK.RBSK rbsk, out double waist, out double waistArea, out double waistArea2, out double waistArea3, out double waistArea4, out PointF centroid, bool useBackground = false) { //Rectangle roi = Rectangle.Empty; //if (image.IsROISet) //{ // roi = image.ROI; // image.ROI = Rectangle.Empty; //} if (BackgroundImage != null && useBackground) { using (Image <Gray, Byte> grayImage = image.Convert <Gray, Byte>()) //using (Image<Gray, Byte> filteredImage = grayImage.SmoothMedian(rbsk.Settings.FilterLevel)) using (Image <Gray, Byte> binaryImage = grayImage.ThresholdBinary(new Gray(rbsk.Settings.BinaryThreshold), new Gray(255))) using (Image <Gray, Byte> backgroundNot = BackgroundImage.Not()) using (Image <Gray, Byte> finalImage = binaryImage.Add(backgroundNot)) using (Image <Gray, Byte> filteredImage = finalImage.SmoothMedian(rbsk.Settings.FilterLevel)) { //ImageViewer.Show(finalImage); PointF[] result = RBSKService.RBSK(filteredImage, rbsk); IBodyDetection bodyDetection = ModelResolver.Resolve <IBodyDetection>(); bodyDetection.BinaryBackground = BackgroundImage; //bodyDetection.ThresholdValue = ThresholdValue; if (result == null) { waist = -1; waistArea = -1; waistArea2 = -1; waistArea3 = -1; waistArea4 = -1; bodyDetection.GetBody(grayImage, out centroid); return(null); } bodyDetection.FindBody(grayImage, out waist, out waistArea, out waistArea2, out waistArea3, out waistArea4, out centroid); return(result); } } waist = -1; waistArea = -1; waistArea2 = -1; waistArea3 = -1; waistArea4 = -1; centroid = PointF.Empty; return(RBSKService.RBSK(image, rbsk)); }
private PointF[] ProcessFrame(Image <Gray, Byte> grayImage, RBSK rbsk, out double waist, out double waistArea, out double waistArea2, out double waistArea3, out double waistArea4, out PointF centroid, out Point[] bodyContour, bool useBackground = false) { //Rectangle roi = Rectangle.Empty; //if (image.IsROISet) //{ // roi = image.ROI; // image.ROI = Rectangle.Empty; //} if (BackgroundImage != null && useBackground) { //using (Image<Gray, Byte> grayImage = image.Convert<Gray, Byte>()) using (Image <Gray, Byte> binaryImage = grayImage.ThresholdBinary(new Gray(rbsk.Settings.BinaryThreshold), new Gray(255))) using (Image <Gray, Byte> backgroundNot = BackgroundImage.Not()) using (Image <Gray, Byte> binaryFinal = binaryImage.Add(backgroundNot)) using (Image <Gray, Byte> finalImage = binaryFinal.SmoothMedian(rbsk.Settings.FilterLevel)) //using (Image<Gray, Byte> finalImageNot = finalImage.Not()) { //ImageViewer.Show(finalImage); ImageViewer.Show(finalImage); PointF[] result = RBSKService.RBSK(finalImage, rbsk); IBodyDetection bodyDetection = ModelResolver.Resolve <IBodyDetection>(); bodyDetection.BinaryBackground = BackgroundImage; //bodyDetection.ThresholdValue = ThresholdValue; if (result == null) { waist = -1; waistArea = -1; waistArea2 = -1; waistArea3 = -1; waistArea4 = -1; //bodyDetection.GetBody(finalImage, out centroid, out bodyContour); bodyContour = null; centroid = PointF.Empty; return(null); } //double vol2, vol3, vol4; //image. //if (!roi.IsEmpty) //{ // image.ROI = roi; //} //PointF dummy; //ImageViewer.Show(finalImage); bodyDetection.FindBody(finalImage, out waist, out waistArea, out waistArea2, out waistArea3, out waistArea4, out centroid, out bodyContour); //if (!centroid.IsEmpty) //{ // ImageViewer.Show(finalImage); // Console.WriteLine("Showing"); //} //CvBlobs blobs = new CvBlobs(); //BlobDetector.Detect(finalImage, blobs); //CvBlob mouseBlob = null; //double maxArea = -1; //foreach (var blob in blobs.Values) //{ // if (blob.Area > maxArea) // { // mouseBlob = blob; // maxArea = blob.Area; // } //} //waist = -1; //waistArea = -1; return(result); } } waist = -1; waistArea = -1; waistArea2 = -1; waistArea3 = -1; waistArea4 = -1; centroid = PointF.Empty; bodyContour = null; return(null); }