Coder Social home page Coder Social logo

pylsd2's Introduction

pylsd2

1. Introduction

pylsd2 is the python bindings for Line Segment Detection algorithm, including LSD and EDLines.

  • LSD part is forked frompylsd, and upgrade lsd from 1.5 to 1.6, thanks primetang
  • EDLines part is forked fromline_detector, thanks frotms

Windows and linux is supported currently, merge request for mac is welcome

2. Install

directly through pip to install it:

[sudo] pip install pylsd2

3. Usage

  • by using cv2 module
import cv2
from pylsd2 import LineSegmentDetection, LineSegmentDetectionED
fullName, out_path = 'car.jpg', 'car_lsd.jpg'
src = cv2.imread(fullName, cv2.IMREAD_COLOR)
gray = cv2.cvtColor(src, cv2.COLOR_BGR2GRAY)
# input single channel image
lines = LineSegmentDetection(gray)  # [(x1, y1, x2, y2, width, p, log_nfa), ...]
# lines = LineSegmentDetectionED(gray)  # [(x1, y1, x2, y2), ...]
for l in lines:
    pt1, pt2 = tuple(l[:2]), tuple(l[2:4])
    cv2.line(src, pt1, pt2, (0, 0, 255), 1)
cv2.imwrite(out_path, src)
  • by using PIL(Image) module
from PIL import Image, ImageDraw
import numpy as np
from pylsd2 import LineSegmentDetection, LineSegmentDetectionED
fullName, out_path = 'car.jpg', 'car_edlines.jpg'
img = Image.open(fullName)
gray = np.asarray(img.convert('L'))
# input single channel image
# lines = LineSegmentDetection(gray)
lines = LineSegmentDetectionED(gray)
draw = ImageDraw.Draw(img)
for l in lines:
    pt1, pt2 = l[:2], l[2:4]
    draw.line((pt1, pt2), fill=(0, 0, 255), width=1)
img.save(out_path)

more examples:

The following is the result:

  • car.jpg Original

  • with lsd algorithm

  • with EDLines algorithm

  • house.png Original

  • with lsd algorithm

  • with EDLines algorithm

  • chairs.jpg Original

  • with lsd algorithm

  • with EDLines algorithm

4. Compile Library from cpp

4.1 Compile For LSD

** Windows **

cd source/lsd && mkdir build && cd build
cmake ..

open the LSD.sln with Visual Studio, and Build The "ALL_BUILD" Project ** Linux **

cd source/lsd && mkdir build_so && cd build_so
cmake ..
cmake --build .

4.2 Compile For EDLines

** Windows **

cd source/edlines && mkdir build && cd build
cmake ..

open the EDLines.sln with Visual Studio, and Build The "ALL_BUILD" Project ** Linux **

cd source/edlines && mkdir build_so && cd build_so
cmake ..
cmake --build .

pylsd2's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.