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
相关推荐
冬奇Lab8 小时前
Workflow 系列(04):Multi-Agent 协调——编排器边界、并发控制与上下文隔离
人工智能·工作流引擎
冬奇Lab8 小时前
每日一个开源项目(第147篇):HyperGraphRAG - 用超图表示 N 元关系,RAG 的第三代范式
人工智能·开源·graphql
甲维斯9 小时前
Github + 阿里云oss实现类似codex的自动更新!
人工智能
阿里云大数据AI技术11 小时前
光轮智能 × 阿里云:共建 Physical AI 云上数据、评测与持续学习基础设施
人工智能·机器学习
机器之心11 小时前
实锤了:Claude Code偷查用户,时区、中国AI实验室全是关键词
人工智能·openai
网易云信11 小时前
Cursor点燃个人开发者,企业级AI为何频频受挫?Agent工厂从提效工具到AI员工的跃迁
人工智能·开源
网易云信11 小时前
解锁触手可及的温暖:网易智企 x Wander Puffs AI 云游泡芙
人工智能
转转技术团队11 小时前
从 PRD 到可验证代码:AI 需求开发闭环实践
人工智能