C# OpenCvSharp 图片模糊检测(拉普拉斯算子)
  yqdtHKhvd9Ja 2023年11月02日 18 0


效果

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

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

项目

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

代码

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/

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
yqdtHKhvd9Ja