def get_mask(uid,fieldid,coordinates,fieldmaxlat,fieldminlat,fieldmaxlong,fieldminlong, field_name): import math import matplotlib.path from matplotlib.path import Path import numpy as np import cv2 from PIL import Image from merge_contour_images import merge_contour_images from oct2py import octave import collections import os import firebase_admin from firebase_admin import credentials from firebase_admin import db from create_index_piechart import create_index_piechart from create_soc_piechart import create_soc_piechart from merge_mask_img import merge_mask_img from estimate_yield import estimate_yield from merge_mask_img import merge_mask_img # from firebase_admin import messaging coordinates = collections.OrderedDict(sorted(coordinates.items())) # print(coordinates) tci_file_name = uid + '/' + fieldid + '/area_estimate_ndvi_' + field_name + '.png' tci = cv2.imread(tci_file_name,0) w_tci,h_tci = tci.shape centerx = round(w_tci/2) centery = round(h_tci/2) zero_lat = fieldmaxlat zero_long = fieldminlong print('coords') X = [] Y = [] pixelsperlat = h_tci/abs(float(fieldmaxlong)-float(fieldminlong)) pixelsperlong = w_tci/abs(float(fieldmaxlat)-float(fieldminlat)) pformatflag =0 for k,v in coordinates.items(): if k.find("P_")>=0: pformatflag = 1 break temp_lat = v['Latitude'] temp_long = v['Longitude'] temp_lat = float(temp_lat) temp_long = float(temp_long) x = round((temp_long-zero_long)*pixelsperlat) y = round((zero_lat-temp_lat)*pixelsperlong) # print(x) # print(y) X.append(x) Y.append(y) if pformatflag == 1: X = [] Y = [] ploc = 1 for k,v in coordinates.items(): pointKey = "P_" + str(ploc) ploc = ploc + 1 try: v = coordinates[pointKey] temp_lat = v['Latitude'] temp_long = v['Longitude'] temp_lat = float(temp_lat) temp_long = float(temp_long) x = round((temp_long-zero_long)*pixelsperlat) y = round((zero_lat-temp_lat)*pixelsperlong) # print(x) # print(y) X.append(x) Y.append(y) except: v = coordinates["a"] temp_lat = v['Latitude'] temp_long = v['Longitude'] temp_lat = float(temp_lat) temp_long = float(temp_long) x = round((temp_long-zero_long)*pixelsperlat) y = round((zero_lat-temp_lat)*pixelsperlong) # print(x) # print(y) X.append(x) Y.append(y) isdir = os.path.isdir(uid) if isdir != True: os.mkdir(uid) poly_m = octave.create_polymask(uid,fieldid,w_tci,h_tci,X,Y) area_pixels, total_pixels = merge_mask_img(uid,('area_estimate_ndvi_' +field_name), fieldid) #area_pixels, total_pixels = merge_mask_img(uid,(fieldid + '/area_estimate_ndvi_' +field_name)) # try: # merge_mask_img(uid, 'rvi_area_estimation') # except Exception as e: # print(e) return area_pixels, total_pixels