使用OpenCV进行模糊检测(拉普拉斯算子)

devtools/2024/9/25 3:33:29/

参考:
使用OpenCV进行模糊检测(拉普拉斯算子)

代码:

# import the necessary packages
from imutils import paths
import argparse
import cv2
import osdef variance_of_laplacian(image):# compute the Laplacian of the image and then return the focus# measure, which is simply the variance of the Laplacianreturn cv2.Laplacian(image, cv2.CV_64F).var()# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--images", required=True, help="path to input directory of images")
ap.add_argument("-o", "--output", required=True, help="path to output directory for saving results")
ap.add_argument("-t", "--threshold", type=float, default=100.0, help="focus measures that fall below this value will be considered 'blurry'")
args = vars(ap.parse_args())# create output directories if they don't exist
blurry_dir = os.path.join(args["output"], "blurry")
not_blurry_dir = os.path.join(args["output"], "not_blurry")
os.makedirs(blurry_dir, exist_ok=True)
os.makedirs(not_blurry_dir, exist_ok=True)# loop over the input images
for imagePath in paths.list_images(args["images"]):# load the image, convert it to grayscale, and compute the# focus measure of the image using the Variance of Laplacian# methodimage = cv2.imread(imagePath)gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)fm = variance_of_laplacian(gray)text = "Not Blurry"# if the focus measure is less than the supplied threshold,# then the image should be considered "blurry"if fm < args["threshold"]:text = "Blurry"outputPath = os.path.join(blurry_dir, os.path.basename(imagePath))else:outputPath = os.path.join(not_blurry_dir, os.path.basename(imagePath))# annotate and save the imagecv2.putText(image, "{}: {:.2f}".format(text, fm), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)cv2.imwrite(outputPath, image)print("Processing complete. Blurry images saved to", blurry_dir)
print("Not blurry images saved to", not_blurry_dir)

结果:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述


http://www.ppmy.cn/devtools/111360.html

相关文章

【数据库】MySQL-基础篇-多表查询

专栏文章索引&#xff1a;数据库 有问题可私聊&#xff1a;QQ&#xff1a;3375119339 目录 一、多表关系 1.一对多 2.多对多 3.一对一 二、多表查询概述 1.数据准备 2.概述 3.分类 三、内连接 1.隐式内连接 2.显式内连接 3.案例 四、外连接 1.左外连接 2.右外连…

微信小程序:wx.login或调用uni.login时报错the code is a mock one

微信小程序&#xff0c;调用wx.login或调用uni.login方法&#xff0c;返回the code is a mock one 原因与解决 原因:没有关联真实的 appid&#xff0c;解决办法&#xff1a;绑定真实的微信小程序的appid

【案例68】录SPR日志卡死

问题现象 顾问在录取spr日志时&#xff0c;发现系统一直在前台处理性能数据&#xff0c;一直未弹出html页面。 问题分析 首先排查服务器时间&#xff0c;发现服务器时间与标准时间差了3min。图为已经调整的。 再录制过程中显示时间已经变更为正确时间。 由于未显示具体操作人…

IP地址、地址分类、子网掩码、子网划分、使用Python计算子网划分

IP 地址&#xff08;Internet Protocol Address&#xff09;乃是用于明确标识网络中各类设备的独一无二的地址。IP 地址主要存在两种重要类型&#xff0c;即 IPv4 和 IPv6 。 IPv4地址 IPv4 地址实则是一个由 32 位二进制数字所构成的标识&#xff0c;通常会以四个十进制数字…

C++类型转换,特殊类设计,IO流

1.类型转换 什么是类型转换&#xff1f;我们知道有些数字类型可以相互转换&#xff0c;如double类型可以转换为int类型&#xff0c;这样的转换会发生切割将double类型的小数部分切割掉丢失精度&#xff1b;还有在前面的多态那块有一个虚函数指针表&#xff0c;这个虚函数指针表…

超分论文ESPCN解读

论文地址&#xff1a;Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional Neural Network 相关知识点总结&#xff1a; 许多SR技术的一个关键假设是&#xff0c;大部分高频数据是冗余的&#xff0c;因此可以从低频分量中准确重建…

数据结构--双链表

目录 一、引言 二 、链表的分类 1.单向或双向 2.带头或不带头 3.循环或不循环 三、双链表的概念与基本结构 1.概念 2.基本结构 三、双链表的常见操作 1.创建节点 2.初始化 3.头插 4.尾插 5.头删 6.尾删 7.打印 8.查找 9.插入节点 10.删除节点 11.销毁链…

flink的大状态复用

在 Apache Flink 中&#xff0c;实现大状态复用主要涉及在不同任务、不同生命周期阶段&#xff0c;甚至不同作业之间共享或重用状态数据。复用大状态可以减少重新加载和重新计算的开销&#xff0c;从而提升作业的效率和业务连续性。下面是几种在 Flink 中复用大状态的常见方法&…