Skip to main content

tezz-pylsd

1. Introduction

tezz-pylsd is the python bindings for LSD - Line Segment Detector.

2. Install

This package uses distutils, which is the default way of installing python modules. To install in your home directory, securely run the following:

git clone https://github.com/tezz-io/tezz-pylsd.git
cd tezz-pylsd
[sudo] python setup.py install

Or directly through pip to install it:

[sudo] pip install tezz-pylsd

3. Usage

We can use the package by using from pylsd.lsd import lsd, and lines = lsd(src) is the call format for the lsd function, where src is a Grayscale Image (H * W numpy.array), and the return value lines is the Detected Line Segment, lines is an N * 5 numpy.array, each row represents a straight line, the 5-dimensional vector is:

[point1.x, point1.y, point2.x, point2.y, width]

According to these presentations, we can use it just like the following code (here is the link):

  • by using cv2 module
import cv2
import numpy as np
import os
from pylsd.lsd import lsd
fullName = 'car.jpg'
folder, imgName = os.path.split(fullName)
src = cv2.imread(fullName, cv2.IMREAD_COLOR)
gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
lines = lsd(gray)
for i in xrange(lines.shape[0]):
    pt1 = (int(lines[i, 0]), int(lines[i, 1]))
    pt2 = (int(lines[i, 2]), int(lines[i, 3]))
    width = lines[i, 4]
    cv2.line(src, pt1, pt2, (0, 0, 255), int(np.ceil(width / 2)))
cv2.imwrite(os.path.join(folder, 'cv2_' + imgName.split('.')[0] + '.jpg'), src)
  • by using PIL(Image) module
from PIL import Image, ImageDraw
import numpy as np
import os
from pylsd.lsd import lsd
fullName = 'house.png'
folder, imgName = os.path.split(fullName)
img = Image.open(fullName)
gray = np.asarray(img.convert('L'))
lines = lsd(gray)
draw = ImageDraw.Draw(img)
for i in xrange(lines.shape[0]):
    pt1 = (int(lines[i, 0]), int(lines[i, 1]))
    pt2 = (int(lines[i, 2]), int(lines[i, 3]))
    width = lines[i, 4]
    draw.line((pt1, pt2), fill=(0, 0, 255), width=int(np.ceil(width / 2)))
img.save(os.path.join(folder, 'PIL_' + imgName.split('.')[0] + '.jpg'))

The following is the result:

  • car.jpg by using cv2 module

  • house.png by using PIL(Image) module

Download files

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

Source Distribution

tezz-pylsd-1.1.tar.gz (61.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tezz_pylsd-1.1-py3-none-any.whl (61.6 kB view details)

Uploaded Python 3

File details

Details for the file tezz-pylsd-1.1.tar.gz.

File metadata

  • Download URL: tezz-pylsd-1.1.tar.gz
  • Upload date:
  • Size: 61.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.2

File hashes

Hashes for tezz-pylsd-1.1.tar.gz
Algorithm Hash digest
SHA256 ea39d488781010180c574eb9d313388b1b3bec18d7e45f41146463d201a88382
MD5 c364eaf67cf2d80fad716c4be7c2472d
BLAKE2b-256 9835dcae64faedc5d7b2f691a4d70d661acd4aefa27306cdeb7f2be04d49a838

See more details on using hashes here.

File details

Details for the file tezz_pylsd-1.1-py3-none-any.whl.

File metadata

  • Download URL: tezz_pylsd-1.1-py3-none-any.whl
  • Upload date:
  • Size: 61.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.9.2

File hashes

Hashes for tezz_pylsd-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa489ed1ddf693771ee6ef58755df345527a479d76f6210e7ab92a4fa33621d1
MD5 2973ea8cc6c013addd93e056ef840d8e
BLAKE2b-256 8a8c34f55dd6c6bba0cc0ce36b598147f87bbd61dc79d08ee7a77a0edf5d6349

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page