热门标签 | 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()

在这里插入图片描述


推荐阅读
  • Explore how Matterverse is redefining the metaverse experience, creating immersive and meaningful virtual environments that foster genuine connections and economic opportunities. ... [详细]
  • PyCharm下载与安装指南
    本文详细介绍如何从官方渠道下载并安装PyCharm集成开发环境(IDE),涵盖Windows、macOS和Linux系统,同时提供详细的安装步骤及配置建议。 ... [详细]
  • 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 接口,解释了其实现机制、用途及注意事项,帮助开发者更好地理解和使用序列化功能。 ... [详细]
  • 本文介绍了如何在C#中启动一个应用程序,并通过枚举窗口来获取其主窗口句柄。当使用Process类启动程序时,我们通常只能获得进程的句柄,而主窗口句柄可能为0。因此,我们需要使用API函数和回调机制来准确获取主窗口句柄。 ... [详细]
  • 本文详细介绍了Java中org.neo4j.helpers.collection.Iterators.single()方法的功能、使用场景及代码示例,帮助开发者更好地理解和应用该方法。 ... [详细]
  • 本文将介绍如何编写一些有趣的VBScript脚本,这些脚本可以在朋友之间进行无害的恶作剧。通过简单的代码示例,帮助您了解VBScript的基本语法和功能。 ... [详细]
  • 本文详细介绍如何使用Python进行配置文件的读写操作,涵盖常见的配置文件格式(如INI、JSON、TOML和YAML),并提供具体的代码示例。 ... [详细]
  • Java 中 Writer flush()方法,示例 ... [详细]
  • Java 类成员初始化顺序与数组创建
    本文探讨了Java中类成员的初始化顺序、静态引入、可变参数以及finalize方法的应用。通过具体的代码示例,详细解释了这些概念及其在实际编程中的使用。 ... [详细]
  • 1.如何在运行状态查看源代码?查看函数的源代码,我们通常会使用IDE来完成。比如在PyCharm中,你可以Ctrl+鼠标点击进入函数的源代码。那如果没有IDE呢?当我们想使用一个函 ... [详细]
  • DNN Community 和 Professional 版本的主要差异
    本文详细解析了 DotNetNuke (DNN) 的两种主要版本:Community 和 Professional。通过对比两者的功能和附加组件,帮助用户选择最适合其需求的版本。 ... [详细]
  • 本文详细介绍了如何构建一个高效的UI管理系统,集中处理UI页面的打开、关闭、层级管理和页面跳转等问题。通过UIManager统一管理外部切换逻辑,实现功能逻辑分散化和代码复用,支持多人协作开发。 ... [详细]
  • 离线环境下的Python及其第三方库安装指南
    在项目开发中,有时会遇到电脑只能连接内网或完全无法联网的情况。本文将详细介绍如何在这种环境下安装Python及其所需的第三方库,确保开发工作的顺利进行。 ... [详细]
  • 本文详细介绍了Java中org.w3c.dom.Text类的splitText()方法,通过多个代码示例展示了其实际应用。该方法用于将文本节点在指定位置拆分为两个节点,并保持在文档树中。 ... [详细]
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社区 版权所有