• 树莓派4B上安装opencv 4.5


    开启树莓派的摄像头
    sudo raspi-config
    1

    sudo sed -i 's#://raspbian.raspberrypi.org#s://mirrors.ustc.edu.cn/raspbian#g' /etc/apt/sources.list 
    sudo sed -i 's#://archive.raspberrypi.org/debian#s://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian#g' /etc/apt/sources.list.d/raspi.list


    更新软件列表
    sudo apt-get update
    sudo apt-get upgrade
    1
    2
    安装opencv工具包
    sudo apt-get install build-essential cmake git pkg-config
    1
    安装opencv图像包
    sudo apt-get install libjpeg8-dev
    sudo apt-get install libtiff5-dev
    sudo apt-get install libjasper-dev
    sudo apt-get install libpng12-dev
    1
    2
    3
    4
    安装视频I/O包
    sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
    1
    安装gtk和优化包
    sudo apt-get install libgtk2.0-dev
    sudo apt-get install libatlas-base-dev gfortran
    1
    2
    下载opencv源码
    git clone https://github.com/opencv/opencv.git
    1
    使用以上网址下载慢的话,这里提供另一个方法,相对来说可以快一些。
    方法就是将GitHub上的opencv同步到码云gitee上,然后通过gitee上下载。
    首先注册GitHub和gitee账号,然后上GitHub将opencv项目fork到自己的GitHub中,在进入gitee的账号中,新建项目,选择从GitHub中导入项目,将opencv导入后,使用gitee的地址下载即可。
    8. 配置编译opencv

    // 进入到opencv的目录
    cd opencv
    // 创建build文件夹
    mkdir build
    // 进入build目录下
    cd build
    // cmake读入所有源文件之后,自动生成makefile,不要忘了最后的两个..
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local ..
    // 编译
    sudo make
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    这里我遇到了个问题,就是按照上面的cmake配置后,make时报错atomic错误,无法进行编译了,在网上找了很多方法,都是Android下的解决方法,最终终于探出方法,将生产makefile的配置步骤改为如下即可成功

    LDFLAGS="-latomic" cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_opencv_python3=on -DBUILD_opencv_python2=off -DOPENCV_EXTRA_MODULES=../modules -DPYTHON3_LIBRARIES=/usr/lib/arm-linux-gnueabihf/libpython3.7m.so
    1
    安装opencv
    sudo make install
    1
    更新动态库
    sudo ldconfig
    1
    11.测试代码

    # coding: utf-8
    import cv2

    cap = cv2.VideoCapture(0) # 打开摄像头

    while(True):
    ret, frame = cap.read() # 读取摄像头图像
    cv2.imshow("test", frame ) # 显示图片

    if cv2.waitKey(1) & 0xFF == ord('q'):
    break

    cap.release() # 释放摄像头
    cv2.destroyAllWindows() # 关闭所有窗口

    sudo apt install fcitx fcitx-pinyin 

    sudo sed -i 's#://raspbian.raspberrypi.org#s://mirrors.ustc.edu.cn/raspbian#g' /etc/apt/sources.list
    sudo sed -i 's#://archive.raspberrypi.org/debian#s://mirrors.ustc.edu.cn/archive.raspberrypi.org/debian#g' /etc/apt/sources.list.d/raspi.list

    sudo apt update
    sudo apt upgrade

    sudo apt install build-essential cmake git pkg-config

    sudo apt install libjpeg8-dev libtiff5-dev

    sudo apt install libjasper-dev libpng12-dev

    sudo apt install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev

    sudo apt install libgtk2.0-dev
    sudo apt install libatlas-base-dev gfortran

    git clone https://github.com/opencv/opencv.git
    cd opencv
    mkdir build
    cd build
    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
    sudo make(not recommend make -j4)
    err: LDFLAGS="-latomic" cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_opencv_python3=on -DBUILD_opencv_python2=off -DOPENCV_EXTRA_MODULES=../modules -DPYTHON3_LIBRARIES=/usr/lib/arm-linux-gnueabihf/libpython3.7m.so
    sudo make install
    sudo ldconfig



    https://blog.csdn.net/jayhgq/article/details/99682481

    successfully 20211220

    sudo raspi-config

    {sudo apt-get install build-essential cmake git pkg-config

    sudo apt-get install libjpeg8-dev

    sudo apt-get install libhdf5-dev libhdf5-serial-dev libhdf5-hl-100

    sudo apt-get install libtiff5-dev

    sudo apt-get install libjasper-dev

    sudo apt-get install libpng12-dev

    sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev

    sudo apt-get install libgtk2.0-dev

    sudo apt install libatlas-base-dev gfortran}   can not install

    git clone https://github.com/opencv/opencv.git

    cd  opencv

    mkdir build

    cd build

    cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

    sudo make 

    sudo make install

    sudo ldconfig

  • 相关阅读:
    HDU 1495 广度优先搜索
    oj 1792:迷宫 广搜和深搜
    oj 1756:八皇后 搜索
    OJ1700 八皇后问题 基本搜索算法
    PAT A1020
    PAT A1103
    PAT A1046 Shortest Distance
    PAT A1059
    PAT B1013
    二分查找
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/15625871.html
Copyright © 2020-2023  润新知