Created
September 23, 2021 19:53
-
-
Save ppizarror/0ce4311d5060454463facd6463c427eb to your computer and use it in GitHub Desktop.
Korea Land and Housing Corporation housing floor plans transformer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run this script within downloaded .zip from https://www.data.go.kr/data/15037046/fileData.do (August 2019) | |
# Contains 330 plans in bmp format, Resolution 230-5092. | |
import os | |
import cv2 | |
import base64 | |
# Retrieve all files | |
json_files = [] | |
def get_files(cwd='.'): | |
for f in os.listdir(cwd): | |
j = cwd + '/' + f # current file | |
if os.path.isdir(f): | |
get_files(j) | |
else: | |
if '.json' in j: | |
json_files.append(j) | |
# Convert from json to image | |
def json_bmp(f, output): | |
with open(f, 'r') as o: | |
o = o.read() | |
b64_name = o.split('base64')[-1].replace(',','').replace('}','') | |
if len(b64_name) % 4 != 0: | |
b64_name = b64_name[:len(b64_name)-len(b64_name) % 4] | |
imgdata = base64.b64decode(b64_name) | |
with open(output, 'wb') as ff: | |
ff.write(imgdata) | |
get_files() | |
# Iterate through all files, and convert to image | |
out = 'plans/' | |
if not os.path.isdir(out): | |
os.mkdir(out) | |
k = 1 | |
szmin, szmax = 1e10, 0 | |
for js in json_files: | |
w = out + '{0}.bmp'.format(k) | |
json_bmp(js, w) | |
k+=1 | |
sz = cv2.imread(w).shape | |
szmin = min(szmin, sz[0], sz[1]) | |
szmax = max(szmax, sz[0], sz[1]) | |
print('Converted {0} files, res {1}-{2}'.format(k-1, szmin, szmax)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment