0.导语

离上一个opencv安装保姆级教程发布已经过去了快一年了,这一年来我收到了来自很多C友的鼓励。打算学opencv的各位朋友都会在安装opencv和各种库过程中浪费掉60%的时间和精力;博主在这一年来尝试各种各样的安装方法,全网搜集各种资料总结了一篇非常详细的opencv和常用库的安装教程,若有帮助记得三连,你的三连是我进步的动力。在这里插入图片描述

1. 正文

1.1下载和安装软件

本文我会通过miniconda+jupyter lab的形式带大家安装opencv;
有很多朋友会问为什么不是anaconda+jupyter lab 或者直接pycharm 来安装呢?在这里我回答一下大家的疑问,通过这一年来的学习和实战,我发现anaconda它带了很多不必要的库并且自身很重,像我这样只能买得起轻薄本的学生党连跑demo都跑不了;pycharm也是比较笨重的编译器,配置opencv的过程更让人恶心,一不小心就会出错显然不适合刚学opencv的C友;
在这里插入图片描述
废话少说开始安装:
WINDOWS安装包下载链接
在这里插入图片描述32位电脑安装上面的,64位安装下面的;电脑的位数怎么看?
右击此电脑→点击属性
第一步
第二步
我以64位为举例,目前大多数电脑都是64位操作系统;下面可以参考我的安装步骤去安装
安装第一步
安装第二步
安装第三步
安装第四步
如果大家以上安装全成功那大家已经成功了快一半了;

1.2 了解miniconda常用指令

安装好之后,打开Anaconda Powershell Prompt (miniconda3);
开启miniconda
注意:是Powershell Prompt,不是Prompt;

开启之后是下面这个黑色窗口:
开启窗口
miniconda是通过创建虚拟环境的方式运行python代码的;所以我们得了解一些常用的指令;比如创建一个虚拟环境,怎么删除虚拟环境等;
常用的五个指令
1.创建环境:
conda create --name 环境名称(英文)
2.进入环境:
conda activate 环境名称
3.退出环境:
conda deactivate
4.删除环境:
conda remove --name 环境名称 --all
5.列出所有环境:
conda env list
创建环境:比如我想创建一个名为xiaore的虚拟环境
虚拟环境创建
输入y确认;
下面我们进入这个环境试试;
进入虚拟环境
这样已经算成功地进入了虚拟环境;
接下来就是退出虚拟环境:
退出虚拟环境
接下来我们列出我们的所有环境:
列出所有环境
这里面base是我们的基础环境,xiaore是我们刚刚创建的虚拟环境;
接下来我们试试删除环境这个命令(删除环境之前必须得退回基础环境base里面在进行删除);

1.3 开始安装opencv

上面的几个步骤都是在现在的这个步骤打基础;安装opencv之前我们必须给我们的虚拟环境里现安装python,然后去修改pip和conda的源;安装opencv和 一些常用库;
那我还是举例刚刚那个虚拟环境为举例演示一下;

1.3.1第一步安装python

打开miniconda,进行 conda create --name 环境名称 python=3.8 命令。python版本可以按照自己的需要去更改,建议是3.8的python。
python安装
输入y 确认。
开始安装python相关库
等安装好之后可以进入虚拟环境里测试一下;
python版本测试
可以看出安装的版本是3.8.16;可以输入exit()来退出;

1.3.2第二步pip和conda换源

换源的目的我觉得大家应该都知道,是为了加速下载过程;为了防止有些库因为有些原因下载不了,具体什么原因不用我说懂得都懂。
一,conda换源方法:
参见:conda换源清华源
二,pip换源
第一步: 在C:\Users\Administrator 目录下 创建pip文件夹
第二步:在第一步创建的文件夹下(C:\Users\Administrator\pip)创建pip.ini文件
第三步:记事本编辑保存pip.ini文件内容为以下部分:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn
注意:pip文件夹要建立到用户目录下的。
例如:
pip文件
如果上面那些过程都已经没问题了,恭喜你已经成功了80%了。

1.3.3安装opencv和matplotlib等库

安装库常用的指令:
conda install 库名
pip install 库名
conda list
pip list
注意:进入自己的虚拟环境之后再安装;
安装opencv
最后显示done表示已经安装成功;
我们来安装一下matplotlib
matpotlib安装
安装成功;
安装成功

1.3.4最后安装jupyter lab:

jupyterlab
运行jupyter lab
运行
jupyter lab界面
如果整个过程没问题的话打开之后应该是这样的一个页面;你已经成功了90%了。

2.跑你的第一个opencv代码


```python
import cv2
import matplotlib.pyplot as plt
img=cv2.imread("./Downloads/xiaoye.jpg")
cv2.namedWindow("Image")
plt.imshow(img)
cv2.waitKey(0)

注意图片在你的文件路径里;

`在这里插入图片描述
``
如果到这一步运行成功,那说明你已经成功地安装opencv和成功运行了;

3.conda常用几个指令

换好源之后安装一些库的话,就进到虚拟环境里头运行
conda install 库名
pip install 库名
就行

4.结束语

看到这里,如果你成功了的话那祝你往后的学习成功和快乐;也希望你能给我个三连支持(好人一生平安)!世界很烦躁,能静下心来去掌握一个技术,去爱自己和生活的都是成功者。最后用稚晖君的一句话来结束本文吧;请不要温和地走进那段良夜,请保持热爱,奔赴星海!
我是小叶同学,谢谢你的喜欢~

GitHub 加速计划 / opencv31 / opencv
77.34 K
55.71 K
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:22 天前 )
4c81e174 RISC-V/AArch64: disable CPU features detection #25901 This PR is the first step in fixing current issues with NEON/RVV, FP16, BF16 and other CPU features on AArch64 and RISC-V platforms. On AArch64 and RISC-V platforms we usually have the platform set by default in the toolchain when we compile it or in the cmake toolchain file or in CMAKE_CXX_FLAGS by user. Then, there are two ways to set platform options: a) "-mcpu=<some_cpu>" ; b) "-march=<arch description>" (e.g. "rv64gcv"). Furthermore, there are no similar "levels" of optimizations as for x86_64, instead we have features (RVV, FP16,...) which can be enabled or disabled. So, for example, if a user has "rv64gc" set by the toolchain and we want to enable RVV. Then we need to somehow parse their current feature set and append "v" (vector optimizations) to this string. This task is quite hard and the whole procedure is prone to errors. I propose to use "CPU_BASELINE=DETECT" by default on AArch64 and RISC-V platforms. And somehow remove other features or make them read-only/detect-only, so that OpenCV wouldn't add any extra "-march" flags to the default configuration. We would rely only on the flags provided by the compiler and cmake toolchain file. We can have some predefined configurations in our cmake toolchain files. Changes made by this PR: - `CMakeLists.txt`: - use `CMAKE_CROSSCOMPILING` instead of `CMAKE_TOOLCHAIN_FILE` to detect cross-compilation. This might be useful in cases of native compilation with a toolchain file - removed obsolete variables `ENABLE_NEON` and `ENABLE_VFPV3`, the first one have been turned ON by default on AArch64 platform which caused setting `CPU_BASELINE=NEON` - raise minimum cmake version allowed to 3.7 to allow using `CMAKE_CXX_FLAGS_INIT` in toolchain files - added separate files with arch flags for native compilation on AArch64 and RISC-V, these files will be used in our toolchain files and in regular cmake - use `DETECT` as default value for `CPU_BASELINE` also allow `NATIVE`, warn user if other values were used (only for AArch64 and RISC-V) - for each feature listed in `CPU_DISPATCH` check if corresponding `CPU_${opt}_FLAGS_ON` has been provided, warn user if it is empty (only for AArch64 and RISC-V) - use `CPU_BASELINE_DISABLE` variable to actually turn off macros responsible for corresponding features even if they are enabled by compiler - removed Aarch64 feature merge procedure (it didn't support `-mcpu` and built-in `-march`) - reworked AArch64 and two RISC-V cmake toolchain files (does not affect Android/OSX/iOS/Win): - use `CMAKE_CXX_FLAGS_INIT` to set compiler flags - use variables `ENABLE_BF16`, `ENABLE_DOTPROD`, `ENABLE_RVV`, `ENABLE_FP16` to control `-march` - AArch64: removed other compiler and linker flags - `-fdata-sections`, `-fsigned-char`, `-Wl,--no-undefined`, `-Wl,--gc-sections` - already set by OpenCV - `-Wa,--noexecstack`, `-Wl,-z,noexecstack`, `-Wl,-z,relro`, `-Wl,-z,now` - can be enabled by OpenCV via `ENABLE_HARDENING` - `-Wno-psabi` - this option used to disable some warnings on older ARM platforms, shouldn't harm - ARM: removed same common flags as for AArch64, but left `-mthumb` and `--fix-cortex-a8`, `-z nocopyreloc` 1 天前
85923c8f Update zlib-ng to 2.2.1 #26113 Release: https://github.com/zlib-ng/zlib-ng/releases/tag/2.2.1 ARM diagnostics patch: https://github.com/zlib-ng/zlib-ng/pull/1774 ### 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. - [ ] The feature is well documented and sample code can be built with the project CMake 1 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐