新版树莓派opencv4.10

安装方式

 

# --- 树莓派直接安装
sudo apt install libopencv-dev python3-opencv

# 4.10版本

# GStreamer:     YES (1.26.0)


# 或者
import cv2
print(cv2.__version__)
print(cv2.getBuildInformation())

  

版本效果

 

4.10.0

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

  Extra modules:
    Location (extra):            <<PKGBUILDDIR>>/contrib/modules
    Version control (extra):     unknown

  Platform:
    Host:                         aarch64
    CMake:                       3.31.6
    CMake generator:             Ninja
    CMake build tool:            /usr/bin/ninja
    Configuration:               Release

  CPU/HW features:
    Baseline:                    NEON FP16
    Dispatched code generation:  NEON_DOTPROD NEON_FP16 NEON_BF16
      requested:                 NEON_FP16 NEON_BF16 NEON_DOTPROD
      NEON_DOTPROD (1 files):    + NEON_DOTPROD
      NEON_FP16 (2 files):       + NEON_FP16
      NEON_BF16 (0 files):       + NEON_BF16

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /usr/bin/c++  (ver 14.2.0)
    C++ flags (Release):         -g -O2 -ffile-prefix-map=<<PKGBUILDDIR>>=. -fstack-pr                  otector-strong -fstack-clash-protection -Wformat -Werror=format-security -mbranch-prot                  ection=standard -Wdate-time -D_FORTIFY_SOURCE=2   -fsigned-char -W -Wall -Wreturn-type                   -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-de                  clarations -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 -f                  file-prefix-map=<<PKGBUILDDIR>>=. -fstack-protector-strong -fstack-clash-protection -W                  format -Werror=format-security -mbranch-protection=standard  -DNDEBUG
    C++ flags (Debug):           -g -O2 -ffile-prefix-map=<<PKGBUILDDIR>>=. -fstack-pr                  otector-strong -fstack-clash-protection -Wformat -Werror=format-security -mbranch-prot                  ection=standard -Wdate-time -D_FORTIFY_SOURCE=2   -fsigned-char -W -Wall -Wreturn-type                   -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-de                  clarations -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  -DDEB                  UG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -g -O2 -Werror=implicit-function-declaration -ffile-p                  refix-map=<<PKGBUILDDIR>>=. -fstack-protector-strong -fstack-clash-protection -Wformat                   -Werror=format-security -mbranch-protection=standard -Wdate-time -D_FORTIFY_SOURCE=2                     -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-se                  curity -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-                  self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -W                  no-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-                  sections -fdata-sections    -fvisibility=hidden -g -O2 -Werror=implicit-function-decla                  ration -ffile-prefix-map=<<PKGBUILDDIR>>=. -fstack-protector-strong -fstack-clash-prot                  ection -Wformat -Werror=format-security -mbranch-protection=standard  -DNDEBUG
    C flags (Debug):             -g -O2 -Werror=implicit-function-declaration -ffile-p                  refix-map=<<PKGBUILDDIR>>=. -fstack-protector-strong -fstack-clash-protection -Wformat                   -Werror=format-security -mbranch-protection=standard -Wdate-time -D_FORTIFY_SOURCE=2                     -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-se                  curity -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-                  self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -W                  no-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-n                  eeded -Wl,--no-undefined -Wl,-z,relro -Wl,-z,now
    Linker flags (Debug):        -Wl,-z,relro -Wl,-z,now  -Wl,--gc-sections -Wl,--as-n                  eeded -Wl,--no-undefined
    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                   cvv datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy                   hdf hfs highgui img_hash imgcodecs imgproc intensity_transform java line_descriptor mc                  c ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency sha                  pe signal stereo stitching structured_light superres surface_matching text tracking vi                  deo videoio videostab viz wechat_qrcode ximgproc xobjdetect xphoto
    Disabled:                    python3 world
    Disabled by dependency:      sfm
    Unavailable:                 cannops cudaarithm cudabgsegm cudacodec cudafeatures2                  d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping                   cudev gapi julia matlab ovis python2 ts
    Applications:                apps
    Documentation:               doxygen python javadoc
    Non-free algorithms:         NO

  GUI:                           QT5
    QT:                          YES (ver 5.15.15 )
      QT OpenGL support:         YES (Qt5::OpenGL 5.15.15)
    OpenGL support:              YES (/usr/lib/aarch64-linux-gnu/libOpenGL.so /usr/lib                  /aarch64-linux-gnu/libGLX.so /usr/lib/aarch64-linux-gnu/libGLU.so)
    VTK support:                 YES (ver 9.3.0)

  Media I/O:
    ZLib:                        /usr/lib/aarch64-linux-gnu/libz.so (ver 1.3.1)
    JPEG:                        /usr/lib/aarch64-linux-gnu/libjpeg.so (ver 62)
    WEBP:                        /usr/lib/aarch64-linux-gnu/libwebp.so (ver encoder: 0                  x0210)
    PNG:                         /usr/lib/aarch64-linux-gnu/libpng.so (ver 1.6.47)
    TIFF:                        /usr/lib/aarch64-linux-gnu/libtiff.so (ver 42 / 4.5.1                  )
    JPEG 2000:                   OpenJPEG (ver 2.5.3)
    OpenEXR:                     OpenEXR::OpenEXR (ver 3.1.11)
    GDAL:                        YES (/usr/lib/aarch64-linux-gnu/libgdal.so)
    GDCM:                        YES (3.0.24)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      YES (2.2.6)
    FFMPEG:                      YES
      avcodec:                   YES (61.19.101)
      avformat:                  YES (61.7.100)
      avutil:                    YES (59.39.100)
      swscale:                   YES (8.3.100)
      avresample:                NO
    GStreamer:                   YES (1.26.0)
    PvAPI:                       NO
    v4l/v4l2:                    YES (linux/videodev2.h)
    gPhoto2:                     YES

  Parallel framework:            TBB (ver 2022.0 interface 12140)

  Trace:                         YES (built-in)

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

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

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

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

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

 

编译安装方法

 

sudo apt install libopenblas-dev
sudo apt install libtbbmalloc2
sudo apt install libdc1394-dev

# 安装必要的依赖
sudo apt update
sudo apt install build-essential cmake git pkg-config libgtk-3-dev libavcodec-dev libavformat-dev libswscale-dev libv4l-dev libxvidcore-dev libx264-dev libjpeg-dev libpng-dev libtiff-dev gfortran openexr libopenblas-dev python3-dev python3-numpy libtbbmalloc2 libdc1394-dev

# 下载OpenCV和OpenCV_contrib的源码:
wget -O opencv-4.6.0.zip https://github.com/opencv/opencv/archive/refs/tags/4.6.0.zip
wget -O opencv_contrib-4.6.0.zip https://github.com/opencv/opencv_contrib/archive/refs/tags/4.6.0.zip
unzip opencv-4.6.0.zip
unzip opencv_contrib-4.6.0.zip

# opencv 可能需要 1.X 版本的 numpy ,树莓派 无法pip安装, 
# apt安装也安装不到 1.x,暂时不安装
# sudo apt install python3-numpy



  
  
# 进入OpenCV目录并配置CMake:
cd opencv-4.6.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_C_EXAMPLES=ON \
      -D INSTALL_PYTHON_EXAMPLES=ON \
      -D OPENCV_GENERATE_PKGCONFIG=ON \
      -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.6.0/modules \
      -D BUILD_EXAMPLES=ON ..
      
# 编译安装
make -j$(nproc)
sudo make install
sudo ldconfig

# 将OpenCV的Python绑定路径添加到 PYTHONPATH:
echo "export PYTHONPATH=/usr/local/lib/python3.13/site-packages:$PYTHONPATH" >> ~/.bashrc
source ~/.bashrc

# 验证OpenCV是否安装成功:
import cv2
print(cv2.__version__)

  

 

posted @ 2025-11-10 17:17  aiplus  阅读(16)  评论(0)    收藏  举报
悬浮按钮示例