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

德州网站推广专业的单位网站建设

德州网站推广,专业的单位网站建设,喀什的网站怎么做,淄博天一建设项目招标代理有限公司网站在进行一个新项目的时候#xff0c;往往缺少一些真实数据#xff0c;导致没办法进行模型训练#xff0c;这时候就需要算法工程师自行制作一些数据了#xff0c;比如这篇文章分享的 bag 目标检测#xff0c;在检测区域没有真实的 bag数据 此时#xff0c;就可以采用图像拼…在进行一个新项目的时候往往缺少一些真实数据导致没办法进行模型训练这时候就需要算法工程师自行制作一些数据了比如这篇文章分享的 bag 目标检测在检测区域没有真实的 bag数据 此时就可以采用图像拼接的方式将凑集到的 bag图像粘贴到场景图像中【前提目标图一般为“大头贴”】当然场景图片并不是所有的位置都可以粘贴一般有特定区域比如 地面、墙壁、某设备等因此还需要采用标注工具将这些目标区域标注出来算法通过读取对应的目标区域随机设定区域内的坐标点进行粘贴将目标图粘贴到场景图当中 当然并不是任何形式的目标图都可以粘贴为了更好的融合场景当中还需要将目标从 大头贴当中给 扣出来即除了目标区域其他区域设置为透明格式这样拼接的效果才“更”加真实一些【还是很假的】 具体的操作过程如何所示代码附最后如有 bug 还望见谅 1、制作底片模版 博主采用的 LabelImg标注工具将底片待粘贴区域标注好 标注完成的 txt 内容 labelImg 的显示界面 2、将对应的大头贴目标头图处理 从 jpg 图像将目标 “扣” 出来此处采用的像素抠图将白色区域设置为透明此处并不通用不同目标的小伙伴自行修改代码png的图像格式可以保存 alpha通道 # !/usr/bin/env python # -*- coding:utf-8 -*- # Time : 2023.11 # Author : 绿色羽毛 # Email : lvseyumaofoxmail.com # Blog : https://blog.csdn.net/ViatorSun # Note : jpg2png.pyimport os import cv2 import numpy as np import os.path as ospfile_path /media/yinzhe/DataYZ/DataSet/DataSet/bag_masknew save_path file_path _outif not osp.exists(save_path):os.makedirs(save_path)img_lst [] for path, dirs, files in os.walk(file_path):for file in files:if os.path.splitext(file)[1] in [.jpg, .png, .JPG, .jpeg]: # 扫描指定格式文件img_dir osp.join(path, file)img_save osp.join(save_path, file)img cv2.imread(img_dir)img cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # 转换为RGB格式png_img osp.join(save_path, file.split(.)[0] .png)white_mask cv2.inRange(img, (200, 200, 200), (255, 255, 255)) # 提取白色部分img cv2.cvtColor(img, cv2.COLOR_RGB2BGRA)img[:,:,3][white_mask 255] 0 # 将白色部分变成透明cv2.imwrite(png_img, img) 3、将底片与透明目标进行叠加融合 叠加融合的方法有很多种此处只采用了最简单的叠加方式也可以考虑 cv2.seamlessClone 最终成果如下图所示 除了生成合成图片标注信息也同步生成 注意 此处的标注信息是按照标注框尺寸保存的【此处隐藏bug后续优化】 提示可以根据目标区域的非透明区域进行保存 # !/usr/bin/env python # -*- coding:utf-8 -*- # Time : 2023.10 # Author : 绿色羽毛 # Email : lvseyumaofoxmail.com # Blog : https://blog.csdn.net/ViatorSun # Note : ps_merge_img.pyimport os import cv2 import random from random import sample import numpy as np import argparse def read_label_txt(label_dir):labels []with open(label_dir) as fp:for f in fp.readlines():labels.append(f.strip().split( ))return labelsdef rescale_yolo_labels(labels, img_shape):height, width, nchannel img_shaperescale_boxes []for box in list(labels):x_c float(box[1]) * widthy_c float(box[2]) * heightw float(box[3]) * widthh float(box[4]) * heightx_left x_c - w * .5y_left y_c - h * .5x_right x_c w * .5y_right y_c h * .5rescale_boxes.append([box[0], int(x_left), int(y_left), int(x_right), int(y_right)])return rescale_boxesdef xyxy2xywh(image, bboxes):height, width, _ image.shapeboxes []for box in bboxes:if len(box) 4:continuecls int(box[0])x_min box[1]y_min box[2]x_max box[3]y_max box[4]w x_max - x_minh y_max - y_minx_c (x_min x_max) / 2.0y_c (y_min y_max) / 2.0x_c x_c / widthy_c y_c / heightw float(w) / widthh float(h) / heightboxes.append([cls, x_c, y_c, w, h])return boxesdef cast_color(img, value):img_t cv2.cvtColor(img,cv2.COLOR_BGR2HSV)h,s,v cv2.split(img_t)# 增加图像对比度v2 np.clip(cv2.add(2*v,value),0,255)img2 np.uint8(cv2.merge((h,s,v2)))img_cast cv2.cvtColor(img2,cv2.COLOR_HSV2BGR) # 改变图像对比度return img_castdef brightness(img, value):img_t cv2.cvtColor(img,cv2.COLOR_BGR2HSV)h,s,v cv2.split(img_t)# 增加图像亮度v1 np.clip(cv2.add(1*v,value),0,255)img1 np.uint8(cv2.merge((h,s,v1)))img_brightness cv2.cvtColor(img1,cv2.COLOR_HSV2BGR) # 改变图像亮度亮度return img_brightnessdef add_alpha_channel(img): 为jpg图像添加alpha通道 b_channel, g_channel, r_channel cv2.split(img) # 拆分jpg图像通道alpha_channel np.ones(b_channel.shape, dtypeb_channel.dtype) * 255 # 创建Alpha通道img_new cv2.merge((b_channel, g_channel, r_channel, alpha_channel)) # 融合通道return img_newdef merge_img(jpg_img, png_img, y1, y2, x1, x2): 将png透明图像与jpg图像叠加y1,y2,x1,x2为叠加位置坐标值# 判断jpg图像是否已经为4通道if jpg_img.shape[2] 3:jpg_img add_alpha_channel(jpg_img)当叠加图像时可能因为叠加位置设置不当导致png图像的边界超过背景jpg图像而程序报错这里设定一系列叠加位置的限制可以满足png图像超出jpg图像范围时依然可以正常叠加yy1 0yy2 png_img.shape[0]xx1 0xx2 png_img.shape[1]if x1 0:xx1 -x1x1 0if y1 0:yy1 - y1y1 0if x2 jpg_img.shape[1]:xx2 png_img.shape[1] - (x2 - jpg_img.shape[1])x2 jpg_img.shape[1]if y2 jpg_img.shape[0]:yy2 png_img.shape[0] - (y2 - jpg_img.shape[0])y2 jpg_img.shape[0]# 获取要覆盖图像的alpha值将像素值除以255使值保持在0-1之间alpha_png png_img[yy1:yy2, xx1:xx2, 3] / 255.0alpha_jpg 1 - alpha_png# 开始叠加for c in range(0, 3):jpg_img[y1:y2, x1:x2, c] ((alpha_jpg * jpg_img[y1:y2, x1:x2, c]) (alpha_png * png_img[yy1:yy2, xx1:xx2, c]))return jpg_imgdef random_add_patches_on_objects(image, mask_lst, rescale_boxes, paste_number):img image.copy()new_bboxes []cl 0random.shuffle(rescale_boxes)for i, rescale_bbox in enumerate(rescale_boxes[:int(len(mask_lst))]): # 待ps图像 目标框中p_img mask_lst[i]bbox_h, bbox_w, bbox_c p_img.shapeobj_xmin, obj_ymin, obj_xmax, obj_ymax rescale_bbox[1:]obj_w obj_xmax - obj_xmin 1 # 目标框尺寸obj_h obj_ymax - obj_ymin 1while not (bbox_w obj_w and bbox_h obj_h): # 如果目标框小于 mask尺寸对mask进行缩放以确保可以放进 bbox中new_bbox_w int(bbox_w * random.uniform(0.5, 0.8))new_bbox_h int(bbox_h * random.uniform(0.5, 0.8))bbox_w, bbox_h new_bbox_w, new_bbox_hsuccess_num 0while success_num paste_number:center_search_space [obj_xmin, obj_ymin, obj_xmax - new_bbox_w - 1, obj_ymax - new_bbox_h - 1] # 选取生成随机点区域if center_search_space[0] center_search_space[2] or center_search_space[1] center_search_space[3]:print( center_search_space error!!!! )success_num 1continuenew_bbox_x_min random.randint(center_search_space[0], center_search_space[2]) # 随机生成点坐标new_bbox_y_min random.randint(center_search_space[1], center_search_space[3])new_bbox_x_left, new_bbox_y_top, new_bbox_x_right, new_bbox_y_bottom new_bbox_x_min, new_bbox_y_min, new_bbox_x_min new_bbox_w - 1, new_bbox_y_min new_bbox_h - 1new_bbox [cl, int(new_bbox_x_left), int(new_bbox_y_top), int(new_bbox_x_right), int(new_bbox_y_bottom)]success_num 1new_bboxes.append(new_bbox)p_img cv2.resize(p_img, (new_bbox_w, new_bbox_h))img merge_img(img, p_img, new_bbox_y_top, new_bbox_y_bottom1, new_bbox_x_left, new_bbox_x_right1)return img, new_bboxesif __name__ __main__:# 用来装载参数的容器parser argparse.ArgumentParser(descriptionPS)# 给这个解析对象添加命令行参数parser.add_argument(-i, --images, default /media/yinzhe/DataYZ/DataSet/DataSet/bag_model,typestr, helppath of images)parser.add_argument(-t, --mask, default /media/yinzhe/DataYZ/DataSet/DataSet/bag_mask,typestr, helppath of masks)parser.add_argument(-s, --saveImage,default /media/yinzhe/DataYZ/DataSet/DataSet/bag_save, typestr, helppath of )parser.add_argument(-c, --scale, default 0.2, typefloat, helpnumber of img)parser.add_argument(-n, --num, default 5, typeint, helpnumber of img)args parser.parse_args() # 获取所有参数mask_filedirs args.maskimages_path args.imagessave_path args.saveImagescale, num args.scale, args.nummask_paths []if not os.path.exists(save_path):os.makedirs(save_path)# 读取所有的 mask 模版mask_lst []for t_path in os.listdir(mask_filedirs):mask cv2.imread(os.path.join(mask_filedirs, t_path), cv2.IMREAD_UNCHANGED)if (mask.shape[2] ! 4): # RGB alphabreakmask_lst.append(mask)# template_paths random.shuffle(template_paths) #打乱顺序for image_path in os.listdir(images_path) :if txt in image_path:continueimage cv2.imread(os.path.join(images_path, image_path))pre_name image_path.split(.)[0]bbox_lst read_label_txt(os.path.join(images_path, pre_name .txt))if image is None or len(bbox_lst) 0:print(empty image !!! or empty label !!!)continue# yolo txt转化为x1y1x2y2rescale_bboxes rescale_yolo_labels(bbox_lst, image.shape) # 转换坐标表示# maskes_path sample(mask_paths, int(len(bbox_lst) * scale))#for i in range(num):maskes sample(mask_lst, int(len(bbox_lst) * scale))img, bboxes random_add_patches_on_objects(image, maskes, rescale_bboxes, 1)boxes xyxy2xywh(img, bboxes)img_name pre_name _ str(i) .jpgprint(handle img:, img_name)cv2.imwrite(os.path.join(save_path, img_name), img)with open(os.path.join(save_path, img_name[:-4] .txt), a) as f:for box in boxes:mess str(3) str(box[1]) str(box[2]) str(box[3] * 0.6) str(box[4]* 0.6) \nf.write(mess)
http://www.dnsts.com.cn/news/65753.html

相关文章:

  • 济南建筑公司实力排名seo服务 文库
  • 重庆网站建设项目wordpress后台无法登陆
  • 东平县住房和城乡建设局网站黄南北京网站建设
  • 有什么好的网站做旅行计划html网页制作心得体会
  • 崇文网站开发如何开发手机端网站
  • 广西建设厅建管处网站wordpress 支付 小程序
  • 免费网页设计模板网站百度云盘下载
  • 外链查询网站南通网站建设公司哪家好
  • 济南网站建设方案报价网站开发那个好
  • 网站维护费用怎么收广州建设工程交易中心怎么样
  • 网站建设和网络推广方案wordpress ios使用
  • 网站建设行业发展状况中国电信 网站备案
  • 中山 在门户网站推广wordpress 前台编辑文章
  • 临沂专业网站制作公司一个好的网站需要具备什么
  • 百色住房和城乡建设部网站wordpress 头部模板
  • 吉林省高等级公路建设局网站为某网站做一则广告语
  • 网站有哪些布局影响网站速度的代码
  • 手机永久免费建站宣传册设计与制作模板免费
  • 网页网站建筑网站ad
  • dw做网站有雪花效果深圳外贸建站网络推广联客易
  • 做网站 图片侵权网页制作软件s
  • 做网站主要用哪种语言有限公司怎么注册
  • 哪些网站开发wordpress设置固定连接打不开
  • 深圳电商网络网站晋中做网站公司
  • 网站建设的公司哪家强菏泽 做网站 多少钱
  • html设计素材网站棠下手机网站建设
  • 余姚住房和建设局网站手机网页开发者模式
  • 做美食网站的优势深圳外贸业务员工资
  • 网站建设硬件设计方案物联网平台有哪些
  • 网站文章采集郓城做网站网络公司