91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

代碼用于產生任意形狀的封閉圖形并將封閉區域內進行賦值

資源截圖

代碼片段和文件信息

#??coding??--utf8

from?matplotlib.path?import?Path
import?matplotlib.patches?as?patches
import?matplotlib.pyplot?as?plt
import?numpy?as?np
import?cv2
import?os
import?scipy.ndimage
def?draw_random_shape(savenamen=8r=0.7):
????‘‘‘
????TODO:繪制不同形狀的圖,n和r控制了形狀的復雜程度,其中n控制復雜的邊長數目,r控制每一個邊長的復雜程度
????:param?n:?變異的邊長數目
????:param?r:?對于圓的擾動程度
????:return:
????‘‘‘

????N?=?n*3?+1?#?圖像的角點數目

????angles?=?np.linspace(02*np.piN)
????codes?=?np.full(NPath.CURVE4)
????codes[0]?=?Path.MOVETO

????verts?=?np.stack((np.cos(angles)np.sin(angles))).T*(2*r*np.random.random(N)+1-r)[:None]
????verts[-1:]?=?verts[0:]
????path?=?Path(vertscodes)
????fig?=?plt.figure()
????ax?=?fig.add_subplot(111)
????path?=?patches.PathPatch(pathfacecolor=‘none‘lw=1)
????ax.add_patch(path)
????ax.set_xlim(np.min(verts)?*?1.1?np.max(verts)?*?1.1)
????ax.set_ylim(np.min(verts)?*?1.1?np.max(verts)?*?1.1)
????ax.axis(‘off‘)
????plt.savefig(savename)
????mask?=?cv2.imread(savename)
????mask?=?mask[::0]
????mask?=?cv2.bitwise_not(mask)????????#?將圖像反相
????mask?=?cv2.Canny(mask0255)????????#?使用canny算子將邊緣值全部二值化為255,這樣使用射線法找到
????cv2.imwrite(savenamemask)

def?img_resize(imgimg_shape):
????imgnew?=?cv2.resize(img?img_shape?interpolation=cv2.INTER_LANCZOS4)
????return?imgnew

def?random_panning(imgthim

評論

共有 條評論