from generic_method import GenericMethod
import cv2 as cv
import matplotlib.pyplot as plt
import time



class ORBMethod(GenericMethod):
    
    grayscale = True
    
    def __init__(self):
        self.name= "ORB" 
        self.orb = cv.ORB_create(10000, 2, 5)
        
        
    def match(self, output_write_path= None):
        start_time = time.time()
        img1 = self.img_temp
        img2 = self.img_full
       
        
        kp1, des1 = self.orb.detectAndCompute(img1,None)
        kp2, des2 = self.orb.detectAndCompute(img2,None)
        
        
        FLANN_INDEX_LSH = 6
        index_params= dict(algorithm = FLANN_INDEX_LSH,
                           table_number = 6,
                           key_size = 1,
                           multi_probe_level = 1)
        search_params=dict(checks=32)
        
        matcher = cv.FlannBasedMatcher(index_params, search_params)

        matches = matcher.knnMatch(des1, des2, 2)
        
        top_left, bottom_right, img_output = self.get_rect_feature_based(matches, kp1,kp2, img1.copy(), img2.copy())
        if(output_write_path):
            plt.imshow(img_output)
            plt.show()
            cv.imwrite(output_write_path,img_output)
        
        #return execution_time
        return time.time() - start_time, top_left, bottom_right
from generic_method import GenericMethod
import cv2 as cv
import matplotlib.pyplot as plt
import time



class ORBMethod(GenericMethod):
    
    grayscale = True
    
    def __init__(self):
        self.name= "ORB" 
        self.orb = cv.ORB_create(10000, 2, 5)
        
        
    def match(self, output_write_path= None):
        start_time = time.time()
        img1 = self.img_temp
        img2 = self.img_full
       
        
        kp1, des1 = self.orb.detectAndCompute(img1,None)
        kp2, des2 = self.orb.detectAndCompute(img2,None)
        
        
        FLANN_INDEX_LSH = 6
        index_params= dict(algorithm = FLANN_INDEX_LSH,
                           table_number = 6,
                           key_size = 1,
                           multi_probe_level = 1)
        search_params=dict(checks=32)
        
        matcher = cv.FlannBasedMatcher(index_params, search_params)

        matches = matcher.knnMatch(des1, des2, 2)
        
        top_left, bottom_right, img_output = self.get_rect_feature_based(matches, kp1,kp2, img1.copy(), img2.copy())
        if(output_write_path):
            plt.imshow(img_output)
            plt.show()
            cv.imwrite(output_write_path,img_output)
        
        #return execution_time
        return time.time() - start_time, top_left, bottom_right
#return execution_time