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
相关推荐
敲代码的玉米C3 分钟前
测试一直在写你的真实数据根
前端·人工智能·架构
Mr.huang18 分钟前
自注意力机制(Self‑Attention)
人工智能·深度学习
品牌测评36 分钟前
大模型推理算力平台推荐分享|六家平台计费与架构拆解
大数据·人工智能·架构
武汉万象奥科40 分钟前
8路AHD摄像头同时输出演示,万象奥科RK3576 AHD硬件方案
人工智能·计算机视觉
LedgerNinja42 分钟前
WEEX 真实情况如何?交易平台如何判断是否可靠
大数据·人工智能·区块链
重庆传粉科技42 分钟前
GEO深度解读:AI时代品牌营销的核心,从内容优化转向事实治理
人工智能
用户69371750013841 小时前
#DeepSeek+Pi‑Agent 王炸组合跑赢 Claude‑Code!
前端·人工智能·后端
顿哥GPT1 小时前
2026年8月11日深度剖析:ChatGPT Plus/Pro 与 Codex 技术实战——构建智能代码生成助手
人工智能·chatgpt
小饕1 小时前
Jetson 设备上部署 ONNX 模型的完整指南:从环境配置到生产级推理
人工智能·大模型端侧部署
aiqianji1 小时前
文风接近真人的AI生成短篇小说软件有哪些?
人工智能·python