网站论坛模板下载,网站建设在哪能看,金蝶云企业云平台,成都全网推广哪家专业项目介绍
项目地址
GitHub - biabu0/Yolov5_D435i: 通过YOLOV5与pyqt5实现一个使用D435i深度摄像头采集特定需求与场景下的深度数据的小程序 通过YOLOV5对指定的区域进行检测#xff0c;当检测到目标进入特定区域时#xff0c;开始保存数据#xff0c;摄像头采用D435i深度…
项目介绍
项目地址
GitHub - biabu0/Yolov5_D435i: 通过YOLOV5与pyqt5实现一个使用D435i深度摄像头采集特定需求与场景下的深度数据的小程序 通过YOLOV5对指定的区域进行检测当检测到目标进入特定区域时开始保存数据摄像头采用D435i深度相机用于采集深度数据集。
指定需要屏蔽的检测区域即使目标进入该区域也无法进行有效的检测应用于特定场景的检测。只有目标在检测区域内才进行数据的采集与保存避免一直采集数据目标离开检测区域则停止保存数据避免在数据采集过程中存在大量的无效数据节约数据清洗时间节省磁盘容量。按照时间存储数据。使用pyqt5设计可视化界面将UI界面与逻辑代码分离。
项目演示视频 演示视频 环境配置 按照requements.txt文件配置yolov5环境安装pyqt5和pyrealsense2。
核心代码解析 detect_logical.py负责加载模型并初始化模型参数选择遮蔽区域以及需要保存的数据文件地址加载D435深度相机数据流将数据送入检测检测到特定目标返回数据保存的标志位进行数据存储。 main_logic.py:主界面可以进行注册账号与登录账号。 ui/ori_ui:ui源文件可以通过使用QTdesigner对UI界面进行修改修改后使用**pyuic5 main.ui ui_main.py**,注意最好使用绝对路径不然可能出现问题转换成py文件。 utlis/id_utlis.py与userInfo.csv用于写入账户信息。
遮蔽区域选择 通过鼠标左键获取需要屏蔽的区域的四个角的位置保存到一个全局变量中用于后序检测的时候生成指定区域的掩码从而屏蔽特定区域。 def mouse_callback(self, event, x, y, flags, param):if event cv2.EVENT_LBUTTONDOWN:# 将位置标准化可选根据需求决定是否需要normalized_x x / self.frame_shape[1]normalized_y y / self.frame_shape[0]# 将位置添加到二维数组中self.mouse_positions.append([normalized_x, normalized_y])return ;def select_mask(self):self.mouse_positions []self.pipeline.start(self.config)frames self.pipeline.wait_for_frames()img_color frames.get_color_frame()# 检查摄像头是否成功打开if img_color is None:print(Error: Could not open video device.)exit()img_color np.asanyarray(img_color.get_data())self.frame_shape img_color.shape[:2]# 创建一个窗口cv2.namedWindow(Camera Image)# 设置鼠标回调函数cv2.setMouseCallback(Camera Image, self.mouse_callback)while True:# 显示图像cv2.imshow(Camera Image, img_color)#等待按键如果按下q键退出循环if cv2.waitKey(0) 0xFF ord(q):break# 释放D435i对象self.pipeline.stop() # 停止RealSense管道# 销毁创建的窗口print(mouse_positions, self.mouse_positions)QtWidgets.QMessageBox.information(self, uNotice, u遮掩区域选择成功, buttonsQtWidgets.QMessageBox.Ok,defaultButtonQtWidgets.QMessageBox.Ok)
选择数据保存地址 直接将寻找的路径保存到全局变量中后序需要保存地址的时候加载进去。 def open_file(self):self.openfile_name_dataset QFileDialog.getExistingDirectory(self, 选择数据集目录)if not self.openfile_name_dataset:QtWidgets.QMessageBox.warning(self, uWarning, u打开文件地址失败, buttonsQtWidgets.QMessageBox.Ok,defaultButtonQtWidgets.QMessageBox.Ok)else:QtWidgets.QMessageBox.information(self, uNotice, u数据集路径为 str(self.openfile_name_dataset), buttonsQtWidgets.QMessageBox.Ok,defaultButtonQtWidgets.QMessageBox.Ok)
采集数据 当检测到目标存在时需要进行数据保存调用该函数。从D435i中获取帧作为参数。将深度帧与彩色帧对齐获取深度图与彩色图。按照时间格式创建数据保存的文件夹可以选择保存四种数据格color彩色图depth:原始深度图npy格式depthjpg与可视化后的彩色图。 def save_dataset(self, frames):align_to rs.stream.coloralign rs.align(align_to) # 对齐aligned_frames align.process(frames)aligned_depth_frame aligned_frames.get_depth_frame()color_frame aligned_frames.get_color_frame()depth_image np.asanyarray(aligned_depth_frame.get_data())depth_data np.asanyarray(aligned_depth_frame.get_data(), dtypeuint16)color_image np.asanyarray(color_frame.get_data())t1 time.strftime(%Y_%m_%d_%H_%M, time.localtime())if not self.openfile_name_dataset:QtWidgets.QMessageBox.warning(self, uWarning, u请先选择数据集地址, buttonsQtWidgets.QMessageBox.Ok,defaultButtonQtWidgets.QMessageBox.Ok)returnsave_path os.path.join(self.openfile_name_dataset, outfile, t1)os.makedirs(save_path, exist_okTrue)os.makedirs(os.path.join(save_path, color), exist_okTrue)os.makedirs(os.path.join(save_path, depth), exist_okTrue)os.makedirs(os.path.join(save_path, depthjpg), exist_okTrue)os.makedirs(os.path.join(save_path, depth_mapped_image), exist_okTrue)saved_count int(time.time() * 1000) #毫秒级的时间戳depth_mapped_image cv2.applyColorMap(cv2.convertScaleAbs(depth_image, alpha0.03), cv2.COLORMAP_JET)# 彩色图片保存为png格式cv2.imwrite(save_path /color/ {}.format(saved_count) .jpg, color_image)# -----------深度图保存信息----------------## 深度信息由采集到的float16直接保存为npy格式np.save(os.path.join(save_path, depth, {}.format(saved_count)), depth_data) ## 黑白图# 使用jpg格式保存的图片图像采集错误还能肉眼发现cv2.imwrite(save_path /depthjpg/ {}.jpg.format(saved_count), depth_image)# 渲染的图片cv2.imwrite(save_path /depth_mapped_image/{}.jpg.format(saved_count), depth_mapped_image)return True
目标检测信息 根据选择掩码阶段选择的四个坐标位置生成mask应用到图像上达到遮蔽区域检测的目的。实现mask后查看掩码具体位置然后进入检测逻辑返回检测信息以及数据保存位。 def detect(self, name_list, img):#(1, 3, 480, 640) [[[145 146 143], [148 149 146# ]]]showimg imghl1 self.mouse_positions[0][1] # 监测区域高度距离图片顶部比例wl1 self.mouse_positions[0][0] # 监测区域高度距离图片左部比例hl2 self.mouse_positions[1][1] # 监测区域高度距离图片顶部比例wl2 self.mouse_positions[1][0] # 监测区域高度距离图片左部比例hl3 self.mouse_positions[3][1] # 监测区域高度距离图片顶部比例wl3 self.mouse_positions[3][0] # 监测区域高度距离图片左部比例hl4 self.mouse_positions[2][1] # 监测区域高度距离图片顶部比例wl4 self.mouse_positions[2][0] # 监测区域高度距离图片左部比例mask np.zeros([img.shape[0], img.shape[1]], dtypenp.uint8)pts np.array([[int(img.shape[1] * wl1), int(img.shape[0] * hl1)], # pts1[int(img.shape[1] * wl2), int(img.shape[0] * hl2)], # pts2[int(img.shape[1] * wl3), int(img.shape[0] * hl3)], # pts3[int(img.shape[1] * wl4), int(img.shape[0] * hl4)]], np.int32)cv2.fillPoly(mask, [pts], (255, 255, 255))mask 255 - mask# 应用mask将mask为0的部分设置为黑色0,0,0img cv2.add(img, np.zeros(np.shape(img), dtypenp.uint8), maskmask)# 2if not self.border:# 只显示一次# 定义框的颜色和线宽border_color (255, 0, 0) # 红色border_thickness 2cv2.polylines(img, [pts], True, border_color, border_thickness)self.border True# 显示结果cv2.imshow(Image with Mask and Border, img)cv2.waitKey(0)cv2.destroyAllWindows()# 2with torch.no_grad():img letterbox(img, new_shapeself.opt.img_size)[0]# Convertimg img[:, :, ::-1].transpose(2, 0, 1) # BGR to RGB, to 3x416x416img np.ascontiguousarray(img)img torch.from_numpy(img).to(self.device)img img.half() if self.half else img.float() # uint8 to fp16/32img / 255.0 # 0 - 255 to 0.0 - 1.0if img.ndimension() 3:img img.unsqueeze(0)# Inference# 1# 1pred self.model(img, augmentself.opt.augment)[0]# Apply NMSpred non_max_suppression(pred, self.opt.conf_thres, self.opt.iou_thres, classesself.opt.classes,agnosticself.opt.agnostic_nms)info_show info_show_target # Process detectionsself.info_show_int 1for i, det in enumerate(pred):if det is not None and len(det):# 3condition (det[:, 5] 0.0) (det[:, 4] 0.6)if condition.any():#print(有人员进入监测区域)info_show_target 有人员进入检测区域self.info_show_int 0else:info_show_target 无人员进入检测区域self.info_show_int 1# 3# Rescale boxes from img_size to im0 sizedet[:, :4] scale_coords(img.shape[2:], det[:, :4], showimg.shape).round()for *xyxy, conf, cls in reversed(det):label %s %.2f % (self.names[int(cls)], conf)name_list.append(self.names[int(cls)])single_info plot_one_box2(xyxy, showimg, labellabel, colorself.colors[int(cls)], line_thickness2)# print(single_info)info_show info_show single_info \nreturn info_show_target, self.info_show_int
视频帧操作逻辑 打开D435i获取彩色图要将彩色图copy一份再送入detect检测逻辑不然会导致最后保存的数据还有检测的目标框。 def show_video_frame(self):frames self.pipeline.wait_for_frames()color_frame frames.get_color_frame()#在此处就获取帧后面获取帧会导致获取color含有检测框# depth_frame frames.get_depth_frame()if not color_frame:self.finish_detect()returncolor_image np.asanyarray(color_frame.get_data())color_image_detect color_image.copy()info_show, info_show_int self.detect([], color_image_detect) # 检测结果写入到原始img上#print(info_show)if info_show_int 0:#print(---开始处理保存数据程序---)flag self.save_dataset(frames)if flag:#print(数据保存成功)info_show 数据保存成功elif info_show_int 1:#print(---停止保存数据程序---)info_show 停止保存数据# 显示检测信息和图像self.ui.textBrowser.setText(info_show)show cv2.resize(color_image_detect, (640, 480))self.result cv2.cvtColor(show, cv2.COLOR_BGR2RGB)showImage QtGui.QImage(self.result.data, self.result.shape[1], self.result.shape[0],QtGui.QImage.Format_RGB888)self.ui.label.setPixmap(QtGui.QPixmap.fromImage(showImage))self.ui.label.setScaledContents(True) 参考
项目UI主要参考使用PyQt5为YoloV5添加界面一_pyqt pyvista-CSDN博客
YOLOv5区域入侵检测【附完整代码以及视频演示】_yolov5入侵检测-CSDN博客
pyqt5学习Python Qt 简介 - 白月黑羽 文章转载自: http://www.morning.xsetx.com.gov.cn.xsetx.com http://www.morning.jhgxh.cn.gov.cn.jhgxh.cn http://www.morning.hytr.cn.gov.cn.hytr.cn http://www.morning.wxgd.cn.gov.cn.wxgd.cn http://www.morning.ryfpx.cn.gov.cn.ryfpx.cn http://www.morning.wdhhz.cn.gov.cn.wdhhz.cn http://www.morning.geledi.com.gov.cn.geledi.com http://www.morning.mflqd.cn.gov.cn.mflqd.cn http://www.morning.mfmx.cn.gov.cn.mfmx.cn http://www.morning.tnmmp.cn.gov.cn.tnmmp.cn http://www.morning.ymtbr.cn.gov.cn.ymtbr.cn http://www.morning.mqss.cn.gov.cn.mqss.cn http://www.morning.mooncore.cn.gov.cn.mooncore.cn http://www.morning.lizpw.com.gov.cn.lizpw.com http://www.morning.bpkqd.cn.gov.cn.bpkqd.cn http://www.morning.kyfnh.cn.gov.cn.kyfnh.cn http://www.morning.yrjhr.cn.gov.cn.yrjhr.cn http://www.morning.rshs.cn.gov.cn.rshs.cn http://www.morning.dmtld.cn.gov.cn.dmtld.cn http://www.morning.lmpfk.cn.gov.cn.lmpfk.cn http://www.morning.lkkkf.cn.gov.cn.lkkkf.cn http://www.morning.lcbgf.cn.gov.cn.lcbgf.cn http://www.morning.dzqyn.cn.gov.cn.dzqyn.cn http://www.morning.pwzzk.cn.gov.cn.pwzzk.cn http://www.morning.gbqgr.cn.gov.cn.gbqgr.cn http://www.morning.rhpgk.cn.gov.cn.rhpgk.cn http://www.morning.jwbfj.cn.gov.cn.jwbfj.cn http://www.morning.bwhcl.cn.gov.cn.bwhcl.cn http://www.morning.xclgf.cn.gov.cn.xclgf.cn http://www.morning.mkxxk.cn.gov.cn.mkxxk.cn http://www.morning.mzrqj.cn.gov.cn.mzrqj.cn http://www.morning.wrtxk.cn.gov.cn.wrtxk.cn http://www.morning.mdmxf.cn.gov.cn.mdmxf.cn http://www.morning.pfgln.cn.gov.cn.pfgln.cn http://www.morning.yqqxj1.cn.gov.cn.yqqxj1.cn http://www.morning.rahllp.com.gov.cn.rahllp.com http://www.morning.psyrz.cn.gov.cn.psyrz.cn http://www.morning.baohum.com.gov.cn.baohum.com http://www.morning.yktwr.cn.gov.cn.yktwr.cn http://www.morning.ckrnq.cn.gov.cn.ckrnq.cn http://www.morning.brps.cn.gov.cn.brps.cn http://www.morning.hxbjt.cn.gov.cn.hxbjt.cn http://www.morning.kdrjd.cn.gov.cn.kdrjd.cn http://www.morning.rfrnc.cn.gov.cn.rfrnc.cn http://www.morning.redhoma.com.gov.cn.redhoma.com http://www.morning.hpcpp.cn.gov.cn.hpcpp.cn http://www.morning.pbmg.cn.gov.cn.pbmg.cn http://www.morning.wzwyz.cn.gov.cn.wzwyz.cn http://www.morning.sldrd.cn.gov.cn.sldrd.cn http://www.morning.ngqdp.cn.gov.cn.ngqdp.cn http://www.morning.nbpqx.cn.gov.cn.nbpqx.cn http://www.morning.qkdcb.cn.gov.cn.qkdcb.cn http://www.morning.lmtbl.cn.gov.cn.lmtbl.cn http://www.morning.rblqk.cn.gov.cn.rblqk.cn http://www.morning.dwwbt.cn.gov.cn.dwwbt.cn http://www.morning.51meihou.cn.gov.cn.51meihou.cn http://www.morning.mgzjz.cn.gov.cn.mgzjz.cn http://www.morning.xfdkh.cn.gov.cn.xfdkh.cn http://www.morning.mdplm.cn.gov.cn.mdplm.cn http://www.morning.jkzjs.cn.gov.cn.jkzjs.cn http://www.morning.iznek.com.gov.cn.iznek.com http://www.morning.gpsrk.cn.gov.cn.gpsrk.cn http://www.morning.ysbhj.cn.gov.cn.ysbhj.cn http://www.morning.fnssm.cn.gov.cn.fnssm.cn http://www.morning.hmqwn.cn.gov.cn.hmqwn.cn http://www.morning.zdzgf.cn.gov.cn.zdzgf.cn http://www.morning.qhtlq.cn.gov.cn.qhtlq.cn http://www.morning.tbhf.cn.gov.cn.tbhf.cn http://www.morning.xcfmh.cn.gov.cn.xcfmh.cn http://www.morning.rgmls.cn.gov.cn.rgmls.cn http://www.morning.bzlgb.cn.gov.cn.bzlgb.cn http://www.morning.snrhg.cn.gov.cn.snrhg.cn http://www.morning.ygztf.cn.gov.cn.ygztf.cn http://www.morning.kkgbs.cn.gov.cn.kkgbs.cn http://www.morning.wcjk.cn.gov.cn.wcjk.cn http://www.morning.qrsrs.cn.gov.cn.qrsrs.cn http://www.morning.pxmyw.cn.gov.cn.pxmyw.cn http://www.morning.ffwrq.cn.gov.cn.ffwrq.cn http://www.morning.hkswt.cn.gov.cn.hkswt.cn http://www.morning.ykgkh.cn.gov.cn.ykgkh.cn