zoukankan      html  css  js  c++  java
  • python识别视频黑屏或者低清晰度

    第一步:获取视频第一帧图片

    https://www.cnblogs.com/pythonywy/p/13749735.html

    第二步:进行识别

    import os
    import numpy as np
    import cv2 as cv
    from skimage import filters, io
    
    
    class DetectException(Exception):
        pass
    
    
    class DetectionUtil:
    
        DARK_THRES_PIXEL = 20
        DARK_THRES_PERCENT = 0.90
        QUALITY_THRES = 30
    
    
        def unqualified_detection(self, image_path):
            """black screen or low quality."""
            # image = cv.imread(image_path)
            try:
                image = io.imread(image_path)
            except Exception as e:
                raise DetectException(e)
            image = image[:, :, ::-1]
            gray_image = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
            row, col = gray_image.shape[:2]
            pixel_count = row*col
    
            dark_condition = (gray_image <self.DARK_THRES_PIXEL)
            dark_array = gray_image[dark_condition]
            if dark_array.size / pixel_count >= self.DARK_THRES_PERCENT:
                return True
            quality = self.genengrad_detection(image)
            if quality < self.QUALITY_THRES:
                return True
            return False
    
        def _preprocess_image(self, image):
            re_img = cv.resize(image, (800, 900), interpolation=cv.INTER_CUBIC)
            gray_image = cv.cvtColor(re_img, cv.COLOR_BGR2GRAY)
            image_matrix = np.matrix(gray_image)
            return image_matrix
    
        def genengrad_detection(self, image):
            matrix =self._preprocess_image(image)
            return np.sqrt(np.sum(filters.sobel(matrix)**2))
    
    
    if __name__ == "__main__":
        print(DetectionUtil().unqualified_detection(r"视频封面地址"))
        #true为黑屏或者低分辨率
    
  • 相关阅读:
    第五小节之JAVA IO流
    第四小节之Java 集合类
    初学的重点
    第三小节之Java API
    实践周java基础软件开发app之五子棋
    出栈合法性
    Python介绍
    Ubuntu主题美化篇
    Ubuntu16.04比较好的一系列软件安装介绍
    Ubuntu使用Shadow socks-qt5
  • 原文地址:https://www.cnblogs.com/pythonywy/p/13815020.html
Copyright © 2011-2022 走看看