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
Release history Release notifications | RSS feed
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)
Built Distribution
Close
Hashes for cv2geojson-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd16165f8db727d5031a5e06b280f3e164a586ee7ac977b2089489c63d549c33 |
|
MD5 | 65c03f4ac6b8a254aca6fc17ee17485e |
|
BLAKE2b-256 | 8168498febd40ccd947e00e4c33ae0ff5ef9de98174fce6a7fe8f71d67776651 |