def parseScale(img, corners, xticks, xtexts, is_X = True):

    if not is_X:
        xticks.reverse()
        xtexts.reverse()

    xticks = np.array(xticks)
    corners = np.array(corners)

    origin = corners[1]

    _xticks = xticks - origin

    # ToDo: Choose indices such that at the idx, text is present
    idx2 = len(xticks) / 2

    assert idx2 != 0
    idx1 = 0
    idx2 = 1

    # import pdb; pdb.set_trace()

    gotp1 = True
    while gotp1:

        try:
            p1 = float(hlp.getOCRText(img.img, xtexts[idx1]))
            gotp1 =False
        except:
            idx1 +=1
            idx2 +=1
        if idx2 > len(xtexts):
            gotp1 = False

    gotp1 = True
    while gotp1:

        try:
            p2 = float(hlp.getOCRText(img.img, xtexts[idx2]))
            gotp1 =False
        except:
            idx2 +=1

        if idx2 > len(xtexts):
            gotp1 = False

    if is_X:
        m = float(p2 - p1)/float (_xticks[idx2][0] - _xticks[idx1][0])
        b = p1 - m*(_xticks[idx1][0])
    else:
        m = float(p2 - p1)/float (_xticks[idx2][1] - _xticks[idx1][1])
        b = p1 - m*(_xticks[idx1][1])

    

    grainStep = int(float(xticks[1][0]-xticks[0][0])/10.0)
    
    return m,b, grainStep
def parseScale(img, corners, xticks, xtexts, is_X=True):

    if not is_X:
        xticks.reverse()
        xtexts.reverse()

    xticks = np.array(xticks)
    corners = np.array(corners)

    origin = corners[1]

    _xticks = xticks - origin

    # ToDo: Choose indices such that at the idx, text is present
    idx2 = len(xticks) / 2

    assert idx2 != 0
    idx1 = 0
    idx2 = 1

    # import pdb; pdb.set_trace()

    gotp1 = True
    while gotp1:

        try:
            p1 = float(hlp.getOCRText(img.img, xtexts[idx1]))
            gotp1 = False
        except:
            idx1 += 1
            idx2 += 1
        if idx2 > len(xtexts):
            gotp1 = False

    gotp1 = True
    while gotp1:

        try:
            p2 = float(hlp.getOCRText(img.img, xtexts[idx2]))
            gotp1 = False
        except:
            idx2 += 1

        if idx2 > len(xtexts):
            gotp1 = False

    if is_X:
        m = float(p2 - p1) / float(_xticks[idx2][0] - _xticks[idx1][0])
        b = p1 - m * (_xticks[idx1][0])
    else:
        m = float(p2 - p1) / float(_xticks[idx2][1] - _xticks[idx1][1])
        b = p1 - m * (_xticks[idx1][1])

    grainStep = int(float(xticks[1][0] - xticks[0][0]) / 10.0)

    return m, b, grainStep
Beispiel #3
0
    def show_ticktexts(self):
        for rect in self.yticksTextRects:
            helpers.plotPoints(self.img.img, rect)
            try:
                print helpers.getOCRText(self.img.img, rect)
            except:
                pass

        for rect in self.xticksTextRects:
            helpers.plotPoints(self.img.img, rect)
            print helpers.getOCRText(self.img.img, rect)
Beispiel #4
0
    def show_ticktexts(self):
        for rect in self.yticksTextRects:
            helpers.plotPoints(self.img.img, rect)
            try:
                print helpers.getOCRText(self.img.img, rect)
            except:
                pass

        for rect in self.xticksTextRects:
            helpers.plotPoints(self.img.img, rect)
            print helpers.getOCRText(self.img.img, rect)
Beispiel #5
0
    def test_ytick_text(self):
        """
        Setup: 
            - Input Test Image (Already done)
            - Corners
            - 1st Tick Point Coordinates
        
        Assertion:
            - Check the OCR on bounding rect and match it with actual text
        
        Things to Find:
            - Corner Points
            - Actual Coordinates of the 1st tick point
            - Actual text content corresponding to 1st tick
            
        """

        self.plot.corners = self.corners
        # self.plot.x_ticks = self.xticks
        self.plot.getBounds()
        self.plot.findTicks()
        ticktextRect = self.plot.findyTickText()
        # import pdb; pdb.set_trace()
        tickText = helper.getOCRText(self.plot.img.img, ticktextRect[1])

        assert tickText == "90"
Beispiel #6
0
    def getAxisCaption(self):

        y1, y2 = self.bounds[0][2]
        x1, x2 = self.corners[0][0], self.corners[2][0]
        x1 -= 5
        x2 += 5

        xaxisCorenrs = [
            (x1, y1),
            (x1, y2),
            (x2, y2),
            (x2, y1),
        ]
        self.plot_caption = helpers.getOCRText(self.img.img, xaxisCorenrs,
                                               "-psm 7")

        y1, y2 = self.bounds[0][1]
        x1, x2 = self.corners[0][0], self.corners[2][0]
        x1 -= 5
        x2 += 5

        xaxisCorenrs = [
            (x1, y1),
            (x1, y2),
            (x2, y2),
            (x2, y1),
        ]
        self.x_caption = helpers.getOCRText(self.img.img, xaxisCorenrs,
                                            "-psm 7")
        # helpers.plotPoints(self.img.img, xaxisCorenrs)

        x1, x2 = self.bounds[1][1]
        y1, y2 = self.corners[0][1], self.corners[1][1]
        x1 -= 5
        x2 += 5
        xaxisCorenrs = [
            (x1, y1),
            (x1, y2),
            (x2, y2),
            (x2, y1),
        ]
        img = helpers.getSubImage(self.img.gray, xaxisCorenrs)
        dst = img.transpose()
        dst = cv2.flip(dst, 1)
        self.y_caption = helpers.getOCRText(dst, None, "-psm 7")
Beispiel #7
0
    def mapLegendToPlots(self):

        self.findLegendCorners()

        strDict = {}
        for rect in self.allLegendTexts:
            txt = helpers.getOCRText(self.img.img, rect, "-psm 7")
            strDict[txt] = rect

        self.h2str = labelsToColoursMapping(self.img.img, strDict, self.allPlots.keys())
Beispiel #8
0
    def getAxisCaption(self):

        y1, y2 = self.bounds[0][2]
        x1, x2 = self.corners[0][0], self.corners[2][0]
        x1 -= 5
        x2 += 5
        
        xaxisCorenrs = [
                (x1, y1),
                (x1, y2),
                (x2, y2),
                (x2, y1),
        ]
        self.plot_caption = helpers.getOCRText(self.img.img, xaxisCorenrs, "-psm 7")

        y1, y2 = self.bounds[0][1]
        x1, x2 = self.corners[0][0], self.corners[2][0]
        x1 -= 5
        x2 += 5
        
        xaxisCorenrs = [
                (x1, y1),
                (x1, y2),
                (x2, y2),
                (x2, y1),
        ]
        self.x_caption = helpers.getOCRText(self.img.img, xaxisCorenrs, "-psm 7")
        # helpers.plotPoints(self.img.img, xaxisCorenrs)

        x1, x2 = self.bounds[1][1]
        y1, y2 = self.corners[0][1], self.corners[1][1]
        x1 -= 5
        x2 += 5
        xaxisCorenrs = [
                (x1, y1),
                (x1, y2),
                (x2, y2),
                (x2, y1),
        ]
        img = helpers.getSubImage(self.img.gray, xaxisCorenrs)
        dst = img.transpose()
        dst = cv2.flip(dst, 1)
        self.y_caption = helpers.getOCRText(dst, None, "-psm 7")
Beispiel #9
0
    def mapLegendToPlots(self):

        self.findLegendCorners()

        strDict = {}
        for rect in self.allLegendTexts:
            txt = helpers.getOCRText(self.img.img, rect, "-psm 7")
            strDict[txt] = rect

        self.h2str = labelsToColoursMapping(self.img.img, strDict,
                                            self.allPlots.keys())
Beispiel #10
0
    def test_extract_yaxis_caption(self):
        """
        Setup: 
            - Input Test Image (Already done)
            - Corners
        Assertion:
            - Check the y-axis caption with hardcoded value

        Things to Find:
            - Rect surrounding the y-axis caption
            - y-axis caption from the Rect
        """
        self.plot.corners = self.corners
        yaxisCaptionRect = self.plot.findYCaption()
        yaxisCaption = helper.getOCRText(self.plot.img, yaxisCaptionRect)
        assert yaxisCaption == self.y_caption
    def test_OCR(self):

        print helper.getOCRText(self.img.img, self.corners)
Beispiel #12
0
    def test_OCR(self):

        print helper.getOCRText(self.img.img, self.corners)