欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

如何判断用于嵌入式平台的 OpenCV 使用了硬件编解码器?

最编程 2024-05-04 16:45:29
...

01 涉及OpenCV编解码库的一个命令行工具

python3 -c 'import cv2; print(cv2.getBuildInformation())'

它可以打印输出详细的OpenCV编译参数和当前的媒体库相关参数,我的rk3588打印的信息是这样的:

cat@lubancat:~$ python3 -c 'import cv2; print(cv2.getBuildInformation())'

General configuration for OpenCV 4.5.1 =====================================
  Version control:               unknown


  Extra modules:
    Location (extra):            /build/opencv-fF3y1A/opencv-4.5.1+dfsg/contrib/modules
    Version control (extra):     unknown

  Platform:
    Timestamp:                   2021-06-16T12:09:47Z
    Host:                        Linux 4.19.0-17-arm64 aarch64
    CMake:                       3.18.4
    CMake generator:             Ninja
    CMake build tool:            /usr/bin/ninja
    Configuration:               Release

  CPU/HW features:
    Baseline:                    NEON FP16

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /usr/bin/c++  (ver 10.2.1)
    C++ flags (Release):         -g -O2 -ffile-prefix-map=/build/opencv-fF3y1A/opencv-4.5.1+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g -O2 -ffile-prefix-map=/build/opencv-fF3y1A/opencv-4.5.1+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security  -DNDEBUG
    C++ flags (Debug):           -g -O2 -ffile-prefix-map=/build/opencv-fF3y1A/opencv-4.5.1+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g  -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -g -O2 -ffile-prefix-map=/build/opencv-fF3y1A/opencv-4.5.1+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g -O2 -ffile-prefix-map=/build/opencv-fF3y1A/opencv-4.5.1+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security  -DNDEBUG
    C flags (Debug):             -g -O2 -ffile-prefix-map=/build/opencv-fF3y1A/opencv-4.5.1+dfsg=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2   -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g  -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,-z,relro -Wl,-z,now  -Wl,--gc-sections -Wl,--as-needed -Wl,-z,relro -Wl,-z,now 
    Linker flags (Debug):        -Wl,-z,relro -Wl,-z,now  -Wl,--gc-sections -Wl,--as-needed  
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          dl m pthread rt
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy hdf hfs highgui img_hash imgcodecs imgproc intensity_transform java line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab viz ximgproc xobjdetect xphoto
    Disabled:                    world
    Disabled by dependency:      sfm
    Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv gapi julia matlab ovis python2 ts
    Applications:                apps
    Documentation:               doxygen python javadoc
    Non-free algorithms:         NO

  GUI: 
    GTK+:                        YES (ver 3.24.24)
      GThread :                  YES (ver 2.66.8)
      GtkGlExt:                  NO
    OpenGL support:              NO
    VTK support:                 YES (ver 9.0.1)

  Media I/O: 
    ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.2.11)
    JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 62)
    WEBP:                        /usr/lib/aarch64-linux-gnu/libwebp.so (ver encoder: 0x020e)
    PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.37)
    TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.2.0)
    JPEG 2000:                   OpenJPEG (ver 2.4.0)
    OpenEXR:                     /usr/lib/aarch64-linux-gnu/libImath-2_5.so /usr/lib/aarch64-linux-gnu/libIlmImf-2_5.so /usr/lib/aarch64-linux-gnu/libIex-2_5.so /usr/lib/aarch64-linux-gnu/libHalf-2_5.so /usr/lib/aarch64-linux-gnu/libIlmThread-2_5.so (ver 2_5)
    GDAL:                        YES (/usr/lib/libgdal.so)
    GDCM:                        YES (3.0.8)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      YES (2.2.6)
    FFMPEG:                      YES
      avcodec:                   YES (58.91.100)
      avformat:                  YES (58.45.100)
      avutil:                    YES (56.51.100)
      swscale:                   YES (5.7.100)
      avresample:                NO
    GStreamer:                   YES (1.18.4)
    PvAPI:                       NO
    v4l/v4l2:                    YES (linux/videodev2.h)
    gPhoto2:                     YES

  Parallel framework:            TBB (ver 2020.3 interface 11103)

  Trace:                         YES (built-in)

  Other third-party libraries:
    Lapack:                      NO
    Eigen:                       YES (ver 3.3.9)
    Custom HAL:                  NO
    Protobuf:                    /usr/lib/aarch64-linux-gnu/libprotobuf.so (3.12.4)

  OpenCL:                        YES (no extra features)
    Include path:                /usr/include/CL
    Link libraries:              Dynamic load

  Python 3:
    Interpreter:                 /usr/bin/python3 (ver 3.9.2)
    Libraries:                   /usr/lib/aarch64-linux-gnu/libpython3.9.so (ver 3.9.2)
    numpy:                       /usr/lib/python3/dist-packages/numpy/core/include (ver 1.19.5)
    install path:                lib/python3.9/dist-packages

  Python (for build):            /usr/bin/python3

  Java:                          
    ant:                         /usr/bin/ant (ver 1.10.9)
    JNI:                         /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include
    Java wrappers:               YES
    Java tests:                  NO

  Install to:                    /usr
-----------------------------------------------------------------

 

与音视频编解码相关的几个重要参数已经列出。这台设备的.264硬编解码器已经在生效状态。

附录A chatGPT关于硬编解码的对答 

如何检查cv2 当前使用的.264编码工具是什么?
要检查OpenCV当前使用的H.264编码器工具,可以使用以下代码:


import cv2

# 获取可用编码器列表
encoder_list = cv2.getBuildInformation().split('\n')
encoder_name = ""

# 查找H.264编码器
for line in encoder_list:
    if 'H.264' in line:
        encoder_name = line.split()[0]
        break

# 打印当前使用的H.264编码器
print("当前使用的H.264编码器:", encoder_name)
运行此代码将打印出当前使用的H.264编码器工具的名称。请注意,OpenCV支持多个H.264编码器,因此可能会打印出多个名称。


video/x-h264  如果实际打包的是这个编码器,我是不是需要把H.264换成x-h264?
不需要将H.264替换为x-h264。实际上,video/x-h264是一种MIME类型(Multipurpose Internet Mail Extensions),用于标识H.264编码的视频文件格式。因此,它们是同一种编码器,只是用不同的名称表示而已。您可以继续使用H.264编码器来处理video/x-h264格式的视频文件。


列表为空,是不是代表没有硬编码器?
不一定。如果获取的可用编码器列表为空,可能是因为OpenCV没有找到可用的编码器或未正确安装编码器。您可以尝试检查编码器是否正确安装或尝试重新安装OpenCV以确保编码器可用。另外,有些编码器可能需要特定的设置或依赖项才能被OpenCV正确识别和使用。您可以查看OpenCV的文档或社区讨论以获得更多帮助和指导。

python3 -c 'import cv2; print(cv2.getBuildInformation())'
这个能看出编解码库相关的信息吗?
这段代码会输出OpenCV编译时的详细信息,包括支持的编解码库以及其他信息。通过查看输出信息,可以了解OpenCV编译时所包含的编解码库及其版本等相关信息。


怎么看.264的编解码库?
要查看是否包含H.264的编解码库,你可以在输出信息中搜索关键词"h264"或者"AVC"来查找相关信息。通常会有类似"FFMPEG: YES (codec h264,avc)"这样的记录来表明是否支持H.264编解码。如果没有找到相关记录,说明当前编译的OpenCV版本可能不包含H.264的编解码库。


avcodec:                   YES (58.91.100)
看起来你的OpenCV编译包含了AVCodec,并支持版本为58.91.100。这意味着你的OpenCV应该支持H.264的编解码。


这是硬编码还是软编码?
这里的AVCodec是指FFmpeg中的音视频编解码器库,通常会支持硬件加速编解码。具体支持硬件编解码还是软件编解码取决于系统和编译设置,一般情况下可以通过设置来选择硬件加速或软件编解码。如果有需要可以查看具体的编译选项和环境来确定。


如何判断它是硬件加速?
要判断OpenCV是否使用硬件加速进行H.264编解码,可以查看编译选项中是否有启用硬件加速相关的选项,比如CUDA、OpenCL、VAAPI、QuickSync等。如果这些选项被启用,并且系统中有相应的硬件加速设备,那么就意味着OpenCV可能在进行H.264编解码时会利用硬件加速。另外,通过查看编码器使用率和性能表现也可以初步判断是否使用硬件加速。如果需要更详细的信息,可以通过相关工具或命令行查看OpenCV的编解码操作是否使用了硬件加速。


arm7的硬件编解码器是什么?
arm7架构上的硬件编解码器可以是一些特定的硬件加速模块或处理器,比如ARM提供的NEON指令集或Mali GPU等。这些硬件可以提供加速H.264编解码的功能,以提升性能和效率。具体支持哪些硬件加速编解码器取决于具体的处理器和硬件设备,可以查看相关的技术文档或资料来了解。


.264相关的那个硬件编解码参数是什么?
H.264相关的硬件编解码参数可以包括一些特定的硬件加速选项,比如支持H.264硬件解码的设备、支持的硬件加速技术(比如CUDA、QuickSync、OpenCL等)、硬件解码器的性能指标等。不同的硬件平台和设备可能有不同的硬件编解码参数,可以根据具体的需求和环境来选择合适的硬件编解码参数。如果需要具体的参数信息,建议参考相关的技术文档或咨询硬件厂商。


在编译cv2是,指定armv7的那个.264相关的编解码参数是什么?
在编译cv2时指定armv7的H.264相关的编解码参数可以包括启用NEON指令集的选项。NEON是ARM架构上的SIMD指令集,可以提供加速处理音视频数据的功能,包括H.264编解码。在编译OpenCV时,可以添加相应的选项来启用NEON指令集的支持,以实现在armv7架构上进行H.264编解码时的硬件加速。具体的编译选项可以参考OpenCV的编译文档或相关的技术资料。

上一篇: springboot 国际化

下一篇: