Analysis
The collected images were analyzed by the computer vision model to detect crops, area coverage of crops was computed and the percentage coverage of each crop was returned.
Tech stack
-
Analyzing images: The computer vision model used was the IBM-Nasa pretrained model available on HuggingFace.
-
Computing area coverage:
OpenCV
was used for this task.
Code snippets
Analyzing images
client = Client("https://ibm-nasa-geospatial-prithvi-100m-multi-temporal-f3e6c26.hf.space/--replicas/809evt65j/")
result = client.predict(file, fn_index=0)
im = Image.open(result[3])
im.save(output + f"-{year}-{season}" + ".jpg")
Area coverage
def calculate_color_percentage(image_path, color):
"""
Each crop is signified by a specific color in the analyzed image
"""
image = cv2.imread(image_path)
hsv_image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
color_lower = np.array(color[0], dtype=np.uint8)
color_upper = np.array(color[1], dtype=np.uint8)
color_mask = cv2.inRange(hsv_image, color_lower, color_upper)
color_pixel_count = cv2.countNonZero(color_mask)
total_pixels = image.shape[0] * image.shape[1]
color_percentage = (color_pixel_count / total_pixels) * 100
return color_percentage