def taskDistance(): # if 'access' not in session: # return redirect('/') latitude = request.args.get('lat') longitude = request.args.get('lng') return jsonify(getDistance(gmaps, start_coords, latitude, longitude)), 200
def findClosestCont(conts, point): minDist = 10000 minCnt = None for cnt in conts: for p in cnt: # import pdb; pdb.set_trace() dist = helpers.getDistance(point, p) if dist < minDist: minDist = dist minCnt = cnt return minCnt
def test_ytick_coordinates(self): """ Setup: - Input Test Image (Already done) - Corners Assertion: - Check if the calculated 1st tick point is approximately correct Things to Find: - Corner Points - Actual Coordinates of the 1st tick point """ self.plot.corners = self.corners self.plot.findTicks() ticks = self.plot.y_ticks assert helper.getDistance(ticks[1], self.first_ytick) < 5
def getImageDistances(img, name): print('') # find center centerX = img.shape[0] // 2 centerY = img.shape[1] // 2 cloneImg = img.copy() # divide circle on the 12 sections for i, angle in enumerate(np.arange(0, 2 * math.pi, math.pi / 6)): distances = [] # rotate image to current angle cloneImg = imutils.rotate(img, angle=(i - 3) * 30) # draw center cv.circle(cloneImg, (centerX, centerY), 2, (255, 0, 0), 2) distances = [] # use 2 grad as one step for a in np.arange(0, math.pi / 6, math.pi / 90): # was red line or not innerPoint = None wasEnd = True # get line equalation endX = centerX + int(math.cos(a) * cloneImg.shape[0]) endY = centerY + int(math.sin(a) * cloneImg.shape[1]) eq = helpers.getEq((centerX, centerY), (endX, endY)) endX = min(endX, cloneImg.shape[0] - 1) endX = max(endX, 0) # get range maxX = max(centerX, endX) minX = min(centerX, endX) for x in range(minX, maxX): y = int(eq(x)) if y >= cloneImg.shape[1]: continue # get cell value cell = cloneImg[y, x] # it's black point if helpers.isBlack(cell) and not innerPoint: innerPoint = [x, y] elif not helpers.isBlack(cell) and innerPoint: # it's out point outPoint = [x, y] # get distance d = helpers.getDistance(innerPoint, outPoint) # too tiny if d < 3: continue # add distance distances.append(d) # draw line cv.line(cloneImg, (innerPoint[0], innerPoint[1]), (outPoint[0], outPoint[1]), colors[i], 1) break else: wasEnd = False if not wasEnd and innerPoint: outPoint = [ cloneImg.shape[0] - 1, int(eq(cloneImg.shape[0] - 1)) ] # get distance d = helpers.getDistance(innerPoint, outPoint) # too tiny if d < 3: continue # add distance distances.append(d) # draw line cv.line(cloneImg, (innerPoint[0], innerPoint[1]), (outPoint[0], outPoint[1]), colors[i], 1) cv.imshow(str(f"{name}_{i}"), cloneImg) print(f"Distance for {name} section {i+1} = {np.average(distances)}") print('')
def main(): photos = helpers.getImages('./in') for name, img in photos.items(): # find center centerX = img.shape[0] // 2 centerY = img.shape[1] // 2 cloneImg = img.copy() outContours = [] innerCountours = [] cv.circle(cloneImg, (centerX, centerY), 2, (255, 0, 0), 2) for i, angle in enumerate(np.arange(0, 2 * math.pi, math.pi / 6)): eY = centerY + int(math.sin(angle) * img.shape[1] // 2) eX = centerX + int(math.cos(angle) * img.shape[0] // 2) #cv.line(img, (centerX, centerY), (x, y), (0, 255, 255), 1) distances = [] for a in np.arange(angle, angle + math.pi / 6, math.pi / 180): innerPoint = None endX = centerX + int(math.cos(a) * img.shape[0]) endY = centerY + int(math.sin(a) * img.shape[1]) eq = helpers.getEq((centerX, centerY), (endX, endY)) endX = min(endX, img.shape[0] - 1) endX = max(endX, 0) maxX = max(centerX, endX) minX = min(centerX, endX) for x in range(minX, maxX): y = int(eq(x)) if y < 0 or y >= img.shape[1]: continue cell = img[y, x] if cell[0] == 0 and cell[1] == 0 and cell[2] == 255: if not innerPoint: innerPoint = [x, y] else: outPoint = [x, y] d = helpers.getDistance(innerPoint, outPoint) distances.append(d) cv.line(cloneImg, (innerPoint[0], innerPoint[1]), (x, y), colors[i], 1) break avgDistance = np.average(distances) print(f"Distance for {name} section {i+1} = {avgDistance}") #cv.line(img, (centerX, centerY), (eX, eY), (0, 255, 255), 1) cv.imshow(str(name), cloneImg) cv.waitKey(0) cv.destroyAllWindows()