import cv2 import numpy as np import json import os import pyclipper jfile=open("/home/ubuntu/图片/1.json")#labelme points=np.array(json.load(jfile)["shapes"][0]["points"],dtype=np.int64)*4 boxs=[points] img = np.zeros((1000, 1000, 3)) label_text_kernel_masks=np.zeros(shape=(6,img.shape[0],img.shape[1]),dtype=np.uint8) n=6 m=0.4 for box in boxs: for i in range(1,n+1): r=1-(1-m)*(n-i)/(n-1) offset=cv2.contourArea(box)*(1-r*r)/cv2.arcLength(box,closed=True) pco = pyclipper.PyclipperOffset() pco.AddPath(box, pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON) box_shrink = pco.Execute(-offset) cv2.fillPoly(label_text_kernel_masks[i-1, :, :], np.array([box_shrink[0]]), color=(255)) cv2.imshow('0',label_text_kernel_masks[0,:,:]) cv2.imshow('1',label_text_kernel_masks[1,:,:]) cv2.imshow('2',label_text_kernel_masks[2,:,:]) cv2.imshow('3',label_text_kernel_masks[3,:,:]) cv2.imshow('4',label_text_kernel_masks[4,:,:]) cv2.imshow('5',label_text_kernel_masks[5,:,:]) cv2.waitKey(0)
cv2 fillpoly pyclipper
最新推荐文章于 2024-05-23 11:45:00 发布