ВКР (1216394), страница 8
Текст из файла (страница 8)
// {
// //IntPtr inputImage = CvInvoke.cvLoadImage(ofd.FileName, LOAD_IMAGE_TYPE.CV_LOAD_IMAGE_COLOR);
// //CvInvoke.cvShowImage("IntPtr", inputImage);
// }
//}
//MessageBox.Show("Opend");
//Thread.Sleep(1000);
buffer = "";
//Image<Bgr, Byte> img = new Image<Bgr, byte>("C:\\s3.jpg");
//pictureBox1.Image = img.ToBitmap();
}
private void button1_Click(object sender, EventArgs e)
{
Image<Bgr, Byte> img = _capture.QueryFrame();
if (img != null)
{
pictureBox1.Image = img.ToBitmap();
//image_array.Add(_capture.QueryFrame().Copy());
}
}
private void Loadad(object sender, EventArgs e)
{
//this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
string[] ports = SerialPort.GetPortNames();
//comboBox1.Items.Clear();
//foreach (string port in ports)
//{
// comboBox1.Items.Add(port);
//}
SerPort = new SerialPort(ports[0].ToString());
//else Application.Exit();
SerPort.BaudRate = 115200;
SerPort.Parity = Parity.None;
SerPort.StopBits = StopBits.One;
SerPort.DataBits = 8;
SerPort.Handshake = Handshake.None;
SerPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
Control.CheckForIllegalCrossThreadCalls = false;
SerPort.ReadBufferSize = 100;
SerPort.ReadTimeout = 100;
SerPort.Open();
// if (!SerPort.IsOpen)
//{
//Application.Exit();
//}
Image<Bgr, Byte> frame;
while ((frame = _capture.QueryFrame())!= null)
{
image_array.Add(frame.Copy());
}
}
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
string outs="0";
//button1.Text = indata;
buffer += indata;
while (buffer.Contains('\n'))
{
if (buffer.IndexOf('\n') < 2) { buffer = ""; break;}
outs = buffer.Substring(0, buffer.IndexOf('\n')-1);
if (buffer.IndexOf('\n') != buffer.Length - 1) buffer = buffer.Substring(buffer.IndexOf('\n'), buffer.Length - buffer.IndexOf('\n'));
else buffer = "";
int truAnd = Convert.ToInt32(outs);
int allFrame = image_array.Count;
int outAng=0;
if (truAnd >= 0) outAng = truAnd - (allFrame * (int)((int)truAnd / (int)allFrame));
else outAng = allFrame - (Math.Abs(truAnd) - (allFrame * (int)((int)Math.Abs(truAnd) / (int)allFrame)));
//Image<Bgr, Byte> img = _capture.QueryFrame(); _capture.
button1.Text = Convert.ToInt32(truAnd).ToString();
label1.Text = buffer;
pictureBox1.Image = image_array[Convert.ToInt32(outAng)].ToBitmap();
//image_array.Add(_capture.QueryFrame().Copy());
}
//count += indata.Length;
//progressBar1.Value = count;
}
}
}















