This guide explains how to annotate new images for training a network to estimate building heights using Mapillary API data, and how to use trained networks for estimation.
-
Directory setup and access token integration
Create the following folders in
annotation_images:
├── new_images/
└── processed_images/
├── .original/
├── .ai/
└── .svg/
And integrate your Mapillary API access token into the code:
- annotation_images/1_image_data_request.py Line 16
- script_prog/python_script.py Line 155
- Image Search and Data Collection
- Search for images fitting your criteria and save them and their data using
1_image_data_request.py. - The images are saved to
new_imagesfolder, data - to1_new_images.xlsx. - Assign project IDs to the images in the first column that correspond to your needs.
- Data Preparation
- Move data from
1_new_images.xlsxto2_all_images.xlsxand save the data with camera position coordinates to GEOJSON using script2_excel_to_geojson.py. - The GEOJSON reprojected into EPSG:3857 is saved into
2_all_images_3857.geojson.
- Image Processing
- Cut each new image from
new_imagestoproccessed_images/originaland open them with Adobe Illustrator or any similar vector image processing tool that allows creating importing JPG, adding circles, and exporting to SVG. - In Adobe Illustrator:
- Open the original JPG and adjust the artboard.
- Add circles and name them correctly. In my work, the first three numbers stood for the project ID of the image, the next two symbols - for the position of points pair in the image from left to right, and the last one was either 1 for the top point or 2 for bottom point - e.g., 048062.
- Then, geolocate the projections of points pair on the ground in QGIS. In the project
3_annotation_qgis.qgz, the2_all_images_3857.geojsonis open, as well as3_ref_points_3857.geojsonwith points from my project geolocated. Add your points to the3_ref_points_3857.geojsonand name them correctly - e.g., the first five numbers of points names that correspond to the points pair. - Save points coordinates from SVG to an Excel file using
3_coordinates_svg_to_excel.py. The coordinates are saved to the worksheet new_coordinates in3_ref_points.xlsx. - Assign to each point pair in the worksheet new_coordinates in
3_ref_points.xlsxthe Building height for ground truth data.
- Examples of images in original format and as SVG can be found in branch
examples-building-height.
- Lines Creation
- Create lines in your QGIS project using the tool "Join by Lines (Hub Lines)" from the processing toolbox. Refer to
4_how_to_create_lines.png.
- Lines Proccessing
- Calculate the length and angles of the lines from the lines layer by copying fields from the layer 5_lines_attributes_example in the QGIS project 3_annotation_qgis.qgz or create new virtual fields as in
5_how_to_calculate_lines.png. - Export the layer as Excel to
5_lines_data.xlsx.
- Data Compilation
- Prepare data for MATLAB Neural Network in
matlab_input_alland filter images as needed. - Merge all data into
matlab_table.xlsxin thescript_progfolder:2_all_images.xlsxtoimage_data_all3_ref_points.xlsxtoref_coordinates5_lines_data.xlsxtolines
- You can then filter the images by user as I did with the images of stefanhrt or filter them by the outlying values of building height or distance.
- Train neural network from the required worksheet of
matlab_table.xlsxusingscript_neural.m. You can adjust the worksheet used, data range, columns used as input, data split (training-validation-testing), and the way to handle the optimization algorthms and hidden layers number. - Use
matlab_main_script.mto use neural network. In the current code, you can compare two neural networks. - The MATLAB program accesses compiled Python program in
__pycache__/python_script.cpython-311.pyc. You can change the code in python_script.py and then recompile usingcompile.py.