Skip to main content

pylsd is the python bindings for LSD - Line Segment Detector

Project description

pylsd

1. Introduction

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/primetang/pylsd.git
cd pylsd
[sudo] python setup.py install

Or directly through pip to install it:

[sudo] pip install 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

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

ocrd-fork-pylsd-0.0.3.tar.gz (46.8 kB view details)

Uploaded Source

Built Distributions

ocrd_fork_pylsd-0.0.3-py3-none-any.whl (47.6 kB view details)

Uploaded Python 3

ocrd_fork_pylsd-0.0.3-py2-none-any.whl (47.6 kB view details)

Uploaded Python 2

File details

Details for the file ocrd-fork-pylsd-0.0.3.tar.gz.

File metadata

  • Download URL: ocrd-fork-pylsd-0.0.3.tar.gz
  • Upload date:
  • Size: 46.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/2.7.9

File hashes

Hashes for ocrd-fork-pylsd-0.0.3.tar.gz
Algorithm Hash digest
SHA256 728c88f2c53372c3614d8f0ffcb610939fab867b08b72603a85b202e9818938f
MD5 c537c32307528840ceeaa647908960c9
BLAKE2b-256 b84fd61c4d2f73cfd8c66c5bfca341ea5cf115fd596015452b875d347becb247

See more details on using hashes here.

File details

Details for the file ocrd_fork_pylsd-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: ocrd_fork_pylsd-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 47.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/2.7.9

File hashes

Hashes for ocrd_fork_pylsd-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 758fc14dc1a76c174397ce9dae6db1f9b3dc530b361767a9714538dd01b9bf03
MD5 3a35bdbe290b7b21c29f86ab83c40f1d
BLAKE2b-256 6adf12fba60b9b3e141f515d69edd539bd066294d6b3be79b12450888819986d

See more details on using hashes here.

File details

Details for the file ocrd_fork_pylsd-0.0.3-py2-none-any.whl.

File metadata

  • Download URL: ocrd_fork_pylsd-0.0.3-py2-none-any.whl
  • Upload date:
  • Size: 47.6 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/2.7.9

File hashes

Hashes for ocrd_fork_pylsd-0.0.3-py2-none-any.whl
Algorithm Hash digest
SHA256 9a33d21c2cb524c3745607029b4bceba55ab6e72f6e720fd11546efd13c5efd7
MD5 4355465dd85b7024c006d6ff174e4fe0
BLAKE2b-256 498a721974593c3df85036591de8735f3767441d028edfbad17bbdb307dbd392

See more details on using hashes here.

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