Python 检测运动模糊 源代码

目录

模拟运动模糊:

[Python 检测运动模糊 源代码](#Python 检测运动模糊 源代码)


模拟运动模糊:

https://blog.csdn.net/jacke121/article/details/109191473

Python 检测运动模糊 源代码

python 复制代码
import cv2
import numpy as np

def detect_motion_blur(img, blur_threshold=100, direction_threshold=0.8):
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    gray = cv2.GaussianBlur(gray, (3,3), 0)

    # Sobel 边缘
    gx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=3)
    gy = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=3)

    magnitude = np.sqrt(gx**2 + gy**2)
    angle = np.arctan2(gy, gx)

    # 模糊程度
    blur_score = cv2.Laplacian(gray, cv2.CV_64F).var()

    # 梯度方向分布统计
    hist, _ = np.histogram(angle, bins=36, range=(-np.pi, np.pi))
    hist = hist / np.sum(hist)

    # 如果梯度方向过于集中(说明只有一个方向清晰)
    concentration = np.max(hist)

    if blur_score < blur_threshold:
        if concentration > direction_threshold:
            return "运动模糊", blur_score, concentration
        else:
            return "普通模糊", blur_score, concentration
    else:
        return "清晰", blur_score, concentration
相关推荐
铅笔侠_小龙虾20 分钟前
深度学习理论推导--梯度下降法
人工智能·深度学习
kaikaile199528 分钟前
基于遗传算法的车辆路径问题(VRP)解决方案MATLAB实现
开发语言·人工智能·matlab
lpfasd12339 分钟前
第1章_LangGraph的背景与设计哲学
人工智能
Aevget1 小时前
界面组件Kendo UI for React 2025 Q3亮点 - AI功能全面提升
人工智能·react.js·ui·界面控件·kendo ui·ui开发
桜吹雪1 小时前
LangChain.js/DeepAgents可观测性
javascript·人工智能
&&Citrus1 小时前
【杂谈】SNNU公共计算平台:深度学习服务器配置与远程开发指北
服务器·人工智能·vscode·深度学习·snnu
乌恩大侠1 小时前
Spark 机器上修改缓冲区大小
人工智能·usrp
STLearner2 小时前
AI论文速读 | U-Cast:学习高维时间序列预测的层次结构
大数据·论文阅读·人工智能·深度学习·学习·机器学习·数据挖掘
数字化顾问2 小时前
(65页PPT)大型集团物料主数据管理系统建设规划方案(附下载方式)
大数据·运维·人工智能