EmguCV3.0幾個控件的使用


 

值方圖(Histogram)是一種統計圖數據,在影像處理中最常被用來統計一張圖像或是感興趣(ROI)區域的色彩分布,在這邊本人使用的EmguCV 2.4.0版的內建值方圖工具只有被包含在WinForm應用程序中至於要如何在WPF繪制值方圖,那就要花比較多的步驟了,我們得自己畫,這部分后續文章會在介紹

 
所以接下來介紹的繪制環境是在C#的WinForm項目,
 
步驟
 
1.加入HistogramBox組件到WinForm
 
點選上排工具 –> 選擇工具箱 –> .Net Framework 組件中點選選擇,找到EmguCV項目下的Emgu.CV.UI.dll並把dll加入后再次看一下.Net Framework 組件便會發現:
 
\
 
2.在Form的設計工具箱中便會找到HistogramBox
\
 
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.UI;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        /*
         * 第一對
         * HistogramBox The control that is used to display histogram(需要事先設計位置)
         * HistogramViewer A view for histogram(彈出新窗口,不需要事先設計)  
         * 第二對
         * ImageBox An image box is a user control that is similar to picture box, but display Emgu CV IImage and provides enhenced functionalities.
         * ImageViewer The Image viewer that display IImage
         * 第三對
         * MatrixBox A control that is used to visualize a matrix(用戶控件) 
         * MatrixViewer A MatrixViewer that is used to visualize a matrix(彈出窗口)
         * 
         * 第四個
         * Operation An operation contains the MethodInfo and the methods parameters. It provides a way to invoke a specific method with the specific parameters.  
         * PanAndZoomPictureBox A picture box with pan and zoom functionality (可以事先圖像的縮放) 
        */
        private void Form1_Load(object sender, EventArgs e)
        {
            Image<Bgr, byte> img = new Image<Bgr, byte>(@"C:\a2.jpg");
            
            //Emgu.CV.UI.ImageBox 需要在窗口中設計
            this.imageBox1.Image = img;
            this.matrixBox1.Matrix = img;
            this.panAndZoomPictureBox1.Image = Image.FromFile(@"C:\a1.jpg");



            //The Imageviewer 直接彈出新的窗口
            Image<Bgr, byte> loadImg = new Image<Bgr, byte>(@"C:\a1.jpg");
            ImageViewer viewer = new ImageViewer(loadImg, "Loaded Image");
            viewer.Show(this);
           
            //1.使用HistogramViewer不需要事先拉到設計窗口中,他是彈出窗口,你只需要直接使用便可以
            HistogramViewer.Show(loadImg[0], 32); //image[0] 顯示Blue,bin = 32
            HistogramViewer.Show(loadImg, 32); //顯示所有信道
            
            //2.使用HistogramBox,需要事先拉窗口中設定在窗口畫面
            this.histogramBox1.GenerateHistograms(loadImg, 32);
            this.histogramBox1.Refresh(); //如果不刷新,圖像顯示一部分,沒有自動縮放的功能
            //this.histogramBox1.Show(); //如果不是刷新圖像,有沒有都可以
        }
    }
}

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM