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.

Files for ocrd-fork-pylsd, version 0.0.4
Filename, size File type Python version Upload date Hashes
Filename, size ocrd_fork_pylsd-0.0.4-cp36-cp36m-macosx_10_9_x86_64.whl (20.3 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp36-cp36m-manylinux1_i686.whl (52.2 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp36-cp36m-manylinux1_x86_64.whl (57.1 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp36-cp36m-manylinux2010_i686.whl (52.2 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp36-cp36m-manylinux2010_x86_64.whl (57.1 kB) File type Wheel Python version cp36 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp37-cp37m-macosx_10_9_x86_64.whl (20.3 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp37-cp37m-manylinux1_i686.whl (52.2 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp37-cp37m-manylinux1_x86_64.whl (57.1 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp37-cp37m-manylinux2010_i686.whl (52.2 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp37-cp37m-manylinux2010_x86_64.whl (57.2 kB) File type Wheel Python version cp37 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp38-cp38-macosx_10_9_x86_64.whl (20.3 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp38-cp38-manylinux1_i686.whl (52.1 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp38-cp38-manylinux1_x86_64.whl (57.1 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp38-cp38-manylinux2010_i686.whl (52.2 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp38-cp38-manylinux2010_x86_64.whl (57.1 kB) File type Wheel Python version cp38 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp39-cp39-macosx_10_9_x86_64.whl (20.3 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp39-cp39-manylinux1_i686.whl (52.1 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp39-cp39-manylinux1_x86_64.whl (57.1 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp39-cp39-manylinux2010_i686.whl (52.1 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-cp39-cp39-manylinux2010_x86_64.whl (57.1 kB) File type Wheel Python version cp39 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-pp36-pypy36_pp73-macosx_10_9_x86_64.whl (18.9 kB) File type Wheel Python version pp36 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-pp36-pypy36_pp73-manylinux1_x86_64.whl (19.9 kB) File type Wheel Python version pp36 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-pp36-pypy36_pp73-manylinux2010_x86_64.whl (19.9 kB) File type Wheel Python version pp36 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (18.9 kB) File type Wheel Python version pp37 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-pp37-pypy37_pp73-manylinux1_x86_64.whl (19.9 kB) File type Wheel Python version pp37 Upload date Hashes View
Filename, size ocrd_fork_pylsd-0.0.4-pp37-pypy37_pp73-manylinux2010_x86_64.whl (19.9 kB) File type Wheel Python version pp37 Upload date Hashes View
Filename, size ocrd-fork-pylsd-0.0.4.tar.gz (22.5 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page