In this post, I introduce a way for reading images using opencv-python
. Suppose that the Python project will be managed by Pipenv (see my previous post).
Installation
You can install opencv-python
using pip:
pipenv install opencv-python
If you try to build official software, you should specify the version of package. The version can be found on PyPI. The latest version of opencv-python
is 4.5.1.48
at 2021/01/05.
You can specify the version like this:
pipenv install opencv-python~=4.5.1.48
Reading image by cv2.imread
You can read images by the function cv2.imread
like this:
import cv2
image = cv2.imread('/path/to/imagefile')
Change /path/to/imagefile
to the path of your image. After reading image, the variable image
above is numpy.ndarray
. If you understand how to manipulate numpy.ndarray
, you can easily conduct image processing.
—
Thanks for reading.
This post is linked to my Youtube channel: https://www.youtube.com/channel/UC-SHOllZQsQFCsbL3BvP1rA
The content might be updated in the future.