1.OpenCV Introduction and Installation

Time:2024-6-19

1. Introduction to OpenCV

OpenCV
   A cross-platform (Linux, Windows, Android and Mac OS operating systems) based on the Apache2.0 license (open source) distribution of computer vision and machine learning software library . Lightweight and efficient (composed of a series of C functions and a small number of C++ classes , while providing Python, Ruby, MATLAB and other languages of the interface ) , but also the implementation of image processing and computer vision aspects of many general-purpose algorithms .

  1. OpenCV was founded by Gary Bradsky at Intel in 1999, and the first version was released in 2000.
  2. OpenCV-Python is a Python API for OpenCV (OpenCV-Python is a Python binding library) that combines the best features of the OpenCV C++ API and the Python language.
  3. OpenCV-Python The underlying source code is written in C/C++ and encapsulated in Python (which solves the problem of slow speed of Python language), and C/C++ easily extends Python (i.e., it is equivalent to using C/C++ as a substitute for Python).

2.OpenCV-Python Installation

(1) Simple installation of opencvpython under Win11 system

① The computer already has Python installed (i.e., it already has the Python packages pip (pip versions are usually updated), numpy, etc.)
➤ Open a command prompt window (2 ways)
🢆1) Search for a command prompt to directly open the
1.OpenCV Introduction and Installation
🢆2) Win+r key to open and type cmd
1.OpenCV Introduction and Installation
➤ pip update (provided Python is already installed)
🢆 1) pip common usage commands

install Installs the package
  download Download package
  uninstall Uninstall package
  freeze outputs installed packages in demand format
  inspect checks the python environment
  list Installed Packages
  show Displays information about installed packages
  check Verify that the installed packages are compatible with dependencies.
  config manages local and global configuration.
  search Search for packages in PyPI
  cache Checks and manages pip's wheel cache.
  index Checks the information available on the package indexes.
  completion An auxiliary command used to complete the command.
  debug Displays information useful for debugging.
  help Displays help for the command.
  -v, --verbose provide more output. Options are additional and can be used up to 3 times
  -V, --version Display the version and exit.
  -q, --quiet Reduce output. The options are additive and can be used up to 3 times (corresponding to the
Warning, Error and Critical log levels).

🢆2) pip version to see the update

# View Version
pip -V
# pip update
pip install --upgrade pip

②Perform installation
➤ Installation (go to cmd command line)

# Official Website Installation
# Direct installation on official website (slower downloads and easy failures due to extranet restrictions)
pip install opencv-python
# High-end versions, some algorithms, etc. not yet mature or open
pip install opencv-contrib-python

# Domestic source installations
# Domestic sources + general installation (Tsinghua sources)
pip install opencv-python  -i https://pypi.tuna.tsinghua.edu.cn/simple
# Add Domestic Sources + Host Trusted Installation
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn opencv-python
# Add Domestic Sources + Host Trusted Installation + 用户权限安装(建议直接使用此条命令)
pip install --user -i https://pypi.tuna.tsinghua.edu.cn/simple --trusted-host pypi.tuna.tsinghua.edu.cn opencv-python

➤ Common domestic mirror installation sources

Tsinghua university: https://pypi.tuna.tsinghua.edu.cn/simple
Aliyun: http://mirrors.aliyun.com/pypi/simple/
Douban: http://pypi.douban.com/simple/
University of Science and Technology of China https://pypi.mirrors.ustc.edu.cn/simple/

(2) Win11 system anaconda install opencv-python

① Download anaconda
Website to download the installation: https://www.anaconda.com/products/distribution#Downloads
1.OpenCV Introduction and Installation
② Install anaconda
➤Click next
1.OpenCV Introduction and Installation
➤ Click on I agree
1.OpenCV Introduction and Installation
➤ Installation for the current user only
1.OpenCV Introduction and Installation
➤ Installation path according to their own decision (path do not have Chinese and spaces), continue to the next step
1.OpenCV Introduction and Installation
➤ the first one must be checked (you don’t have to configure the environment variables yourself)
1.OpenCV Introduction and Installation
③ Perform opencv-python installation (2 methods)
➤ Method 1: Install in anaconda base environment – open jupyter notebook and run it directly
pip install –user -i https://pypi.tuna.tsinghua.edu.cn/simple –trusted-host pypi.tuna.tsinghua.edu.cn opencv-python
➤ Method 2: Installation in the anaconda base environment – open the prompt installation
1.OpenCV Introduction and Installation
pip install –user -i https://pypi.tuna.tsinghua.edu.cn/simple –trusted-host pypi.tuna.tsinghua.edu.cn opencv-python
1.OpenCV Introduction and Installation

(3) Win11 system to create conda virtual environment to install opencv-python

① Open Anaconda Prompt (anaconda)
1.OpenCV Introduction and Installation
② create conda virtual environment OpenCV (conda create -n virtual environment name python=version number)
➤ Creating opencv: conda create -n opencv python=3.9
1.OpenCV Introduction and Installation
➤ Activate the virtual environment: conda activate opencv
1.OpenCV Introduction and Installation
➤ Perform an OpenCV installation: pip install –user -i https://pypi.tuna.tsinghua.edu.cn/simple –trusted-host pypi.tuna.tsinghua.edu.cn opencv-python
1.OpenCV Introduction and Installation
➤ Check for successful installation
python
cv2. _ _version _ _
1.OpenCV Introduction and Installation

Recommended Today

[MySQL]: DDL Database Definitions and Operations

Article Catalog preamble I. Classification of SQL II. DDL database operations 2.1 Query all databases 2.2 Querying the current database 2.3 Creation of databases 2.4 Deletion of databases 2.5 Switching databases 3. DDL table operations 3.1 Query Creation 3.2 Data types 3.3 Modifications 3.4 Delete . Full Summary preamble SQL is a powerful language that […]