# AUTOGENERATED! DO NOT EDIT! File to edit: ../Line.ipynb.

# %% auto 0
__all__ = ['LineFeature']

# %% ../Line.ipynb 3
import torch
import cv2
import numpy as np
import kornia


class LineFeature(nn.Module):
    def __init__(self, line_detector, dense_descriptor, matcher):
        super().__init__()
        self.line_detector = line_detector
        self.dense_descriptor = dense_descriptor
        self.matcher = matcher

    def detect_line_segments(self, image):
        return
    
    def get_image_descriptors(self, image):
        return
    
    def match_lines(self, input_dict={}):
        return 
    
    def forward(self, x:torch.Tensor, mask=None):
        max_val = x.max()
        if max_val < 2.0:
            img_np = (255 * kornia.tensor_to_image(x)).astype(np.uint8)
        else:
            img_np =  kornia.tensor_to_image(x).astype(np.uint8)
        if mask is not None:
            mask = kornia.tensor_to_image(x).astype(np.uint8)
        kpts = self.features.detect(img_np, mask)
        # Compute descriptors
        if self.make_upright:
            kpts = make_keypoints_upright(kpts)
            kpts = kpts[:min(len(kpts), self.max_kpts)]
        lafs, resp = laf_from_opencv_kpts(kpts, mrSize=self.mrSize, with_resp=True, device=x.device)
        return lafs, resp
