视频分割、分类、行为标注工具

视频Object、Region、Skeleton标注工具

原文git地址:https://github.com/anucvml/vidat

本文代码:链接:https://pan.baidu.com/s/1i3Z2ZCR6mrSZraW4ydRE3w
提取码:q3r5

此工具为浏览器内视频注释工具。

该项目的目的是为计算机视觉和机器学习应用开发一个高质量的视频注释工具,具有以下需求:

  1. 非专家使用简单高效。
  2. 支持多种注释类型,包括时间段、对象边界框、语义和实例区域、轨迹和人体姿势(骨架)。
  3. 在浏览器中运行,无需外部库或需要服务器端处理。但很容易插入后端以进行繁重的“在环”处理(例如,来自边界框的片段或来自部分标签的帧完成)。
  4. 兼容所有(大多数)现代浏览器和操作系统,包括平板电脑。
  5. 安全的。数据不需要离开本地机器(因为没有服务器端处理)。
  6. 开源。

Screenshots

Object

在这里插入图片描述

Region

在这里插入图片描述

Skeleton

在这里插入图片描述

Skeleton Type

在这里插入图片描述

Action

在这里插入图片描述

Usage

您需要先部署Vidat,然后使用URL 参数将视频加载到 Vidat

1、首先要部署nginx,官网下载对用版本的nginx: http://nginx.org/en/download.html

2、启动nginx,可以双击nginx.exe或者使用cmd进入该路径下使用命令start nginx启动

3、验证nginx是否配置好,打开浏览器输入http://localhost:80即可查看nginx欢迎界面

(注释:如果80端口被占用,服务启动失败,修改配置文件nginx.conf)

 server {
        listen       8088; # 更改对应的端口
        server_name  localhost;  # 服务的名字

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

4、nginx停止服务,进入nginx安装路径下执行nginx -s stop 命令

5、部署Vidat,将对应文件夹放入到html文件夹下,启动nginx即可(同上启动nginx一样),注意将之前测试的nginx停止。

6、访问http://localhost:8088/vidat-v2.0.0/index.html地址即可,地址进行拼接http://localhost:8088/ + vidat-v2.0.0/index.html(后面是文件夹的路径)
7、检查是否启动成功。
在这里插入图片描述


数据格式(data)

数据要求:使用视频数据,本软件不支持cv2图片转视频格式,解码使用的是java解码,文件提供了java图像转视 频代码。

package cn.morethink.nettyexample.util;
import org.bytedeco.ffmpeg.global.avcodec;
import org.bytedeco.ffmpeg.global.avutil;
import org.bytedeco.javacv.FFmpegFrameRecorder;
import org.bytedeco.javacv.FrameRecorder;
import org.bytedeco.javacv.Java2DFrameConverter;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class Img2mp4 {
    
    


    public static void main(String[] args) throws Exception {
    
    

        //合成的MP4 存放的地址路径 这里的路径并不会自动创建,需要手动提前创建好,否则会报错
        String mp4SavePath = "E:\\vidat-latest\\video\\000006.mp4";
        //图片存放的地址路径
        String img = "E:\\vidat-latest\\picture";
        int width = 2400;
        int height = 1800;
        //读取所有图片
        File file = new File(img);
        File[] files = file.listFiles();
        Map<Integer, File> imgMap = new HashMap<Integer, File>();
        int num = 0;
        for (File imgFile : files) {
    
    
            imgMap.put(num, imgFile);
            num++;
        }
        createMp4(mp4SavePath, imgMap, width, height);
    }

    private static void createMp4(String mp4SavePath, Map<Integer, File> imgMap, int width, int height) throws FrameRecorder.Exception {
    
    
        //视频宽高最好是按照常见的视频的宽高  16:9  或者 9:16
        FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(mp4SavePath, width, height);
        //设置视频编码层模式     import org.bytedeco.ffmpeg.global.avcodec;可能需要手动复制添加
        recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
        //设置视频为10帧每秒
        recorder.setFrameRate(10);
        //设置视频图像数据格式    import org.bytedeco.ffmpeg.global.avutil;可能需要手动复制添加
        recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);

        recorder.setFormat("mp4");
        try {
    
    
            recorder.start();
            Java2DFrameConverter converter = new Java2DFrameConverter();
            //根据图片数量/10 生成视频的秒数.
            for (int i = 0; i < 7 ; i++) {
    
    
                BufferedImage read = ImageIO.read(imgMap.get(i));
                // 调整每秒插入视频的图片数, 数值越小 视频越流畅 性能消耗越大
                for (int j = 0; j < 10; j++) {
    
    
                    recorder.record(converter.getFrame(read));
                }

            }
        } catch (Exception e) {
    
    
            e.printStackTrace();
        } finally {
    
    
            //最后一定要结束并释放资源
            recorder.stop();
            recorder.release();
        }
    }

}

数据结果:本视频标注结果是vidat-latest\public\annotation\example.json,同样提供了将格式转为labelme格式

import argparse
import json
import cv2
import numpy as np
import os

"""
parser = argparse.ArgumentParser()
parser.add_argument("square", help="display a square of a given number", type=int)
args = parser.parse_args()
print(args.square** 2)
"""

load_f = open(r"E:\vidat-latest\public\annotation\ning71x-16-0672_10_000000.json", encoding="utf-8")
anno = json.load(load_f)
# print(anno)
# print(anno.keys())
total_json = {}
version = anno["version"]
print(version)
annotation = anno["annotation"]
config = anno["config"]
print(annotation.keys())
video = annotation["video"]
keyframeList = annotation["keyframeList"]
regionAnnotationListMap = annotation["regionAnnotationListMap"]
# print(regionAnnotationListMap["0"])
shapes = []
if regionAnnotationListMap["0"]:
    for i in range(len(regionAnnotationListMap["0"])):
        single_particle = {}
        points = regionAnnotationListMap["0"][i]["pointList"]
        print(len(points))
        point_lists = []
        label = regionAnnotationListMap["0"][i]["labelId"]
        # print(label)
        shape_type = "polygon"
        flags = []
        for i in range(len(points)):
            point_x = points[i]["x"]
            point_y = points[i]["y"]
            point_lists.append([point_x, point_y])
        single_particle.update({"label": label,
                                "points": point_lists,
                                "group_id": None,
                                "shape_type": shape_type,
                                "flags": []})
        
        # print(single_particle)
        shapes.append(single_particle)
# print(shapes)
imagePath = video["src"]
imageData = None
imgHeight = video["height"]
imgWidth = video["width"]

total_json.update({"version": version,
                   "flags": [],
                   "shapes": shapes,
                   "imagePath": imagePath,
                   "imageData": imageData,
                   "imgHeight": imgHeight,
                   "imgWidth": imgWidth})

with open(r"E:\vidat-latest\public\annotation\labelme_ning71x-16-0672_10_000000.json", "w", encoding="utf-8") as f:
    json.dump(total_json, f, ensure_ascii=False)

        
            

数据保存:当前数据标注结束以后,对标注结果下载,保存名字自定义,保存名字更改为视频呢名字,方便使用。


视频教程:

链接:https://pan.baidu.com/s/1y_J3QtkmrEVYtIOgV-Eueg
提取码:rbys

参考资料

https://github.com/anucvml/vidat
@misc{zhang2020vidat,
author = {Jiahao Zhang and Stephen Gould and Itzik Ben-Shabat},
title = {Vidat—{ANU} {CVML} Video Annotation Tool},
howpublished = {\url{https://github.com/anucvml/vidat}},
year = {2020}
}
感谢vidat团队开源。

猜你喜欢

转载自blog.csdn.net/TF666666/article/details/127546691
今日推荐