资源简介
通过opencv-python调用摄像头, 传入YOLACT模型进行实时在线的目标检测和MASK标记.
详见博客 https://blog.csdn.net/Augurlee/article/details/103574125
详见博客 https://blog.csdn.net/Augurlee/article/details/103574125
代码片段和文件信息
import torch
import torch.backends.cudnn as cudnn
from data import COLORS
from data import cfg set_cfg
from yolact import Yolact
from utils.augmentations import FastbaseTransform
from utils import timer
from utils.functions import SavePath
from layers.output_utils import postprocess undo_image_transformation
import cv2 as cv
from collections import defaultdict
# 参数配置
score_threshold = 0.15
top_k = 15
display_masks = True
display_text = True
display_bboxes = True
display_scores = True
# 全局变量
iou_thresholds = [x / 100 for x in range(50 100 5)]
coco_cats = {} # Call prep_coco_cats to fill this
coco_cats_inv = {}
color_cache = defaultdict(lambda: {})
def prep_display(dets_out img h w undo_transform=True class_color=False mask_alpha=0.45 fps_str=‘‘):
“““
Note: If undo_transform=False then im_h and im_w are allowed to be None.
“““
if undo_transform:
img_numpy = undo_image_transformation(img w h)
img_gpu = torch.Tensor(img_numpy).cuda()
else:
img_gpu = img / 255.0
h w _ = img.shape
with timer.env(‘Postprocess‘):
t = postprocess(dets_out w h visualize_lincomb=False
crop_masks=True
score_threshold=score_threshold)
torch.cuda.synchronize()
with timer.env(‘Copy‘):
if cfg.eval_mask_branch:
# Masks are drawn on the GPU so don‘t copy
masks = t[3][:top_k]
classes scores boxes = [x[:top_k].cpu().numpy() for x in t[:3]]
num_dets_to_consider = min(top_k classes.shape[0])
for j in range(num_dets_to_consider):
if scores[j] < score_threshold:
num_dets_to_consider = j
break
# Quick and dirty lambda for selecting the color for a particular index
# Also keeps track of a per-gpu color cache for maximum speed
def get_color(j on_gpu=None):
global color_cache
color_idx = (classes[j] * 5 if class_color else j * 5) % len(COLORS)
if on_gpu is not None and color_idx in color_cache[on_gpu]:
return color_cache[on_gpu][color_idx]
else:
color = COLORS[color_idx]
if not undo_transform:
# The image might come in as RGB or BRG depending
color = (color[2] color[1] color[0])
if on_gpu is not None:
color = torch.Tensor(color).to(on_gpu).float() / 255.
color_cache[on_gpu][color_idx] = color
return color
# First draw the masks on the GPU where we can do it really fast
# Beware: very fast but possibly unintelligible mask-drawing code ahead
# I wish I had access to OpenGL or Vulkan but alas I guess Pytorch tensor operations will have to suffice
# After this mask is of size [num_dets h w 1]
if display_masks and cfg.eval_mask_branch and num_dets_to_consider > 0:
masks = masks[:
- 上一篇:Python多线程子域名扫描自带字典
- 下一篇:基于python的深度信念网络
相关资源
- python人脸识别(opencv)
- 图片智能拼接(opencv)
- 计算机视觉 opencv 数数.ipynb
- python opencv 银行卡识别.ipynb
- python opencv 图片更换背景. ipynb
- 计算机视觉 opencv 答题卡阅卷.ipynb
- 计算机视觉 opencv 检测不合格产品.
- 计算机视觉 opencv 做一个动态时钟.
- 计算机视觉 opencv 哈哈镜
- 计算机视觉 opencv 蒙太奇.ipynb
- 计算机视觉 opencv 超像素分割.ipynb
- 计算机视觉 opencv 医学图片处理.ipy
- python摄像头自动识别工业用反色二维
- 人脸检测和识别(opencv3+python)
- python检测图片是否有人脸
- python语言实现的基于opencv的表针识别
- OpenCV入门教程+OpenCV官方教程中文版
- opencv+Python的教程大全
- opencv手势识别
- Python+OpenCv项目代码
- python 识别物体跟踪
- 通过python使用opencv计算图像的中心
- 用Pythonopencv提取图像中的红色区域
- 段力辉大神翻译原版OpenCV-Python
- OpenCV-Python 中文教程278991
- OpenCV官方教程中文版Python版带完整书
- dlib18.17 编译好的python-dlib库 不需要
- OpenCV Python 手册
- 带图形界面、车牌识别源码python+ope
- 从视频中分离前景目标的Python & Matl
评论
共有 条评论