test_images图像导入测试(失败两个,成功一个).py

import unittest

import numpy as np

import sys
sys.path.append('C:\\Users\\011241\\Desktop\\Image Stitching\\stitching-main\\tests\\context.py')
from context import Images, _FilenameImages, _NumpyImages, load_test_img, test_input


class TestImages(unittest.TestCase):
    def test_numpy_image_input(self):
        images = Images.of([load_test_img("s1.jpg"), load_test_img("s2.jpg")])
        self.assertTrue(isinstance(images, _NumpyImages))
        self.assertEqual(images.names, ["1", "2"])
        self.check_s_images(images)

    def test_named_image_input(self):
        images = Images.of([test_input("s1.jpg"), test_input("s2.jpg")])
        self.assertTrue(isinstance(images, _FilenameImages))
        self.assertTrue(images.names[0].endswith("s1.jpg"))
        self.assertTrue(images.names[1].endswith("s2.jpg"))
        self.check_s_images(images)

    def check_s_images(self, images):
        self.assertTrue(isinstance(images, Images))

        full_np_arrays = list(images)
        shapes = [img.shape for img in full_np_arrays]
        np.testing.assert_array_equal(shapes, [(700, 1246, 3), (700, 1385, 3)])

        np.testing.assert_array_equal(images.sizes, [(1246, 700), (1385, 700)])

        low_sizes = images.get_scaled_img_sizes(Images.Resolution.LOW)
        np.testing.assert_array_equal(low_sizes, [(422, 237), (469, 237)])

        low_np_arrays1 = list(images.resize(Images.Resolution.LOW))
        low_np_arrays2 = list(images.resize(Images.Resolution.LOW, full_np_arrays))
        low_shapes1 = [img.shape for img in low_np_arrays1]
        low_shapes2 = [img.shape for img in low_np_arrays2]
        np.testing.assert_array_equal(low_shapes1, low_shapes2)
        np.testing.assert_array_equal(low_shapes1, (((237, 422, 3), (237, 469, 3))))

        ratio = images.get_ratio(Images.Resolution.MEDIUM, Images.Resolution.LOW)
        self.assertEqual(ratio, 0.408248290463863)

    def test_images(self):
        self.assertEqual(Images.Resolution.LOW.name, "LOW")
        self.assertEqual(Images.Resolution.LOW.value, 0.1)

        images = Images.of(["1", "2"], 10)
        self.assertEqual(images._scalers["MEDIUM"].megapix, 10)


def start_test():
    unittest.main()


if __name__ == "__main__":
    start_test()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值