您的位置:首页 > 游戏 > 手游 > 网页图片设计_怎么做网络游戏推广_seo是什么意思为什么要做seo_培训计划方案模板

网页图片设计_怎么做网络游戏推广_seo是什么意思为什么要做seo_培训计划方案模板

2024/10/6 2:20:20 来源:https://blog.csdn.net/qq_53959016/article/details/142212515  浏览:    关键词:网页图片设计_怎么做网络游戏推广_seo是什么意思为什么要做seo_培训计划方案模板
网页图片设计_怎么做网络游戏推广_seo是什么意思为什么要做seo_培训计划方案模板

此笔记是为记录一下,为解决某模型只能预测一张图,并且不能生成相应的txt文件的问题


def main():if os.path.isdir(directory_path):files = os.listdir(directory_path)for file in files:file_path = os.path.join(directory_path, file)if os.path.isfile(file_path):try:origin_img = np.asarray(Image.open(file_path).convert('RGB'))bboxes = [[1, 2, 3, 4], [5, 6, 7, 8]]scores = [100, 99]cls_inds = [0, 1]vis_res = visualize(origin_img, bboxes, scores, cls_inds, conf=0.6, save_name=os.path.basename(file_path), save_result=True)print(os.path.basename(file_path))except Exception as e:print(f"读取文件 {file} 时发生错误:{e}")else:print(f"{directory_path} 不是一个目录。")
def visualize(image, bboxes, scores, cls_inds, conf, save_name='vis.jpg', save_result=True):# 写入txt文件 一行一行的写入vis_img, labels = vis(image, bboxes, scores, cls_inds, conf, class_names)img_name = save_name.split('.')[0]txt_name = img_name + '.txt'if save_result:  # 把已经框好的照片写进去save_path = os.path.join(output_dir, save_name)print(f"save visualization results at {save_path}")save_txt_path = os.path.join(output_dir, txt_name)for i in range(len(labels)):label = labels[i]with open(save_txt_path, 'a') as fp:fp.write(label)# cv2.imwrite(save_path, vis_img[:, :, ::-1])return vis_img
def vis(img, boxes, scores, cls_ids, conf=0.5, class_names=None):# 返回labels数组labels = []for i in range(len(boxes)):box = boxes[i]cls_id = int(cls_ids[i])score = scores[i]if score < conf:continuex0 = int(box[0])y0 = int(box[1])x1 = int(box[2])y1 = int(box[3])x2 = float(box[0])y2 = float(box[1])x3 = float(box[2])y3 = float(box[3])score_txt = float(score)label = str(x2)+' '+str(y2)+' '+str(x3)+' '+str(y3)+' '+str(score)+' '+str(cls_id)+'\n'labels.append(label)return img, labels

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com