在Ubuntu上安裝Python后,可通過以下幾種方法安裝OpenCV:
pip3 install opencv-python,可安裝最新版OpenCV。若需特定版本,如4.1.1.26,則使用pip3 install opencv-python==4.1.1.26。也可通過清華鏡像源加速下載,命令為pip3 install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn。sudo apt update,然后安裝python3-opencv,命令為sudo apt install python3-opencv。sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev python3-dev python3-numpy等。再從GitHub克隆OpenCV源代碼,進入源碼目錄創建構建目錄并編譯安裝,最后配置環境變量。