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
- linux
- 프로세스
- python
- 프로그래밍
- 쉘
- Computer Vision
- 코딩
- 턱걸이
- TensorFlow
- 백준
- 백준알고리즘
- Windows 10
- C++
- c
- 영상처리
- 딥러닝
- 텐서플로우
- shell
- C언어
- 운영체제
- 리눅스
- 알고리즘
- 시스템프로그래밍
- 학습
- CV
- OpenCV
- 공부
- Windows10
Archives
- Today
- Total
줘이리의 인생적기
CV - opencv(Python) 이미지 열기, 창 띄우기, 픽셀 접근 본문
728x90
이미지를 열어서 픽셀에 접근하는 함수를 짜 보고, imageread 함수와 imageshow 함수에 대해 알아보겠습니다.
1번. (0,0) ~ (200,200)까지 검은색으로 채우기
2번. 사진 (100,100) ~ (200,200)까지 검은색으로 채우기
코드 원형 설명
#이미지 불러오기
def imageRead(openpath, flag=cv2.IMREAD_UNCHANGED):
image = cv2.imread(openpath, flag)
if image is not None:
print("Image Opened")
return image
else:
print("Image Not Opened")
print("Program Abort")
exit()
#창 띄우기
def imageShow(imagename, image, flag=cv2.WINDOW_GUI_EXPANDED):
cv2.namedWindow(imagename, flag)
cv2.imshow(imagename, image)
cv2.waitKey()
return
def imageWrite(imagename, image):
return cv2.imwrite(imagename, image)
#픽셀 접근
def getPixel(image, x, y, c=None):
return image[y, x, c]
def setPixel(image, x, y, value, c=None):
image[y, x, c] = value
return image
1번 코드
더보기
# -*- coding: utf-8 -*-
from OpenCV_Functions import *
#(0,0)~(200,200)픽셀까지 검은색으로 채우기
def imageProcessing(image):
result = imageCopy(image)
for i in range(0, 200):
for j in range(0, 200):
result = setPixel(result, i, j, [0, 0, 0])
return result
#이미지 불러오기
road_image_01 = "/home/opencv-mds/Downloads/road.jpg"
image_color = imageRead(road_image_01, cv2.IMREAD_COLOR)
result = imageProcessing(image_color)
#창 띄우기
imageShow("ex01", result, cv2.WINDOW_NORMAL)
2번 코드
더보기
# -*- coding: utf-8 -*-
from OpenCV_Functions import *
#(100,100)~(200,200)픽셀까지 검은색으로 채우기
def imageProcessing(image):
result = imageCopy(image)
for i in range(100,200):
for j in range(100, 200):
result = setPixel(result, i, j, [0, 0, 0])
return result
#이미지 불러오기
road_image_01 = "/home/opencv-mds/Downloads/road.jpg"
image_color = imageRead(road_image_01, cv2.IMREAD_COLOR)
result = imageProcessing(image_color)
#창 띄우기
imageShow("ex01", result, cv2.WINDOW_NORMAL)
imageread 함수
# Blue - Green - Red 순서의 3채널 이미지로 열림
imageread(filename, cv2.IMREAD_COLOR)
# 회색조 1채널로 열림
imageread(filename, cv2.IMREAD_GRAYSCALE)
# 1채널 회색조 이미지는 1채널로 열리고, 3채널 컬러 이미지는 3채널 BGR로 열림
imageread(filename, cv2.IMREAD_UNCHANGED)
imageshow 함수
# NORMAL: 좌표와 좌표의 RGB 값 확인 가능, 화면 크기 전환 가능 및 비율 유지
imageShow("image_color, cv2.WINDOW_NORMAL", image_color, cv2.WINDOW_NORMAL)
# AUTOSIZE : 좌표와 좌표의 RGB 값 확인 가능, 화면 크기 전환 불가능 및 비율 유지
imageShow("image_color, cv2.WINDOW_AUTOSIZE", image_color, cv2.WINDOW_AUTOSIZE)
# FREERATIO : 좌표와 좌표의 RGB 값 확인 가능, 화면 크기 전환 가능 및 비율 유지 안됨
imageShow("image_color, cv2.WINDOW_FREERATIO", image_color, cv2.WINDOW_FREERATIO)
# WINDOW_GUI_NORMAL : 좌표와 좌표의 RGB 값 확인 불가능, 화면 크기 전환 가능 및 비율 유지
imageShow("image_color, cv2.WINDOW_GUI_NORMAL", image_color, cv2.WINDOW_GUI_NORMAL)
# WINDOW_GUI_EXPANDED : 좌표와 좌표의 RGB 값 확인 가능, 화면 크기 전환 가능 및 비율 유지
imageShow("image_color, cv2.WINDOW_GUI_EXPANDED", image_color, cv2.WINDOW_GUI_EXPANDED)
'공부 > Computer Vision(py)' 카테고리의 다른 글
CV - opencv(Python) addImage, addWeightedImage, imageThreshold (0) | 2020.07.16 |
---|---|
CV - opencv(Python) 비디오에 라인, 원, 사각형 그리기 (0) | 2020.07.13 |
CV - opencv(Python) White, Yellow 차선 검출 (0) | 2020.07.10 |
CV - opencv(Python) ROI, Channels (0) | 2020.07.09 |
CV - 영상처리 개념 (0) | 2020.07.07 |