方法一:
import cv2
import numpy as np
a = cv2.imread('c5.jpg', 1)
b = np.zeros(a.shape, dtype=np.uint8)
# 上下左右边距
b[5:50, 15:100] = 255
c = cv2.bitwise_and(b, a)
d = cv2.bitwise_and(a, c)
cv2.imwrite('c1.jpg', c)
方法二:
import cv2
a = cv2.imread('c5.jpg', 1)
# 上下左右边距值
a[5:50, 15:100] = 255
cv2.imwrite('c2.jpg', a)
import cv2
a = cv2.imread('c5.jpg', 1)
# 上下左右边距值
a[5:50, 15:100] = 0
cv2.imwrite('c3.jpg', a)
方法三:
import cv2
import numpy as np
import os
import glob
def detect_img():
path = '、imgs_input/test/0.jpg'
outdir = '/imgs_output/'
for jpgfile in glob.glob(path):
img = cv2.imread(jpgfile)
shape = img.shape
points_704 = np.array([[80, 530], [440, 530], [270, 50], [225, 50]])
height = shape[1]
# 图片的高度尺寸
if height != 1155:
continue
img_origin = img.copy()
cv2.fillConvexPoly(img, points_704, 1)
bitwisexor = cv2.bitwise_xor(img, img_origin)
cv2.imwrite(os.path.join(outdir, os.path.basename(jpgfile)), bitwisexor)
detect_img()