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.CvEnum;
using Emgu.CV.Structure;
using Emgu.CV.UI;
using Emgu.Util;
using System.Diagnostics;
using Emgu.CV.ML;
using Emgu.CV.ML.Structure;
namespace 数字识别
{
public partial class Form1 : Form
{
//int oldwidth=32;
//int oldheight=45;
public Form1()
{
InitializeComponent();
//Image<Gray, byte> src1 = new Image<Gray, byte>("Desert.jpg");//灰度图就是单通道图
Image<Gray, byte> src = new Image<Gray, byte>("b.png"); //读取图片并进行灰度化处理
Image<Gray, byte> submat = new Image<Gray, byte>(src.Width, src.Height);
//Image<Gray, byte> submat1 = new Image<Gray, byte>(src.Height,src.Width);
CvInvoke.Threshold(src, src, 100, 255, ThresholdType.BinaryInv);//二值化
imageBox1.Image = src;
// // 感兴趣区域ROI图片裁剪
// int x = submat.Width - oldwidth;
// int y = submat.Height - oldheight;
// Image<Gray, Byte> roisize = new Image<Gray, byte>(oldwidth, oldheight); //要裁剪的图片大小
// Rectangle rect = new Rectangle(x, y, oldwidth, oldheight);
// CvInvoke.cvSetImageROI(submat, rect);
//roisize= submat.Clone();
//imageBox3.Image = roisize;
// // 感兴趣区域ROI图片裁剪
int res = cutLeft(src);
Image<Gray, byte> leftImg = src.Copy();//不能用clone()的方法
cutTop(leftImg);
imageBox2.Image = src;
imageBox3.Image = leftImg;
int i = 0;
while (res == 0)
{
string strNum1 = i.ToString();
string strLeft1 = "Left";
string strNumLeft1 = string.Format("{0}{1}", strNum1, strLeft1);
string strNum2 = i.ToString();
string strLeft2 = "Left";
string strNumLeft2 = string.Format("{0}{1}", strNum2, strLeft2);
i += i;
CvInvoke.Imshow(strNumLeft1, leftImg);
CvInvoke.Imwrite("D:\\" + strNumLeft1.ToString() + ".jpg", leftImg);//
Image<Gray, byte> srcTmp = leftImg;
res = cutLeft(srcTmp);
}
//CvInvoke.cvGetCol(src, submat, 30);//获取图像的某一列
//CvInvoke.cvGetRow(src, submat1, 30);/