Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,9 @@ import streamlit as st
|
|
| 5 |
from skimage import measure
|
| 6 |
from io import BytesIO
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
def preprocess_image(image):
|
| 9 |
img = cv2.imdecode(np.frombuffer(image.read(), np.uint8), cv2.IMREAD_COLOR)
|
| 10 |
|
|
@@ -34,10 +37,12 @@ def draw_contours(image, contours):
|
|
| 34 |
cv2.drawContours(output_image, contours, -1, (0, 255, 0), 3)
|
| 35 |
return output_image
|
| 36 |
|
| 37 |
-
def
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
def remove_shadows(image):
|
| 43 |
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
|
@@ -75,12 +80,12 @@ def main():
|
|
| 75 |
# Step 6: Draw the predicted rooftop boundaries
|
| 76 |
output_img = draw_contours(image_no_shadows, filtered_contours)
|
| 77 |
|
| 78 |
-
# Step 7: Calculate the area of the rooftop
|
| 79 |
-
total_area =
|
| 80 |
|
| 81 |
# Step 8: Display the result
|
| 82 |
st.image(output_img, channels="BGR", caption="Detected Rooftop with Boundaries")
|
| 83 |
-
st.write(f"Total Rooftop Area: {total_area}
|
| 84 |
|
| 85 |
if __name__ == "__main__":
|
| 86 |
main()
|
|
|
|
| 5 |
from skimage import measure
|
| 6 |
from io import BytesIO
|
| 7 |
|
| 8 |
+
# Define the scale factor: 1 pixel = X meters (for example, 1 pixel = 0.5 meter)
|
| 9 |
+
SCALE_FACTOR = 0.5 # In meters, adjust as per your image's scale
|
| 10 |
+
|
| 11 |
def preprocess_image(image):
|
| 12 |
img = cv2.imdecode(np.frombuffer(image.read(), np.uint8), cv2.IMREAD_COLOR)
|
| 13 |
|
|
|
|
| 37 |
cv2.drawContours(output_image, contours, -1, (0, 255, 0), 3)
|
| 38 |
return output_image
|
| 39 |
|
| 40 |
+
def calculate_area_in_meters(contours):
|
| 41 |
+
total_area_pixels = sum(cv2.contourArea(contour) for contour in contours)
|
| 42 |
+
|
| 43 |
+
# Convert pixel area to real-world area (in square meters)
|
| 44 |
+
total_area_meters = total_area_pixels * (SCALE_FACTOR ** 2)
|
| 45 |
+
return total_area_meters
|
| 46 |
|
| 47 |
def remove_shadows(image):
|
| 48 |
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
|
|
|
|
| 80 |
# Step 6: Draw the predicted rooftop boundaries
|
| 81 |
output_img = draw_contours(image_no_shadows, filtered_contours)
|
| 82 |
|
| 83 |
+
# Step 7: Calculate the actual area of the rooftop (in square meters)
|
| 84 |
+
total_area = calculate_area_in_meters(filtered_contours)
|
| 85 |
|
| 86 |
# Step 8: Display the result
|
| 87 |
st.image(output_img, channels="BGR", caption="Detected Rooftop with Boundaries")
|
| 88 |
+
st.write(f"Total Rooftop Area: {total_area:.2f} square meters")
|
| 89 |
|
| 90 |
if __name__ == "__main__":
|
| 91 |
main()
|