예제 #1
0
def test_image_from_opencv():
    """load image from OpenCV object check"""
    import cv2
    img1 = Image(path=TEST_IMAGE_PATH)
    img2 = Image(opencv_image=cv2.imread(TEST_IMAGE_PATH))
    assert img1.diff_percent(img2) == 0
    assert img1 == img2
예제 #2
0
def test_image_save():
    """save image check"""
    path_save = '/tmp/MoLA_test/test.jpg'

    img = Image(path=TEST_IMAGE_PATH)
    img.save(path_save, quality=100)

    assert Image(path=path_save) == img
예제 #3
0
def test_image_from_row():
    """load image from raw string check"""
    with open(TEST_IMAGE_PATH, 'rb') as f:
        raw = f.read()

    img1 = Image(path=TEST_IMAGE_PATH)
    img2 = Image(raw=raw)
    assert img1.diff_percent(img2) == 0
    assert img1 == img2
예제 #4
0
def test_image_diff_percent():
    """different_percent method check"""
    img = Image(path=TEST_IMAGE_PATH)

    assert img.diff_percent(img) == 0
    assert img == img

    img2 = Image(path=TEST_IMAGE_PATH).greyscale()
    assert img.diff_percent(img2) == 100
    assert img != img2
예제 #5
0
def test_image_cast():
    """cast image check"""
    img = Image(path=TEST_IMAGE_PATH)
    cast_img = Image(path=TEST_IMAGE_PATH)

    # cast loop
    for _ in range(10):
        cast_img = Image(opencv_image=cast_img.get_opencv())
        cast_img = Image(pil_image=cast_img.get_pil())

    assert img == cast_img
    def _make_snapshot_done(self, result):
        """Process after make_snapshot method"""

        if not result:
            return

        image = Image(raw=result)

        # motion detection check
        if self.__snapshot:
            diff_percent = image.diff_percent(self.__snapshot)
            if diff_percent > self.motion_threshold:
                event = self.fire(
                    "motion_detection", new=image, old=self.__snapshot, device=self, diff_percent=diff_percent
                )
                self.fire("analyse_image", image=image, device=self, parent=event)

        self.__snapshot_timestamp = time.time()
        self.__snapshot = image
        return image
예제 #7
0
def test_image_from_pil():
    """load image from PIL object check"""
    img1 = Image(path=TEST_IMAGE_PATH)
    img2 = Image(pil_image=ImagePil.open(TEST_IMAGE_PATH))
    assert img1.diff_percent(img2) == 0
    assert img1 == img2