Spaces:
Runtime error
Runtime error
Update src/app.py
Browse files- src/app.py +15 -7
src/app.py
CHANGED
|
@@ -1,18 +1,19 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
-
import
|
| 5 |
import plotly.express as px
|
| 6 |
|
| 7 |
st.set_page_config(layout="wide")
|
| 8 |
st.title("2D to 3D Reconstruction Demo")
|
| 9 |
|
| 10 |
-
# Load
|
| 11 |
-
with open("
|
| 12 |
-
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
|
|
|
| 16 |
|
| 17 |
sift = cv2.SIFT_create(nfeatures=nfeatures)
|
| 18 |
|
|
@@ -23,6 +24,9 @@ def match_and_reconstruct(img1, img2):
|
|
| 23 |
kp1, des1 = sift.detectAndCompute(gray1, None)
|
| 24 |
kp2, des2 = sift.detectAndCompute(gray2, None)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
| 26 |
bf = cv2.BFMatcher()
|
| 27 |
matches = bf.knnMatch(des1, des2, k=2)
|
| 28 |
|
|
@@ -38,6 +42,10 @@ def match_and_reconstruct(img1, img2):
|
|
| 38 |
pts2 = np.float32([kp2[m.trainIdx].pt for m in good])
|
| 39 |
|
| 40 |
E, _ = cv2.findEssentialMat(pts1, pts2, cv2.RANSAC, 0.999, 1.0)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
_, R, t, _ = cv2.recoverPose(E, pts1, pts2)
|
| 42 |
|
| 43 |
P1 = np.hstack((np.eye(3), np.zeros((3,1))))
|
|
@@ -72,4 +80,4 @@ if uploaded1 and uploaded2:
|
|
| 72 |
)
|
| 73 |
st.plotly_chart(fig, use_container_width=True)
|
| 74 |
else:
|
| 75 |
-
st.error("Not enough matches found.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
+
import pickle
|
| 5 |
import plotly.express as px
|
| 6 |
|
| 7 |
st.set_page_config(layout="wide")
|
| 8 |
st.title("2D to 3D Reconstruction Demo")
|
| 9 |
|
| 10 |
+
# Load SFM model
|
| 11 |
+
with open("sfm_model.pkl", "rb") as f:
|
| 12 |
+
model = pickle.load(f)
|
| 13 |
|
| 14 |
+
# Eğer model dict olarak kaydedildiyse:
|
| 15 |
+
nfeatures = model.get("nfeatures", 2000)
|
| 16 |
+
ratio_thresh = model.get("ratio_test_threshold", 0.75)
|
| 17 |
|
| 18 |
sift = cv2.SIFT_create(nfeatures=nfeatures)
|
| 19 |
|
|
|
|
| 24 |
kp1, des1 = sift.detectAndCompute(gray1, None)
|
| 25 |
kp2, des2 = sift.detectAndCompute(gray2, None)
|
| 26 |
|
| 27 |
+
if des1 is None or des2 is None:
|
| 28 |
+
return None
|
| 29 |
+
|
| 30 |
bf = cv2.BFMatcher()
|
| 31 |
matches = bf.knnMatch(des1, des2, k=2)
|
| 32 |
|
|
|
|
| 42 |
pts2 = np.float32([kp2[m.trainIdx].pt for m in good])
|
| 43 |
|
| 44 |
E, _ = cv2.findEssentialMat(pts1, pts2, cv2.RANSAC, 0.999, 1.0)
|
| 45 |
+
|
| 46 |
+
if E is None:
|
| 47 |
+
return None
|
| 48 |
+
|
| 49 |
_, R, t, _ = cv2.recoverPose(E, pts1, pts2)
|
| 50 |
|
| 51 |
P1 = np.hstack((np.eye(3), np.zeros((3,1))))
|
|
|
|
| 80 |
)
|
| 81 |
st.plotly_chart(fig, use_container_width=True)
|
| 82 |
else:
|
| 83 |
+
st.error("Not enough matches found.")
|