lsd程序matlab,lsd python程序

920487fbef17

920487fbef17

example_cv2.py

import cv2

import numpy as np

import os

from pylsd1.lsd import *

fullName = 'xian3.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 range(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)

lsd.py

from .bindings.lsd_ctypes import *

def lsd(src):

rows, cols = src.shape

src = src.reshape(1, rows * cols).tolist()[0]

temp = os.path.abspath(str(np.random.randint(

1, 1000000)) + 'ntl.txt').replace('\\', '/').encode('utf-8')

lens = len(src)

src = (ctypes.c_double * lens)(*src)

lsdlib.lsdGet(src, ctypes.c_int(rows), ctypes.c_int(cols), ctypes.c_char_p(temp))

fp = open(temp, 'r')

cnt = fp.read().strip().split(' ')

fp.close()

os.remove(temp)

count = int(cnt[0])

dim = int(cnt[1])

lines = np.array([float(each) for each in cnt[2:]])

lines = lines.reshape(count, dim)

return lines

__init__.py

from . import lsd

lsd_ctypes.py

import ctypes

import os

import sys

import random

import numpy as np

def load_lsd_library():

root_dir = os.path.abspath(os.path.dirname(__file__))

libnames = ['linux/liblsd.so']

libdir = 'lib'

if sys.platform == 'win32':

if sys.maxsize > 2 ** 32:

libnames = ['win32/x64/lsd.dll', 'win32/x64/liblsd.dll']

else:

libnames = ['win32/x86/lsd.dll', 'win32/x86/liblsd.dll']

elif sys.platform == 'darwin':

libnames = ['darwin/liblsd.dylib']

while root_dir != None:

for libname in libnames:

try:

lsdlib = ctypes.cdll[os.path.join(root_dir, libdir, libname)]

return lsdlib

except Exception as e:

pass

tmp = os.path.dirname(root_dir)

if tmp == root_dir:

root_dir = None

else:

root_dir = tmp

# if we didn't find the library so far, try loading without

# a full path as a last resort

for libname in libnames:

try:

# print "Trying",libname

lsdlib = ctypes.cdll[libname]

return lsdlib

except:

pass

return None

lsdlib = load_lsd_library()

if lsdlib == None:

raise ImportError('Cannot load dynamic library. Did you compile LSD?')

__init__.py   (bindings文件目录下)

from .lsd_ctypes import *

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值