estimator

 avatar
unknown
python
3 years ago
2.4 kB
3
Indexable
'''
Created on 5 gru 2022

@author: SzymonPolak
'''

import cv2
import numpy as np
import math

class AnchorEstimator:
    def __init__(self):
        self.estimatedPoint = Point("anchorEstimatedPos",0,0)
        self.choosenPoint = Point("anchorEstimatedPos",0,0)
       
    def calcDistances(self, points):
        for pointA in points:
            for pointB in points:
                self.calcDistance(pointA, pointB)
        return
        
    def calcDistance(self, pointA, pointB):
        xAxisDiff = abs(pointA.x - pointB.x)
        yAxisDiff = abs(pointA.y - pointB.y)
        powered = math.pow(xAxisDiff,2)+math.pow(yAxisDiff,2)
        print("PointA:", pointA.x, pointA.y, "PointB:", pointB.x, pointB.y, "xdiff:",xAxisDiff, "ydiff:", yAxisDiff, "distance:", math.sqrt(powered))
        return math.sqrt(powered)
        
class Point():
    def __init__(self, name, x, y):
        self.x=x
        self.y=y
        self.name = name
    
    def setCoords(self, x, y):
        self.x = x
        self.y = y
            
    def drawPoint(self, image):
        radius = 5
        thickness = 2 
        coords = (self.x, self.y) 
        cv2.circle(image, coords, radius, (255,0,0), thickness)
        font = cv2.FONT_HERSHEY_SIMPLEX
        fontScale = 0.50
        color = (255, 0, 0)
        coords = (self.x-15, (self.y)+20)  
        cv2.putText(image, self.name, coords, font, fontScale, color, 1, cv2.LINE_AA)
        
    @staticmethod    
    def drawPoints( image, points):
        for point in points:
            point.drawPoint(image)
            
def createImage(height, width):
    image = np.zeros((width,height,3), np.uint8)
    image[0:height,0:width] = (255,255,255)  # white background
    return image
        
if __name__ == '__main__':
    print("Hello")
    anchorEstimator = AnchorEstimator()
    image = createImage(900, 900)
    #anchors = [ Point("0000", 200, 200), Point("1111", 400, 200), Point("2222", 600, 200), Point("3333", 200, 400), Point("4444", 400, 400), Point("5555", 600, 400), Point("6666", 200, 600), Point("7777", 400, 600), Point("8888", 600, 600)]
    anchorsTest = [ Point("0000", 200, 200), Point("1111", 400, 200), Point("2222", 600, 200) ]
    Point.drawPoints(image, anchorsTest)
    anchorEstimator.calcDistances(anchorsTest)
    cv2.imshow('frame', image)
    cv2.waitKey(3000)
    pass

Editor is loading...