Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 운영체제
- 텐서플로우
- error
- python
- Windows 10
- 프로세스
- linux
- 턱걸이
- c
- 백준
- Windows10
- 학습
- C언어
- 프로그래밍
- 공부
- 쉘
- TensorFlow
- 회귀
- Computer Vision
- shell
- CV
- 코딩
- OpenCV
- 알고리즘
- 영상처리
- 딥러닝
- 백준알고리즘
- C++
- 시스템프로그래밍
- 리눅스
Archives
- Today
- Total
줘이리의 인생적기
CV - opencv(python) imread, copy 본문
728x90
python으로 하는 opencv를 다시 시작해보도록 하겠습니다.
아주 대표적인 사진이죠.
lenna사진을 불러오는 imread 함수를 알아보고 flag도 알아보겠습니다.
import cv2
def function1():
image = cv2.imread('lenna.bmp', cv2.IMREAD_COLOR) #default 값(1)
#image = cv2.imread('lenna.bmp', cv2.IMREAD_GRAYSCALE) #흑백(0)
#image = cv2.imread('lenna.bmp', cv2.IMREAD_UNCHANGED) #alpha channel까지 포함(-1)
if image is None:
print('Image load failed!')
return
print('image의 type은 ', type(image))
print('image의 shape는 ', image.shape)
if len(image.shape) == 2:
print('image is a grayscale image')
elif len(image.shape) == 3: #color BGR로 나타내주어야 하기 때문에 shape = 3
print('image is a true color image')
cv2.imshow('image window', image)
cv2.waitKey()
cv2.destroyAllWindows()
if __name__ == '__main__':
function1()
이와 같은 결과가 나왔네요!
grayscale은 shape를 찍으면 값이 2개가 나옵니다.
------------------------------------------------------------
다음 예제는 image 복사 관련 예제입니다.
import cv2
def function2():
image1 = cv2.imread('lenna.bmp')
image2 = image1
image3 = image1.copy()
image1[:,:] = (255, 255, 255) #모든 픽셀 흰색으로 변경
cv2.imshow('img1', image1)
cv2.imshow('img2', image2)
cv2.imshow('img3', image3)
cv2.waitKey()
cv2.destroyAllWindows()
if __name__ == '__main__':
function2()
image1과 image2의 복사방법과 image1와 image3의 복사 방법이 달랐습니다.
그에 따른 결과가 이렇게 나왔네요.
'공부 > Computer Vision(py)' 카테고리의 다른 글
CV - opencv(Python) Hough Transform(설명필요) (0) | 2020.07.24 |
---|---|
CV - opencv(Python) Geometric Transform(설명필요) (0) | 2020.07.23 |
CV - opencv(Python) Morphology (0) | 2020.07.22 |
CV - opencv(Python) Canny Edge (0) | 2020.07.21 |
CV - opencv(Python) 경계선 검출(edge detection) (0) | 2020.07.20 |