使用C/C++开发

以Ubuntu为例,打开终端,输入以下命令:

sudo apt-get install libopencv-dev python3-opencv libopencv-contrib-dev
# 若使用RedHat系,则要使用yum的安装命令以替代apt

然后就装好了。可以在

/usr/lib/

下面找到装好的OpenCV库。cmake中使用下面几条语句以使用opencv:

cmake_minimum_required(VERSION 3.16.3)
project(test)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_DIRCTORIES})
add_executable(testmain.cpp)
target_link_libraries(test ${OpenCV_LIBS})

Python

打开终端,输入:

pip install opencv-python opencv-contrib-python -i https://pypi.tuna.tsinghua.edu.cn/simple
# 如果不需要contrib的功能,可以去掉
# -i和后面的网址可以让你从清华镜像源安装,加快速度,输就完事了

安装完毕后就可以使用了,终端输入:

python
import cv2
cv2.__version__ #注意是两个下划线,此行代码会输出opencv的版本

需要注意的是,通过apt/yum等安装的opencv,一般不是最新版本。若需要安装你需要的版本,请参考开发环境配置_HNU跃鹿战队的博客-CSDN博客

GitHub 加速计划 / opencv31 / opencv
238
21
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:4 个月前 )
6950bedb Use Mat::total() in Darknet IO 1 天前
105a7747 doc: update image codec configuration reference (add AVIF, fix JPEG XL) #28393 This PR updates the build configuration documentation to: - Add AVIF to the supported format list (it was missing). - Clarify that some codecs (AVIF, JPEG XL) do not support BUILD_* options because OpenCV does not bundle their source code. - Update the description to include "write" capabilities for these formats. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake 2 天前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐