pylsd-nova
1. Introduction
pylsd-nova is a python binding for LSD - Line Segment Detector.
This is a fork from original pylsd binding. This fork works for Python 3 and adds the ability to change lsd parameters from python call.
2. Install
This package uses distutils, which is the default way of installing python modules. For installing by cloning the repository you can run the following commands:
git clone https://github.com/AndranikSargsyan/pylsd-nova.git
cd pylsd-nova
pip install .
Or install directly through pip:
pip install pylsd-nova
3. Usage
You can use the package by importing like from pylsd import lsd, and calling segments = lsd(img) by optionally passing other lsd parameters mentioned below. img is a Grayscale Image (H x W numpy.ndarray), and the return value segments contains detected line segments.
segments is an N x 5 numpy.ndarray. Each row represents a straight line. The 5-dimensional row format is:
[point1.x, point1.y, point2.x, point2.y, width]
These are the parameters of lsd, which can be changed through keyword arguments of lsd call:
-
scale (float): Scale the image by Gaussian filter to 'scale'. -
sigma_scale (float): Sigma for Gaussian filter is computed assigma = sigma_scale / scale. -
quant (float): Bound to the quantization error on the gradient norm. -
ang_th (float): Gradient angle tolerance in degrees. -
eps (float): Detection threshold,-log10(NFA). -
density_th (float): Minimal density of region points in rectangle. -
n_bins (int): Number of bins in pseudo-ordering of gradient modulus. -
max_grad (float): Gradient modulus in the highest bin. The default value corresponds to the highest gradient modulus on images with gray levels in [0,255].
You can use it just like the following code (here is the link to examples):
- by using cv2 module
import cv2
import numpy as np
import os
from pylsd import lsd
full_name = 'car.jpg'
folder, img_name = os.path.split(full_name)
img = cv2.imread(full_name, cv2.IMREAD_COLOR)
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
segments = lsd(img_gray, scale=0.5)
for i in range(segments.shape[0]):
pt1 = (int(segments[i, 0]), int(segments[i, 1]))
pt2 = (int(segments[i, 2]), int(segments[i, 3]))
width = segments[i, 4]
cv2.line(img, pt1, pt2, (0, 0, 255), int(np.ceil(width / 2)))
cv2.imwrite(os.path.join(folder, 'cv2_' + img_name.split('.')[0] + '.jpg'), img)
- by using PIL(Image) module
import numpy as np
import os
from PIL import Image, ImageDraw
from pylsd import lsd
full_name = 'house.png'
folder, img_name = os.path.split(full_name)
img = Image.open(full_name)
img_gray = np.asarray(img.convert('L'))
segments = lsd(img_gray, scale=0.5)
draw = ImageDraw.Draw(img)
for i in range(segments.shape[0]):
pt1 = (int(segments[i, 0]), int(segments[i, 1]))
pt2 = (int(segments[i, 2]), int(segments[i, 3]))
width = segments[i, 4]
draw.line((pt1, pt2), fill=(0, 0, 255), width=int(np.ceil(width / 2)))
img.save(os.path.join(folder, 'PIL_' + img_name.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 pylsd-nova 1.2.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 | Provenance | Actions |
|---|---|---|---|---|
| pylsd-nova-1.2.1.tar.gz | 172.3 kB | Without provenance | Details for pylsd-nova-1.2.1.tar.gz |
Release files / pylsd-nova-1.2.1.tar.gz
| Download URL | pylsd-nova-1.2.1.tar.gz |
|---|---|
| Size | 172.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec8cf78c7059034e151c2cd9c069390cf7540bf7c60b2057c30f917acacd0de8
|
|
BLAKE2b-256 checksum How to use checksums |
8b3b1abd072eb4586f31e7ebe8f95a58fbf64a84fedf9a3ec21a982ae73c9605
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.7
|
Security for pylsd-nova 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.