import os import leafmap from samgeo import tms_to_geotiff import rasterio from rasterio.plot import show import subprocess import re # m = leafmap.Map(center=[16.836161, 81.047963], zoom=17) # m.add_basemap("SATELLITE") bbox = [81.0426, 16.8328, 81.0538, 16.8421] from samgeo import SamGeo, tms_to_geotiff, get_basemaps img_path = "/content/field.tif" tms_to_geotiff(output=img_path, bbox=bbox, zoom=17, source="Satellite", overwrite=True) label='Palm_Treess' yolo_command = [ "python", "/content/yolov5/detect.py", "--weights", "/content/drive/MyDrive/palm/best.pt", "--img", "640", "--conf", "0.25", "--source", img_path ] output = subprocess.check_output(yolo_command, text=True, stderr=subprocess.STDOUT) result_lines = output.split('\n') total_count = 0 for line in result_lines: match = re.search(rf"(\d+) {label}", line) if match: number_of_palms = int(match.group(1)) total_count += number_of_palms print(f"Total number of palms detected: {total_count}")