Harsh-7300 commited on
Commit
bb8e815
·
verified ·
1 Parent(s): 2f602e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -22
app.py CHANGED
@@ -3,7 +3,8 @@ import numpy as np
3
 
4
  def process_rooftop_image(image_path, geographic_bounds):
5
  """
6
- Process the rooftop image to detect rooftops, exclude shadows, and calculate real-world area.
 
7
 
8
  Parameters:
9
  image_path (str): Path to the input image (PNG or JPG).
@@ -12,7 +13,7 @@ def process_rooftop_image(image_path, geographic_bounds):
12
 
13
  Returns:
14
  final_image (numpy array): Image with predicted boundaries and excluded shadows.
15
- real_world_area (float): Computed rooftop area in square meters.
16
  """
17
  # Load the image
18
  image = cv2.imread(image_path)
@@ -69,30 +70,46 @@ def process_rooftop_image(image_path, geographic_bounds):
69
 
70
  # Conversion factor: real-world area per pixel
71
  conversion_factor = (lat_conversion * lon_conversion) / (image.shape[0] * image.shape[1])
72
- real_world_area = pixel_area * conversion_factor # in square meters
73
 
74
  # Step 9: Overlay contours on the original image
75
  final_image = image.copy()
76
  cv2.drawContours(final_image, contours, -1, (0, 255, 0), 2)
77
 
78
- return final_image, real_world_area
79
 
80
- # Example Usage
81
- geographic_bounds = {
82
- 'lat_min': 12.9716,
83
- 'lat_max': 12.9756,
84
- 'lon_min': 77.5946,
85
- 'lon_max': 77.5986,
86
- }
87
- input_image_path = "behindpmi.png"
88
 
89
- final_image, calculated_area = process_rooftop_image(input_image_path, geographic_bounds)
90
- print(f"Calculated Rooftop Area: {calculated_area:.2f} square meters")
91
-
92
- # Save the final image with contours
93
- cv2.imwrite("processed_image_with_boundaries.png", final_image)
94
-
95
- # Display the final image
96
- cv2.imshow("Rooftop Detection", final_image)
97
- cv2.waitKey(0)
98
- cv2.destroyAllWindows()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  def process_rooftop_image(image_path, geographic_bounds):
5
  """
6
+ Process the rooftop image to detect rooftops, exclude shadows,
7
+ and calculate usable area for solar panels.
8
 
9
  Parameters:
10
  image_path (str): Path to the input image (PNG or JPG).
 
13
 
14
  Returns:
15
  final_image (numpy array): Image with predicted boundaries and excluded shadows.
16
+ usable_area (float): Computed rooftop area usable for solar panels in square meters.
17
  """
18
  # Load the image
19
  image = cv2.imread(image_path)
 
70
 
71
  # Conversion factor: real-world area per pixel
72
  conversion_factor = (lat_conversion * lon_conversion) / (image.shape[0] * image.shape[1])
73
+ usable_area = pixel_area * conversion_factor # in square meters
74
 
75
  # Step 9: Overlay contours on the original image
76
  final_image = image.copy()
77
  cv2.drawContours(final_image, contours, -1, (0, 255, 0), 2)
78
 
79
+ return final_image, usable_area
80
 
 
 
 
 
 
 
 
 
81
 
82
+ if __name__ == "__main__":
83
+ # Prompt user for inputs
84
+ image_path = input("Enter the path to the rooftop image (PNG or JPG): ")
85
+ print("Enter the geographic bounds of the image:")
86
+ lat_min = float(input("Latitude Min: "))
87
+ lat_max = float(input("Latitude Max: "))
88
+ lon_min = float(input("Longitude Min: "))
89
+ lon_max = float(input("Longitude Max: "))
90
+
91
+ geographic_bounds = {
92
+ 'lat_min': lat_min,
93
+ 'lat_max': lat_max,
94
+ 'lon_min': lon_min,
95
+ 'lon_max': lon_max,
96
+ }
97
+
98
+ try:
99
+ # Process the image and calculate the usable area
100
+ final_image, calculated_area = process_rooftop_image(image_path, geographic_bounds)
101
+
102
+ # Save and display results
103
+ output_path = "output_rooftop_with_boundaries.jpg"
104
+ cv2.imwrite(output_path, final_image)
105
+
106
+ print(f"Usable Rooftop Area for Solar Panels: {calculated_area:.2f} square meters")
107
+ print(f"Processed image saved to: {output_path}")
108
+
109
+ # Display the final image with detected boundaries
110
+ cv2.imshow("Processed Rooftop", final_image)
111
+ cv2.waitKey(0)
112
+ cv2.destroyAllWindows()
113
+
114
+ except Exception as e:
115
+ print(f"Error: {e}")