Skip to main content

Export contour annotations as geojson formatted data

Project description

cv2geojson

cv2geojson is an open source project to export annotation contours extracted using OpenCV-python package to GeoJSON format.

Introduction

In digital pathology, images are often quite large and dedicated software tools like QuPath are required to aid visualisation. The python package cv2geojson export contours detected using cv2.findContours as polygons using GeoJSON format for visualisation in QuPath.

Installation

The recommended way to install is via pip:

pip install cv2geojson

Example

import cv2 as cv
import geojson
import cv2geojson

# read sample image
img = cv.imread('./example/img_01.png')
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

# Extract annotation contours
contours, hierarchy = cv.findContours(img, cv.RETR_CCOMP, cv.CHAIN_APPROX_SIMPLE)

# convert contours to geojson format
geometries = cv2geojson.contour2geometry(contours, hierarchy)
features = [cv2geojson.geometry2feature(geometry) for geometry in geometries]
annotation = geojson.FeatureCollection(features)

# export annotation
with open('./example/geocontours_01.geojson', 'w') as writer:
    geojson.dump(annotation, writer)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cv2geojson-0.0.5.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

cv2geojson-0.0.5-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page