利用python和opencv批量去掉图片黑边

2021-07-11 12:04

阅读:803

标签:nal   origin   nump   from   you   box   os.path   around   rom   

import os
import cv2
import numpy as np
from scipy.stats import mode
import time
import concurrent.futures

‘‘‘
    multi-process to crop pictures.
‘‘‘


def crop(file_path_list):
    origin_path, save_path = file_path_list
    img = cv2.imread(origin_path)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    closed_1 = cv2.erode(gray, None, iterations=4)
    closed_1 = cv2.dilate(closed_1, None, iterations=4)
    blurred = cv2.blur(closed_1, (9, 9))
    # get the most frequent pixel
    num = mode(blurred.flat)[0][0] + 1
    # the threshold depends on the mode of your images‘ pixels
    num = num if num 

 

利用python和opencv批量去掉图片黑边

标签:nal   origin   nump   from   you   box   os.path   around   rom   

原文地址:https://www.cnblogs.com/laresh/p/9551518.html


评论


亲,登录后才可以留言!