当前位置:首页 > 编程笔记 > 正文
已解决

C# OpenCvSharp 图片模糊检测(拉普拉斯算子)

来自网友在路上 179879提问 提问时间:2023-09-24 01:09:47阅读次数: 79

最佳答案 问答题库798位专家为你答疑解惑

效果

项目

代码

using OpenCvSharp;
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 System.Windows.Forms.VisualStyles;
using static System.Net.Mime.MediaTypeNames;namespace OpenCvSharp_模糊检测_拉普拉斯算子_
{public partial class Form1 : Form{public Form1(){InitializeComponent();}string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";string image_path = "";Mat image = new Mat();Mat gray = new Mat();Mat laplacian = new Mat();double threshold = 100;double measure = 0;private void button1_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = fileFilter;if (ofd.ShowDialog() != DialogResult.OK) return;pictureBox1.Image = null;image_path = ofd.FileName;pictureBox1.Image = new Bitmap(image_path);textBox1.Text = "";image = new Mat(image_path);}private void button3_Click(object sender, EventArgs e){if (image_path == ""){return;}Cv2.CvtColor(image, gray, ColorConversionCodes.BGR2GRAY);Cv2.Laplacian(gray, laplacian, gray.Type(), 3, 1, 0, BorderTypes.Default);Cv2.MeanStdDev(laplacian, out var mean, out var stddev);measure = stddev.Val0 * stddev.Val0;if (measure > threshold){textBox1.Text = "不模糊,拉普拉斯算子方差: " + measure.ToString();}else{textBox1.Text = "模糊,拉普拉斯算子方差: " + measure.ToString();}}}
}

Demo下载

模糊度检测算法来自 :https://pyimagesearch.com/2015/09/07/blur-detection-with-opencv/

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"C# OpenCvSharp 图片模糊检测(拉普拉斯算子)":http://eshow365.cn/6-12428-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!