Spaces:
Runtime error
Runtime error
File size: 2,079 Bytes
7cf7dd1 7a4ceef 7cf7dd1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
from cProfile import label
import gradio as gr
import cv2
import matplotlib.pyplot as plt
from scipy import ndimage
from scipy.ndimage.filters import convolve
import numpy as np
def sift(img1, img2):
sift = cv2.SIFT_create()
keypoints_1, descriptors_1 = sift.detectAndCompute(img1,None)
keypoints_2, descriptors_2 = sift.detectAndCompute(img2,None)
bf = cv2.BFMatcher(cv2.NORM_L1, crossCheck=True)
matches = bf.match(descriptors_1,descriptors_2)
matches = sorted(matches, key = lambda x:x.distance)
img3 = cv2.drawMatches(img1, keypoints_1, img2, keypoints_2, matches[:50], img2, flags=2)
return img3
def orb(img1, img2):
orb = cv2.ORB_create()
keypoints_1, descriptors_1 = orb.detectAndCompute(img1,None)
keypoints_2, descriptors_2 = orb.detectAndCompute(img2,None)
bf = cv2.BFMatcher(cv2.NORM_L1, crossCheck=True)
matches = bf.match(descriptors_1,descriptors_2)
matches = sorted(matches, key = lambda x:x.distance)
img3 = cv2.drawMatches(img1, keypoints_1, img2, keypoints_2, matches[:50], img2, flags=2)
return img3
def match(img1, img2):
img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
sift_res = sift(img1, img2)
orb_res = orb(img1, img2)
return [sift_res, orb_res]
interface = gr.Interface(
title = "SIFT and ORB Image Matching ๐ผ ๐ ๐ผ",
description = "<h3>Scale Invariant Feature Transform (SIFT) & Oriented FAST and Rotated BRIEF (ORB) </h3> <br> <b>Select training and query images ๐ผ</b>",
article='~ Ivanrs',
allow_flagging = "never",
fn = match,
inputs = [
gr.Image(label = "Train Image", shape = [300, 200]),
gr.Image(label = "Query Image", shape = [300, 200]),
],
outputs = [
gr.Image(label = "SIFT Output"),
gr.Image(label = "ORB Output"),
],
examples = [
["img1.jpg", "img2.jpg"],
["img3.jpg", "img4.jpg"],
["img5.jpg", "img6.png"],
["img7.jpeg", "img8.jpeg"]
]
)
interface.launch(share = False) |