Emgu 获取图片第一个数字

这篇博客展示了如何使用Emgu CV库来处理图像,特别是从图像中提取数字。通过二值化、图像裁剪等步骤,实现对数字的定位。代码中包含了cutLeft和cutTop函数,用于左右和上下的图像切割,以帮助提取单一数字。此外,还涉及到图像的ROI(感兴趣区域)操作和像素求和,以识别和分离数字。
摘要由CSDN通过智能技术生成

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);/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值