c# OpenCvSharp 画线 矩形 圆形 椭圆
using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using
using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using
using OpenCvSharp;
using OpenCvSharp.Extensions;
using DlibDotNet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
usin
using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.T
显示方式1:OpenCvSharp窗体 var window = new Window(“cv”);
显示方式2:Windows 窗体 PictureBox控件
using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
usin
通过NuGet添加程序包。注意 Windows下选择 OpenCvSharp4.Windows。
OpenCvSharp4.Extensions
using OpenCvSharp;
using OpenCvSharp.Extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using Syst
import dlib
import cv2
# 使用 dlib 的正面人脸检测器 frontal_face_detector
detector = dlib.get_frontal_face_detector()
# 打开摄像头
cap = cv2.VideoCapture(0)
# 摄像头打开状态
while cap.isOpened():
flag, img = cap.read()
# 每帧数据延时 1ms,延时为 0 读取的是静态帧
k = cv
pip install dlib -i https://pypi.tuna.tsinghua.edu.cn/simple/
错误1:没有安装依赖库报错
错误2:没有安装c++库报错
正确按照步骤:
1、安装c++。通过VisualStudioSetup.exe安装。
2、安装依赖库,再安装dlib。
1、安装Cmake库
pip install cmake -i https://pypi.tuna.tsinghua.edu.cn/simple/
一、环境搭建
1、下载YOLOv5代码。https://github.com/ultralytics/yolov5
目录结构:
tutorial.ipynb(可以用jupyter notebook打开)。
2、安装依赖包。根据requirements.txt按需安装 或者 默认安装。
pip install -r requirements.txt
3、权重文件yolov5s.pt默认不存在,可以手动下载。访问https://github.com/ultraly
C:\Python39\Lib\site-packages\torch\nn\modules\upsampling.py
把参数recompute_scale_factor=self.recompute_scale_factor注释掉。
安装:pip install labelimg
启动:在cmd命令行中输入 labelimg
“Create RectBox”进行框选,输入标签名称。目前labelimg支持PascalVOC、YOLO、CreateML三种标注格式。
“Open Dir”打开目录。
“Change Save Dir”修改保存目录。
“Auto Save mode”自动保存。
一、演示
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
us
1、创建一个ASP.NET Web项目。选中Web API。
2、创建一个控制器 BillController
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.W
import cv2
import numpy as np
# 读取图像
img = cv2.imread(‘pic/qipan.jpg’)
# 转化为灰度图
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 检测角点必须保证图像为浮点数据类型
gray = np.float32(gray)
# gray:输入的浮点灰度图
# 2: 检测中考虑的领域大小
# 3:sobel求导中使用的窗口大小
# 0.
import cv2
import matplotlib.pyplot as plt
# 画图文字使用黑体字显示(显示中文,默认不支持中文)
plt.rcParams[‘font.sans-serif’] = [‘SimHei’]
img = cv2.imread(‘pic/st.png’)
img_gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
# 采用二值化方式处理图像,像素值在182-255之间为1,小于182像素值的
import cv2
import matplotlib.pyplot as plt
# 画图文字使用黑体字显示(显示中文,默认不支持中文)
plt.rcParams[‘font.sans-serif’] = [‘SimHei’]
# 读取图片
img = cv2.imread(‘demo.png’)
# 转换通道
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# 使用Canny算法,滞后阈值分别设定为200,300
import numpy as np
import cv2
import matplotlib.pylab as plt
import matplotlib as mpl
mpl.rcParams[‘font.sans-serif’] = [‘SimHei’]
# 指定默认字体为黑体
mpl.rcParams[‘axes.unicode_minus’] = False
# 正常显示负号
# 原图
img = cv2.imread(“lena.jpeg”)
import cv2
import numpy as np
import matplotlib.pylab as plt
import matplotlib as mpl
# 绘制线
# 生成一个空的黑底图像
# np.zeros()有两个参数,一个是创建的图片矩阵大小,另一个是数据类型。
# 512,512是像素(第一个512 像素 高,第二个512 像素 宽),3指BGR三种颜色。
img = np.zeros((512, 512, 3), np.uin
filter2D (src, dst, ddepth, kernel)
src 应用过滤器的源图像。
dst 应用过滤器后输出图像的名称。
ddepth 输出图像的深度 [-1 将给出与输入图像相同的输出图像深度]。
kernel 我们希望图像与之卷积的二维矩阵。
import cv2
import numpy as np
import matplotlib.pylab as plt
import matplotlib as mpl
# 读取图像
i
高斯滤波是一种线性平滑滤波,适用于消除高斯噪声,广泛应用于图像处理的减噪过程。
通俗的讲,高斯滤波就是对整幅图像进行加权平均的过程,每一个像素点的值,都由其本身和邻域内的其他像素值经过加权平均后得到。
高斯滤波的具体操作是:用一个模板(或称卷积、掩模)扫描图像中的每一个像素,用模板确定的邻域内像素的加权平均灰度值去替代模板中心像素点的值。
对应均值滤波和方框滤波来说,其邻域内每个像素的权重是相等的。而在高斯滤波中,会将中心点的权重值加大,远离中心点的权重值减小,在此基础上计算邻域内各
中值滤波法是一种非线性平滑技术,它将每一像素点的灰度值设置为该点某邻域窗口内的所有像素点灰度值的中值。
中值滤波的方法是用某种结构的二维滑动模板,将板内像素按照像素值的大小进行排序,生成上升(或下降)的为二维数据序列。
中值滤波会选取数字图像或数字序列中像素点及其周围临近像素点(一共有奇数个像素点)的像素值,将这些像素值排序,然后将位于中间位置的像素值作为当前像素点的像素值,让周围的像素值接近真实值,从而消除孤立的噪声点。
在该序列中,处于中心位置(也叫中心点或中值点)的值是“