generate_defect.py 文件源码

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

项目:Seg 作者: gxd1994 项目源码 文件源码
def generate_crack(img,label_img,num,ratio_area,aspect,length_ratio):
    ratio_area_l,ratio_area_h = ratio_area
    length_ratio_l,length_ratio_h = length_ratio
    area_l = img.shape[0]*img.shape[1]*ratio_area_l
    area_h = img.shape[0]*img.shape[1]*ratio_area_h
    length_l = min( img.shape[0],img.shape[1]) * length_ratio_l
    length_h = min( img.shape[0],img.shape[1]) * length_ratio_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] = 0

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


问题


面经


文章

微信
公众号

扫码关注公众号