/// <summary> /// Calculate the histogram for the region of interest and saves it under /// initialHistogram. /// </summary> private void UpdateHistogram() { // release the previous histogram if any. if (initialHistogram != null) { initialHistogram.Release(); } // if there's no image, just return. if (image == null) { return; } // we use symmetric bins and entire range. int[] bpBins = { NumberOfBins, NumberOfBins, NumberOfBins }; CVPair[] bpRanges = { new CVPair(0, 255), new CVPair(0, 255), new CVPair(0, 255) }; // calculate histogram for region of interest and display it in panel. image.RegionOfInterest = originalImage.SelectionRect; this.initialHistogram = image.CalcHistogram(bpBins, bpRanges); initHisto.ShowHistogram(image); image.ResetROI(); ResetSegmentation(); RefreshImages(); }
private void video_SelectionChanged(object sender, EventArgs f) { if (videoPlayer.LastFrame == null) { return; } using (CVImage region = videoPlayer.LastFrame.CopyRegion(video.SelectionRect)) { selectionHistogram = region.CalcHistogram(30); } ProcessRegionGrowing(); }
private void meanShiftNoMask_SelectionChanged(object sender, EventArgs e) { using (CVImage frame = videoPlayer.LastFrame.CopyRegion(meanShiftNoMask.SelectionRect)) { if (histNoMask != null) { histNoMask.Dispose(); } histNoMask = frame.CalcHistogram(Bins); noMaskHist.BinsPerChannel = Bins; noMaskHist.ShowHistogram(frame); } NextFrame(false); }
private void CalculateMaskedHistogram() { if (videoPlayer.LastFrame == null) { return; } using (CVImage frame = videoPlayer.LastFrame.CopyRegion(meanShift.SelectionRect)) { // create a list of real fg and bg markers. List <Point> realFg = new List <Point>(meanShift.GetMarkerLocations(Color.Blue)); List <Point> realBg = new List <Point>(meanShift.GetMarkerLocations(Color.Red)); // create the histogram mask. using (CVImage mask = MaskedHistogram.PrepareMask(frame, realFg.ToArray(), realBg.ToArray(), includeNeautral.Checked, ffThresh.Value)) { maskPicture.Image = mask.ToBitmap(); // show mask histogram to user interface. maskHistogram.BinsPerChannel = Bins; maskHistogram.ShowHistogram(frame, mask); // calculate new histogram (dispose old one if exist). if (hist != null) { hist.Dispose(); } hist = frame.CalcHistogram(Bins, mask); // apply mask to overlay (just for ui). using (CVImage masked = MaskedHistogram.ApplyMask(frame, mask)) { maskOverlay.Image = masked.ToBitmap(); } } } NextFrame(false); }