Exemplo n.º 1
0
    def findFilterTest(self):
        imgCopy = CommonHelpMethodsClass.copyImage(self.img)
        obj = CommonHelpMethodsClass.loadJsonAnnotations("FilterTest")

        min = np.array([obj['minColor']])
        max = np.array([obj['maxColor']])
        width = obj['w']
        height = obj['h']
        x, y, w, h = FindByOpenCVClass.FindByColorSegmentation(imgCopy, min, max, width, height)
        cropArea = CommonHelpMethodsClass.cropImage(imgCopy, x, y, w, h)
        filterTest = GuiObject(obj['name'], obj['parent'], x, y, w, h, cropArea)

        return filterTest
Exemplo n.º 2
0
    def findTestInTestsTable(self, crop, text):
        min = np.array([255, 255, 255])
        max = np.array([255, 255, 255])
        contours = FindByOpenCVClass.findContoursByMinMaxColors(img, min, max)

        test = None
        for contour in contours:
            x, y, w, h = cv.boundingRect(contour)
            crop = CommonHelpMethodsClass.cropImage(img, x, y, w, h)
            actualText = CommonHelpMethodsClass.getTextFromImage(crop)
            print(actualText)
            if text in actualText:
                pass
                #print(actualText)
                #test = GuiObject("Test:" + str(text), "TestsTable", x, y, w, h, crop)

        return test
Exemplo n.º 3
0
    def findTestReferenceOfFilterTest(self):
        imgCopy = CommonHelpMethodsClass.copyImage(self.img)
        obj = CommonHelpMethodsClass.loadJsonAnnotations("Test Reference")
        filterTest = self.findFilterTest()
    
        min = np.array([250, 250, 250])
        max = np.array([255, 255, 255])
        width = 218
        height = 17
        text = "Test Reference"

        x, y, w, h = FindByOpenCVClass.FindByColorSegmentationAndName(filterTest.img, text, min, max, width, height)
        origX, origY = CommonHelpMethodsClass.findOriginalCoordinates(filterTest.x, filterTest.y, x, y)
        cropArea = CommonHelpMethodsClass.cropImage(imgCopy, origX, origY, w, h)
        testReferenceOfFilterTest = GuiObject("TestReverenceOfFilterTestField", "FilterTest", origX, origY, w, h, cropArea)

        return testReferenceOfFilterTest
Exemplo n.º 4
0
 def findContoursByMinMaxColors(img, min, max):
     imgCopy = CommonHelpMethodsClass.copyImage(img)
     min = np.array(min)
     max = np.array(max)
     blur = cv.GaussianBlur(imgCopy, (9, 9), 0)
     thresh = cv.inRange(blur, min, max)
     contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE,
                                           cv.CHAIN_APPROX_SIMPLE)
     return contours
Exemplo n.º 5
0
    def findTestsTable(self, text):
        imgCopy = CommonHelpMethodsClass.copyImage(self.img)

        contours, hierarchy = FindByOpenCVClass.findContoursByThreshold(imgCopy, 238, 240)

        for contour in contours:
            x, y, w, h = cv.boundingRect(contour)

            if (w > 600 and h > 300) and (w < 1600):
                crop = CommonHelpMethodsClass.cropImage(img, x, y, w, h)
                actualText = CommonHelpMethodsClass.getTextFromImage(crop)

                if text in actualText:
                    point1, point2 = FindByOpenCVClass.getPointsFromContour(contour)
                    cv.rectangle(img, point1, point2, (0,255,0), 1)
                    #cropArea = CommonHelpMethodsClass.cropImage(img, x, y, w, h)
                    testsTable = GuiObject("TestsTable", "Tests", x, y, w, h, crop)
                break

        #CommonHelpMethodsClass.ShowImage(crop)

        return testsTable
Exemplo n.º 6
0
    def findByContoursAndText(img, text, minThreshold, maxThreshold):
        imgCopy = CommonHelpMethodsClass.copyImage(img)
        img_rgb = cv.cvtColor(img, cv.COLOR_BGR2RGB)
        img_gray = cv.cvtColor(img_rgb, cv.COLOR_RGB2GRAY)
        ret, thresh1 = cv.threshold(img_gray, minThreshold, maxThreshold,
                                    cv.THRESH_BINARY)
        contours, hierarchy = cv.findContours(thresh1, cv.RETR_CCOMP,
                                              cv.CHAIN_APPROX_SIMPLE)

        for contour in contours:
            x, y, w, h = cv.boundingRect(contour)
            point1 = (x, y)
            point2 = (x + w, y + h)
            #ONLY FOR DEBUG
            if (w > 300 and h > 300) and (w < 1600):
                crop = CommonHelpMethodsClass.cropImage(img, x, y, w, h)
                actualText = CommonHelpMethodsClass.getTextFromImage(crop)
                print(actualText)
                cv.rectangle(img, point1, point2, (0, 255, 0), 1)
                if text in actualText:
                    cv.rectangle(img, point1, point2, (0, 255, 0), 1)
                    return x, y, w, h
Exemplo n.º 7
0
 def FindByColorSegmentationAndName(img, text, minColor, maxColor, width,
                                    height):
     shiftW = 5
     shiftH = 5
     min = minColor
     max = maxColor
     blur = cv.GaussianBlur(img, (3, 3), 0)
     thresh = cv.inRange(blur, min, max)
     contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE,
                                           cv.CHAIN_APPROX_SIMPLE)
     x, y, w, h = -1, -1, -1, -1
     for contour in contours:
         x, y, w, h = cv.boundingRect(contour)
         if (w > width - shiftW
                 and w < width + shiftW) and (h > h - shiftH
                                              and h < h + shiftH):
             if CommonHelpMethodsClass.validateText(img, text, x, y, w,
                                                    h) == True:
                 print("Text is: " + text)
                 print(x, y, w, h)
                 cv.drawContours(img, [contour], 0, (0, 255, 0), 3)
                 break
     #FindByOpenCVClass.ShowImage(img)
     return x, y, w, h