if neg < self.aug_settings['occ_background']['prob']: # 在当前图像中找到一块背景区域作为遮挡块 occ_image = search_image occ_image_, occ_box_, _ = self.crop127255(occ_image, search_bbox, self.search_size) occ_bbox = random_background(occ_image_, occ_box_, min_rate=self.aug_settings['occ_background']['crop_rate_min'], max_rate=self.aug_settings['occ_background']['crop_rate_max'], protect_settings=rand( self.aug_settings['occ_background']['protect_rate_min'], self.aug_settings['occ_background']['protect_rate_max'])) occ_bbox = list(map(int, occ_bbox)) # search_bbox = list(map(int, search_bbox)) cv2.rectangle(occ_image, (occ_bbox[0], occ_bbox[1]), (occ_bbox[2], occ_bbox[3]), (0, 255, 0), 3) # cv2.rectangle(occ_image, (search_bbox[0], search_bbox[1]), (search_bbox[2], search_bbox[3]), (0, 255, 0), 3) cv2.imshow('occ_name', occ_image_) cv2.waitKey(100) if occ_bbox is not None: # occ_image_, occ_box_, _ = self.crop127255(occ_image, occ_bbox, self.search_size) # # 遮挡块需要带一定背景区域 # occ_box_ = box2roi(occ_box, rate_w=self.roi_rate(), rate_h=self.roi_rate(), # boundary=[255, 255]) box = list(map(int, occ_bbox)) # 裁剪出遮挡块 occ = occ_image_[box[1]: box[3] + 1, box[0]: box[2] + 1] # 将遮挡块覆盖到目标框位置上,并计算box被遮挡部分的占比 search_img_, occed_box, overlap = random_occ(search_img, search_box, obj=occ, center_rate=self.aug_settings['center_rate'], try_num=self.aug_settings['try_num'], overlap_thresh=self.aug_settings[ 'overlap_thresh']) # 当目标大部分被完全覆盖时,才完成有效的遮挡扩增 # if occed_box is not None and overlap > self.aug_settings['overlap_thresh']: search_img = search_img_ pos = 0.0
# if neg < self.aug_settings['occ_background']['prob']:
# # 在当前图像中找到一块背景区域作为遮挡块
# occ_image = search_image
# occ_bbox = random_background(occ_image, search_bbox,
# min_rate=self.aug_settings['occ_background']['crop_rate_min'],
# max_rate=self.aug_settings['occ_background']['crop_rate_max'],
# protect_settings=rand(
# self.aug_settings['occ_background']['protect_rate_min'],
# self.aug_settings['occ_background']['protect_rate_max']))
# if occ_bbox is not None:
# occ_image_, occ_box, _ = self.crop127255(occ_image, occ_bbox, self.search_size)
# # 遮挡块需要带一定背景区域
# occ_box_ = box2roi(occ_box, rate_w=self.roi_rate(), rate_h=self.roi_rate(),
# boundary=[255, 255])
# box = list(map(int, occ_box_))
# # 裁剪出遮挡块
# occ = occ_image_[box[1]: box[3] + 1, box[0]: box[2] + 1]
# # 将遮挡块覆盖到目标框位置上,并计算box被遮挡部分的占比
# search_img_, occed_box, overlap = random_occ(search_img, search_box, obj=occ,
# center_rate=self.aug_settings['center_rate'],
# try_num=self.aug_settings['try_num'],
# overlap_thresh=self.aug_settings[
# 'overlap_thresh'])
# # 当目标大部分被完全覆盖时,才完成有效的遮挡扩增
# if occed_box is not None and overlap > self.aug_settings['overlap_thresh']:
# search_img = search_img_
# pos = 0.0