栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++ 使用ffmpeg解码video模块,包括CPU解码和GPU解码,使用opencv读写视频和叠加roi,读取并反序列化检测点txt文件并使用opencv叠加轨迹。

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C++ 使用ffmpeg解码video模块,包括CPU解码和GPU解码,使用opencv读写视频和叠加roi,读取并反序列化检测点txt文件并使用opencv叠加轨迹。

仓库代码地址:https://gitee.com/liudegui/video_decode_detect_bbox_example 解码、检测和视频叠加 解码

使用ffmpeg解码video模块,包括CPU解码和GPU解码

检测

使用opencv官方示例中的人脸检测模型检测(haarcascade),将检测点结果序列化成字符串,写入txt文件中。

视频和roi叠加

使用opencv读写视频和叠加roi,读取并反序列化检测点txt文件并使用opencv叠加。

目录结构
  • decode_video:视频解码库;

  • mock_detect:使用opencv视频检测库;

  • detect_video:集成解码、检测程序;

  • video_bbox_drawer:视频叠加roi程序。


使用C++11编写的序列化方法,而不是json等,C++程序间使用
#pragma once
// ref: https://github.com/chanfun-ren/ChanfunRpc
// ref: https://my.oschina.net/u/3312209/blog/4313738

#include 
#include 
#include 
#include 
#include 
#include 
#include 


// ref:https://stackoverflow.com/questions/25123458/is-trivially-copyable-is-not-a-member-of-std
#if (__GNUG__ && __GNUC__ < 5) || __cplusplus < 201402L // for C++11
// ref https://zhuanlan.zhihu.com/p/27186999
namespace std14 {
    template 
    class integer_sequence {
    public:
        using value_type = T;
        static_assert(std::is_integral::value,
            "not integral type");
        static constexpr std::size_t size() noexcept {
            return sizeof...(Ints);
        }
    };
    template 
    using index_sequence = integer_sequence;

    namespace Detail_ {

        template 
        struct IntSeqImpl {
            using TValue = T;
            static_assert(std::is_integral::value,
                "not integral type");
            static_assert(Begin >= 0 && Begin < End,
                "unexpected argument (Begin<0 || Begin<=End)");

            template 
            struct IntSeqCombiner;

            template 
            struct IntSeqCombiner,
                integer_sequence> {
                using TResult = integer_sequence;
            };

            using TResult = typename IntSeqCombiner
                ::TResult,
                typename IntSeqImpl::TResult>
                ::TResult;
        };

        template 
        struct IntSeqImpl {
            using TValue = T;
            static_assert(std::is_integral::value,
                "not integral type");
            static_assert(Begin >= 0, "unexpected argument (Begin<0)");
            using TResult = integer_sequence;
        };

        template 
        struct IntSeqImpl {
            using TValue = T;
            static_assert(std::is_integral::value,
                "not integral type");
            static_assert(Begin >= 0, "unexpected argument (Begin<0)");
            using TResult = integer_sequence;
        };
    }

    template 
    using make_integer_sequence =
        typename Detail_::IntSeqImpl::TResult;

    template 
    using make_index_sequence = make_integer_sequence;

    template
    using index_sequence_for = make_index_sequence;
}
///
    #define IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
    #define MAKE_INDEX_SEQUENCE std14::make_index_sequence
    #define INDEX_SEQUENCE std14::index_sequence
#else
    #define IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable::value
    #define MAKE_INDEX_SEQUENCE std::make_index_sequence
    #define INDEX_SEQUENCE std::index_sequence
#endif

// 可平凡复制 
template ::type N = 0>
void serialize(std::ostream & os, const T & val)  { 
    os.write((const char *)&val,sizeof(T)); 
} 

// pair
template 
void serialize(std::ostream & os, const std::pair & val) {
    serialize(os, val.first);
    serialize(os, val.second);
}

// std::string
void serialize(std::ostream & os, const std::string &val) {
    size_t size = val.size();
    os.write((const char *)&size, sizeof(size));
    os.write((const char *)val.data(), size * sizeof(typename std::string::value_type));
}

//容器 
template ::value_type, typename T::value_type>::value
    , int>::type N = 0> 
void serialize(std::ostream & os, const T & val) {
    size_t size = val.size();
    os.write((const char *)&size, sizeof(size_t));
    for (auto & v : val) {
        serialize(os, v); 
    } 
}


// tuple
template
int _Serialize(std::ostream & os, T& val) {
    serialize(os, val);
    return 0;
}

template
void _Serialize(std::ostream & os, Tuple& tup, INDEX_SEQUENCE) {
    std::initializer_list{_Serialize(os, std::get(tup))...};
}


template 
void serialize(std::ostream & os, const std::tuple& val) {
    _Serialize(os, val, MAKE_INDEX_SEQUENCE{});
}




// 可平凡复制 
template ::type N = 0>
void deserialize(std::istream & is, T & val) { 
     is.read((char *)&val, sizeof(T)); 
}

// std::string
void deserialize(std::istream & is, std::string &val) {
    size_t size = 0; 
    is.read((char*)&size, sizeof(size_t));
    val.resize(size);
    auto count = size * sizeof(typename std::string::value_type);
    is.read((char *)val.data(), count);
}


//pair
template 
struct ImpDeserialize {
    template
    static void get(std::istream & is, T & val) {
        size_t size = 0;
        is.read((char *)&size, sizeof(size_t));
        for (size_t i = 0; i < size; i++)
        {
            V v;
            deserialize(is, v);
            val.insert(val.end(), v);
        }
    }
};

template 
struct ImpDeserialize> {
    template
    static void get(std::istream & is, T & val) {
        size_t size = 0;
        is.read((char *)&size, sizeof(size_t));
        for (size_t i = 0; i < size; i++) {
            K k;
            V v;
            deserialize(is, k);
            deserialize(is, v);
            val.emplace(k, v);
        }
        
    }
};

// 容器 
template ::value_type, typename T::value_type>::value
    , int>::type N = 0>
void deserialize(std::istream & is, T & val) {
    ImpDeserialize::get(is, val);
}


//tuple
template
int _Deserialize(std::istream & is, T& val) {
    deserialize(is, val);
    return 0;
}

template
void _Deserialize(std::istream & is, Tuple& tup, INDEX_SEQUENCE) {
    std::initializer_list{_Deserialize(is, std::get(tup))...};
}


template 
void deserialize(std::istream & is, std::tuple& val) {
    _Deserialize(is, val, MAKE_INDEX_SEQUENCE{});
}

转载请注明:文章转载自 www.mshxw.com
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号