2015-05-14 3 views
-1

Я пытаюсь запустить этот код с помощью C# и emgucv, чтобы нарисовать гистограмму для изображения, но он продолжает давать мне ошибку, что «The имя «InitializeComponent()» не существует в текущем контексте ». Я попытался добавить ссылки, но он не работает.Имя «InitializeComponent()» не существует в текущем контексте (C#, emgucv)

using ZedGraph; 
using System; 

using System.Linq; 
using System.Text; 
using System.Drawing; 
using System.Runtime.InteropServices; 
using Emgu.CV; 
using Emgu.CV.CvEnum; 
using Emgu.CV.UI; 
using Emgu.Util; 
using Emgu.CV.Structure; 
using System.Windows.Forms; 
using System.ComponentModel; 
using System.Data; 
using System.IO; 
using System.Windows.Markup; 
using System.Windows; 
using System.Windows.Input; 
using System.Windows.Threading; 
using System.Xaml; 
using System.Xml; 
; 



namespace My_EMGU_Program 
{ 
    public partial class Form1 : Form 
    { 
    public Form1() 
    { 
     InitializeComponent(); 

    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     OpenFileDialog Openfile = new OpenFileDialog(); 
     if (Openfile.ShowDialog() == DialogResult.OK) 
     { 
     Image<Bgr, byte> img = new Image<Bgr, byte>(Openfile.FileName); 
     float[] BlueHist; 
     float[] GreenHist; 
     float[] RedHist; 
     DenseHistogram Histo = new DenseHistogram(255, new RangeF(0, 255)); 
     Image<Gray, Byte> img2Blue = img[0]; 
     Image<Gray, Byte> img2Green = img[1]; 
     Image<Gray, Byte> img2Red = img[2]; 

     Histo.Calculate(new Image<Gray, Byte>[] { img2Blue }, true, null); 
     //The data is here 
     //Histo.MatND.ManagedArray 
     BlueHist = new float[256]; 
     Histo.MatND.ManagedArray.CopyTo(BlueHist, 0); 

     Histo.Clear(); 

     Histo.Calculate(new Image<Gray, Byte>[] { img2Green }, true, null); 
     GreenHist = new float[256]; 
     Histo.MatND.ManagedArray.CopyTo(GreenHist, 0); 

     Histo.Clear(); 

     Histo.Calculate(new Image<Gray, Byte>[] { img2Red }, true, null); 
     RedHist = new float[256]; 
     Histo.MatND.ManagedArray.CopyTo(RedHist, 0); 

     float[] GrayHist; 

     Image<Gray, Byte> img_gray = new Image<Gray, byte>    (Openfile.FileName); 

     Histo.Calculate(new Image<Gray, Byte>[] { img_gray }, true, null); 
     //The data is here 
     //Histo.MatND.ManagedArray 
     GrayHist = new float[256]; 
     Histo.MatND.ManagedArray.CopyTo(GrayHist, 0); 


     /*This Methof call will produced the Histograms for you*/ 
     Add_Histogram(GrayHist, "Gray Histogram"); 
     Add_Histogram(BlueHist, "Blue Histogram"); 
     Add_Histogram(GreenHist, "Green Histogram"); 
     Add_Histogram(RedHist, "Red Histogram"); 
     } 
    } 

    /* You can extend this method to set line colour x and y titles quite easily */ 
    //Global X Y locations to stack Histograms 
    int X = 10, Y = 10; 
    Panel panel1 = new Panel(); 
    void Add_Histogram(float[] Histo_dat, string Histo_Title = "Histogram Title") 
    { 

     //Create the Control 
     ZedGraphControl zgc = new ZedGraphControl(); 
     zgc.Location = new Point(Y, X); 
     zgc.Size = new Size(panel1.Width - 20, 200); 
     X += (zgc.Size.Height + 20); //increas X for next Graph 

     GraphPane myPane = zgc.GraphPane; 

     myPane.Title.Text = Histo_Title; 
     myPane.XAxis.Title.Text = "X Axis - Pixel Bin Values"; 
     myPane.YAxis.Title.Text = "Y Axis - Total Number of Pixels"; 

     //Create an array that Zedgraph can use 
     PointPairList list1 = new PointPairList(); 
     for (int i = 0; i < Histo_dat.Length; i++) 
     { 
     list1.Add(new PointPair(i, Histo_dat[i])); 
     } 

     //Add the data to the control 
     LineItem myCurve = myPane.AddCurve("Title", list1, Color.Blue, SymbolType.Circle); 
     zgc.AxisChange(); 

     //Add the controll and refresh form 
     panel1.Controls.Add(zgc); 
     this.Refresh(); 


    } 

    //In case you wish to restart and draw newly calculated histograms 
    void Clear_Histograms() 
    { 

     panel1.Controls.Clear(); 
     X = 10; 
    } 
    } 
} 

ответ

1

Form1 - частичный класс.
Это означает, что есть еще один файл Form1.designer.cs, который содержит отсутствующий метод.
Вы не можете просто скопировать и вставить этот код - вам нужны файлы, которые его сопровождают:
Form1.cs, Form1.designer.cs и, возможно, некоторые файлы ресурсов, такие как Form1.resx.
Я предлагаю пройтись по основам, прежде чем пытаться выполнить сложный код.

Смежные вопросы