当前位置:网站首页>Image fuzzy processing batch production fuzzy data set

Image fuzzy processing batch production fuzzy data set

2022-07-23 11:47:00 mandala -chen

File structure 1 As shown in the figure below
 Insert picture description here

# coding: utf-8
import numpy as np
import cv2 as cv
import os
 
def motion_blur(image, degree=30 ,angle=45):
    image = np.array(image)
 
    #  Here we generate motion blur at any angle kernel Matrix , degree The bigger it is , The more fuzzy 
    M = cv.getRotationMatrix2D((degree / 2, degree / 2), angle, 1)
    motion_blur_kernel = np.diag(np.ones(degree))
    motion_blur_kernel = cv.warpAffine(motion_blur_kernel, M, (degree, degree))
 
    motion_blur_kernel = motion_blur_kernel / degree
    blurred = cv.filter2D(image, -1, motion_blur_kernel)
 
    # convert to uint8
    cv.normalize(blurred, blurred, 0, 255, cv.NORM_MINMAX)
    blurred = np.array(blurred, dtype=np.uint8)
    return blurred
# Read and process in batches 
filePath = 'C:\\Users\\ Chen Dongxiang \\Desktop\\ New folder  (4)\\abc\\'
for i in os.listdir(filePath):
    img = cv.imread("./abc/"+i)
    img_ = motion_blur(img)
    cv.imwrite(i,img_)
原网站

版权声明
本文为[mandala -chen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/204/202207230537069300.html