C# OpenCvSharp DNN 部署yolov5不规则四边形目标检测

本文主要是介绍C# OpenCvSharp DNN 部署yolov5不规则四边形目标检测,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

目录

效果

模型信息

项目

代码

下载


C# OpenCvSharp DNN 部署yolov5不规则四边形目标检测

效果

模型信息

Inputs
-------------------------
name:images
tensor:Float[1, 3, 1024, 1024]
---------------------------------------------------------------

Outputs
-------------------------
name:output
tensor:Float[1, 64512, 11]
---------------------------------------------------------------

项目

代码

using OpenCvSharp;
using OpenCvSharp.Dnn;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Numerics;
using System.Reflection;
using System.Windows.Forms;

namespace OpenCvSharp_DNN_Demo
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";

        DateTime dt1 = DateTime.Now;
        DateTime dt2 = DateTime.Now;

        float confThreshold;
        float nmsThreshold;
        float objThreshold;

        float[,] anchors = new float[3, 6] {
                                           {31, 30, 28, 49, 50, 31},
                                           {46, 45, 58, 58, 74, 74},
                                           {94, 94, 115, 115, 151, 151}
                                           };

        float[] stride = new float[3] { 8.0f, 16.0f, 32.0f };

        string modelpath;

        int inpHeight;
        int inpWidth;

        List<string> class_names;
        int num_class;

        Net opencv_net;
        Mat BN_image;

        Mat image;
        Mat result_image;

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;

            pictureBox1.Image = null;
            pictureBox2.Image = null;
            textBox1.Text = "";

            image_path = ofd.FileName;
            pictureBox1.Image = new Bitmap(image_path);
            image = new Mat(image_path);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            confThreshold = 0.5f;
            nmsThreshold = 0.5f;
            objThreshold = 0.5f;

            modelpath = "model/best.onnx";

            inpHeight = 1024;
            inpWidth = 1024;

            opencv_net = CvDnn.ReadNetFromOnnx(modelpath);

            class_names = new List<string>();
            StreamReader sr = new StreamReader("model/coco.names");
            string line;
            while ((line = sr.ReadLine()) != null)
            {
                class_names.Add(line);
            }
            num_class = class_names.Count();

            image_path = "test_img/1.png";
            pictureBox1.Image = new Bitmap(image_path);

        }

        float sigmoid(float x)
        {
            return (float)(1.0 / (1 + Math.Exp(-x)));
        }

        Mat ResizeImage(Mat srcimg, out int newh, out int neww, out int top, out int left)
        {
            int srch = srcimg.Rows, srcw = srcimg.Cols;
            top = 0;
            left = 0;
            newh = inpHeight;
            neww = inpWidth;
            Mat dstimg = new Mat();
            if (srch != srcw)
            {
                float hw_scale = (float)srch / srcw;
                if (hw_scale > 1)
                {
                    newh = inpHeight;
                    neww = (int)(inpWidth / hw_scale);
                    Cv2.Resize(srcimg, dstimg, new OpenCvSharp.Size(neww, newh), 0, 0, InterpolationFlags.Area);
                    left = (int)((inpWidth - neww) * 0.5);
                    Cv2.CopyMakeBorder(dstimg, dstimg, 0, 0, left, inpWidth - neww - left, BorderTypes.Constant);
                }
                else
                {
                    newh = (int)(inpHeight * hw_scale);
                    neww = inpWidth;
                    Cv2.Resize(srcimg, dstimg, new OpenCvSharp.Size(neww, newh), 0, 0, InterpolationFlags.Area);
                    top = (int)((inpHeight - newh) * 0.5);
                    Cv2.CopyMakeBorder(dstimg, dstimg, top, inpHeight - newh - top, 0, 0, BorderTypes.Constant);
                }
            }
            else
            {
                Cv2.Resize(srcimg, dstimg, new OpenCvSharp.Size(neww, newh));
            }
            return dstimg;
        }

        float IoU(BoxInfo polya, BoxInfo polyb, int max_w, int max_h)
        {
            List<List<OpenCvSharp.Point>> poly_array0 = new List<List<OpenCvSharp.Point>>();
            List<List<OpenCvSharp.Point>> poly_array1 = new List<List<OpenCvSharp.Point>>();
            poly_array0.Add(polya.pts);
            poly_array1.Add(polyb.pts);

            Mat _poly0 = Mat.Zeros(max_h, max_w, MatType.CV_8UC1);
            Mat _poly1 = Mat.Zeros(max_h, max_w, MatType.CV_8UC1);
            Mat _result = new Mat();

            List<List<OpenCvSharp.Point>> _pts0 = new List<List<OpenCvSharp.Point>>();
            List<int> _npts0 = new List<int>();

            foreach (var item in poly_array0)
            {
                if (item.Count < 3)//invalid poly
                    return -1f;

                _pts0.Add(item);
                _npts0.Add(item.Count);

            }

            List<List<OpenCvSharp.Point>> _pts1 = new List<List<OpenCvSharp.Point>>();
            List<int> _npts1 = new List<int>();

            foreach (var item in poly_array1)
            {
                if (item.Count < 3)//invalid poly
                    return -1f;

                _pts1.Add(item);
                _npts1.Add(item.Count);

            }

            Cv2.FillPoly(_poly0, _pts0, new Scalar(1));
            Cv2.FillPoly(_poly1, _pts1, new Scalar(1));

            Cv2.BitwiseAnd(_poly0, _poly1, _result);

            int _area0 = Cv2.CountNonZero(_poly0);
            int _area1 = Cv2.CountNonZero(_poly1);
            int _intersection_area = Cv2.CountNonZero(_result);
            float _iou = (float)_intersection_area / (float)(_area0 + _area1 - _intersection_area);
            return _iou;
        }

        void nms(List<BoxInfo> input_boxes, int max_w, int max_h)
        {
            input_boxes.Sort((a, b) => { return a.score > b.score ? -1 : 1; });

            bool[] isSuppressed = new bool[input_boxes.Count];

            for (int i = 0; i < input_boxes.Count(); ++i)
            {
                if (isSuppressed[i]) { continue; }
                for (int j = i + 1; j < input_boxes.Count(); ++j)
                {
                    if (isSuppressed[j]) { continue; }
                    float ovr = IoU(input_boxes[i], input_boxes[j], max_w, max_h);
                    if (ovr >= nmsThreshold)
                    {
                        isSuppressed[j] = true;
                    }
                }
            }

            for (int i = isSuppressed.Length - 1; i >= 0; i--)
            {
                if (isSuppressed[i])
                {
                    input_boxes.RemoveAt(i);
                }
            }

        }

        private unsafe void button2_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }
            textBox1.Text = "检测中,请稍等……";
            pictureBox2.Image = null;
            Application.DoEvents();

            image = new Mat(image_path);

            int newh = 0, neww = 0, padh = 0, padw = 0;
            Mat dstimg = ResizeImage(image, out newh, out neww, out padh, out padw);

            BN_image = CvDnn.BlobFromImage(dstimg, 1 / 255.0, new OpenCvSharp.Size(inpWidth, inpHeight), new Scalar(0, 0, 0), true, false);

            //配置图片输入数据
            opencv_net.SetInput(BN_image);

            //模型推理,读取推理结果
            Mat[] outs = new Mat[3] { new Mat(), new Mat(), new Mat() };
            string[] outBlobNames = opencv_net.GetUnconnectedOutLayersNames().ToArray();

            dt1 = DateTime.Now;

            opencv_net.Forward(outs, outBlobNames);

            dt2 = DateTime.Now;

            int num_proposal = outs[0].Size(1);
            int nout = outs[0].Size(2);

            if (outs[0].Dims > 2)
            {
                outs[0] = outs[0].Reshape(0, num_proposal);
            }

            float ratioh = 1.0f * image.Rows / newh, ratiow = 1.0f * image.Cols / neww;

            float* pdata = (float*)outs[0].Data;

            List<BoxInfo> generate_boxes = new List<BoxInfo>();

            int row_ind = 0;

            for (int n = 0; n < 3; n++)
            {

                int num_grid_x = (int)(inpWidth / stride[n]);
                int num_grid_y = (int)(inpHeight / stride[n]);

                for (int q = 0; q < 3; q++)    //anchor
                {
                    float anchor_w = anchors[n, q * 2];
                    float anchor_h = anchors[n, q * 2 + 1];
                    for (int i = 0; i < num_grid_y; i++)
                    {
                        for (int j = 0; j < num_grid_x; j++)
                        {
                            float box_score = sigmoid(pdata[8]);
                            if (box_score > objThreshold)
                            {

                                Mat scores = outs[0].Row(row_ind).ColRange(9, 9 + num_class);
                                double minVal, max_class_socre;
                                OpenCvSharp.Point minLoc, classIdPoint;
                                // Get the value and location of the maximum score
                                Cv2.MinMaxLoc(scores, out minVal, out max_class_socre, out minLoc, out classIdPoint);

                                int class_idx = classIdPoint.X;
                                max_class_socre = sigmoid((float)max_class_socre) * box_score;
                                if (max_class_socre > confThreshold)
                                {
                                    List<OpenCvSharp.Point> pts = new List<OpenCvSharp.Point>();
                                    for (int k = 0; k < 8; k += 2)
                                    {
                                        float x = (pdata[k] + j) * stride[n];  //x
                                        float y = (pdata[k + 1] + i) * stride[n];   //y
                                        x = (x - padw) * ratiow;
                                        y = (y - padh) * ratioh;
                                        pts.Add(new OpenCvSharp.Point(x, y));
                                    }

                                    Rect r = Cv2.BoundingRect(pts);

                                    generate_boxes.Add(new BoxInfo(pts, (float)max_class_socre, class_idx));
                                }
                            }
                            row_ind++;
                            pdata += nout;
                        }
                    }

                }

            }

            nms(generate_boxes, image.Cols, image.Rows);

            result_image = image.Clone();

            for (int ii = 0; ii < generate_boxes.Count; ++ii)
            {
                int idx = generate_boxes[ii].label;

                for (int jj = 0; jj < 4; jj++)
                {
                    Cv2.Line(result_image, generate_boxes[ii].pts[jj], generate_boxes[ii].pts[(jj + 1) % 4], new Scalar(0, 0, 255), 2);
                }

                string label = class_names[idx] + ":" + generate_boxes[ii].score.ToString("0.00");

                int xmin = (int)generate_boxes[ii].pts[0].X;
                int ymin = (int)generate_boxes[ii].pts[0].Y - 10;

                Cv2.PutText(result_image, label, new OpenCvSharp.Point(xmin, ymin - 5), HersheyFonts.HersheySimplex, 0.75, new Scalar(0, 0, 255), 1);
            }

            pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());
            textBox1.Text = "推理耗时:" + (dt2 - dt1).TotalMilliseconds + "ms";
        }

        private void pictureBox2_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox2.Image);
        }

        private void pictureBox1_DoubleClick(object sender, EventArgs e)
        {
            Common.ShowNormalImg(pictureBox1.Image);
        }
    }
}

using OpenCvSharp;
using OpenCvSharp.Dnn;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Numerics;
using System.Reflection;
using System.Windows.Forms;namespace OpenCvSharp_DNN_Demo
{public partial class frmMain : Form{public frmMain(){InitializeComponent();}string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";string image_path = "";DateTime dt1 = DateTime.Now;DateTime dt2 = DateTime.Now;float confThreshold;float nmsThreshold;float objThreshold;float[,] anchors = new float[3, 6] {{31, 30, 28, 49, 50, 31},{46, 45, 58, 58, 74, 74},{94, 94, 115, 115, 151, 151}};float[] stride = new float[3] { 8.0f, 16.0f, 32.0f };string modelpath;int inpHeight;int inpWidth;List<string> class_names;int num_class;Net opencv_net;Mat BN_image;Mat image;Mat result_image;private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = fileFilter;if (ofd.ShowDialog() != DialogResult.OK) return;pictureBox1.Image = null;pictureBox2.Image = null;textBox1.Text = "";image_path = ofd.FileName;pictureBox1.Image = new Bitmap(image_path);image = new Mat(image_path);}private void Form1_Load(object sender, EventArgs e){confThreshold = 0.5f;nmsThreshold = 0.5f;objThreshold = 0.5f;modelpath = "model/best.onnx";inpHeight = 1024;inpWidth = 1024;opencv_net = CvDnn.ReadNetFromOnnx(modelpath);class_names = new List<string>();StreamReader sr = new StreamReader("model/coco.names");string line;while ((line = sr.ReadLine()) != null){class_names.Add(line);}num_class = class_names.Count();image_path = "test_img/1.png";pictureBox1.Image = new Bitmap(image_path);}float sigmoid(float x){return (float)(1.0 / (1 + Math.Exp(-x)));}Mat ResizeImage(Mat srcimg, out int newh, out int neww, out int top, out int left){int srch = srcimg.Rows, srcw = srcimg.Cols;top = 0;left = 0;newh = inpHeight;neww = inpWidth;Mat dstimg = new Mat();if (srch != srcw){float hw_scale = (float)srch / srcw;if (hw_scale > 1){newh = inpHeight;neww = (int)(inpWidth / hw_scale);Cv2.Resize(srcimg, dstimg, new OpenCvSharp.Size(neww, newh), 0, 0, InterpolationFlags.Area);left = (int)((inpWidth - neww) * 0.5);Cv2.CopyMakeBorder(dstimg, dstimg, 0, 0, left, inpWidth - neww - left, BorderTypes.Constant);}else{newh = (int)(inpHeight * hw_scale);neww = inpWidth;Cv2.Resize(srcimg, dstimg, new OpenCvSharp.Size(neww, newh), 0, 0, InterpolationFlags.Area);top = (int)((inpHeight - newh) * 0.5);Cv2.CopyMakeBorder(dstimg, dstimg, top, inpHeight - newh - top, 0, 0, BorderTypes.Constant);}}else{Cv2.Resize(srcimg, dstimg, new OpenCvSharp.Size(neww, newh));}return dstimg;}float IoU(BoxInfo polya, BoxInfo polyb, int max_w, int max_h){List<List<OpenCvSharp.Point>> poly_array0 = new List<List<OpenCvSharp.Point>>();List<List<OpenCvSharp.Point>> poly_array1 = new List<List<OpenCvSharp.Point>>();poly_array0.Add(polya.pts);poly_array1.Add(polyb.pts);Mat _poly0 = Mat.Zeros(max_h, max_w, MatType.CV_8UC1);Mat _poly1 = Mat.Zeros(max_h, max_w, MatType.CV_8UC1);Mat _result = new Mat();List<List<OpenCvSharp.Point>> _pts0 = new List<List<OpenCvSharp.Point>>();List<int> _npts0 = new List<int>();foreach (var item in poly_array0){if (item.Count < 3)//invalid polyreturn -1f;_pts0.Add(item);_npts0.Add(item.Count);}List<List<OpenCvSharp.Point>> _pts1 = new List<List<OpenCvSharp.Point>>();List<int> _npts1 = new List<int>();foreach (var item in poly_array1){if (item.Count < 3)//invalid polyreturn -1f;_pts1.Add(item);_npts1.Add(item.Count);}Cv2.FillPoly(_poly0, _pts0, new Scalar(1));Cv2.FillPoly(_poly1, _pts1, new Scalar(1));Cv2.BitwiseAnd(_poly0, _poly1, _result);int _area0 = Cv2.CountNonZero(_poly0);int _area1 = Cv2.CountNonZero(_poly1);int _intersection_area = Cv2.CountNonZero(_result);float _iou = (float)_intersection_area / (float)(_area0 + _area1 - _intersection_area);return _iou;}void nms(List<BoxInfo> input_boxes, int max_w, int max_h){input_boxes.Sort((a, b) => { return a.score > b.score ? -1 : 1; });bool[] isSuppressed = new bool[input_boxes.Count];for (int i = 0; i < input_boxes.Count(); ++i){if (isSuppressed[i]) { continue; }for (int j = i + 1; j < input_boxes.Count(); ++j){if (isSuppressed[j]) { continue; }float ovr = IoU(input_boxes[i], input_boxes[j], max_w, max_h);if (ovr >= nmsThreshold){isSuppressed[j] = true;}}}for (int i = isSuppressed.Length - 1; i >= 0; i--){if (isSuppressed[i]){input_boxes.RemoveAt(i);}}}private unsafe void button2_Click(object sender, EventArgs e){if (image_path == ""){return;}textBox1.Text = "检测中,请稍等……";pictureBox2.Image = null;Application.DoEvents();image = new Mat(image_path);int newh = 0, neww = 0, padh = 0, padw = 0;Mat dstimg = ResizeImage(image, out newh, out neww, out padh, out padw);BN_image = CvDnn.BlobFromImage(dstimg, 1 / 255.0, new OpenCvSharp.Size(inpWidth, inpHeight), new Scalar(0, 0, 0), true, false);//配置图片输入数据opencv_net.SetInput(BN_image);//模型推理,读取推理结果Mat[] outs = new Mat[3] { new Mat(), new Mat(), new Mat() };string[] outBlobNames = opencv_net.GetUnconnectedOutLayersNames().ToArray();dt1 = DateTime.Now;opencv_net.Forward(outs, outBlobNames);dt2 = DateTime.Now;int num_proposal = outs[0].Size(1);int nout = outs[0].Size(2);if (outs[0].Dims > 2){outs[0] = outs[0].Reshape(0, num_proposal);}float ratioh = 1.0f * image.Rows / newh, ratiow = 1.0f * image.Cols / neww;float* pdata = (float*)outs[0].Data;List<BoxInfo> generate_boxes = new List<BoxInfo>();int row_ind = 0;for (int n = 0; n < 3; n++){int num_grid_x = (int)(inpWidth / stride[n]);int num_grid_y = (int)(inpHeight / stride[n]);for (int q = 0; q < 3; q++)    //anchor{float anchor_w = anchors[n, q * 2];float anchor_h = anchors[n, q * 2 + 1];for (int i = 0; i < num_grid_y; i++){for (int j = 0; j < num_grid_x; j++){float box_score = sigmoid(pdata[8]);if (box_score > objThreshold){Mat scores = outs[0].Row(row_ind).ColRange(9, 9 + num_class);double minVal, max_class_socre;OpenCvSharp.Point minLoc, classIdPoint;// Get the value and location of the maximum scoreCv2.MinMaxLoc(scores, out minVal, out max_class_socre, out minLoc, out classIdPoint);int class_idx = classIdPoint.X;max_class_socre = sigmoid((float)max_class_socre) * box_score;if (max_class_socre > confThreshold){List<OpenCvSharp.Point> pts = new List<OpenCvSharp.Point>();for (int k = 0; k < 8; k += 2){float x = (pdata[k] + j) * stride[n];  //xfloat y = (pdata[k + 1] + i) * stride[n];   //yx = (x - padw) * ratiow;y = (y - padh) * ratioh;pts.Add(new OpenCvSharp.Point(x, y));}Rect r = Cv2.BoundingRect(pts);generate_boxes.Add(new BoxInfo(pts, (float)max_class_socre, class_idx));}}row_ind++;pdata += nout;}}}}nms(generate_boxes, image.Cols, image.Rows);result_image = image.Clone();for (int ii = 0; ii < generate_boxes.Count; ++ii){int idx = generate_boxes[ii].label;for (int jj = 0; jj < 4; jj++){Cv2.Line(result_image, generate_boxes[ii].pts[jj], generate_boxes[ii].pts[(jj + 1) % 4], new Scalar(0, 0, 255), 2);}string label = class_names[idx] + ":" + generate_boxes[ii].score.ToString("0.00");int xmin = (int)generate_boxes[ii].pts[0].X;int ymin = (int)generate_boxes[ii].pts[0].Y - 10;Cv2.PutText(result_image, label, new OpenCvSharp.Point(xmin, ymin - 5), HersheyFonts.HersheySimplex, 0.75, new Scalar(0, 0, 255), 1);}pictureBox2.Image = new Bitmap(result_image.ToMemoryStream());textBox1.Text = "推理耗时:" + (dt2 - dt1).TotalMilliseconds + "ms";}private void pictureBox2_DoubleClick(object sender, EventArgs e){Common.ShowNormalImg(pictureBox2.Image);}private void pictureBox1_DoubleClick(object sender, EventArgs e){Common.ShowNormalImg(pictureBox1.Image);}}
}

下载

源码下载

这篇关于C# OpenCvSharp DNN 部署yolov5不规则四边形目标检测的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/488871

相关文章

C#连接SQL server数据库命令的基本步骤

《C#连接SQLserver数据库命令的基本步骤》文章讲解了连接SQLServer数据库的步骤,包括引入命名空间、构建连接字符串、使用SqlConnection和SqlCommand执行SQL操作,... 目录建议配合使用:如何下载和安装SQL server数据库-CSDN博客1. 引入必要的命名空间2.

golang程序打包成脚本部署到Linux系统方式

《golang程序打包成脚本部署到Linux系统方式》Golang程序通过本地编译(设置GOOS为linux生成无后缀二进制文件),上传至Linux服务器后赋权执行,使用nohup命令实现后台运行,完... 目录本地编译golang程序上传Golang二进制文件到linux服务器总结本地编译Golang程序

Linux系统性能检测命令详解

《Linux系统性能检测命令详解》本文介绍了Linux系统常用的监控命令(如top、vmstat、iostat、htop等)及其参数功能,涵盖进程状态、内存使用、磁盘I/O、系统负载等多维度资源监控,... 目录toppsuptimevmstatIOStatiotopslabtophtopdstatnmon

如何在Ubuntu 24.04上部署Zabbix 7.0对服务器进行监控

《如何在Ubuntu24.04上部署Zabbix7.0对服务器进行监控》在Ubuntu24.04上部署Zabbix7.0监控阿里云ECS服务器,需配置MariaDB数据库、开放10050/1005... 目录软硬件信息部署步骤步骤 1:安装并配置mariadb步骤 2:安装Zabbix 7.0 Server

C#读写文本文件的多种方式详解

《C#读写文本文件的多种方式详解》这篇文章主要为大家详细介绍了C#中各种常用的文件读写方式,包括文本文件,二进制文件、CSV文件、JSON文件等,有需要的小伙伴可以参考一下... 目录一、文本文件读写1. 使用 File 类的静态方法2. 使用 StreamReader 和 StreamWriter二、二进

C#中Guid类使用小结

《C#中Guid类使用小结》本文主要介绍了C#中Guid类用于生成和操作128位的唯一标识符,用于数据库主键及分布式系统,支持通过NewGuid、Parse等方法生成,感兴趣的可以了解一下... 目录前言一、什么是 Guid二、生成 Guid1. 使用 Guid.NewGuid() 方法2. 从字符串创建

C# 比较两个list 之间元素差异的常用方法

《C#比较两个list之间元素差异的常用方法》:本文主要介绍C#比较两个list之间元素差异,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录1. 使用Except方法2. 使用Except的逆操作3. 使用LINQ的Join,GroupJoin

C++ 检测文件大小和文件传输的方法示例详解

《C++检测文件大小和文件传输的方法示例详解》文章介绍了在C/C++中获取文件大小的三种方法,推荐使用stat()函数,并详细说明了如何设计一次性发送压缩包的结构体及传输流程,包含CRC校验和自动解... 目录检测文件的大小✅ 方法一:使用 stat() 函数(推荐)✅ 用法示例:✅ 方法二:使用 fsee

OpenCV实现实时颜色检测的示例

《OpenCV实现实时颜色检测的示例》本文主要介绍了OpenCV实现实时颜色检测的示例,通过HSV色彩空间转换和色调范围判断实现红黄绿蓝颜色检测,包含视频捕捉、区域标记、颜色分析等功能,具有一定的参考... 目录一、引言二、系统概述三、代码解析1. 导入库2. 颜色识别函数3. 主程序循环四、HSV色彩空间

C#如何去掉文件夹或文件名非法字符

《C#如何去掉文件夹或文件名非法字符》:本文主要介绍C#如何去掉文件夹或文件名非法字符的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录C#去掉文件夹或文件名非法字符net类库提供了非法字符的数组这里还有个小窍门总结C#去掉文件夹或文件名非法字符实现有输入字