forked from cvg/limap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove official TP-LSD submodule * Added TP-LSD line detector * Minor fix in ReadMe * add M6D and M8D definitions in limap. * include tp_lsd into requirements.txt. * minor update on readme. * Install TP-LSD in dev mode Co-authored-by: B1ueber2y <[email protected]>
- Loading branch information
Showing
12 changed files
with
100 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,7 @@ | |
[submodule "third-party/hawp"] | ||
path = third-party/hawp | ||
url = [email protected]:cherubicXN/hawp.git | ||
ignore = dirty | ||
ignore = dirty | ||
[submodule "third-party/TP-LSD"] | ||
path = third-party/TP-LSD | ||
url = [email protected]:rpautrat/TP-LSD.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .tp_lsd import TPLSDDetector |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os, sys | ||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
from base_detector import BaseDetector, BaseDetectorOptions | ||
|
||
import cv2 | ||
import numpy as np | ||
import torch | ||
from tp_lsd.utils.reconstruct import TPS_line | ||
from tp_lsd.utils.utils import load_model | ||
from tp_lsd.modeling.TP_Net import Res320 | ||
|
||
|
||
class TPLSDDetector(BaseDetector): | ||
def __init__(self, options = BaseDetectorOptions()): | ||
super(TPLSDDetector, self).__init__(options) | ||
# Load the TP-LSD model | ||
head = {'center': 1, 'dis': 4, 'line': 1} | ||
ckpt = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))), | ||
'third-party/TP-LSD/pretraineds/Res512.pth') | ||
self.net = load_model(Res320(head), ckpt) | ||
self.net = self.net.cuda().eval() | ||
|
||
def get_module_name(self): | ||
return "tp_lsd" | ||
|
||
def detect(self, camview): | ||
img = camview.read_image(set_gray=False) | ||
segs = self.detect_tplsd(img, self.net) | ||
return segs | ||
|
||
def detect_tplsd(self, img, net): | ||
H, W = img.shape[:2] | ||
hsv = cv2.cvtColor(img, cv2.COLOR_RGB2HSV) | ||
imgv0 = hsv[..., 2] | ||
imgv = cv2.resize(imgv0, (0, 0), fx=1. / 4, fy=1. / 4, interpolation=cv2.INTER_LINEAR) | ||
imgv = cv2.GaussianBlur(imgv, (5, 5), 3) | ||
imgv = cv2.resize(imgv, (W, H), interpolation=cv2.INTER_LINEAR) | ||
imgv = cv2.GaussianBlur(imgv, (5, 5), 3) | ||
|
||
imgv1 = imgv0.astype(np.float32) - imgv + 127.5 | ||
imgv1 = np.clip(imgv1, 0, 255).astype(np.uint8) | ||
hsv[..., 2] = imgv1 | ||
inp = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR) | ||
|
||
inp = (inp.astype(np.float32) / 255.) | ||
inp = torch.from_numpy(inp.transpose(2, 0, 1)).unsqueeze(0).cuda() | ||
with torch.no_grad(): | ||
outputs = net(inp) | ||
lines = TPS_line(outputs[-1], 0.25, 0.5, H, W)[0].reshape(-1, 2, 2) | ||
|
||
# Use the line length as score | ||
lines = np.concatenate([ | ||
lines.reshape(-1, 4), | ||
np.linalg.norm(lines[:, 0] - lines[:, 1], axis=1, keepdims=True)], | ||
axis=1) | ||
|
||
return lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters