갈루아의 반서재

728x90

opencv-python 라이브러리를 Ubuntu 18.04 아나콘다 환경에 설치해보자. 

(lindy) founder@casey:~$ pip install opencv-python
Collecting opencv-python
  Downloading https://files.pythonhosted.org/packages/44/35/6db0fa2e644922533ddc                                       2a3c41d1a86dabefce89d9db85ec31dcc69dc2e3/opencv_python-4.1.1.26-cp37-cp37m-manyl                                       inux1_x86_64.whl (28.7MB)
     |████████████████████████████████| 28.7MB 32.4MB/s
Requirement already satisfied: numpy>=1.14.5 in ./anaconda3/envs/lindy/lib/pytho                                       n3.7/site-packages (from opencv-python) (1.16.4)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.1.1.26

설치된 버전 확인

(lindy) founder@casey:~$ python
Python 3.7.3 (default, Mar 27 2019, 22:11:17)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>>
>>>
>>> import cv2
>>> print(cv2.__version__)
4.1.1
>>>

이미지를 보여주는 간단한 코드를 실행해보자.

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('checklist.jpg',cv2.IMREAD_GRAYSCALE)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

원격에서 노트북을 실행한 상태로 코드 실행시 다음과 같이 커널과 충돌이 발생한다. 

이 경우 다음과 같이 코드를 수정하여 실행하면 이미지를 볼 수 있다. https://stackoverflow.com/questions/43943333/cv2-imshow-crashes-kernel

%matplotlib inline
from matplotlib import pyplot as plt
import cv2
import numpy as np

image = cv2.imread('checklist.jpg',cv2.IMREAD_GRAYSCALE)
plt.imshow(image)
plt.show()

 

이하 참고 링크

https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_image_display/py_image_display.html

 

Getting Started with Images — OpenCV-Python Tutorials 1 documentation

Getting Started with Images Goals Here, you will learn how to read an image, how to display it and how to save it back You will learn these functions : cv2.imread(), cv2.imshow() , cv2.imwrite() Optionally, you will learn how to display images with Matplot

opencv-python-tutroals.readthedocs.io

https://pythonprogramming.net/loading-images-python-opencv-tutorial/

 

Python Programming Tutorials

OpenCV with Python for Image and Video Analysis Progress: 0% --> OpenCV with Python Intro and loading Images tutorial Welcome to a tutorial series, covering OpenCV, which is an image and video processing library with bindings in C++, C, Python, and Java. O

pythonprogramming.net

 

728x90