博客来源于: https://www.cnblogs.com/wyh0923/p/16528354.html
# -*- coding: utf-8 -*-
# https://gov.pkulaw.cn/
1. import io
2. import json
3. from pathlib import Path
4. from PIL import Image
5. import base64
6. import cv2
7. import time
8. import requests
9. sess = requests.session()
11. class SlideCrack(object):
12. def __init__(self, front, bg, out=None):
13. """
14. init code
15. :param front: 缺口图片
16. :param bg: 背景图片
17. :param out: 输出图片
18. """
19. self.front = front
20. self.bg = bg
21. self.out = out
25. @staticmethod
26. def clear_white(img):
27. # 清除图片的空白区域,这里主要清除滑块的空白
28. img = cv2.imread(img)
29. rows, cols, channel = img.shape
30. min_x = 255
31. min_y = 255
32. max_x = 0
33. max_y = 0
34. for x in range(1, rows):
35. for y in range(1, cols):
36. t = set(img[x, y])
37. if len(t) >= 2:
38. if x <= min_x:
39. min_x = x
40. elif x >= max_x:
41. max_x = x
42.