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 testNoneImg_xywh(self): Roi_xywh = [10, 20, 30, 40] with testNumpy.assert_raises(IPT.IPTError): IPT.getRoiImg(None, Roi_xywh, IPT.ROI_TYPE_XYWH)
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)
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)
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)
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)
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))