private void compareHistButton_Click(object sender, RoutedEventArgs e) { int i = 0; //值方圖匹配的參數預設 histMatchRate = 1; matchIndex = -1; ShowHistViewer(templateHistImgBox, showTemplateHistImg, "樣板影像"); foreach (Contour <System.Drawing.Point> c in topContours) { if (i == 3) { break; } DenseHistogram observedRectHist; Image <Bgr, byte> observedContourRectImg = DetectObjects.GetBoundingBoxImage(c, loadTestImg); double compareRate = DetectObjects.CompareHistogram(templateHist, observedContourRectImg, out observedRectHist); if (compareRate < histMatchRate) { histMatchRate = compareRate; matchIndex = i; } showObservedHistImg = SystemToolBox.DrawHsvHistogram(observedRectHist); ShowHistViewer(new ImageViewer(), showObservedHistImg, "觀察影像" + i); System.Windows.MessageBox.Show("compareRate is =" + compareRate.ToString()); i++; } }
private void HsvHistButton_Click(object sender, EventArgs e) { int HBins = 50; int SBins = 0; int VBins = 0; bool isCorrectValue = false; if (HistDim == 1 && int.TryParse(HBinTextBox.Text, out HBins)) { isCorrectValue = true; } else if (HistDim == 2 && int.TryParse(HBinTextBox.Text, out HBins) && int.TryParse(SBinTextBox.Text, out SBins)) { isCorrectValue = true; } else { MessageBox.Show("數值不對"); } if (wantExtractFeatureImage != null && isCorrectValue) { if (learningSys != null) { learningSys.SetLearningImage(wantExtractFeatureImage); } else { learningSys = new FeatureLearning(wantExtractFeatureImage); } templateHist = learningSys.CalHist(HistDim, HBins, SBins, VBins); if (HistDim <= 2) { showTemplateHistImg = SystemToolBox.DrawHsvHistogram(templateHist); ShowHistViewer(templateHistImgBox, showTemplateHistImg, "樣板影像"); } else { MessageBox.Show("Dim = " + HistDim + ",can;t draw"); } } else { MessageBox.Show("圖片未載入"); } }
private void loadHistFileButton_Click(object sender, RoutedEventArgs e) { string filename = OpenLearnedHistogramDataFile(); if (filename != null) { templateHistFilePathName = filename; templateHist = DetectObjects.ReadHistogram(templateHistFilePathName, true); if (templateHist.Dimension < 3) { showTemplateHistImg = SystemToolBox.DrawHsvHistogram(templateHist); ShowHistViewer(templateHistImgBox, showTemplateHistImg, "樣板影像"); } else { System.Windows.MessageBox.Show("Dim = " + templateHist.Dimension.ToString() + ",can;t draw"); } } }