Ejemplo n.º 1
0
 def calculateCenterOfMass(self):
     sumX = 0
     sumY = 0
     index = 0
     for _, point in enumerate(self.points):
         sumX += point.x * point.weight
         sumY += point.y * point.weight
         index += 1
     if (index > 0):
         self.cm = APoint(int(sumX / index), int(sumY / index))
     else:
         self.cm = APoint(0, 0)
     return self.cm
Ejemplo n.º 2
0
 def scalePoints(self, scaleFactor):
     scaledPoints = list()
     for _, point in enumerate(self.points):
         len_x = scaleFactor * (point.x - self.cm.x)
         len_y = scaleFactor * (point.y - self.cm.y)
         newPoint = APoint(len_x + self.cm.x, len_y + self.cm.y)
         scaledPoints.append(newPoint)
     self.points = scaledPoints
Ejemplo n.º 3
0
 def __init__(self, theName, theImage):
     self.name = theName
     self.image = theImage
     self.cm = APoint(0, 0)
     self.hits = list()
     if (len(self.image.shape) == 2):
         self.height, self.width = self.image.shape
     else:
         self.height, self.width, _ = self.image.shape
     if (self.traced):
         show(self.name, self.image)
Ejemplo n.º 4
0
 def moveScalePointOp(self, point, offsetAsPoint, angleData):
     #TODO: refactor, move out constants
     new_mass_center_x = self.cm.x + offsetAsPoint.x
     new_mass_center_y = self.cm.y + offsetAsPoint.y
     delta_x = point.x - self.cm.x
     delta_y = point.y - self.cm.y
     new_x = new_mass_center_x + (angleData.cosAngle *
                                  delta_x) - (angleData.sinAngle * delta_y)
     new_y = new_mass_center_y + (angleData.sinAngle *
                                  delta_x) + (angleData.cosAngle * delta_y)
     return APoint(new_x, new_y)
Ejemplo n.º 5
0
    def _get_perpendicularMiddleLine(self):
        # Calculate the average middle from the projections
        mx = my = 0
        projectionLines = self.projectionLines
        count = len(projectionLines) * 2  # Avoid double division of average
        for p, projectedP in projectionLines:
            mx += p.x + projectedP.x
            my += p.y + projectedP.y

        #FIXME: I'm not sure if APoint (from apoint.py) is the correct object to use here:
        m = APoint(mx / count, my / count)

        # Now project this window middle points on the two lines again.
        pp0 = self.point.getProjectedPoint(m)
        pp1 = self.parent.getProjectedPoint(m)
        return pp0, pp1
Ejemplo n.º 6
0
 def extractFeatures(self):
     imgInverted = cv2.bitwise_not(self.image)
     if (self.traced):
         show('Tracing this', imgInverted)
     mum_labels, labels, stats, centroids = cv2.connectedComponentsWithStats(
         imgInverted)
     self.points = list()
     if (self.traced):
         print(set(labels.reshape(-1).tolist()))
         output(str(centroids))
         output(str(labels))
         output(str(stats))
         output(' Labels count: ' + str(mum_labels))
     for i in range(mum_labels):
         # skip 0 item
         if (i != 0):
             point = APoint(centroids[i][0], centroids[i][1])
             self.points.append(point)
             if (self.traced):
                 output('Found: ' + str(i) + ' at:' + str(point.x) + '/' +
                        str(point.y))
     if (self.traced):
         self.showPoints(self.image, self.points)
Ejemplo n.º 7
0
 def findOffset(self):
     offsetX = self.dataTentative.centerOfMass(
     ).x - self.dataReference.centerOfMass().x
     offsetY = self.dataTentative.centerOfMass(
     ).y - self.dataReference.centerOfMass().y
     return APoint(offsetX, offsetY)