OpenCV 4.2 (on Ubuntu 20.04)で画像ファイル読み込み
OpenCV 4.2 (on Ubuntu 20.04)で画像ファイル読み込み
- ひさびさにインストールしたので手順を忘れていた。docker化したい
sudo apt update
sudo apt -y upgrade
sudo apt install -y build-essential
sudo apt install -y python3-opencv
sudo apt install -y python3-matplotlib
chino@kafu:~$ python3 ./read_image.py
Traceback (most recent call last):
File "./read_image.py", line 4, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
matplotlib also can install through pip3.
chino@kafu:~$ python3 ./read_image.py
Traceback (most recent call last):
File "./read_image.py", line 5, in <module>
from matplotlib import pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
Traceback (most recent call last):
File "./read_image.py", line 10, in <module>
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(4.2.0) ../modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# read_image.py : test for reading image | |
import cv2 | |
from matplotlib import pyplot as plt | |
#Read the image | |
filename1 = "/home/chino/sample.png" #absolute path | |
img = cv2.imread(filename1, 1) | |
#plt.imshow(img) | |
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | |
plt.imshow(img_rgb) | |
plt.show() |
On Ubuntu 20.04 it read image and display by usin…
- インストールはこれ
sharo$kirima:~$ sudo apt update
sharo$kirima:~$ sudo apt upgrade -y
sharo$kirima:~$ sudo apt install -y build-essential
Ref. https://docs.opencv.org/3.4/d2/de6/tutorial_py_setup_in_ubuntu.html
sharo$kirima:~$ sudo apt install -y python3-opencv
It changed to python3-opencv from python-opencv.
sharo@kirima:~$ python3
Python 3.8.2 (default, Apr 27 2020, 15:53:34)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2 as cv
>>> print(cv.__version__)
4.2.0
>>> exit()
On Ubuntu 20.04 it install OpenCV 4.2.0