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
相关推荐
小陈工2 小时前
Python Web开发入门(十七):Vue.js与Python后端集成——让前后端真正“握手言和“
开发语言·前端·javascript·数据库·vue.js·人工智能·python
墨染天姬6 小时前
【AI】端侧AIBOX可以部署哪些智能体
人工智能
AI成长日志6 小时前
【Agentic RL】1.1 什么是Agentic RL:从传统RL到智能体学习
人工智能·学习·算法
2501_948114246 小时前
2026年大模型API聚合平台技术评测:企业级接入层的治理演进与星链4SAPI架构观察
大数据·人工智能·gpt·架构·claude
小小工匠6 小时前
LLM - awesome-design-md 从 DESIGN.md 到“可对话的设计系统”:用纯文本驱动 AI 生成一致 UI 的新范式
人工智能·ui
黎阳之光6 小时前
黎阳之光:视频孪生领跑者,铸就中国数字科技全球竞争力
大数据·人工智能·算法·安全·数字孪生
小超同学你好7 小时前
面向 LLM 的程序设计 6:Tool Calling 的完整生命周期——从定义、决策、执行到观测回注
人工智能·语言模型
智星云算力7 小时前
本地GPU与租用GPU混合部署:混合算力架构搭建指南
人工智能·架构·gpu算力·智星云·gpu租用
jinanwuhuaguo7 小时前
截止到4月8日,OpenClaw 2026年4月更新深度解读剖析:从“能力回归”到“信任内建”的范式跃迁
android·开发语言·人工智能·深度学习·kotlin
xiaozhazha_7 小时前
效率提升80%:2026年AI CRM与ERP深度集成的架构设计与实现
人工智能