Commit 6ad10b10 authored by Jean-Marie Lepioufle's avatar Jean-Marie Lepioufle
Browse files

add collosm, update mains, and rm examples

parent 501373ca
# osmaug v0.01dev
# osmaug v0.02dev
A package for:
- getting OpenStreet Map pictures around specific locations.
- implementing simple picture augmentation.
- Combining a dataset with the name of the file of an augmented OSM tile.
## Install
Package 'osmaug' require [geckodriver](https://github.com/mozilla/geckodriver/releases).
Package 'osmaug' requires [geckodriver](https://github.com/mozilla/geckodriver/releases).
```bash
cd /tmp
......@@ -20,15 +21,12 @@ pip3 install -e .
python osmaug/getosm.py -c config.json
python osmaug/augmosm.py -c config.json
```
## Example
```bash
python osmaug/getosm.py -c osmaug/example/osm.json
python osmaug/augmosm.py -c osmaug/example/augmosm.json
python osmaug/collosm.py -c config.json
```
## Related works
## Examples
Have a look at our [case studies](https://git.nilu.no/aqdl/case_studies) repository.
The package is a close adaptation of : [osm2img](https://git.nilu.no/deepair/osm2img),[osmsubsetter](https://git.nilu.no/deepair/osmsubsetter),[imgaug](https://git.nilu.no/deepair/imgaug).
## Related works
The package is a close adaptation of : [osm2img](https://git.nilu.no/deepair/osm2img), [osmsubsetter](https://git.nilu.no/deepair/osmsubsetter), [imgaug](https://git.nilu.no/deepair/imgaug).
import argparse
from typing import Dict
import json
import pandas as pd
import os
from skimage import io, img_as_float, img_as_ubyte
from PIL import Image
import numpy as np
from osmaug.dictionnary.dictionnary_tf import augm_dict
from osmaug.transformation.crop import crop
def augmosm_function(params: Dict):
workdir = os.path.join(params['workdir'])
if not os.path.exists(workdir):
sys.exit('workdir does not exist: '+workdir)
resdir = os.path.join(workdir,"augm")
if not os.path.exists(resdir):
os.mkdir(resdir)
print("resdir: "+resdir)
files = pd.DataFrame.from_dict(params['files'], orient='columns')
for index, row in files.iterrows():
print("-> "+row['name'])
img = img_as_float(io.imread(os.path.join(workdir,row["name"])))
augm = augm_dict[row['augmentation']]
img = augm(img)
img = crop(img, delta=row["delta_pixel"])
pil_img = Image.fromarray(img_as_ubyte(img)).save(os.path.join(resdir,"aug_"+row['augmentation']+"_"+row["name"]))
from osmaug.transformation.augmosm_main import augmosm_main
def main():
"""
......
import argparse
import json
from osmaug.combine.collosm_main import collosm_function
def main():
"""
Main collosm_function.
"""
parser = argparse.ArgumentParser(description="Argument parsing for combining osm pictures filename to dataset")
parser.add_argument("-c", help="Config")
args = parser.parse_args()
with open(args.c,encoding='utf8') as f:
collosm_config = json.load(f)
collosm_function(augmosm_config)
print("Combining OSM pictures augmentation to dataset completed.")
if __name__ == "__main__":
main()
import random
hash = random.getrandbits(128)
print("hash value: %032x" % hash)
uuid.uuid4().hex
from typing import Dict
import pandas as pd
import os
from skimage import io, img_as_float, img_as_ubyte
from PIL import Image
import numpy as np
import uuid
from osmaug.dictionnary.dictionnary_tf import augm_dict
from osmaug.transformation.crop import crop
def collosm_function(params: Dict):
workdir = os.path.join(params['workdir'])
if not os.path.exists(workdir):
sys.exit('workdir does not exist: '+workdir)
imgdir = os.path.join(workdir,'osm')
if not os.path.exists(imgdir):
os.mkdir(imgdir)
augmdir = os.path.join(workdir,'augm')
if not os.path.exists(augmdir):
os.mkdir(augmdir)
datadir = os.path.join(workdir,'data')
if not os.path.exists(datadir):
os.mkdir(datadir)
df = pd.read_csv(params['file']['name'],sep=',')
df['ID'] = df['ID'].apply(str)
zoom = pd.DataFrame.from_dict(params['osm'], orient='columns')
filenames = {}
for index_zoom, row_zoom in zoom.iterrows():
filename_tmp = []
for index, row in df.iterrows():
filename = row['ID']+'_zoom_'+row_zoom['zoom']+'.jpg'
print(filename)
img = img_as_float(io.imread(os.path.join(imgdir,filename)))
augm = augm_dict[params['augmentation']['augmentation']]
img = augm(img)
img = crop(img, delta=params['augmentation']['delta_pixel'])
filename_aug = str(uuid.uuid4().hex)+'_'+filename
Image.fromarray(img_as_ubyte(img)).save(os.path.join(augmdir,filename_aug))
filename_tmp.append(filename_aug)
filenames['z'+row_zoom["zoom"]] = filename_tmp
df_file = pd.DataFrame(filenames)
res = pd.concat([df.reset_index(drop=True), df_file], axis=1)
res.to_csv(os.path.join(datadir,'dataset.csv'))
{
"files" : [
{
"name": "bygdøy_zoom_19.jpg", "augmentation" : "affineRandom", "delta_pixel" : 112
},
{
"name": "alna_zoom_19.jpg" , "augmentation" : "affineRandom", "delta_pixel" : 112
}
],
"workdir" : "C:/Users/jml/Documents/osm"
}
{
"points" : [
{
"name": "bygdøy", "coords" : [59.919306, 10.6965], "conv_crs" : "+proj=utm +zone=32V, +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs", "delta_meters" : 100
},
{
"name": "alna" , "coords" : [59.927689, 10.846545], "conv_crs" : "+proj=utm +zone=32V, +north +ellps=WGS84 +datum=WGS84 +units=m +no_defs", "delta_meters" : 100
}
],
"zoom" : 19,
"workdir" : "C:/Users/jml/Documents/",
"driver_bin" : "C:/Users/jml/Documents/geckodriver.exe"
}
import argparse
from typing import Dict
import json
import pandas as pd
import os
from osmaug.osm.map import make_bbox, load_map, map2png, png2jpg
def getosm_function(params: Dict):
driver_bin = params['driver_bin']
workdir = os.path.join(params['workdir'])
if not os.path.exists(workdir):
sys.exit('workdir does not exist: '+workdir)
resdir = os.path.join(workdir,"osm")
if not os.path.exists(resdir):
os.mkdir(resdir)
print("resdir: "+resdir)
zoom = params['zoom']
points = pd.DataFrame.from_dict(params['points'], orient='columns')
for index, row in points.iterrows():
print("-> "+row['name'])
tmp = make_bbox(row['coords'],row['conv_crs'],row['delta_meters'])
file = os.path.join(resdir,row['name']+'_zoom_'+str(zoom)+'.html')
load_map(tmp,zoom,file)
tmp = map2png(file, 5, driver_bin)
tmp = png2jpg(tmp)
from osmaug.osm.getosm_main import getosm_main
def main():
"""
......
from typing import Dict
import pandas as pd
import os
from osmaug.osm.map import make_bbox, load_map, map2png, png2jpg
def getosm_function(params: Dict):
driver_bin = params['driver_bin']
workdir = os.path.join(params['workdir'])
if not os.path.exists(workdir):
sys.exit('workdir does not exist: '+workdir)
resdir = os.path.join(workdir,"osm")
if not os.path.exists(resdir):
os.mkdir(resdir)
zoom = params['zoom']
points = pd.DataFrame.from_dict(params['points'], orient='columns')
for index, row in points.iterrows():
print("-> "+row['ID'])
tmp = make_bbox(row['coords'],row['conv_crs'],row['delta_meters'])
file = os.path.join(resdir,row['ID']+'_zoom_'+str(zoom)+'.html')
load_map(tmp,zoom,file)
tmp_png = map2png(file, 5, driver_bin)
tmp_jpg = png2jpg(tmp_png)
os.remove(file)
os.remove(tmp_png)
......@@ -40,7 +40,6 @@ def map2png(file, delay, driver_bin):
driver.get('file://{}'.format(file))
# Give the map tiles some time to load
time.sleep(delay)
print(file)
driver.save_screenshot(file.replace('.html', '.png'))
driver.quit()
return(file.replace('.html', '.png'))
......
from typing import Dict
import pandas as pd
import os
from skimage import io, img_as_float, img_as_ubyte
from PIL import Image
import numpy as np
from osmaug.dictionnary.dictionnary_tf import augm_dict
from osmaug.transformation.crop import crop
def augmosm_function(params: Dict):
workdir = os.path.join(params['workdir'])
if not os.path.exists(workdir):
sys.exit('workdir does not exist: '+workdir)
resdir = os.path.join(workdir,"augm")
if not os.path.exists(resdir):
os.mkdir(resdir)
files = pd.DataFrame.from_dict(params['files'], orient='columns')
for index, row in files.iterrows():
print("-> "+row['name'])
img = img_as_float(io.imread(os.path.join(workdir,row["name"])))
augm = augm_dict[row['augmentation']]
img = augm(img)
img = crop(img, delta=row["delta_pixel"])
pil_img = Image.fromarray(img_as_ubyte(img)).save(os.path.join(resdir,"aug_"+row['augmentation']+"_"+row["name"]))
......@@ -16,13 +16,14 @@ dev_requirements = []
setup(
name='osmaug',
version='0.01dev',
version='0.02dev',
author='Jean-Marie Lepioufle, Islen Vallejo',
author_email='jml@nilu.no, iv@nilu.no',
packages=[
'osmaug',
'osmaug.osm',
'osmaug.transformation'],
'osmaug.transformation',
'osmaug.combine'],
license='MIT + Copyright NILU',
description='A package for getting OpenStreet Map pictures and implementing augmentation.',
long_description = long_description,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment