热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

关于物体(车辆)震颤(熄火)检测研究

关于物体(车辆)震颤(熄火)检测研究关于物体(车辆)震颤(熄火)检测

关于物体(车辆)震颤(熄火)检测研究关于物体(车辆)震颤(熄火)检测研究()()



一 分析视频数据中车辆的振动和光影变化


1.1 边缘检测

import cv2
import os
import time
import torch.nn as nn
import torch
import numpy as np
import torchvision.transforms as transforms
import torchvision
from PIL import Image
from matplotlib import pyplot as pltnp.set_printoptions(threshold=np.inf)
# threshold表示: Total number of array elements to be print(输出数组的元素数目)cap1 = cv2.VideoCapture("static.mkv") # 0 使用默认的电脑摄像头
cap2 = cv2.VideoCapture("move.mkv") # 0 使用默认的电脑摄像头
while (True):# 1.获取一帧帧图像ret1, static = cap1.read()ret2, move = cap2.read()# 转灰度图static = cv2.cvtColor(static, cv2.COLOR_BGR2GRAY)move = cv2.cvtColor(move, cv2.COLOR_BGR2GRAY)# 确定阈值threshold = 130# 阈值分割ret1, static = cv2.threshold(static, threshold, 255, cv2.THRESH_BINARY)ret2, move = cv2.threshold(move, threshold, 255, cv2.THRESH_BINARY)cv2.imshow('static', static)cv2.imshow('move', move)# 按下“q”键停止if cv2.waitKey(1) & 0xFF == ord('q'): # cv2.waitKey(1) 1毫秒读一次break
cap1.release()
cap2.release()
cv2.destroyAllWindows()

在这里插入图片描述

1.2 转HSV查看亮度等变化

在这里插入图片描述
在这里插入图片描述



二 分析总结:

正面车辆振动和静止状态在震颤不明显,除去振动,另一方面,颜色光影变化在车辆振动时,也不明显,同时随着帧数的变化,摄像头所拍视频存在大面积轻微噪声,基本覆盖住了车辆振动造成的光影变化。

从正面进行车辆的震颤检测和光度变化等进行熄火检测不现实,建议拍摄尾部视频,进行排气管震颤或者冒烟检测

今日拍摄了车辆尾部视频,整体尾部振动不明显,排气管振动不明显,排出气体基本透明,无法检测。



三 结果:

检测视频车辆熄火,未成功!



四 研究过程中的收获:可以对车辆进行检测和分割

使用FasterRCNN进行车辆视频检测使用FasterRCNN进行车辆视频检测使FasterRCNN

import cv2
import os
import time
import torch.nn as nn
import torch
import numpy as np
import torchvision.transforms as transforms
import torchvision
from PIL import Image
from matplotlib import pyplot as pltBASE_DIR = os.path.dirname(os.path.abspath(__file__))
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")COCO_INSTANCE_CATEGORY_NAMES = ['__background__', 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus','train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'N/A', 'stop sign','parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow','elephant', 'bear', 'zebra', 'giraffe', 'N/A', 'backpack', 'umbrella', 'N/A', 'N/A','handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball','kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket','bottle', 'N/A', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl','banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza','donut', 'cake', 'chair', 'couch', 'potted plant', 'bed', 'N/A', 'dining table','N/A', 'N/A', 'toilet', 'N/A', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone','microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'N/A', 'book','clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'
]
cap &#61; cv2.VideoCapture("move.mkv") # 0 使用默认的电脑摄像头while (True):# 1.获取一帧帧图像ret, frame &#61; cap.read()# 2.获取模型model &#61; torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained&#61;True)model.eval()# 3.图像送进模型preprocess &#61; transforms.Compose([transforms.ToTensor(),])# 3.1. preprocessimg_chw &#61; preprocess(frame)# 3.2 to deviceif torch.cuda.is_available():img_chw &#61; img_chw.to(&#39;cuda&#39;)model.to(&#39;cuda&#39;)# 3.3 forwardinput_list &#61; [img_chw]with torch.no_grad():tic &#61; time.time()# print("input img tensor shape:{}".format(input_list[0].shape))output_list &#61; model(input_list)output_dict &#61; output_list[0]# print("pass: {:.3f}s".format(time.time() - tic))# for k, v in output_dict.items():# print("key:{}, value:{}".format(k, v))# 3.4. visualizationout_boxes &#61; output_dict["boxes"].cpu()out_scores &#61; output_dict["scores"].cpu()out_labels &#61; output_dict["labels"].cpu()num_boxes &#61; out_boxes.shape[0]max_vis &#61; 2thres &#61; 0.995for idx in range(0, min(num_boxes, max_vis)):score &#61; out_scores[idx].numpy() # 置信分数bbox &#61; out_boxes[idx].numpy() # 边框坐标class_name &#61; COCO_INSTANCE_CATEGORY_NAMES[out_labels[idx]] # 类别输出if score < thres:continueframe &#61; cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 3)print("坐标&#xff1a;",(bbox[0], bbox[1]), (bbox[2], bbox[3]))loacation &#61; str(((bbox[2]-bbox[0]),(bbox[3]-bbox[1])))frame &#61; cv2.putText(frame,loacation, (int(bbox[0]), int(bbox[1])), cv2.FONT_HERSHEY_COMPLEX_SMALL, 0.8, (0, 0, 0))cv2.imshow(&#39;frame&#39;, frame)# 按下“q”键停止if cv2.waitKey(1) & 0xFF &#61;&#61; ord(&#39;q&#39;): # cv2.waitKey(1) 1毫秒读一次break
cap.release()
cv2.destroyAllWindows()

在这里插入图片描述

使用MaskerRCNN进行车辆视频的检测和分割使用MaskerRCNN进行车辆视频的检测和分割使MaskerRCNN

import cv2
import os
import time
import torch.nn as nn
import torch
import numpy as np
import torchvision.transforms as transforms
import torchvision
from PIL import Image
from matplotlib import pyplot as plt
import random
# np.set_printoptions(threshold&#61;np.inf)
# threshold表示: Total number of array elements to be print(输出数组的元素数目)BASE_DIR &#61; os.path.dirname(os.path.abspath(__file__))
device &#61; torch.device("cuda" if torch.cuda.is_available() else "cpu")COCO_INSTANCE_CATEGORY_NAMES &#61; [&#39;__background__&#39;, &#39;person&#39;, &#39;bicycle&#39;, &#39;car&#39;, &#39;motorcycle&#39;, &#39;airplane&#39;, &#39;bus&#39;,&#39;train&#39;, &#39;truck&#39;, &#39;boat&#39;, &#39;traffic light&#39;, &#39;fire hydrant&#39;, &#39;N/A&#39;, &#39;stop sign&#39;,&#39;parking meter&#39;, &#39;bench&#39;, &#39;bird&#39;, &#39;cat&#39;, &#39;dog&#39;, &#39;horse&#39;, &#39;sheep&#39;, &#39;cow&#39;,&#39;elephant&#39;, &#39;bear&#39;, &#39;zebra&#39;, &#39;giraffe&#39;, &#39;N/A&#39;, &#39;backpack&#39;, &#39;umbrella&#39;, &#39;N/A&#39;, &#39;N/A&#39;,&#39;handbag&#39;, &#39;tie&#39;, &#39;suitcase&#39;, &#39;frisbee&#39;, &#39;skis&#39;, &#39;snowboard&#39;, &#39;sports ball&#39;,&#39;kite&#39;, &#39;baseball bat&#39;, &#39;baseball glove&#39;, &#39;skateboard&#39;, &#39;surfboard&#39;, &#39;tennis racket&#39;,&#39;bottle&#39;, &#39;N/A&#39;, &#39;wine glass&#39;, &#39;cup&#39;, &#39;fork&#39;, &#39;knife&#39;, &#39;spoon&#39;, &#39;bowl&#39;,&#39;banana&#39;, &#39;apple&#39;, &#39;sandwich&#39;, &#39;orange&#39;, &#39;broccoli&#39;, &#39;carrot&#39;, &#39;hot dog&#39;, &#39;pizza&#39;,&#39;donut&#39;, &#39;cake&#39;, &#39;chair&#39;, &#39;couch&#39;, &#39;potted plant&#39;, &#39;bed&#39;, &#39;N/A&#39;, &#39;dining table&#39;,&#39;N/A&#39;, &#39;N/A&#39;, &#39;toilet&#39;, &#39;N/A&#39;, &#39;tv&#39;, &#39;laptop&#39;, &#39;mouse&#39;, &#39;remote&#39;, &#39;keyboard&#39;, &#39;cell phone&#39;,&#39;microwave&#39;, &#39;oven&#39;, &#39;toaster&#39;, &#39;sink&#39;, &#39;refrigerator&#39;, &#39;N/A&#39;, &#39;book&#39;,&#39;clock&#39;, &#39;vase&#39;, &#39;scissors&#39;, &#39;teddy bear&#39;, &#39;hair drier&#39;, &#39;toothbrush&#39;
]
cap &#61; cv2.VideoCapture("move.mkv") # 0 使用默认的电脑摄像头def random_colour_masks(image):colours &#61; [[0, 255, 0], [0, 0, 255], [255, 0, 0], [0, 255, 255], [255, 255, 0], [255, 0, 255], [80, 70, 180],[250, 80, 190], [245, 145, 50], [70, 150, 250], [50, 190, 190]]r &#61; np.zeros_like(image).astype(np.uint8)g &#61; np.zeros_like(image).astype(np.uint8)b &#61; np.zeros_like(image).astype(np.uint8)r[image &#61;&#61; 1], g[image &#61;&#61; 1], b[image &#61;&#61; 1] &#61; colours[random.randrange(0, 10)]coloured_mask &#61; np.stack([r, g, b], axis&#61;2)return coloured_maskwhile (True):# 1.获取一帧帧图像ret, frame &#61; cap.read()# 2.获取模型model &#61; torchvision.models.detection.maskrcnn_resnet50_fpn(pretrained&#61;True)model.eval()# 3.图像送进模型preprocess &#61; transforms.Compose([transforms.ToTensor(),])# 3.1. preprocessimg_chw &#61; preprocess(frame)# 3.2 to deviceif torch.cuda.is_available():img_chw &#61; img_chw.to(&#39;cuda&#39;)model.to(&#39;cuda&#39;)# 3.3 forwardinput_list &#61; [img_chw]with torch.no_grad():tic &#61; time.time()# print("input img tensor shape:{}".format(input_list[0].shape))output_list &#61; model(input_list)output_dict &#61; output_list[0]# print("pass: {:.3f}s".format(time.time() - tic))# for k, v in output_dict.items():# print("key:{}, value:{}".format(k, v))# 3.4. visualizationout_boxes &#61; output_dict["boxes"].cpu()out_scores &#61; output_dict["scores"].cpu()out_labels &#61; output_dict["labels"].cpu()out_masks &#61; output_dict["masks"].cpu()#print(out_masks[1].numpy())num_boxes &#61; out_boxes.shape[0]max_vis &#61; 40thres &#61; 0.5masks &#61; (output_dict["masks"] > 0.5).squeeze().detach().cpu().numpy()for i in range(len(masks)):rgb_mask &#61; random_colour_masks(masks[i])frame &#61; cv2.addWeighted(frame, 1, rgb_mask, 0.5, 0)# rgb_mask &#61; random_colour_masks(masks[])# frame &#61; cv2.addWeighted(frame, 1, rgb_mask, 0.5, 0)# 下面的注释解开&#xff0c;就是加上检测# for idx in range(0, min(num_boxes, max_vis)):## score &#61; out_scores[idx].numpy() # 置信分数# bbox &#61; out_boxes[idx].numpy() # 边框坐标# class_name &#61; COCO_INSTANCE_CATEGORY_NAMES[out_labels[idx]] # 类别输出## if score # continue# frame &#61; cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 3)# print("坐标&#xff1a;",(bbox[0], bbox[1]), (bbox[2], bbox[3]))# loacation &#61; str(((bbox[2]-bbox[0]),(bbox[3]-bbox[1])))# frame &#61; cv2.putText(frame,loacation, (int(bbox[0]), int(bbox[1])), cv2.FONT_HERSHEY_COMPLEX_SMALL, 0.8, (0, 0, 0))cv2.imshow(&#39;frame&#39;, frame)# 按下“q”键停止if cv2.waitKey(1) & 0xFF &#61;&#61; ord(&#39;q&#39;): # cv2.waitKey(1) 1毫秒读一次break
cap.release()
cv2.destroyAllWindows()

在这里插入图片描述


推荐阅读
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • 本文深入探讨了 Java 中的 Serializable 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • 本文详细介绍了Java中org.neo4j.helpers.collection.Iterators.single()方法的功能、使用场景及代码示例,帮助开发者更好地理解和应用该方法。 ... [详细]
  • 本文详细介绍了 GWT 中 PopupPanel 类的 onKeyDownPreview 方法,提供了多个代码示例及应用场景,帮助开发者更好地理解和使用该方法。 ... [详细]
  • 本文介绍如何使用Objective-C结合dispatch库进行并发编程,以提高素数计数任务的效率。通过对比纯C代码与引入并发机制后的代码,展示dispatch库的强大功能。 ... [详细]
  • 本文详细介绍了如何在Linux系统上安装和配置Smokeping,以实现对网络链路质量的实时监控。通过详细的步骤和必要的依赖包安装,确保用户能够顺利完成部署并优化其网络性能监控。 ... [详细]
  • 1.如何在运行状态查看源代码?查看函数的源代码,我们通常会使用IDE来完成。比如在PyCharm中,你可以Ctrl+鼠标点击进入函数的源代码。那如果没有IDE呢?当我们想使用一个函 ... [详细]
  • 本文深入探讨 MyBatis 中动态 SQL 的使用方法,包括 if/where、trim 自定义字符串截取规则、choose 分支选择、封装查询和修改条件的 where/set 标签、批量处理的 foreach 标签以及内置参数和 bind 的用法。 ... [详细]
  • 本文详细介绍了Java中org.eclipse.ui.forms.widgets.ExpandableComposite类的addExpansionListener()方法,并提供了多个实际代码示例,帮助开发者更好地理解和使用该方法。这些示例来源于多个知名开源项目,具有很高的参考价值。 ... [详细]
  • 深入解析Spring Cloud Ribbon负载均衡机制
    本文详细介绍了Spring Cloud中的Ribbon组件如何实现服务调用的负载均衡。通过分析其工作原理、源码结构及配置方式,帮助读者理解Ribbon在分布式系统中的重要作用。 ... [详细]
  • 在前两篇文章中,我们探讨了 ControllerDescriptor 和 ActionDescriptor 这两个描述对象,分别对应控制器和操作方法。本文将基于 MVC3 源码进一步分析 ParameterDescriptor,即用于描述 Action 方法参数的对象,并详细介绍其工作原理。 ... [详细]
  • 本文详细介绍如何使用Python进行配置文件的读写操作,涵盖常见的配置文件格式(如INI、JSON、TOML和YAML),并提供具体的代码示例。 ... [详细]
  • 本文介绍了如何使用 Spring Boot DevTools 实现应用程序在开发过程中自动重启。这一特性显著提高了开发效率,特别是在集成开发环境(IDE)中工作时,能够提供快速的反馈循环。默认情况下,DevTools 会监控类路径上的文件变化,并根据需要触发应用重启。 ... [详细]
  • 深入理解 SQL 视图、存储过程与事务
    本文详细介绍了SQL中的视图、存储过程和事务的概念及应用。视图为用户提供了一种灵活的数据查询方式,存储过程则封装了复杂的SQL逻辑,而事务确保了数据库操作的完整性和一致性。 ... [详细]
author-avatar
Mister-Sky_724
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有