IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> OpenCV学习笔记C# -> 正文阅读

[人工智能]OpenCV学习笔记C#

?

?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.CvEnum;
using Emgu.CV.UI;
using Emgu.CV.Structure;
using Emgu.CV.Util;
using Emgu.CV.OCR;
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            String win1 = "Test Window  Form";
            //新建窗口
            CvInvoke.NamedWindow(win1);
            //新建图像
            Mat img = new Mat(200, 700, DepthType.Cv8U, 3);
            //设置图像颜色
            img.SetTo(new Bgr(255, 66, 0).MCvScalar);
            //绘制文字
            CvInvoke.PutText(img, "Hello, worNI MA BI DE!", new System.Drawing.Point(10, 80), FontFace.HersheyComplex, 2.0, new Bgr(0, 255, 255).MCvScalar, 4);
            //显示
            CvInvoke.Imshow(win1, img);
            CvInvoke.WaitKey(0);
            //CvInvoke.DestroyWindow(win1);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Mat img = CvInvoke.Imread(@"C:\Users\11018\Pictures\20180705160930798.png", ImreadModes.Unchanged);
            if (img.IsEmpty)
            {
                Console.WriteLine("can not load the image \n");
            }
            CvInvoke.Imshow("Image", img);//显示图片
            Mat grayImg = new Mat();
            //转换为灰度图像
            CvInvoke.CvtColor(img, grayImg, ColorConversion.Rgb2Gray);
            CvInvoke.Imshow("Gray Image", grayImg);
            //sobel
            Mat sobelImg = new Mat();
            CvInvoke.Sobel(grayImg, sobelImg, grayImg.Depth, 1, 0);
            //使用canny算子查找边缘
            Mat cannyImg = new Mat();
            CvInvoke.Canny(grayImg, cannyImg, 20, 40);
            CvInvoke.Imshow("Canny Image", cannyImg);
            CvInvoke.WaitKey(0); 

        }

        private void button3_Click(object sender, EventArgs e)
        {
            //简单图像处理
            Mat src = CvInvoke.Imread(@"C:\Users\11018\Pictures\5CA23D13-A58E-4fd1-871C-194BC5B6AF93.png", ImreadModes.Unchanged);
            if (src.IsEmpty)
            {
                Console.WriteLine("can not load the image \n");
            }
            CvInvoke.Imshow("Image", src);
            CvInvoke.CvtColor(src, src, ColorConversion.Rgb2Gray);//黑白
            //直方图均匀化
            //Mat dst = new Mat(src.Size, DepthType.Cv8U, 1);
            //CvInvoke.EqualizeHist(src, dst);
            //CvInvoke.Imshow("Equalization", src);

            //高斯滤波
            CvInvoke.GaussianBlur(src, src, new Size(3, 3), 3);
            CvInvoke.Imshow("GaussianBlur Image", src);

            //均值滤波
            CvInvoke.Blur(src, src, new Size(3, 3), new Point(-1, -1));
            CvInvoke.Imshow("Blur Image", src);

            //二值化
            CvInvoke.Threshold(src, src, 70, 255, ThresholdType.BinaryInv);
            CvInvoke.Imshow("Threshold Image", src);

            //膨胀
            Mat struct_element1 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.Dilate(src, src, struct_element1, new Point(-1, -1), 2, BorderType.Default, new MCvScalar(0, 0, 0));
            CvInvoke.Imshow("penzhang", src);
            //腐蚀
            //Mat struct_element2 = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(5, 5), new Point(-1, -1));
            //CvInvoke.Erode(src, src, struct_element2, new Point(-1, -1), 5, BorderType.Default, new MCvScalar(0, 0, 0));


            闭操作
            Mat struct_element = CvInvoke.GetStructuringElement(ElementShape.Rectangle, new Size(3, 3), new Point(-1, -1));
            CvInvoke.MorphologyEx(src, src, MorphOp.Close, struct_element, new Point(-1, -1), 3, BorderType.Default, new MCvScalar(0, 0, 0));
            CvInvoke.Imshow("Erode Image bi caozuo ", src);

            Mat dst_canny = new Mat();
            CvInvoke.Canny(src, dst_canny, 20, 40);//画出边缘地区
            CvInvoke.Imshow("Canny Image", dst_canny);
            CvInvoke.WaitKey(0);

        }

        private void button4_Click(object sender, EventArgs e)
        {
            
            ImageViewer viewer = new ImageViewer();
            //读取视频
            VideoCapture capture = new VideoCapture(@"C:\Users\11018\Pictures\vdo\ats.wmv");
            //视频帧率
            //Console.WriteLine("Frame rate = " + capture.GetCaptureProperty(Emgu.CV.CvEnum.CapProp.Fps));
            Application.Idle += new EventHandler(delegate (object sender, EventArgs e)
            {
                //获得的图像
                viewer.Image = capture.QueryFrame();
            });
            viewer.ShowDialog();

        }

        private void button5_Click(object sender, EventArgs e)
        {
            //加载图像
            var dialog = new OpenFileDialog();
            dialog.Filter = "图片(*.jpg/*.png/*.gif/*.bmp)|*.jpg;*.png;*.gif;*.bmp";
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                var filename = dialog.FileName;
                Image<Bgr, Byte> image;
                image = new Image<Bgr, byte>(@filename);
                imageBox1.Image = image;
            }

        }

        private void button6_Click(object sender, EventArgs e)
        {
            Image<Bgr, Byte> img = new Image<Bgr, Byte>(640, 400, new Bgr(169, 200, 0));//(640,400)为ImageBox1控件大小
            imageBox1.Image = img;//在ImageBox1控件中显示图像 
        }

        private void button7_Click(object sender, EventArgs e)
        {
            //从文件加载图像
            String imagePath = @"C:\Users\11018\Pictures\state2.png";
            Image<Bgr, Byte> src = new Image<Bgr, byte>(@imagePath);
            CvInvoke.Imshow("src", src);
            //将图像转换为灰度
            UMat grayImage = new UMat();
            CvInvoke.CvtColor(src, grayImage, ColorConversion.Bgr2Gray);

            //使用高斯滤波去除噪声
            CvInvoke.GaussianBlur(grayImage, grayImage, new Size(5, 5), 3);
            //CvInvoke.Imshow("Blur Image", grayImage);
            //霍夫圆检测
            CircleF[] circles = CvInvoke.HoughCircles(grayImage, HoughModes.Gradient, 2.0, 20.0, 100.0, 180.0, 5);
            #region draw circles
            Image<Bgr, Byte> circleImage = src.Clone();
            foreach (CircleF circle in circles)
                circleImage.Draw(circle, new Bgr(Color.Blue), 2);
            CvInvoke.Imshow("HoughCircles", circleImage);
            CvInvoke.WaitKey(0);
            #endregion

        }

        private void button8_Click(object sender, EventArgs e)
        {
            //从文件加载图像
            String imagePath = @"C:\Users\11018\Pictures\ats\1.png";
            Image<Bgr, Byte> src = new Image<Bgr, byte>(@imagePath);
            CvInvoke.Imshow("src", src);
            //将图像转换为灰度
            UMat grayImage = new UMat();
            CvInvoke.CvtColor(src, grayImage, ColorConversion.Bgr2Gray);
            //使用高斯滤波去除噪声
            CvInvoke.GaussianBlur(grayImage, grayImage, new Size(5, 5), 3);
            //CvInvoke.Imshow("Blur Image", grayImage);

            #region Lines detection
            UMat cannyEdges = new UMat();
            CvInvoke.Canny(grayImage, cannyEdges, 100, 120);
            //CvInvoke.Imshow("Canny Image", cannyEdges);
            LineSegment2D[] lines = CvInvoke.HoughLinesP(cannyEdges, 1, Math.PI / 20.0, 30, 80, 30);
            #endregion

            #region draw lines
            Image<Bgr, Byte> lineImage = src.Clone();
            foreach (LineSegment2D line in lines)
                lineImage.Draw(line, new Bgr(Color.HotPink), 1);
            CvInvoke.Imshow("lineImage", lineImage);
            CvInvoke.WaitKey();
            #endregion

        }

        private void button9_Click(object sender, EventArgs e)
        {
            //从文件加载图像
            String imagePath = @"C:\Users\11018\Pictures\模板匹配\l.png";
            Image<Bgr, Byte> src = new Image<Bgr, byte>(@imagePath);
            CvInvoke.Imshow("src", src);
            //将图像转换为灰度
            UMat grayImage = new UMat();
            CvInvoke.CvtColor(src, grayImage, ColorConversion.Bgr2Gray);
            //使用高斯滤波去除噪声
            CvInvoke.GaussianBlur(grayImage, grayImage, new Size(3, 3), 3);
            //CvInvoke.Imshow("Blur Image", grayImage);

            #region Canny and edge detection
            UMat cannyEdges = new UMat();
            CvInvoke.Canny(grayImage, cannyEdges, 60, 180);
            CvInvoke.Imshow("Canny Image", cannyEdges);
            #endregion


            #region Find triangles and rectangles找三角形和矩形
            List<Triangle2DF> triangleList = new List<Triangle2DF>();
            List<RotatedRect> boxList = new List<RotatedRect>(); //旋转的矩形框

            using (VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint())
            {
                CvInvoke.FindContours(cannyEdges, contours, null, RetrType.List, ChainApproxMethod.ChainApproxSimple);
                int count = contours.Size;
                for (int i = 0; i < count; i++)
                {
                    using (VectorOfPoint contour = contours[i])
                    using (VectorOfPoint approxContour = new VectorOfPoint())
                    {
                        CvInvoke.ApproxPolyDP(contour, approxContour, CvInvoke.ArcLength(contour, true) * 0.1, true);//发现轮廓
                        //仅考虑面积大于50的轮廓
                        if (CvInvoke.ContourArea(approxContour, false) > 50)
                        {
                            //if (approxContour.Size == 3) //轮廓有3个顶点:三角形
                            //{
                            //    Point[] pts = approxContour.ToArray();
                            //    triangleList.Add(new Triangle2DF(pts[0], pts[1], pts[2]));
                            //}
                            if (approxContour.Size == 4) //轮廓有4个顶点
                            {
                                #region determine if all the angles in the contour are within [80, 100] degree
                                bool isRectangle = true;
                                Point[] pts = approxContour.ToArray();
                                LineSegment2D[] edges = PointCollection.PolyLine(pts, true);

                                for (int j = 0; j < edges.Length; j++)
                                {
                                    double angle = Math.Abs(edges[(j + 1) % edges.Length].GetExteriorAngleDegree(edges[j]));
                                    
                                    if (angle < 80 || angle > 100)
                                    {
                                        isRectangle = false;
                                        //可能是梯形哦
                                        textBox1.Text += angle.ToString()+"\r\n";
                                      //  boxList.Add(CvInvoke.MinAreaRect(approxContour));
                                    }
                                }
                                #endregion
                                if (isRectangle) boxList.Add(CvInvoke.MinAreaRect(approxContour));
                            }
                        }
                    }
                }
            }
            #endregion

            //显示结果
            #region draw triangles and rectangles
            Image<Bgr, Byte> triangleRectangleImage = src.CopyBlank();
            foreach (Triangle2DF triangle in triangleList)
                triangleRectangleImage.Draw(triangle, new Bgr(Color.DarkBlue), 2);

            CvInvoke.Imshow("sanjiaoxing", triangleRectangleImage);

            Image<Bgr, Byte> RectangleImage = src.CopyBlank();
            foreach (RotatedRect box in boxList)
                RectangleImage.Draw(box, new Bgr(Color.DarkOrange), 2);

            CvInvoke.Imshow("4bianxing", RectangleImage);
            CvInvoke.WaitKey();
            #endregion

        }

        private void button10_Click(object sender, EventArgs e)
        {
            OpenFileDialog open;
            open = new OpenFileDialog();
            Image<Bgr, Byte> src = null;
            if (open.ShowDialog() == DialogResult.OK)
            {
                // filename = open.FileName;
                //pictureBox2.Load(filename);
                src = new Image<Bgr, byte>(open.FileName);
            }

            //从文件加载图像
            // String imagePath = @"C:\Users\11018\Pictures\ats\hb.png";
            //Image<Bgr, Byte> src = new Image<Bgr, byte>(@imagePath);
            //Mat grayImg = new Mat();
            //CvInvoke.CvtColor(src, src, ColorConversion.Rgb2Gray);
           // CvInvoke.Imshow("Gray Image", src);
            CvInvoke.Imshow("Gray src", src);

            Mat dst = new Mat();

            CvInvoke.Canny(src, dst, 120, 180);

            //创建用于存储轮廓的VectorOfVectorOfPoint数据类型
            VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();

            CvInvoke.FindContours(dst, contours, null, Emgu.CV.CvEnum.RetrType.External,Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);

            //用于存储筛选过后的轮廓
            VectorOfVectorOfPoint use_contours = new VectorOfVectorOfPoint();
            //获取联通区域个数
            int ksize = contours.Size;


            for (int i = 0; i < ksize; i++)
            {
                //获取独立的连通轮廓
                VectorOfPoint contour = contours[i];
                //用于存放逼近的结果
                VectorOfPoint approx_curve = new VectorOfPoint();

                //计算连通轮廓的长度
                double length = CvInvoke.ArcLength(contour, false);

                //if (length > 68)  //&& length <150  可以过滤线条
                //{
                    //几何逼近,精度为连通域轮廓周长的0.05倍。
                    //IInputArray curve;输入需要逼近的轮廓,一般类型为VectorOfPoint。
                    //IOutputArray approxCurve:逼近的结果,与输入的类型一致。里面的点代表多边形顶点坐标。
                    //double epsilon:逼近精度。
                    CvInvoke.ApproxPolyDP(contour, approx_curve, length * 0.04, true);
                    //if (CvInvoke.ContourArea(approx_curve, false) > 900)
                    //{
                        //approx_Curve.Size 代表顶点个数,即多边形边数。
                        if (approx_curve.Size == 4)
                        {
                            //添加筛选后的连通轮廓
                            use_contours.Push(contour);
                        }
                    //}
                //}
            }
            CvInvoke.DrawContours(src, use_contours, -1, new MCvScalar(66,66, 250),3);
            imageBox1.Image = src;

            //return;
            //if (((Button)sender).Text == "按面积筛选")
            //{
            //    for (int i = 0; i < ksize; i++)
            //    {
            //        //获取独立的连通轮廓
            //        VectorOfPoint contour = contours[i];

            //        //计算连通轮廓的面积
            //        double area = CvInvoke.ContourArea(contour);
            //        //进行面积筛选
            //        if (area >= Convert.ToInt32(30))
            //        {
            //            //添加筛选后的连通轮廓
            //            use_contours.Push(contour);
            //        }
            //    }
            //    CvInvoke.DrawContours(src, use_contours, -1, new MCvScalar(0, 0, 255), 2);
            //}
            //if (((Button)sender).Text == "按周长筛选")
            //{
            //    for (int i = 0; i < ksize; i++)
            //    {
            //        //获取独立的连通轮廓
            //        VectorOfPoint contour = contours[i];
            //        //计算连通轮廓的周长
            //        double length = CvInvoke.ArcLength(contour, false);
            //        //进行周长筛选
            //        if (length >= Convert.ToInt32(100))
            //        {
            //            //添加筛选后的连通轮廓
            //            use_contours.Push(contour);
            //        }
            //    }
            //    CvInvoke.DrawContours(src, use_contours, -1, new MCvScalar(0, 0, 255), 2);
            //}
//   面积筛选:CvInvoke.ContourArea()
//周长筛选:CvInvoke.ArcLength()
//多边形筛选:CvInvoke.ApproxPolyDP()
           // imageBox1.Image = src;
        }
        private void findcar_Click(object sender, EventArgs e)
        {
            OpenFileDialog open;
            open = new OpenFileDialog();
            Image<Bgr, Byte> src = null;
            if (open.ShowDialog() == DialogResult.OK)
            {
                // filename = open.FileName;
                //pictureBox2.Load(filename);
                src = new Image<Bgr, byte>(open.FileName);
            }
            //从文件加载图像
            // String imagePath = @"C:\Users\11018\Pictures\ats\hb.png";
            //Image<Bgr, Byte> src = new Image<Bgr, byte>(@imagePath);
            CvInvoke.Imshow("src", src);
            Mat dst = new Mat();
            CvInvoke.Canny(src, dst, 120, 180);
            //创建用于存储轮廓的VectorOfVectorOfPoint数据类型
            VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
            CvInvoke.FindContours(dst, contours, null, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);
            //用于存储筛选过后的轮廓
            VectorOfVectorOfPoint use_contours = new VectorOfVectorOfPoint();
            //获取联通区域个数
            int ksize = contours.Size;
            for (int i = 0; i < ksize; i++)
            {
                //获取独立的连通轮廓
                VectorOfPoint contour = contours[i];
                //用于存放逼近的结果
                VectorOfPoint approx_curve = new VectorOfPoint();

                //计算连通轮廓的长度
                double length = CvInvoke.ArcLength(contour, false);

                //if (length > 68)  //&& length <150  可以过滤线条
                //{
                    //几何逼近,精度为连通域轮廓周长的0.05倍。
                    //IInputArray curve;输入需要逼近的轮廓,一般类型为VectorOfPoint。
                    //IOutputArray approxCurve:逼近的结果,与输入的类型一致。里面的点代表多边形顶点坐标。
                    //double epsilon:逼近精度。
                    CvInvoke.ApproxPolyDP(contour, approx_curve, length * 0.05, true);
                    //if (CvInvoke.ContourArea(approx_curve, false) > 900)
                    //{
                        //approx_Curve.Size 代表顶点个数,即多边形边数。
                        if (approx_curve.Size == 4)
                        {
                            //添加筛选后的连通轮廓
                            use_contours.Push(contour);
                        }
                    //}
                //}
            }
            CvInvoke.DrawContours(src, use_contours, -1, new MCvScalar(66, 55, 250), 2);
            imageBox1.Image = src;


        }



        private void ocrx()
        {
            Tesseract _ocr;//创建Tesseract 类
            string path = @"D:\tessdata";//申明数据源的路径,在运行目录的tessdata 文件夹下。
            string language = "eng";//申明选择语言。
            try
            {
                _ocr = new Tesseract(path, language, OcrEngineMode.Default);//指定参数实例化tessdata 类。地址为空时,需将tessdata文件夹放在debug根目录                        
                _ocr.PageSegMode = PageSegMode.SingleBlock;
                _ocr.SetImage(imageBox1.Image);
                int result = _ocr.Recognize();
                if (result != 0)
                {
                    MessageBox.Show("识别失败!");
                    return;
                }
                Tesseract.Character[] characters = _ocr.GetCharacters();//获取识别数据
                //Bgr drawColor = new Bgr(Color.Blue);//创建Bgr 为蓝色。
                //foreach (Tesseract.Character c in characters)//遍历每个识别数据。
                //{
                //    image.Draw(c.Region, drawColor, 1);//绘制检测到的区域。
                //}
                //imageBox1.Image = image;//显示绘制矩形区域的图像            
                String text = _ocr.GetUTF8Text();//得到识别字符串。
                textBox1.Text += text + "\r\n";//显示获取的字符串。
            }
            catch
            {
                MessageBox.Show("检查运行目录是否有语言包");
            }
        }
        private void button11_Click(object sender, EventArgs e)
        {
            OpenFileDialog open;
            open = new OpenFileDialog();
            Image<Bgr, Byte> src = null;
            if (open.ShowDialog() == DialogResult.OK)
            {
               // filename = open.FileName;
                //pictureBox2.Load(filename);
                src = new Image<Bgr, byte>(open.FileName);
            }

            //从文件加载图像
            //String imagePath = @"C:\Users\11018\Pictures\ats\22.png";
            //Image<Bgr, Byte> src = new Image<Bgr, byte>(@imagePath);
            CvInvoke.Imshow("src", src);

            Mat hsvimg = new Mat();
            Mat mask = new Mat();

            double h_min = int.Parse(hmin.Text), s_min = int.Parse(smin.Text), v_min = int.Parse(vmin.Text);
            double h_max = int.Parse(hmax.Text), s_max = int.Parse(smax.Text), v_max = int.Parse(vmax.Text);


            Bgr min = new Bgr(h_min, s_min, v_min);//黄色的最小值,允许一定的误差。
            Bgr max = new Bgr(h_max, s_max, v_max);//黄色的最大值,允许一定的误差。
            Image<Gray, byte> result = src.InRange(min, max);//进行颜色提取。


            //imageBox1.Image = result;//显示提取颜色区域。
            //CvInvoke.Imshow("heibai train", result);

            //CvInvoke.DrawContours(result, use_contours, -1, new MCvScalar(66, 55, 250), 2);
            //CvInvoke.Canny(result, result, 20, 40);//画出边缘地区
            //CvInvoke.Imshow("Canny train", result);
            CvInvoke.Imshow("src 222Imagede", result);
            imageBox1.Image = result;
           
            //image = new Image<Bgr, byte>(open.FileName);
            //Rectangle rName = new Rectangle(0, 0, result.Width, result.Height);
            //Image<Bgr, byte> imageSource = result.GetSubRect(rName);
            //Image<Gray, byte> imageGrayscale = imageSource.Convert<Gray, Byte>();
            result = result.ThresholdBinary(new Gray(110), new Gray(255));
            CvInvoke.Imshow("src Imagede", result);
            CvInvoke.Canny(result, result, 20, 40);//画出边缘地区
            this.imageBox1.Image = result;
            ocrx();
            return;
            Mat dst = new Mat();

            CvInvoke.Canny(result, dst, 120, 180);

            //创建用于存储轮廓的VectorOfVectorOfPoint数据类型
            VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();

            CvInvoke.FindContours(dst, contours, null, Emgu.CV.CvEnum.RetrType.External, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);

            //用于存储筛选过后的轮廓
            VectorOfVectorOfPoint use_contours = new VectorOfVectorOfPoint();
            //获取联通区域个数
            int ksize = contours.Size;



            for (int i = 0; i < ksize; i++)
            {
                //获取独立的连通轮廓
                VectorOfPoint contour = contours[i];
                //用于存放逼近的结果
                VectorOfPoint approx_curve = new VectorOfPoint();

                //计算连通轮廓的长度
                double length = CvInvoke.ArcLength(contour, false);

                //if (length > 68)  //&& length <150  可以过滤线条
                //{
                    //几何逼近,精度为连通域轮廓周长的0.05倍。
                    //IInputArray curve;输入需要逼近的轮廓,一般类型为VectorOfPoint。
                    //IOutputArray approxCurve:逼近的结果,与输入的类型一致。里面的点代表多边形顶点坐标。
                    //double epsilon:逼近精度。
                    CvInvoke.ApproxPolyDP(contour, approx_curve, length * 0.04, true);
                    //if (CvInvoke.ContourArea(approx_curve, false) > 900)
                    //{
                        //approx_Curve.Size 代表顶点个数,即多边形边数。
                        if (approx_curve.Size == 4)
                        {
                            //添加筛选后的连通轮廓
                            use_contours.Push(contour);
                        }
                    //}
                //}
            }
            CvInvoke.DrawContours(result, use_contours, -1, new MCvScalar(66, 55, 225), 2);
            imageBox1.Image = result;

        }


    }
}

?


namespace WinFormsApp1
{
    partial class Form1
    {
        /// <summary>
        ///  Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        ///  Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        ///  Required method for Designer support - do not modify
        ///  the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.button3 = new System.Windows.Forms.Button();
            this.button4 = new System.Windows.Forms.Button();
            this.imageBox1 = new Emgu.CV.UI.ImageBox();
            this.button5 = new System.Windows.Forms.Button();
            this.button6 = new System.Windows.Forms.Button();
            this.button7 = new System.Windows.Forms.Button();
            this.button8 = new System.Windows.Forms.Button();
            this.button9 = new System.Windows.Forms.Button();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.button10 = new System.Windows.Forms.Button();
            this.txtAera = new System.Windows.Forms.TextBox();
            this.button11 = new System.Windows.Forms.Button();
            this.hmin = new System.Windows.Forms.TextBox();
            this.hmax = new System.Windows.Forms.TextBox();
            this.smax = new System.Windows.Forms.TextBox();
            this.smin = new System.Windows.Forms.TextBox();
            this.vmax = new System.Windows.Forms.TextBox();
            this.vmin = new System.Windows.Forms.TextBox();
            this.label1 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.button12 = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.imageBox1)).BeginInit();
            this.SuspendLayout();
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(12, 12);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "文字";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(12, 52);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 1;
            this.button2.Text = "黑白描边";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // button3
            // 
            this.button3.Location = new System.Drawing.Point(12, 100);
            this.button3.Name = "button3";
            this.button3.Size = new System.Drawing.Size(75, 23);
            this.button3.TabIndex = 2;
            this.button3.Text = "图片描边膨胀";
            this.button3.UseVisualStyleBackColor = true;
            this.button3.Click += new System.EventHandler(this.button3_Click);
            // 
            // button4
            // 
            this.button4.Location = new System.Drawing.Point(12, 149);
            this.button4.Name = "button4";
            this.button4.Size = new System.Drawing.Size(75, 23);
            this.button4.TabIndex = 3;
            this.button4.Text = "读取视频";
            this.button4.UseVisualStyleBackColor = true;
            this.button4.Click += new System.EventHandler(this.button4_Click);
            // 
            // imageBox1
            // 
            this.imageBox1.Location = new System.Drawing.Point(126, 3);
            this.imageBox1.Name = "imageBox1";
            this.imageBox1.Size = new System.Drawing.Size(1971, 1077);
            this.imageBox1.TabIndex = 2;
            this.imageBox1.TabStop = false;
            // 
            // button5
            // 
            this.button5.Location = new System.Drawing.Point(12, 194);
            this.button5.Name = "button5";
            this.button5.Size = new System.Drawing.Size(98, 23);
            this.button5.TabIndex = 4;
            this.button5.Text = "加载图片";
            this.button5.UseVisualStyleBackColor = true;
            this.button5.Click += new System.EventHandler(this.button5_Click);
            // 
            // button6
            // 
            this.button6.Location = new System.Drawing.Point(12, 223);
            this.button6.Name = "button6";
            this.button6.Size = new System.Drawing.Size(98, 21);
            this.button6.TabIndex = 5;
            this.button6.Text = "画一个背景图";
            this.button6.UseVisualStyleBackColor = true;
            this.button6.Click += new System.EventHandler(this.button6_Click);
            // 
            // button7
            // 
            this.button7.Location = new System.Drawing.Point(12, 271);
            this.button7.Name = "button7";
            this.button7.Size = new System.Drawing.Size(108, 23);
            this.button7.TabIndex = 6;
            this.button7.Text = "霍夫曼圆形检测";
            this.button7.UseVisualStyleBackColor = true;
            this.button7.Click += new System.EventHandler(this.button7_Click);
            // 
            // button8
            // 
            this.button8.Location = new System.Drawing.Point(12, 300);
            this.button8.Name = "button8";
            this.button8.Size = new System.Drawing.Size(75, 23);
            this.button8.TabIndex = 7;
            this.button8.Text = "线条检测";
            this.button8.UseVisualStyleBackColor = true;
            this.button8.Click += new System.EventHandler(this.button8_Click);
            // 
            // button9
            // 
            this.button9.Location = new System.Drawing.Point(12, 340);
            this.button9.Name = "button9";
            this.button9.Size = new System.Drawing.Size(75, 23);
            this.button9.TabIndex = 8;
            this.button9.Text = "找三角形矩形";
            this.button9.UseVisualStyleBackColor = true;
            this.button9.Click += new System.EventHandler(this.button9_Click);
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(12, 794);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(100, 243);
            this.textBox1.TabIndex = 9;
            // 
            // button10
            // 
            this.button10.Location = new System.Drawing.Point(10, 378);
            this.button10.Name = "button10";
            this.button10.Size = new System.Drawing.Size(75, 23);
            this.button10.TabIndex = 10;
            this.button10.Text = "找梯形";
            this.button10.UseVisualStyleBackColor = true;
            this.button10.Click += new System.EventHandler(this.button10_Click);
            // 
            // txtAera
            // 
            this.txtAera.Location = new System.Drawing.Point(12, 765);
            this.txtAera.Name = "txtAera";
            this.txtAera.Size = new System.Drawing.Size(100, 23);
            this.txtAera.TabIndex = 11;
            // 
            // button11
            // 
            this.button11.Location = new System.Drawing.Point(12, 419);
            this.button11.Name = "button11";
            this.button11.Size = new System.Drawing.Size(75, 23);
            this.button11.TabIndex = 12;
            this.button11.Text = "颜色过滤";
            this.button11.UseVisualStyleBackColor = true;
            this.button11.Click += new System.EventHandler(this.button11_Click);
            // 
            // hmin
            // 
            this.hmin.Location = new System.Drawing.Point(49, 458);
            this.hmin.Name = "hmin";
            this.hmin.Size = new System.Drawing.Size(36, 23);
            this.hmin.TabIndex = 13;
            this.hmin.Text = "50";
            // 
            // hmax
            // 
            this.hmax.Location = new System.Drawing.Point(84, 458);
            this.hmax.Name = "hmax";
            this.hmax.Size = new System.Drawing.Size(36, 23);
            this.hmax.TabIndex = 14;
            this.hmax.Text = "77";
            // 
            // smax
            // 
            this.smax.Location = new System.Drawing.Point(84, 487);
            this.smax.Name = "smax";
            this.smax.Size = new System.Drawing.Size(36, 23);
            this.smax.TabIndex = 16;
            this.smax.Text = "255";
            // 
            // smin
            // 
            this.smin.Location = new System.Drawing.Point(49, 487);
            this.smin.Name = "smin";
            this.smin.Size = new System.Drawing.Size(36, 23);
            this.smin.TabIndex = 15;
            this.smin.Text = "150";
            // 
            // vmax
            // 
            this.vmax.Location = new System.Drawing.Point(84, 516);
            this.vmax.Name = "vmax";
            this.vmax.Size = new System.Drawing.Size(36, 23);
            this.vmax.TabIndex = 18;
            this.vmax.Text = "10";
            // 
            // vmin
            // 
            this.vmin.Location = new System.Drawing.Point(49, 516);
            this.vmin.Name = "vmin";
            this.vmin.Size = new System.Drawing.Size(36, 23);
            this.vmin.TabIndex = 17;
            this.vmin.Text = "0";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(12, 461);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(17, 17);
            this.label1.TabIndex = 19;
            this.label1.Text = "H";
            // 
            // label2
            // 
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(12, 489);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(15, 17);
            this.label2.TabIndex = 20;
            this.label2.Text = "S";
            // 
            // label3
            // 
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(12, 519);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(16, 17);
            this.label3.TabIndex = 21;
            this.label3.Text = "V";
            // 
            // button12
            // 
            this.button12.Location = new System.Drawing.Point(10, 579);
            this.button12.Name = "button12";
            this.button12.Size = new System.Drawing.Size(75, 23);
            this.button12.TabIndex = 22;
            this.button12.Text = "黑白找车";
            this.button12.UseVisualStyleBackColor = true;
            this.button12.Click += new System.EventHandler(this.findcar_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(2098, 1081);
            this.Controls.Add(this.button12);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.vmax);
            this.Controls.Add(this.vmin);
            this.Controls.Add(this.smax);
            this.Controls.Add(this.smin);
            this.Controls.Add(this.hmax);
            this.Controls.Add(this.hmin);
            this.Controls.Add(this.button11);
            this.Controls.Add(this.txtAera);
            this.Controls.Add(this.button10);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.button9);
            this.Controls.Add(this.button8);
            this.Controls.Add(this.button7);
            this.Controls.Add(this.button6);
            this.Controls.Add(this.button5);
            this.Controls.Add(this.imageBox1);
            this.Controls.Add(this.button4);
            this.Controls.Add(this.button3);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.imageBox1)).EndInit();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Button button3;
        private System.Windows.Forms.Button button4;
        private Emgu.CV.UI.ImageBox imageBox1;
        private System.Windows.Forms.Button button5;
        private System.Windows.Forms.Button button6;
        private System.Windows.Forms.Button button7;
        private System.Windows.Forms.Button button8;
        private System.Windows.Forms.Button button9;
        private System.Windows.Forms.TextBox textBox1;
        private System.Windows.Forms.Button button10;
        private System.Windows.Forms.TextBox txtAera;
        private System.Windows.Forms.Button button11;
        private System.Windows.Forms.TextBox hmin;
        private System.Windows.Forms.TextBox hmax;
        private System.Windows.Forms.TextBox smax;
        private System.Windows.Forms.TextBox smin;
        private System.Windows.Forms.TextBox vmax;
        private System.Windows.Forms.TextBox vmin;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Button button12;
    }
}

  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2021-11-01 11:35:03  更:2021-11-01 11:35:26 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/27 6:17:29-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码