generate_defect.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:Seg 作者: gxd1994 项目源码 文件源码
def generate_spot(img,label_img,num,ratio_area,aspect):

    ratio_area_l,ratio_area_h = ratio_area
    area_l = img.shape[0]*img.shape[1]*ratio_area_l
    area_h = img.shape[0]*img.shape[1]*ratio_area_h

    count = 0
    while True:
        rect_list = random_rect(1,img.shape,(0,1),(0,1))

        handle_img = np.copy(img)

        rect = rect_list[0]
        x,y,h,w = rect
        # roi = handle_img[y:y+h,x:x+w]
        handle_img[y:y+h,x:x+w] = 255

        pixelpoints,hull = convex_hull_generate(img,rect,10)
        w_,h_ = cv2.minAreaRect(hull)[1]
        if w_ != 0 and h_ != 0:
            if (cv2.contourArea(hull) > area_l and  cv2.contourArea(hull) < area_h) and  max(w_/h_,h_/w_) < aspect: #and max(w_,h_)>length:
                img[pixelpoints] = handle_img[pixelpoints]
                label_img[pixelpoints] = 255 
                count += 1
                if count >= num:
                    break
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号