make_samples.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:segmenty 作者: paulfitz 项目源码 文件源码
def motion_blur(img):
    size = random.randint(3, 15)
    # generating the kernel
    kernel_motion_blur = np.zeros((size, size))
    x0 = int((size-1)/2)
    y0 = int((size-1)/2)
    dx = 0
    dy = 0
    while dx == 0 and dy == 0:
        dx = random.randint(-1, 1)
        dy = random.randint(-1, 1)
    ct = 0
    for k in range(-size, size):
        x = x0 + k * dx
        y = y0 + k * dy
        if x >= 0 and y >= 0 and x < size and y < size:
            kernel_motion_blur[x, y] = 1
            ct += 1
    kernel_motion_blur = kernel_motion_blur / ct
    # applying the kernel to the input image
    output = cv2.filter2D(img, -1, kernel_motion_blur)
    return output
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号