当前位置: 首页 > news >正文

网站主题 模板南海建设工程交易网站

网站主题 模板,南海建设工程交易网站,科技助手和平精英,做pc端软件可以参考那些网站以下教程用于验证转成YOLO使用的txt格式,适用场景:矩形框,配合json格式文件转成YOLO使用的txt格式脚本使用。 https://blog.csdn.net/StopAndGoyyy/article/details/138681454 使用方式:将img_path和label_path分别填入对应的图…

 以下教程用于验证转成YOLO使用的txt格式,适用场景:矩形框,配合json格式文件转成YOLO使用的txt格式脚本使用。

https://blog.csdn.net/StopAndGoyyy/article/details/138681454

使用方式:将img_path和label_path分别填入对应的图片(文件夹)及标签(文件夹)路径,运行。show_num参数控制最大展示数量,按空格切换。

import os
import numpy as np
import cv2img_format = ['.jpg', '.png', '.jpeg']
colors = [(0, 0, 0), (128, 0, 0), (0, 128, 0), (128, 128, 0), (0, 0, 128), (128, 0, 128), (0, 128, 128),(128, 128, 128), (64, 0, 0), (192, 0, 0), (64, 128, 0), (192, 128, 0), (64, 0, 128), (192, 0, 128),(64, 128, 128), (192, 128, 128), (0, 64, 0), (128, 64, 0), (0, 192, 0), (128, 192, 0), (0, 64, 128),(128, 64, 12)]def get_files(img_path, label_path):img_list = []label_list = []datast_img_format = Noneassert os.path.exists(img_path) and os.path.exists(label_path), print("⭐⭐文件夹不存在⭐⭐")if os.path.isdir(img_path):for i in os.listdir(img_path):if os.path.splitext(i)[-1] in img_format:# i = i.replace(os.path.splitext(i)[-1], '')img_list.append(i)datast_img_format=img_list[-1].split('.')[-1]if os.path.isdir(label_path):for i in os.listdir(label_path):if os.path.splitext(i)[-1] == '.txt':i = i.replace(os.path.splitext(i)[-1], '')label_list.append(i)print("路径下无jpg,png,jpeg格式的图片,当前图像路径:" + str(img_path) if len(img_list) == 0 else "图像总数为:" + str(len(img_list)))print("路径下无标签文件,当前标签路径" + str(label_path) if len(label_list) == 0 else "标签总数为:" + str(len(label_list)))img_without_label = []for i in img_list:if i.replace(os.path.splitext(i)[-1], '') not in label_list:img_without_label.append(i)if len(img_without_label) != 0:print("标签丢失的图像有:" + str(img_without_label))ok_img = list(set(img_list) - set(img_without_label))return [i.replace('.jpg', '') for i in ok_img], '.'+datast_img_format# 坐标转换
def xywh2xyxy(x, w1, h1, img):label, x, y, w, h = xx_t = x * w1y_t = y * h1w_t = w * w1h_t = h * h1top_left_x = x_t - w_t / 2top_left_y = y_t - h_t / 2bottom_right_x = x_t + w_t / 2bottom_right_y = y_t + h_t / 2cv2.rectangle(img, (int(top_left_x), int(top_left_y)), (int(bottom_right_x), int(bottom_right_y)),colors[int(label)] if int(label) < len(colors) else colors[0], 2)cv2.putText(img, text=str(int(label)), org=(int(top_left_x), int(top_left_y)), fontFace=cv2.FONT_HERSHEY_COMPLEX,fontScale=1, color=colors[int(label)] if int(label) < len(colors) else colors[0], thickness=3)return imgif __name__ == '__main__':# 修改输入图片文件夹img_path = r"O:\DeepLearningTool\01_handle_dataset\dataset\object\image"# img_path = r"O:\DeepLearningTool\dataset\image"# 修改输入标签文件夹label_path = r"O:\DeepLearningTool\01_handle_dataset\dataset\object\label"# label_path = r"O:\DeepLearningTool\dataset\label"# 输出文件夹outfile = './'# 是否展示绘制的图片if_show = True# 最大展示图片的数量(按空格切换)show_num = 3# 是否保存绘制的图片if_save = Falseif os.path.isdir(img_path):ok_img, datast_img_format = get_files(img_path, label_path)haveShow = 0for i in ok_img:assert os.path.exists(str(img_path) + '\\' + i + datast_img_format)img = cv2.imread(str(img_path) + '\\' + i + datast_img_format)h, w = img.shape[:2]with open(label_path + '\\' + i + '.txt', 'r') as f:lb = np.array([x.split() for x in f.read().strip().splitlines()], dtype=np.float32)for x in lb:img = xywh2xyxy(x, w, h, img)if if_show:cv2.namedWindow('Image with label', 0)cv2.resizeWindow('Image with label', 600, 500)cv2.imshow('Image with label', img)cv2.waitKey(0)if if_save:outfile = outfile if len(outfile) > 0 else './output/'if not os.path.exists('./output/'):os.mkdir('./output/')print(outfile + i)cv2.imwrite(outfile+i+datast_img_format, img)haveShow += 1if haveShow == show_num:breakelse:img = cv2.imread(str(img_path))h, w = img.shape[:2]assert os.path.isfile(label_path), '标签路径错误'with open(label_path) as f:lb = np.array([x.split() for x in f.read().strip().splitlines()], dtype=np.float32)for x in lb:img = xywh2xyxy(x, w, h, img)if if_show:cv2.namedWindow('Image with label', 0)cv2.resizeWindow('Image with label', 600, 500)cv2.imshow('Image with label', img)cv2.waitKey(0)

http://www.yayakq.cn/news/528833/

相关文章:

  • 国内网站主机万网续费登录网站
  • 有公众号要不要做网站新闻营销发稿平台
  • 雁塔区网站建设郑州网站建设乚汉狮网络
  • 企业模式网站列表管理器wordpress安装memcached
  • 网站开发价位评估最优惠的郑州网站建设
  • 怎么做平台网站吗六安城市网地址
  • 网站建设作业网站收费系统平台
  • 如何建设一个专业的网站重庆网站seo公司哪家好
  • 中国融资网网站加速优化
  • 长安营销型网站建设做网站收录
  • 个别网站网速慢怎么做黄页引流推广网站
  • 办公用品网站建设北京互联网公司
  • oa系统网站建设方案做棋牌网站建设哪家便宜
  • 上行2m可以做网站网站地图页面
  • 如何进行网站备案网站空格 教程
  • 电子商务网站建设系统功能微信商城和小程序的区别
  • 做网站的猫腻高权重域名做网站
  • 网站建设发朋友圈的图片网站续费方案
  • wordpress jupiter外贸网站如何做seo
  • 网站建设事项软件开发外包公司是干嘛的
  • 网站建设预算计算方法做网站美工的理由
  • 怎么建设空包网站知名的网站建设公司排名
  • 动漫毕业设计作品网站桐乡市住房建设局网站
  • 静态网站 服务器医药类网站建设评价
  • 怎么上网站做简易注销的步骤哈尔滨建站
  • 什么是网站asp网站qq登录
  • 西安城市建设职业学院官方网站有关于网站建设的参考文献
  • 宿州企业官方网站建设怎么安装的wordpress主题
  • 辽宁建设工程信息网开标大厅简述sem对seo的影响
  • 网站子站怎么做的服务器安全模式怎么进