티스토리 뷰

728x90
반응형

file.txt 파일을 열면 그냥 아래와 같이 19836 줄의 괄호로 둘러쌓인 무언가가 나옵니다.

 

(0,0,195,195,195)
(0,1,195,195,195)
(0,2,195,195,195)
(0,3,195,195,195)
(0,4,195,195,195)
(0,5,195,195,195)
(0,6,195,195,195)
(0,7,195,195,195)
...중략...
(37,521,195,195,195)

딱 보아도 x, y, r, g b 값일 것 같았습니다. 그래서 도박하는 생각으로 그냥 코드로 해당 x와 y 지점에 주어진 RGB 값을 입력하게 해보았습니다.

 

결과 코드는 다음과 같습니다.

import cv2 as cv
img = cv.imread('blank.png')
file =open('file.txt','r')
line = file.read().split('\n')
i = 0
for x in range(38):
	for y in range(522):
		rgb = line[i].split("(")[1].split(")")[0]
		try:
			img[x,y][0] = rgb.split(",")[4]
			img[x,y][1] = rgb.split(",")[3]
			img[x,y][2] = rgb.split(",")[2]
		except:
			pass
		i +=1
cv.imshow('flag',img)
cv.waitKey(0)

 

혹시나 No module named 'cv2' 오류가 나신다면 opencv 라이브러리가 python에 설치되어 있지 않은 것인지 확인 해보시고 설치가 되어 있지 않다면 설치 해줘야합니다. 설치 명령어는 다음과 같습니다. cv2 가 아니라 opencv-python 으로 해줘야 합니다.

C:\Users\domdomi>pip install opencv-python
Requirement already satisfied: opencv-python in c:\python39\lib\site-packages (4.5.3.56)
Requirement already satisfied: numpy>=1.19.3 in c:\python39\lib\site-packages (from opencv-python) (1.21.2)
WARNING: You are using pip version 21.1.3; however, version 21.2.4 is available.
You should consider upgrading via the 'c:\python39\python.exe -m pip install --upgrade pip' command.

 

728x90
반응형
댓글