米尔电子
直播中

jf_99374259

2年用户 71经验值
擅长:处理器/DSP
私信 关注
[技术]

【米尔-全志T113-i开发板试用】发布opencv-mobile米尔t113i专享预编译包

MYC-YT113i核心板及开发板

真正的国产核心板,100%国产物料认证

  • 国产T113-i处理器配备2*Cortex-A7@1.2GHz ,RISC-V
  • 外置DDR3接口、支持视频编解码器、HiFi4 DSP
  • 接口丰富:视频采集接口、显示器接口、USB2.0 接口、CAN 接口、千兆以太网接口
  • 工业级:-40℃~+85℃、尺寸37mm*39mm
  • 邮票孔+LGA,140+50PIN

运行时检查当前设备是否是米尔t113-i

读取 /proc/device-tree/model 文件内容,判断是否为 sun8iw20

根据 https://linux-sunxi.org/Allwinner_SoC_Family 网站资料,sun8iw20 就是 T113 核心代号,因此这个检查方法可能在其他厂商的T113芯片上也能成功

bool is_t113i()
{
    FILE* fp = fopen("/proc/device-tree/model", "rb");
    char buf[1024];
    fgets(buf, 1024, fp);
    fclose(fp);

    return (strncmp(buf, "sun8iw20", 8) == 0);
}

opencv highgui 模块整合t113-i JPG硬件编解码

https://bbs.elecfans.com/jishu_2412192_1_1.html

https://bbs.elecfans.com/jishu_2412208_1_1.html

https://bbs.elecfans.com/jishu_2412253_1_1.html

接前面几篇的技术性探索,使用T113-i的视频编解码硬件加速JPG读写

  1. 动态加载全志编解码库

解码部分

void* libcdc_base = dlopen("/usr/lib/libcdc_base.so", RTLD_GLOBAL | RTLD_LAZY);
void* libvideoengine = dlopen("/usr/lib/libvideoengine.so", RTLD_LOCAL | RTLD_NOW);
void* libvdecoder = dlopen("/usr/lib/libvdecoder.so", RTLD_LOCAL | RTLD_NOW);

编码部分

void* libvencoder = dlopen("/usr/lib/libvencoder.so", RTLD_LOCAL | RTLD_NOW);

通过 dlsym 获得库函数的入口

CreateVideoDecoder = (PFN_CreateVideoDecoder)dlsym(libvdecoder, "CreateVideoDecoder");
// 省略 ...

VideoEncCreate = (PFN_VideoEncCreate)dlsym(libvencoder, "VideoEncCreate");
// 省略 ...
  1. 图片属性过滤

硬件编解码对JPG图片有限制

  • 只支持baseline,不支持progressive
  • 只支持2倍数的宽高
  • 不支持过大和过小分辨率
  • 解码不支持grayscale颜色空间的JPG

在初始化解码/编码时候,判断相关属性,如果不满足硬件编解码要求,则返回错误,opencv highgui自动退回软件编解码

// progressive not supported
if (progressive)
    return -1;

// grayscale not supported
if (sampling_factor == 4)
    return -1;

if (width % 2 != 0 || height % 2 != 0)
    return -1;

if (width < 8 && height < 8)
    return -1;
  1. kannarotate 图片旋转加速

考虑 EXIF 的旋转信息,需要对JPG解码出的 RGB 旋转得到最终的画面

kannarotate 是 ncnn 项目中针对 ARM 平台优化的图像旋转函数家族,支持1/2/3/4通道

我们把这些代码抠出来,放到 opencv highgui 模块里使用

图片.png

在 Github Action 上直接编译米尔t113-i的opencv-mobile库

opencv-mobile的release.yml使用Github Action服务器,每次tag后触发,自动下载最新代码和补丁,并编译打包,发布成release

release.yml 有一个章节针对开发板,在devboard matrix中照着其他开发板添加 myir-t113i 步骤整合进去

- name: myir-t113i
  single-core: false
  cmake-toolchain: arm-linux-gnueabi.toolchain.cmake
  setup-toolchain-cmd: |
    git clone --depth 1 https://github.com/MYIR-ALLWINNER/toolchain.git
  setup-env-cmd: |
    export PATH=$PATH:$GITHUB_WORKSPACE/toolchain/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi/bin

添加README
图片.png

测试米尔t113-i专享版opencv-mobile

直接下载米尔t113-i专享预编译包,解压

project(testjpg)
cmake_minimum_required(VERSION 3.5)

set(CMAKE_BUILD_TYPE release)

# opencv4 requires c++11
set(CMAKE_CXX_STANDARD 11)

set(OpenCV_DIR /home/nihui/dev/opencv-mobile/opencv-mobile-4.9.0-myir-t113i/lib/cmake/opencv4)
find_package(OpenCV REQUIRED)

add_executable(testjpg testjpg.cpp)
target_link_libraries(testjpg ${OpenCV_LIBS})

编写一段简单的 opencv 读写图片代码,统计耗时

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

double get_current_time()
{
    struct timeval tv;
    gettimeofday(&tv, NULL);

    return tv.tv_sec * 1000.0 + tv.tv_usec / 1000.0;
}

int main(int argc, char** argv)
{
    const char* imagepath = argc == 2 ? argv[1] : "in.jpg";

    for (int i = 0; i < 5; i++)
    {
        double t0 = get_current_time();

        cv::Mat bgr = cv::imread(imagepath, 1);
        cv::imwrite("out0.jpg", bgr);

        double t1 = get_current_time();
        fprintf(stderr, "%.2f\n", t1-t0);
    }

    return 0;
}

配置工具链,cmake编译,上传开发板一条龙脚本

export PATH=$PATH:/home/nihui/osd/MYIR-ALLWINNER-toolchain/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi/bin

cmake -DCMAKE_TOOLCHAIN_FILE=../../toolchains/arm-linux-gnueabi.toolchain.cmake -DCMAKE_BUILD_TYPE=Release ..
make

arm-linux-gnueabi-strip testjpg

adb push testjpg /root/

米尔t113-i专享版opencv-mobile

sh-4.4# LD_LIBRARY_PATH=. ./testjpg 1920x1080.jpg
INFO   : cedarc <CedarPluginVDInit:84>: register mjpeg decoder success!
this device is not whitelisted for jpeg decoder cvi
this device is not whitelisted for jpeg decoder cvi
this device is not whitelisted for jpeg decoder cvi
this device is not whitelisted for jpeg encoder rkmpp
INFO   : cedarc <log_set_level:43>: Set log level to 5 from /vendor/etc/cedarc.conf
ERROR  : cedarc <DebugCheckConfig:316>: now cedarc log level:5
ERROR  : cedarc <VideoEncCreate:241>: now cedarc log level:5
167.95
ERROR  : cedarc <DebugCheckConfig:316>: now cedarc log level:5
ERROR  : cedarc <VideoEncCreate:241>: now cedarc log level:5
151.90
ERROR  : cedarc <DebugCheckConfig:316>: now cedarc log level:5
ERROR  : cedarc <VideoEncCreate:241>: now cedarc log level:5
144.78
ERROR  : cedarc <DebugCheckConfig:316>: now cedarc log level:5
ERROR  : cedarc <VideoEncCreate:241>: now cedarc log level:5
163.58
ERROR  : cedarc <DebugCheckConfig:316>: now cedarc log level:5
ERROR  : cedarc <VideoEncCreate:241>: now cedarc log level:5
149.63

普通版opencv-mobile

sh-4.4# LD_LIBRARY_PATH=. ./testjpg 1920x1080.jpg
this device is not whitelisted for jpeg decoder aw cedarc
this device is not whitelisted for jpeg decoder aw cedarc
this device is not whitelisted for jpeg decoder cvi
this device is not whitelisted for jpeg decoder cvi
this device is not whitelisted for jpeg decoder cvi
this device is not whitelisted for jpeg encoder aw cedarc
this device is not whitelisted for jpeg encoder rkmpp
1006.43
1000.41
977.98
967.70
980.38

米尔t113-i专享版opencv-mobile性能提升巨大!

图片.png

更多回帖

发帖
×
20
完善资料,
赚取积分