コード例 #1
0
 def testGetRoiImg_xywh(self):
     Img = np.random.randint(0, 255, (10, 10), dtype=np.uint8)
     Roi_xywh = self.TypeFunc([1, 2, 4, 5])
     Offset_2x1, RoiImg = IPT.getRoiImg(Img,
                                        Roi_xywh,
                                        roiType=IPT.ROI_TYPE_XYWH)
     GTRoiImg = Img[2:7, 1:5]
     GTOffset = np.array([1, 2]).reshape(2, 1)
     np.testing.assert_array_equal(GTRoiImg, RoiImg)
     np.testing.assert_array_equal(GTOffset, Offset_2x1)
     np.testing.assert_array_equal(RoiImg.shape, (5, 4))
コード例 #2
0
    # # cv2.waitKey()
    # for contour in Contours:
    #     print 'contour:\n', contour
    #     Canvas = np.zeros((50, 50), np.uint8)
    #     cv2.drawContours(Canvas, [contour], 0, color=155, thickness=1)
    #     cv2.namedWindow('Canvas', cv2.WINDOW_NORMAL)
    #     cv2.imshow('Canvas', Canvas)
    #     cv2.waitKey()
    #
    # # im_in = cv2.imread("nickel.jpg", cv2.IMREAD_GRAYSCALE);

    # ============= im fill =============== #
    SrcImg = cv2.imread('../Datas/Input/holes.tif', 0)
    _, BinImg = cv2.threshold(SrcImg, 100, 255, cv2.THRESH_BINARY_INV)
    cv2.imshow("BinImg", BinImg)
    AfterFilled = IPT.fillHoles(BinImg, backGroundValue=255, foreGroundValue=0)
    cv2.imshow('Filled', AfterFilled)
    cv2.waitKey()
    # im_in = np.zeros((50, 50), np.uint8)
    # im_in[25:, 35:40] = 255
    # im_in[25:, 5:10] = 255
    # im_in[25:30, 10:40] = 255
    #
    # # Threshold.
    # # Set values equal to or above 220 to 0.
    # # Set values below 220 to 255.
    #
    # th, im_th = cv2.threshold(im_in, 220, 255, cv2.THRESH_BINARY);
    #
    # # Copy the thresholded image.
    # im_floodfill = im_th.copy()
コード例 #3
0
 def testXYXY2XYWH(self):
     Roi_xyxy = self.TypeFunc([1, 1, 3, 3])
     Out = IPT.cvtRoi(roi=Roi_xyxy, flag=IPT.ROI_CVT_XYXY2XYWH)
     np.testing.assert_array_equal(Out, [1, 1, 2, 2])
コード例 #4
0
 def testNoneImg_xywh(self):
     Roi_xywh = [10, 20, 30, 40]
     with testNumpy.assert_raises(IPT.IPTError):
         IPT.getRoiImg(None, Roi_xywh, IPT.ROI_TYPE_XYWH)
コード例 #5
0
 def testMinusInValid_xywh(self):
     Roi_xywh = [10, 20, -30, -40]
     with testNumpy.assert_raises(IPT.IPTError):
         IPT.getRoiImg(self.Img, Roi_xywh, IPT.ROI_TYPE_XYWH)
コード例 #6
0
 def testMinusInValid_xyxy(self):
     Roi_xyxy = [-10, -20, -30, -40]
     with testNumpy.assert_raises(IPT.IPTError):
         IPT.getRoiImg(self.Img, Roi_xyxy, IPT.ROI_TYPE_XYXY)
コード例 #7
0
 def testMinusValid_xywh(self):
     Roi_xywh = [-10, -20, 30, 40]
     _, RoiImg = IPT.getRoiImg(self.Img, Roi_xywh, IPT.ROI_TYPE_XYWH)
     print RoiImg.shape
     assert RoiImg.shape == (20, 20)
コード例 #8
0
 def testMinusValid_xyxy(self):
     Roi_xyxy = [-10, -20, 30, 40]
     _, RoiImg = IPT.getRoiImg(self.Img, Roi_xyxy, IPT.ROI_TYPE_XYXY)
     assert RoiImg.shape == (40, 30)
コード例 #9
0
 def testZero_xywh(self):
     Roi_xywh = [10, 20, 0, 0]
     _, RoiImg = IPT.getRoiImg(self.Img, Roi_xywh, IPT.ROI_TYPE_XYWH)
     assert RoiImg is not None
     testNumpy.assert_array_equal(RoiImg, np.array([]).reshape(0, 0))
コード例 #10
0
 def testMinus_xywh(self):
     Roi_xywh = [-10, -20, -20, -20]
     GTRoi_xyxy = [-10, -20, -30, -40]
     Roi_xyxy = IPT.cvtRoi(Roi_xywh, IPT.ROI_CVT_XYWH2XYXY)
     testNumpy.assert_array_equal(Roi_xyxy, GTRoi_xyxy)
コード例 #11
0
 def testZero_xywh(self):
     Roi_xywh = [10, 20, 0, 0]
     GTRoi_xyxy = [10, 20, 10, 20]
     Roi_xyxy = IPT.cvtRoi(Roi_xywh, IPT.ROI_CVT_XYWH2XYXY)
     testNumpy.assert_array_equal(Roi_xyxy, GTRoi_xyxy)
コード例 #12
0
    def testGetRoiImg_xywh(self):
        Img = np.random.randint(0, 255, (10, 10), dtype=np.uint8)
        Roi_xywh = self.TypeFunc([1, 2, 4, 5])
        Offset_2x1, RoiImg = IPT.getRoiImg(Img,
                                           Roi_xywh,
                                           roiType=IPT.ROI_TYPE_XYWH)
        GTRoiImg = Img[2:7, 1:5]
        GTOffset = np.array([1, 2]).reshape(2, 1)
        np.testing.assert_array_equal(GTRoiImg, RoiImg)
        np.testing.assert_array_equal(GTOffset, Offset_2x1)
        np.testing.assert_array_equal(RoiImg.shape, (5, 4))

    # def testInRoi_xyxy(self):
    # def testInRoi_xywh(self):
    # def testInRoi_rotate(self):
    # def testDrawRoiImg_xywh(self):
    # def testDrawRoiImg_xyxy(self):
    # def testDrawRoiImg_rotate(self):


class TestRoiType_Array(TestRoiType):
    TypeFunc = np.array


class TestRoiType_tuple(TestRoiType):
    TypeFunc = tuple


if __name__ == '__main__':
    print IPT.test(doctests=True)