MeshToGeotiff - A fast Python algorithm to convert a 3D mesh into a GeoTIFF

Overview

MeshToGeotiff - A fast Python algorithm to convert a 3D mesh into a GeoTIFF

Python class for converting (very fast) 3D Meshes/Surfaces to Raster DEMs (as Geotiff) or regular point cloud grids.

  • Supports gridding overlapping surfaces (e.g. highest, lowest, or first result)
  • Supports output to regular x,y,z grid
  • Supports output to Geotiff DEMs
  • Supports point colour averaging (and outputting colour raster to TIF with heightmap)

Example of output

Motivation

I worked on a project that used polygonal meshes and wanted to integrate parts that relied on raster computations. There was a need to shift between the two paradigms without having to wait too long for conversion.

I couldn't find anything fast enough in Python to seamlessly transition between mesh and rasters. This uses Numba for parallel loops and has been heavily optimised for computation speed (intended to compete with c++ benchmarks for similar computations).

The benchmarks below indicate speeds expected on an average PC (at least for 3D processing purposes).

Installation Instructions

With pip

Requires rasterio (which also needs gdal). These libraries are easier installed from pre-compiled wheels.

You will need rasterio and gdal. The easiest way to install these will be a pre-compiled versions for your platform from:

Python 3.7, Windows, amd64:

python -m pip install https://download.lfd.uci.edu/pythonlibs/w6tyco5e/GDAL-3.3.3-cp37-cp37m-win_amd64.whl
python -m pip install https://download.lfd.uci.edu/pythonlibs/w6tyco5e/rasterio-1.2.10-cp37-cp37m-win_amd64.whl

Python 3.8, Windows, amd64:

python -m pip install https://download.lfd.uci.edu/pythonlibs/w6tyco5e/GDAL-3.3.3-cp38-cp38-win_amd64.whl
python -m pip install https://download.lfd.uci.edu/pythonlibs/w6tyco5e/rasterio-1.2.10-cp38-cp38-win_amd64.whl

Python 3.9, Windows, amd64:

python -m pip install https://download.lfd.uci.edu/pythonlibs/w6tyco5e/GDAL-3.3.3-cp39-cp39-win_amd64.whl
python -m pip install https://download.lfd.uci.edu/pythonlibs/w6tyco5e/rasterio-1.2.10-cp39-cp39-win_amd64.whl

With those satisfied it should be fine to pip install this:

python -m pip install git+https://github.com/jeremybutlermaptek/mesh_to_geotiff

or

python -m pip install https://github.com/jeremybutlermaptek/mesh_to_geotiff/raw/main/dist/mesh_to_geotiff-0.1.0-py3-none-any.whl

When running examples, if you see this error: ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject

Update numpy to 1.2 and/or reinstall:

python -m pip install --upgrade --force-reinstall numpy

To create a wheel for this:

python setup.py bdist_wheel

Usage

See examples:

from mesh_to_geotiff import MeshObject, MeshToGeotiff
import trimesh
mesh = trimesh.load_mesh("input_mesh.obj", "obj")
# Not providing colours will default to green.. colours are optional
mesh_object = MeshObject(points=mesh.vertices, point_colours=None, facets=mesh.faces)
grid_surface = MeshToGeotiff(verbose=True)

print("Calculating grid")
print("Note: First time running requires numba to compile and cache - may add 15sec overhead once")
grid_surface.compute_grid(mesh_object, grid_spacing=1.0)

print("Creating tif outputs")
# Exporting RGB map is optional, shown for example purposes
saved_as_heights, save_as_rgba = grid_surface.save_geotiff("export_heightmap.tif", "export_rgbmap.tif")
print(f"Saved DEM to: {saved_as_heights}")
print(f"Saved RGB to: {save_as_rgba}")

valid_xyzs = grid_surface.grid_points[grid_surface.null_mask]
print(valid_xyzs)

Benchmarks

Note: Upon the first run, Numba must compile/cache. This can add 15~ seconds to the first-time run that will disappear after that. Benchmarks are after this has happened once.

Test surface:

  • Points: 194,114
  • Facets: 384,874
  • Surface area: 728,550m² (Bounding: approx 1,240m x 970m)

Initial surface

The output DEM looks like this: DEM tif output

Benchmark PC:

  • CPU: AMD Ryzen 5 3600
  • RAM: 64gb
  • GPU: GTX1060
  • OS: Windows 10 x64

Gridding to 1m:

  • Total time to grid: 0.82sec
  • Time to save geotiff: 0.06sec
  • Tif size: 1.6mb
  • Total raster cells: 1,185,532

1m grid

Gridding to 0.5m:

  • Total time to grid: 0.97sec
  • Time to save geotiff: 0.13sec
  • Tif size: 5.76mb
  • Total raster cells: 4,735,248

0.5m grid

Gridding to 0.1m:

  • Total time to grid: 4.93sec
  • Time to save geotiff: 6.3sec
  • Tif size: 75mb
  • Total raster cells: 118,259,020

0.1m grid

Gridding to 0.05m:

  • Total time to grid: 19.99sec
  • Time to save geotiff: 24.5sec
  • Tif size: 223mb
  • Total raster cells: 472,973,166

0.05m grid

InverseRenderNet: Learning single image inverse rendering, CVPR 2019.

InverseRenderNet: Learning single image inverse rendering !! Check out our new work InverseRenderNet++ paper and code, which improves the inverse rend

Ye Yu 141 Dec 20, 2022
Creating of virtual elements of the graphical interface using opencv and mediapipe.

Virtual GUI Creating of virtual elements of the graphical interface using opencv and mediapipe. Element GUI Output Description Button By default the b

Aleksei 4 Jun 16, 2022
Ready-to-use OCR with 80+ supported languages and all popular writing scripts including Latin, Chinese, Arabic, Devanagari, Cyrillic and etc.

EasyOCR Ready-to-use OCR with 80+ languages supported including Chinese, Japanese, Korean and Thai. What's new 1 February 2021 - Version 1.2.3 Add set

Jaided AI 16.7k Jan 03, 2023
7th place solution

SIIM-FISABIO-RSNA-COVID-19-Detection 7th place solution Validation: We used iterative-stratification with 5 folds (https://github.com/trent-b/iterativ

11 Jul 17, 2022
A curated list of resources dedicated to scene text localization and recognition

Scene Text Localization & Recognition Resources A curated list of resources dedicated to scene text localization and recognition. Any suggestions and

CarlosTao 1.6k Dec 22, 2022
Face Recognizer using Opencv Python

Face Recognizer using Opencv Python The first step create your own dataset with file open-cv-create_dataset second step You can put the photo accordin

Han Izza 2 Nov 16, 2021
Volume Control using OpenCV

Gesture-Volume-Control Volume Control using OpenCV Here i made volume control using Python and OpenCV in which we can control the volume of our laptop

Mudit Sinha 3 Oct 10, 2021
A bot that extract text from images using the Tesseract OCR.

Text from image (OCR) @ocr_text_bot A simple bot to extract text from images. Usage What do I need? A AWS key configured locally, see here. NodeJS. I

Weverton Marques 4 Aug 06, 2021
Line based ATR Engine based on OCRopy

OCR Engine based on OCRopy and Kraken using python3. It is designed to both be easy to use from the command line but also be modular to be integrated

948 Dec 23, 2022
OCR powered screen-capture tool to capture information instead of images

NormCap OCR powered screen-capture tool to capture information instead of images. Links: Repo | PyPi | Releases | Changelog | FAQs Content: Quickstart

575 Dec 31, 2022
Tools for manipulating and evaluating the hOCR format for representing multi-lingual OCR results by embedding them into HTML.

hocr-tools About About the code Installation System-wide with pip System-wide from source virtualenv Available Programs hocr-check -- check the hOCR f

OCRopus 285 Dec 08, 2022
Steve Tu 71 Dec 30, 2022
When Age-Invariant Face Recognition Meets Face Age Synthesis: A Multi-Task Learning Framework (CVPR 2021 oral)

MTLFace This repository contains the PyTorch implementation and the dataset of the paper: When Age-Invariant Face Recognition Meets Face Age Synthesis

Hzzone 120 Jan 05, 2023
FOTS Pytorch Implementation

News!!! Recognition branch now is added into model. The whole project has beed optimized and refactored. ICDAR Dataset SynthText 800K Dataset detectio

Ning Lu 599 Dec 19, 2022
Recognizing cropped text in natural images.

ASTER: Attentional Scene Text Recognizer with Flexible Rectification ASTER is an accurate scene text recognizer with flexible rectification mechanism.

Baoguang Shi 681 Jan 02, 2023
This tool will help you convert your text to handwriting xD

So your teacher asked you to upload written assignments? Hate writing assigments? This tool will help you convert your text to handwriting xD

Saurabh Daware 4.2k Jan 07, 2023
MORAN: A Multi-Object Rectified Attention Network for Scene Text Recognition

MORAN: A Multi-Object Rectified Attention Network for Scene Text Recognition Python 2.7 Python 3.6 MORAN is a network with rectification mechanism for

Canjie Luo 595 Dec 27, 2022
This is the open source implementation of the ICLR2022 paper "StyleNeRF: A Style-based 3D-Aware Generator for High-resolution Image Synthesis"

StyleNeRF: A Style-based 3D-Aware Generator for High-resolution Image Synthesis StyleNeRF: A Style-based 3D-Aware Generator for High-resolution Image

Meta Research 840 Dec 26, 2022
Recognizing the text contents from a scanned visiting card

Recognizing the text contents from a scanned visiting card. The application which is used to recognize the text from scanned images,printeddocuments,r

Faizan Habib 1 Jan 28, 2022
An expandable and scalable OCR pipeline

Overview Nidaba is the central controller for the entire OGL OCR pipeline. It oversees and automates the process of converting raw images into citable

81 Jan 04, 2023