Example #1
0
 def ProjectLineSegmentEnds(self):
     projLineSegments = []
     for ls in self._lineSegments:
         lss = ls.startPoint
         lse = ls.endPoint
         lssp = MathUtils.ProjectToLine2(self._line.startPoint,
                                         self._line.endPoint, lss)
         lsep = MathUtils.ProjectToLine2(self._line.startPoint,
                                         self._line.endPoint, lse)
         lsp = Line2(lssp, lsep)
         projLineSegments.append(lsp)
     self._lineSegments = projLineSegments
Example #2
0
    def ArrowHeadDirection(Feature_Manager):
        OriginalImg = Feature_Manager._ImageOriginal.copy()
        OutputImg = OriginalImg.copy()
        DimensionalLines = Feature_Manager._DetectedDimensionalLine
        ArrowHeadsList = Feature_Manager._DetectedArrowHead
        for dl in DimensionalLines:
            for ah in dl._ArrowHeads:
                p1 = ah._BoundingBoxP1
                p2 = ah._BoundingBoxP2
                TempImg = OriginalImg[p1.y:p2.y + 4, p1.x:p2.x + 4]
                TempImg = ImgTransform.ImgAspectResize(TempImg, 100, 100)

                cornerImg = TempImg.copy()
                gray = cv2.cvtColor(TempImg, cv2.COLOR_BGR2GRAY)
                corners = cv2.goodFeaturesToTrack(gray, 20, 0.09, 10, True)
                corners = np.int0(corners)
                cornerPts = []
                xpts = []
                ypts = []
                for i in corners:
                    x, y = i.ravel()
                    p = Point2(x, y)
                    xpts.append(x)
                    ypts.append(y)
                    cornerPts.append(p)
                    cv2.circle(cornerImg, (x, y), 1, 255, -1)
                xc = np.mean(xpts)
                yc = np.mean(ypts)
                c = Point2(xc, yc)
                dictPt = {}
                for i in cornerPts:
                    d = sqrt((c.x - i.x)**2 + (c.y - i.y)**2)
                    dictPt[i] = d
                sortedDict = sorted(dictPt.items(), key=operator.itemgetter(1))
                extremePt = sortedDict[len(sortedDict) - 1][0]
                cv2.circle(cornerImg, (extremePt.x, extremePt.y), 3, 255, -1)
                projectedPt = MathUtils.ProjectToLine2(
                    dl._Leaders[0].startPoint, dl._Leaders[0].endPoint,
                    extremePt)
                projectedCorner = MathUtils.ProjectToLine2(
                    dl._Leaders[0].startPoint, dl._Leaders[0].endPoint, c)
                Direction = Cognition.GetDirection(projectedPt,
                                                   projectedCorner)
                ah._Direction = Direction
                Cognition.AssignArrowHeadsDirection(ArrowHeadsList,
                                                    ah._ArrowCenter, Direction)
                print(Direction)
Example #3
0
 def ProjectCorners(self):
     corners = self._cornerPoints
     projCorners = []
     for cp in corners:
         pcp = MathUtils.ProjectToLine2(self._line.startPoint,
                                        self._line.endPoint, cp)
         projCorners.append(pcp)
     self._cornerPoints = projCorners
Example #4
0
 def SetEnds(self):
     points = []
     numCorners = len(self._cornerPoints)
     if numCorners >= 1:
         lsp1, lsp2 = SpecialLineSegments.SeggregatePoints(
             self._lineSegments, self._line)
         lsp1 = MathUtils.ProjectToLine2(self._line.startPoint,
                                         self._line.endPoint, lsp1)
         lsp2 = MathUtils.ProjectToLine2(self._line.startPoint,
                                         self._line.endPoint, lsp2)
         cs = self._cornerPoints[0]
         ce = self._cornerPoints[numCorners - 1]
         points.append(lsp1)
         points.append(lsp2)
         points.append(cs)
         points.append(ce)
         sortedEndPts = SpecialLineSegments.sortPoints(points, self._line)
         numPts = len(sortedEndPts)
         s = sortedEndPts[0]
         e = sortedEndPts[numPts - 1]
         line = Line2(s, e)
         self._line = line
Example #5
0
    def EntityCorrelation(Feature_Manager):
        entityLines = Feature_Manager._DetectedLine
        dimensions = Feature_Manager._DetectedDimension
        EntitiesCorrelated = []
        for d in dimensions:
            CorrelatedLines = []
            cE = CorrelatedEntity()
            for a in d._DimensionalLines._ArrowHeads:
                BB = Cognition.SortCoordinates(
                    [a._BoundingBoxP1, a._BoundingBoxP2])
                bbMin = BB[0]
                bbMax = BB[1]
                direction = a._Direction
                if direction == "West":
                    shortListedLines = []
                    for l in entityLines:
                        if bbMin.x + 3 > l.startPoint.x and fabs(
                                l.endPoint.x - l.startPoint.x) < 3 and fabs(
                                    l.endPoint.y - l.startPoint.y) > 5:
                            shortListedLines.append(l)

                    for l in shortListedLines:
                        projectedPt = MathUtils.ProjectToLine2(
                            l.startPoint, l.endPoint, bbMin)
                        projectedDistance = bbMin.DistanceTo(projectedPt)
                        if projectedDistance < 8:  #<7
                            CorrelatedLines.append(l)

                elif direction == "East":
                    shortListedLines = []
                    for l in entityLines:

                        if bbMax.x - 3 < l.startPoint.x and fabs(
                                l.endPoint.x - l.startPoint.x) < 3 and fabs(
                                    l.endPoint.y - l.startPoint.y) > 5:
                            shortListedLines.append(l)

                    for l in shortListedLines:

                        projectedPt = MathUtils.ProjectToLine2(
                            l.startPoint, l.endPoint, bbMax)
                        projectedDistance = bbMax.DistanceTo(projectedPt)
                        if projectedDistance < 8:  #<7
                            CorrelatedLines.append(l)

                elif direction == "North":
                    shortListedLines = []
                    for l in entityLines:
                        if bbMin.y + 3 > l.startPoint.y and fabs(
                                l.endPoint.y - l.startPoint.y) < 3 and fabs(
                                    l.endPoint.x - l.startPoint.x) > 5:
                            shortListedLines.append(l)

                    for l in shortListedLines:
                        projectedPt = MathUtils.ProjectToLine2(
                            l.startPoint, l.endPoint, bbMin)
                        projectedDistance = bbMin.DistanceTo(projectedPt)
                        if projectedDistance < 8:  #<7
                            CorrelatedLines.append(l)

                elif direction == "South":
                    shortListedLines = []
                    for l in entityLines:
                        if bbMax.y - 3 < l.startPoint.y and fabs(
                                l.endPoint.y - l.startPoint.y) < 3 and fabs(
                                    l.endPoint.x - l.startPoint.x) > 5:
                            shortListedLines.append(l)

                    for l in shortListedLines:
                        projectedPt = MathUtils.ProjectToLine2(
                            l.startPoint, l.endPoint, bbMax)
                        projectedDistance = bbMax.DistanceTo(projectedPt)
                        if projectedDistance < 8:  #<7
                            CorrelatedLines.append(l)

            cE.ExtractCorrelatedEntity(cE, d, CorrelatedLines)
            EntitiesCorrelated.append(cE)
        Feature_Manager._CorrelatedEntities = EntitiesCorrelated
Example #6
0
    def Detect(Feature_Manager):

        lines = Feature_Manager._DetectedLine
        dimension = Feature_Manager._DetectedDimension
        supportLinesegments = []
        entityLinesegments = []
        dist_Img = Cognition.DistanceTransform(Feature_Manager._ImageCleaned)
        minVal, maxVal, minLoc, maxLoc = cv2.minMaxLoc(dist_Img)
        for l in lines:
            for seg in l:
                PointsBetweenLine = SpecialLineSegments.PixelScanner(
                    seg.startPoint, seg.endPoint, dist_Img)
                sLinesPoints = []
                eLinePoints = []
                for i in PointsBetweenLine:
                    t = Cognition.CheckThicknessInVicinity(
                        i[0], i[1], dist_Img)
                    pt = Point2(i[0], i[1])
                    if t is None:
                        continue
                    if t <= 0.6 * maxVal:
                        sLinesPoints.append(pt)
                    else:
                        eLinePoints.append(pt)
                sortSuppPts = sLinesPoints
                sortEntPts = eLinePoints
                if (len(sortSuppPts) > 1):
                    startsupportPt = sortSuppPts[0]
                    for i in range(0, len(sortSuppPts) - 1):
                        p1 = sortSuppPts[i]
                        p2 = sortSuppPts[i + 1]
                        dist = p1.DistanceTo(p2)
                        if dist > 30:
                            Supportlinesegment = Line2(startsupportPt, p1)
                            supportLinesegments.append(Supportlinesegment)
                            startsupportPt = p2
                    Supportlinesegment = Line2(startsupportPt, p2)
                    supportLinesegments.append(Supportlinesegment)
                if (len(sortEntPts) > 1):
                    startentityPt = sortEntPts[0]
                    elines = []
                    for i in range(0, len(sortEntPts) - 1):
                        eline = []
                        p1 = sortEntPts[i]
                        p2 = sortEntPts[i + 1]
                        dist = p1.DistanceTo(p2)
                        if dist > 2:
                            entitylinesegment = Line2(startentityPt, p1)
                            eline.append(entitylinesegment)
                            entityLinesegments.append(eline)
                            startentityPt = p2
                    entitylinesegment = Line2(startentityPt, p2)
                    elines.append(entitylinesegment)
                    entityLinesegments.append(elines)
        for d in dimension:
            SupportL = []
            for a in d._DimensionalLines._ArrowHeads:
                BB = Cognition.SortCoordinates(
                    [a._BoundingBoxP1, a._BoundingBoxP2])
                bbMin = BB[0]
                bbMax = BB[1]
                direction = a._Direction
                if direction == "West":
                    shortListedLines = []
                    SupportLSW = []
                    for ls in supportLinesegments:
                        if bbMin.x + 3 > ls.startPoint.x and fabs(
                                ls.endPoint.x - ls.startPoint.x) < 3 and fabs(
                                    ls.endPoint.y - ls.startPoint.y) > 5:
                            shortListedLines.append(ls)
                    for ls in shortListedLines:
                        projectedPt = MathUtils.ProjectToLine2(
                            ls.startPoint, ls.endPoint, bbMin)
                        projectedDistance = bbMin.DistanceTo(projectedPt)
                        if projectedDistance < 8:  #<7
                            SupportLSW.append(ls)
                    SupportL.append(SupportLSW)
                elif direction == "East":
                    shortListedLines = []
                    SupportLSE = []
                    for ls in supportLinesegments:
                        if bbMax.x - 3 < ls.startPoint.x and fabs(
                                ls.endPoint.x - ls.startPoint.x) < 3 and fabs(
                                    ls.endPoint.y - ls.startPoint.y) > 5:
                            shortListedLines.append(ls)
                    for ls in shortListedLines:
                        projectedPt = MathUtils.ProjectToLine2(
                            ls.startPoint, ls.endPoint, bbMax)
                        projectedDistance = bbMax.DistanceTo(projectedPt)
                        if projectedDistance < 8:
                            SupportLSE.append(ls)
                    SupportL.append(SupportLSE)
                elif direction == "North":
                    shortListedLines = []
                    SupportLSN = []
                    for ls in supportLinesegments:
                        if bbMin.y + 3 > ls.startPoint.y and fabs(
                                ls.endPoint.y - ls.startPoint.y) < 3 and fabs(
                                    ls.endPoint.x - ls.startPoint.x) > 5:
                            shortListedLines.append(ls)
                    for ls in shortListedLines:
                        projectedPt = MathUtils.ProjectToLine2(
                            ls.startPoint, ls.endPoint, bbMin)
                        projectedDistance = bbMin.DistanceTo(projectedPt)
                        if projectedDistance < 8:
                            SupportLSN.append(ls)
                    SupportL.append(SupportLSN)
                elif direction == "South":
                    SupportLSS = []
                    shortListedLines = []
                    for ls in supportLinesegments:
                        if bbMax.y - 3 < ls.startPoint.y and fabs(
                                ls.endPoint.y - ls.startPoint.y) < 3 and fabs(
                                    ls.endPoint.x - ls.startPoint.x) > 5:
                            shortListedLines.append(ls)
                    for ls in shortListedLines:
                        projectedPt = MathUtils.ProjectToLine2(
                            ls.startPoint, ls.endPoint, bbMax)
                        projectedDistance = bbMax.DistanceTo(projectedPt)
                        if projectedDistance < 8:
                            SupportLSS.append(ls)
                    SupportL.append(SupportLSS)
            d._SupportLines = SupportL
        Feature_Manager._DetectedLine = entityLinesegments