LoginSignup
0
0

More than 1 year has passed since last update.

Python3: OpenCV を使う

Last updated at Posted at 2017-06-05

Arch Linux では、簡単に、opencv がインストールできます

sudo pacman -S opencv
sudo pacman -S hdf5
sudo pacman -S gtkglext
sudo pacman -S python-opencv

対話形式でインストールの確認

$ python
Python 3.9.5 (default, May 12 2021, 17:14:51) 
[GCC 10.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.5.2'

ちゃんとインストールできているか確認するプログラムです。
題材の Lenna.jpg は、インターネットですぐに見つかります。

imshow.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
#   imshow.py
#
#                       May/16/2021
# --------------------------------------------------------------------
import os
import sys
import cv2

sys.stderr.write("*** 開始 ***\n")
print("version = " + cv2.__version__)
#
file_in = "Lenna.jpg"
if os.path.exists(file_in):
    img = cv2.imread(file_in)
    img_gray = cv2.imread(file_in,cv2.IMREAD_GRAYSCALE)
else:
    sys.stderr.write("*** error *** %s doesn't exist ***\n" % file_in)
    exit(1)
#
cv2.imshow("color",img)
cv2.imshow("gray",img_gray)
cv2.waitKey(0)
cv2.destroyAllWindows()
#
sys.stderr.write("*** 終了 ***\n")
# --------------------------------------------------------------------

次の環境で動作を確認

Arch Linux (5.12.3-arch1-1)
Python 3.9.5

関連情報
Python3: OpenCV で顔認識

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0