Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,75 +1,20 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import cv2
|
| 3 |
-
import numpy as np
|
| 4 |
-
import plotly.graph_objects as go
|
| 5 |
from PIL import Image
|
|
|
|
| 6 |
|
| 7 |
-
def
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
keypoints, descriptors = orb.detectAndCompute(gray, None)
|
| 11 |
-
return keypoints, descriptors
|
| 12 |
-
|
| 13 |
-
def match_features(desc1, desc2):
|
| 14 |
-
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
|
| 15 |
-
matches = bf.match(desc1, desc2)
|
| 16 |
-
matches = sorted(matches, key=lambda x: x.distance)
|
| 17 |
-
return matches[:50] # Keep top 50 matches
|
| 18 |
-
|
| 19 |
-
def create_point_cloud(images):
|
| 20 |
-
if len(images) < 2:
|
| 21 |
-
st.error("Please upload at least two images.")
|
| 22 |
-
return None
|
| 23 |
-
|
| 24 |
-
keypoints_list = []
|
| 25 |
-
descriptors_list = []
|
| 26 |
-
for image in images:
|
| 27 |
-
kp, desc = preprocess_image(image)
|
| 28 |
-
keypoints_list.append(kp)
|
| 29 |
-
descriptors_list.append(desc)
|
| 30 |
-
|
| 31 |
-
points_3d = []
|
| 32 |
-
for i in range(len(images) - 1):
|
| 33 |
-
matches = match_features(descriptors_list[i], descriptors_list[i+1])
|
| 34 |
-
for match in matches:
|
| 35 |
-
pt1 = keypoints_list[i][match.queryIdx].pt
|
| 36 |
-
pt2 = keypoints_list[i+1][match.trainIdx].pt
|
| 37 |
-
x = (pt1[0] + pt2[0]) / 2
|
| 38 |
-
y = (pt1[1] + pt2[1]) / 2
|
| 39 |
-
z = len(matches) - match.distance
|
| 40 |
-
points_3d.append([x, y, z])
|
| 41 |
-
|
| 42 |
-
return np.array(points_3d)
|
| 43 |
-
|
| 44 |
-
def visualize_point_cloud(points):
|
| 45 |
-
fig = go.Figure(data=[go.Scatter3d(
|
| 46 |
-
x=points[:, 0],
|
| 47 |
-
y=points[:, 1],
|
| 48 |
-
z=points[:, 2],
|
| 49 |
-
mode='markers',
|
| 50 |
-
marker=dict(
|
| 51 |
-
size=2,
|
| 52 |
-
color=points[:, 2],
|
| 53 |
-
colorscale='Viridis',
|
| 54 |
-
opacity=0.8
|
| 55 |
-
)
|
| 56 |
-
)])
|
| 57 |
-
fig.update_layout(margin=dict(l=0, r=0, b=0, t=0))
|
| 58 |
-
return fig
|
| 59 |
|
| 60 |
-
st.
|
| 61 |
-
st.write("Upload multiple images of an object from different angles to generate a basic point cloud.")
|
| 62 |
|
| 63 |
-
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
|
|
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
point_cloud = create_point_cloud(images)
|
| 71 |
-
if point_cloud is not None and len(point_cloud) > 0:
|
| 72 |
-
fig = visualize_point_cloud(point_cloud)
|
| 73 |
-
st.plotly_chart(fig, use_container_width=True)
|
| 74 |
-
else:
|
| 75 |
-
st.error("Failed to create point cloud. Please try with different images.")
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 2 |
from PIL import Image
|
| 3 |
+
import numpy as np
|
| 4 |
|
| 5 |
+
def main():
|
| 6 |
+
st.title("Simple Image Uploader")
|
| 7 |
+
st.write("Upload an image to display it.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
uploaded_file = st.file_uploader("Choose an image", type=['png', 'jpg', 'jpeg'])
|
|
|
|
| 10 |
|
| 11 |
+
if uploaded_file is not None:
|
| 12 |
+
image = Image.open(uploaded_file)
|
| 13 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 14 |
|
| 15 |
+
# Display image information
|
| 16 |
+
st.write(f"Image size: {image.size}")
|
| 17 |
+
st.write(f"Image format: {image.format}")
|
| 18 |
|
| 19 |
+
if __name__ == "__main__":
|
| 20 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|