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
Metadata
Release files for tezz-pylsd 1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tezz-pylsd-1.1.tar.gz | 61.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tezz_pylsd-1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 123.4 kB
Release files / tezz-pylsd-1.1.tar.gz
| Download URL | tezz-pylsd-1.1.tar.gz |
|---|---|
| Size | 61.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ea39d488781010180c574eb9d313388b1b3bec18d7e45f41146463d201a88382
|
|
BLAKE2b-256 checksum How to use checksums |
9835dcae64faedc5d7b2f691a4d70d661acd4aefa27306cdeb7f2be04d49a838
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.2
|
Release files / tezz_pylsd-1.1-py3-none-any.whl
| Download URL | tezz_pylsd-1.1-py3-none-any.whl |
|---|---|
| Size | 61.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fa489ed1ddf693771ee6ef58755df345527a479d76f6210e7ab92a4fa33621d1
|
|
BLAKE2b-256 checksum How to use checksums |
8a8c34f55dd6c6bba0cc0ce36b598147f87bbd61dc79d08ee7a77a0edf5d6349
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.2
|