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

从零学做网站西安网站价格

从零学做网站,西安网站价格,黄村做网站建设,市场营销策划方案3000字先把模型放在如下目录 运行如下代码 import cv2 import numpy as npclass Onnx_clf:def __init__(self, onnx:strdnn_model1/plane02.onnx, img_size640, classlist:list[plane]) - None: func: 读取onnx模型,并进行目标识别para onnx:模型路径img_size:输出图片大小,和模…先把模型放在如下目录 运行如下代码 import cv2 import numpy as npclass Onnx_clf:def __init__(self, onnx:strdnn_model1/plane02.onnx, img_size640, classlist:list[plane]) - None: func: 读取onnx模型,并进行目标识别para onnx:模型路径img_size:输出图片大小,和模型直接相关classlist:类别列表return: Noneself.net cv2.dnn.readNet(onnx) # 读取模型self.img_size img_size # 输出图片尺寸大小self.classlist classlist # 读取类别列表def img_identify(self, img, ifshowTrue) - np.ndarray: func: 图片识别para img: 图片路径或者图片数组ifshow: 是否显示图片return: 图片数组if type(img) str: src cv2.imread(img)else: src imgheight, width, _ src.shape #注意输出的尺寸是先高后宽_max max(width, height)resized np.zeros((_max, _max, 3), np.uint8)resized[0:height, 0:width] src # 将图片转换成正方形防止后续图片预处理(缩放)失真# 图像预处理函数,缩放裁剪,交换通道 img scale out_size swapRBblob cv2.dnn.blobFromImage(resized, 1/255.0, (self.img_size, self.img_size), swapRBTrue)prop _max / self.img_size # 计算缩放比例dst cv2.resize(src, (round(width/prop), round(height/prop)))# print(prop) # 注意这里不能取整而是需要取小数否则后面绘制框的时候会出现偏差self.net.setInput(blob) # 将图片输入到模型out self.net.forward() # 模型输出# print(out.shape)out np.array(out[0])out out[out[:, 4] 0.5] # 利用numpy的花式索引,速度更快, 过滤置信度低的目标boxes out[:, :4]confidences out[:, 4]class_ids np.argmax(out[:, 5:], axis1)class_scores np.max(out[:, 5:], axis1)# out2 out[0][out[0][:][4] 0.5]# for i in out[0]: # 遍历每一个框# class_max_score max(i[5:])# if i[4] 0.5 or class_max_score 0.25: # 过滤置信度低的目标# continue# boxes.append(i[:4]) # 获取目标框: x,y,w,h (x,y为中心点坐标)# confidences.append(i[4]) # 获取置信度# class_ids.append(np.argmax(i[5:])) # 获取类别id# class_scores.append(class_max_score) # 获取类别置信度indexes cv2.dnn.NMSBoxes(boxes, confidences, 0.25, 0.45) # 非极大值抑制, 获取的是索引# print(indexes)iffall True if len(indexes)!0 else False# print(iffall)for i in indexes: # 遍历每一个目标, 绘制目标框box boxes[i]class_id class_ids[i]score round(class_scores[i], 2)x1 round((box[0] - 0.5*box[2])*prop)y1 round((box[1] - 0.5*box[3])*prop)x2 round((box[0] 0.5*box[2])*prop)y2 round((box[1] 0.5*box[3])*prop)# print(x1, y1, x2, y2)self.drawtext(src,(x1, y1), (x2, y2), self.classlist[class_id] str(score))dst cv2.resize(src, (round(width/prop), round(height/prop)))if ifshow:cv2.imshow(result, dst)cv2.waitKey(0)return dst, iffalldef video_identify(self, video_path:str) - None: func: 视频识别para video_path: 视频路径return: Nonecap cv2.VideoCapture(video_path)fps cap.get(cv2.CAP_PROP_FPS)# print(fps)while cap.isOpened():ret, frame cap.read()#键盘输入空格暂停输入q退出key cv2.waitKey(1) 0xffif key ord( ): cv2.waitKey(0)if key ord(q): breakif not ret: breakimg, res self.img_identify(frame, False)cv2.imshow(result, img)print(res)if cv2.waitKey(int(1000/fps)) ord(q):breakcap.release()cv2.destroyAllWindows()staticmethoddef drawtext(image, pt1, pt2, text): func: 根据给出的坐标和文本,在图片上进行绘制para image: 图片数组; pt1: 左上角坐标; pt2: 右下角坐标; text: 矩形框上显示的文本,即类别信息return: NonefontFace cv2.FONT_HERSHEY_COMPLEX_SMALL # 字体# fontFace cv2.FONT_HERSHEY_COMPLEX # 字体fontScale 1.5 # 字体大小line_thickness 3 # 线条粗细font_thickness 2 # 文字笔画粗细line_back_color (0, 0, 255) # 线条和文字背景颜色:红色font_color (255, 255, 255) # 文字颜色:白色# 绘制矩形框cv2.rectangle(image, pt1, pt2, colorline_back_color, thicknessline_thickness)# 计算文本的宽高: retval:文本的宽高; baseLine:基线与最低点之间的距离(本例未使用)retval, baseLine cv2.getTextSize(text,fontFacefontFace,fontScalefontScale, thicknessfont_thickness)# 计算覆盖文本的矩形框坐标topleft (pt1[0], pt1[1] - retval[1]) # 基线与目标框上边缘重合(不考虑基线以下的部分)bottomright (topleft[0] retval[0], topleft[1] retval[1])cv2.rectangle(image, topleft, bottomright, thickness-1, colorline_back_color) # 绘制矩形框(填充)# 绘制文本cv2.putText(image, text, pt1, fontScalefontScale,fontFacefontFace, colorfont_color, thicknessfont_thickness)if __name__ __main__:clf Onnx_clf()import tkinter as tkfrom tkinter.filedialog import askopenfilenametk.Tk().withdraw() # 隐藏主窗口, 必须要用否则会有一个小窗口source askopenfilename(titletest2.mp4)# source rC:\Users\Zeoy\Desktop\YOLOData\data\IMG_568.jpgif source.endswith(.jpg) or source.endswith(.png) or source.endswith(.bmp):res, out clf.img_identify(source, False)print(out)cv2.imshow(result, res)cv2.waitKey(0)elif source.endswith(.mp4) or source.endswith(.avi):print(视频识别中...按q退出)clf.video_identify(source)else:print(不支持的文件格式)
http://www.dnsts.com.cn/news/39962.html

相关文章:

  • 网站建设教程 冰美人视频宿迁网站建设价位
  • 旅游网站结构图网站建设框架搭建
  • 北海建设网站网站建设步骤 高清教 程
  • 网站空间买多大的公司注册地址规定
  • ps做图下载网站制作网站需要域名还需要什么
  • 网站这么上百度网络营销代运营服务
  • 如何做网站服务器网站首页 动画案例
  • 网站优化意见东莞我的网站建设
  • 西安网站开发建设建立自己的网站需要服务器吗
  • 营销网站的例子网站推广计划书具体包含哪些基本内容?
  • 萝岗网站建设制作网站建设甲方原因造成停工
  • 医院信息化建设会议安排网站wordpress菜单不能打开
  • 自己公司网站自己能做吗长寿做网站
  • jsp小型网站开发代码公司网站做推广支出分录
  • 网站pv uv统计营销网站制作设计
  • 项目立项流程图带seo服务的网站定制
  • 用网站做自我介绍ppt室内设计难学吗
  • 公司申请网站备案中山电子商务网站建设
  • 囊谦县公司网站建设杭州公司注册代理公司
  • 珠海 网站 设计网站建设需要多少内存
  • 长春哪里做网站百度不喜欢wordpress
  • 如何在招聘网站上选个好公司做销售php 网站模板 x11
  • 怎样做商城网站的推广wordpress页脚美化
  • 高端网站建设wanghess烟台网络科技有限公司
  • 有哪些专做旅游定制的网站房地产销售营销方案
  • 安微省住房和城乡建设厅网站吉林关键词排名优化软件
  • 亳州企业网站建设企业名录搜索软件推荐
  • 航空总医院医院网站建设招标网站杭州网页制作设计营销
  • 网站设计构想跑腿app开发
  • 苏州全网网站建设网站懒加载怎么做