import cv2 import numpy as np # Calculates the array limits def getLimits(array): idx = np.nonzero(array)[0] return [idx[0], idx[-1]] def fillHoles(array): nonzeroIdx = np.nonzero(array)[0] idx = np.arange(nonzeroIdx[0], nonzeroIdx[-1]) zeroIdx = idx[array[idx] == 0] for i in zeroIdx: array[i] = array[i-1] # Smoothes an array def smooth(array, halfKernel): dim = len(array) smoothedArray = np.zeros(dim) integralArray = np.cumsum(array) for i in range(dim): start = max(0, i - halfKernel) end = min(dim - 1, i + halfKernel) if start - 1 >= 0: smoothedArray[i] = (integralArray[end]- integralArray[start - 1])/(end + 1 - start) else: smoothedArray[i] = integralArray[end]/(end + 1) return smoothedArray # Calculates the color intensity from the array values def getColorIntensity(array, minValue, maxValue, exponent): return np.uint8(np.clip(255 * (np.power(array, exponent) - minValue) / (maxValue-minValue), 0, 255)) # Calculates the color intensity from the array values def getColorIntensityLog(array, maxValue, deltaValue): idx = np.nonzero(array) array[idx] = np.log10(array[idx]) + 2.3 return np.uint8(np.clip(255 * (array - maxValue)/ deltaValue, 0, 255)) # Calculates the value of a gaussian distribution with maximum value 1 def gaussianDistribution(x, mean, sigma): return np.exp(-0.5 * np.power((x - mean)/sigma, 2.0)) def writeCoordinates(frame, x, y, longitude, latitude): fontFace = cv2.FONT_HERSHEY_SIMPLEX fontScale = 0.8 thickness = 1 fontProperties = dict(fontFace=fontFace, fontScale=fontScale, color=(200, 200, 200), lineType=cv2.LINE_AA, thickness=thickness) cv2.putText(frame, 'l:', (x, y), **fontProperties) cv2.putText(frame, 'b:', (x + 170, y), **fontProperties) longitudeText = '{0:.2f},'.format(longitude) rect,baseline = cv2.getTextSize(longitudeText, fontFace, fontScale, thickness) cv2.putText(frame, longitudeText, (x + 145 - rect[0], y), **fontProperties) latitudeText = '{0:.2f}'.format(latitude) rect,baseline = cv2.getTextSize(latitudeText, fontFace, fontScale, thickness) cv2.putText(frame, latitudeText, (x + 280-rect[0], y), **fontProperties)