C# 4.0 名称';初始化组件()';在当前上下文中不存在(c#,emgucv)
我试图使用c#和emgucv运行此代码来绘制图像的直方图,但它不断给我一个错误,即“name”InitializeComponent()“在当前上下文中不存在”。我试图添加参考资料,但不起作用C# 4.0 名称';初始化组件()';在当前上下文中不存在(c#,emgucv),c#-4.0,c#-3.0,emgucv,C# 4.0,C# 3.0,Emgucv,我试图使用c#和emgucv运行此代码来绘制图像的直方图,但它不断给我一个错误,即“name”InitializeComponent()“在当前上下文中不存在”。我试图添加参考资料,但不起作用 using ZedGraph; using System; using System.Linq; using System.Text; using System.Drawing; using System.Runtime.InteropServices; using Emgu.CV; using Emg
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;
}
}
}
使用ZedGraph;
使用制度;
使用System.Linq;
使用系统文本;
使用系统图;
使用System.Runtime.InteropServices;
使用Emgu.CV;
使用Emgu.CV.CvEnum;
使用Emgu.CV.UI;
使用Emgu.Util;
使用Emgu.CV.Structure;
使用System.Windows.Forms;
使用系统组件模型;
使用系统数据;
使用System.IO;
使用System.Windows.Markup;
使用System.Windows;
使用System.Windows.Input;
使用System.Windows.Threading;
使用System.Xaml;
使用System.Xml;
;
名称空间My_EMGU_程序
{
公共部分类Form1:Form
{
公共表格1()
{
初始化组件();
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
OpenFileDialog Openfile=新建OpenFileDialog();
if(Openfile.ShowDialog()==DialogResult.OK)
{
Image img=新图像(Openfile.FileName);
浮动[]蓝历史;
绿色主义者;
浮动[]RedHist;
DenseShistogram Histo=新的DenseShistogram(255,新范围f(0255));
图像img2Blue=img[0];
图像img2Green=img[1];
图像img2Red=img[2];
历史计算(新图像[]{img2Blue},真,空);
//数据在这里
//历史博物馆
BlueHist=新浮点[256];
历史材料管理材料(BlueHist,0);
透明组织();
历史计算(新图像[]{img2Green},真,空);
GreenHist=新浮动[256];
历史材料管理材料(GreenHist,0);
透明组织();
历史计算(新图像[]{img2Red},真,空);
RedHist=新浮点[256];
历史匹配管理数据集复制到(RedHist,0);
浮动[]灰色历史;
Image img_gray=新图像(Openfile.FileName);
历史计算(新图像[]{img_gray},真,空);
//数据在这里
//历史博物馆
GrayHist=新浮点[256];
历史匹配管理数据集(灰色历史,0);
/*此方法调用将为您生成直方图*/
添加_直方图(GrayHist,“灰色直方图”);
添加_直方图(BlueHist,蓝色直方图);
添加_直方图(GreenHist,绿色直方图);
添加_直方图(RedHist,红色直方图);
}
}
/*您可以将此方法扩展为非常轻松地设置线条颜色x和y标题*/
//用于堆叠直方图的全局X Y位置
int X=10,Y=10;
面板1=新面板();
void Add_直方图(float[]Histo_dat,string Histo_Title=“直方图标题”)
{
//创建控件
ZedGraphControl zgc=新的ZedGraphControl();
zgc.位置=新点(Y,X);
zgc.尺寸=新尺寸(面板1.宽度-20,200);
X+=(zgc.Size.Height+20);//为下一个图形增加X
GraphPane myPane=zgc.GraphPane;
myPane.Title.Text=历史标题;
myPane.XAxis.Title.Text=“X轴-像素位值”;
myPane.YAxis.Title.Text=“Y轴-像素总数”;
//创建Zedgraph可以使用的数组
PointPairList list1=新的PointPairList();
对于(int i=0;i
Form1
是一个部分类。这意味着另一个文件Form1.designer.cs包含缺少的方法。
您不能只是复制和粘贴代码-您需要随附的文件:
Form1.cs
,Form1.designer.cs
以及一些资源文件,如Form1.resx
我建议在尝试复杂的代码之前先学习基础知识