예제 #1
0
    def it_can_show_its_thumbnail(self, tmpdir):
        tmp_path_ = tmpdir.mkdir("myslide")
        image = PILImageMock.DIMS_500X500_RGBA_COLOR_155_249_240
        image.save(os.path.join(tmp_path_, "mywsi.png"), "PNG")
        slide_path = os.path.join(tmp_path_, "mywsi.png")
        slide = Slide(slide_path, "processed")

        slide.save_thumbnail()

        assert ImageShow.show(PIL.Image.open(slide.thumbnail_path))
예제 #2
0
 def handle_image_PIL(self, data, mime):
     if mime not in ('image/png', 'image/jpeg'):
         return False
     try:
         from PIL import Image, ImageShow
     except ImportError:
         return False
     raw = base64.decodestring(data[mime].encode('ascii'))
     img = Image.open(BytesIO(raw))
     return ImageShow.show(img)
예제 #3
0
 def handle_image_PIL(self, data, mime):
     if mime not in ('image/png', 'image/jpeg'):
         return False
     try:
         from PIL import Image, ImageShow
     except ImportError:
         return False
     raw = base64.decodestring(data[mime].encode('ascii'))
     img = Image.open(BytesIO(raw))
     return ImageShow.show(img)
예제 #4
0
    def test_show(self):
        class TestViewer:
            methodCalled = False

            def show(self, image, title=None, **options):
                self.methodCalled = True
                return True
        viewer = TestViewer()
        ImageShow.register(viewer, -1)

        im = hopper()
        self.assertTrue(ImageShow.show(im))
        self.assertTrue(viewer.methodCalled)
예제 #5
0
    def test_show(self):
        class TestViewer:
            methodCalled = False

            def show(self, image, title=None, **options):
                self.methodCalled = True
                return True

        viewer = TestViewer()
        ImageShow.register(viewer, -1)

        im = hopper()
        self.assertTrue(ImageShow.show(im))
        self.assertTrue(viewer.methodCalled)
예제 #6
0
def test_viewer_show(order):
    class TestViewer(ImageShow.Viewer):
        def show_image(self, image, **options):
            self.methodCalled = True
            return True

    viewer = TestViewer()
    ImageShow.register(viewer, order)

    for mode in ("1", "I;16", "LA", "RGB", "RGBA"):
        viewer.methodCalled = False
        with hopper(mode) as im:
            assert ImageShow.show(im)
        assert viewer.methodCalled

    # Restore original state
    ImageShow._viewers.pop(0)
예제 #7
0
    def test_show(self):
        class TestViewer(ImageShow.Viewer):
            methodCalled = False

            def show_image(self, image, **options):
                self.methodCalled = True
                return True
        viewer = TestViewer()
        ImageShow.register(viewer, -1)

        for mode in ("1", "I;16", "LA", "RGB", "RGBA"):
            im = hopper(mode)
            self.assertTrue(ImageShow.show(im))
            self.assertTrue(viewer.methodCalled)

        # Restore original state
        ImageShow._viewers.pop(0)
예제 #8
0
 def showImage(self):
     from PIL import Image, ImageShow
     with Image.open(
             r"C:\Users\cryos\Documents\Screenshot 2020-12-04 195747.jpg"
     ) as imag:
         ImageShow.show(imag)
예제 #9
0
def test_show():
    for mode in ("1", "I;16", "LA", "RGB", "RGBA"):
        im = hopper(mode)
        assert ImageShow.show(im)
import pydirectinput as pdi
import pyautogui
import time
from getBoundingBox import getBoundingBox
import cv2
import numpy
from PIL import Image, ImageShow

#first get the bounding box
topLeft = getBoundingBox()

img = pyautogui.screenshot(region=(topLeft[0], topLeft[1], 640, 400))
processedImage = numpy.asarray(img)
print(processedImage.ndim)
print(processedImage.shape)
print(processedImage.size)
print(processedImage[0, 0, :])
#PIL.ImageShow.show(img)

newIm = Image.fromarray(processedImage)
ImageShow.show(newIm)
def create_words_data_5on5_with_spaces(rel_in_path, rel_out_path, map_size,
                                       format, images_num):
    dir_in = './' + rel_in_path
    dir_out = './' + rel_out_path

    output_format = format

    os.makedirs(dir_out, exist_ok=True)
    env = lmdb.open(dir_out, map_size=map_size)
    cache = {}
    cnt = 1

    dir_in_path = pathlib.Path(dir_in)
    chr_dirs = os.listdir(dir_in_path)
    idx_to_chr_path = defaultdict(def_value)
    aleph = ord('א')
    for chr_dir in chr_dirs:
        # print(chr(int(chr_dir) + aleph))
        chr_dir_path = dir_in + chr_dir
        cur_chr_path = pathlib.Path(chr_dir_path)
        chr_files = os.listdir(cur_chr_path)
        for chr_file in chr_files:
            cur_chr_img_path = chr_dir_path + '/' + chr_file
            idx_to_chr_path[int(chr_dir)].append(cur_chr_img_path)

    non_ending_letters = 'אבגדהוזחטיכלמנסעפצקרשת'
    ending_letters = 'אבגדהוזחטיךלמןסעףץקרשת'
    low_letters = 'נקךןת'

    bg = './bg.jpg'
    bg = Image.open(bg)
    bg = np.asarray(bg)
    words_count = 0
    total_copies = []
    total_bytes = 0
    images_count = 0
    while images_count < images_num:
        one_or_two = np.random.randint(0, 10)
        if one_or_two == 3:
            word_len = np.random.randint(11, 20)
        else:
            word_len = np.random.randint(1, 11)

        is_lower = np.zeros(word_len)

        images = []
        length_upper = 0
        length_lower = 0
        width = 0

        label = ''
        # letters generations separetly
        for i in range(word_len - 1):
            letter = np.random.randint(22)
            if non_ending_letters[letter] in low_letters:
                is_lower[word_len - 1 - i] = 1
            letter_idx = ord(non_ending_letters[letter]) - ord('א')
            label += chr(letter_idx + ord('א'))
            letter_imgs = idx_to_chr_path[letter_idx]
            amount = len(letter_imgs)
            img_num = np.random.randint(amount - 1)
            letter_img_path = letter_imgs[img_num]

            cur_chr_img = Image.open(letter_img_path)
            cur_chr_img = np.asarray(cur_chr_img)
            cur_length, cur_width, channels = cur_chr_img.shape
            if channels == 4:  # remove the alpha channel
                cur_chr_img = cur_chr_img[:, :, :-1]
            width += cur_width
            images.append(cur_chr_img)
            if non_ending_letters[letter] in low_letters:
                length_lower = max(length_lower, cur_length)
            else:
                length_upper = max(length_upper, cur_length)

        # last letter in ending letters
        letter = np.random.randint(22)
        if ending_letters[letter] in low_letters:
            is_lower[0] = 1
        letter_idx = ord(ending_letters[letter]) - ord('א')
        label += chr(letter_idx + ord('א'))
        letter_imgs = idx_to_chr_path[letter_idx]
        amount = len(letter_imgs)
        img_num = np.random.randint(amount - 1)
        letter_img_path = letter_imgs[img_num]

        cur_chr_img = Image.open(letter_img_path)
        cur_chr_img = np.asarray(cur_chr_img)
        cur_length, cur_width, channels = cur_chr_img.shape
        if channels == 4:  # remove the alpha channel
            cur_chr_img = cur_chr_img[:, :, :-1]
        width += cur_width
        images.append(cur_chr_img)
        if non_ending_letters[letter] in low_letters:
            length_lower = max(length_lower, cur_length)
        else:
            length_upper = max(length_upper, cur_length)

        if length_upper > length_lower:
            total_length = ceil(length_upper + length_lower / 2)
        else:
            total_length = ceil(length_lower + length_upper / 2)

        # word generation from letters
        # print(label)

        # background_img = Image.fromarray(background)
        # ImageShow.show(background_img)
        # print()
        # save image in lmdb
        # _, format = chr_file.split('.')
        # if output_format == 'same':
        # output_format = format
        # word writing to lmdb in compressed form with bytesIO - reduces total size

        words_count += 1
        # place diversity images generation

        row_shift = 3
        col_shift = 3
        _, width_step, _ = list(reversed(images))[0].shape
        copies = 0
        for cls in range(col_shift + 1):
            for rws in range(row_shift + 1):
                for c in range(0, cls + 1):
                    for r in range(0, rws + 1):
                        width_start_idx = 0
                        background = np.copy(bg[0:total_length,
                                                0:width * 2, :])
                        for i, (letter_img, is_low) in enumerate(
                                zip(reversed(images), is_lower)):
                            cur_len, cur_width, _ = letter_img.shape
                            if not is_low:
                                start_idx = length_upper - cur_len
                            else:
                                start_idx = total_length - cur_len
                            col_end_idx = width_start_idx + cur_width

                            background[start_idx:(start_idx + cur_len),
                                       width_start_idx:(
                                           col_end_idx), :] = letter_img
                            cur_space_width = cur_width / 10
                            cur_space = int(
                                np.random.randint(-2, 4) * cur_space_width)
                            if i < word_len - 1:
                                width_start_idx += cur_width + cur_space
                            else:
                                width_start_idx += cur_width
                                background = background[:,
                                                        0:width_start_idx, :]

                        cur_word_img = background
                        word_l, word_w, _ = background.shape

                        background = np.copy(
                            bg[0:word_l + word_l * cls,
                               0:word_w + width_step * rws, :])
                        background[c * word_l:(c + 1) * word_l,
                                   r * width_step:word_w +
                                   r * width_step, :] = cur_word_img
                        background_img = Image.fromarray(background)
                        ImageShow.show(background_img)
                        copies += 1
                        imageKey = 'image-%09d'.encode() % cnt
                        labelKey = 'label-%09d'.encode() % cnt
                        total_bytes += len(imageKey) + len(labelKey)
                        background = Image.fromarray(background)
                        with io.BytesIO() as output:
                            background.save(output, format=output_format)
                            imageBin = output.getvalue()
                            total_bytes += len(imageBin) + len(label.encode())
                        cache[imageKey] = imageBin
                        cache[labelKey] = label.encode()
                        if cnt % 1000 == 0:
                            env.set_mapsize(int(total_bytes * 1.12))
                            writeCache(env, cache)
                            cache = {}
                            print('Written %d' % cnt)
                        cnt += 1
        images_count += copies
        total_copies.append(copies)

    if len(cache) != 0:
        env.set_mapsize(int(total_bytes * 1.09))
        writeCache(env, cache)
        cache = {}
        print('Written %d' % (cnt - 1))
    nSamples = cnt - 1
    cache['num-samples'.encode()] = str(nSamples).encode()
    writeCache(env, cache)
    print(
        'Created dataset with %d samples of size %d bytes with %d words and %d copies in average'
        %
        (nSamples, total_bytes, words_count, np.asarray(total_copies).mean()))
예제 #12
0
    def it_can_show_its_thumbnail(self, tmpdir):
        slide, _ = base_test_slide(tmpdir,
                                   PILIMG.RGBA_COLOR_500X500_155_249_240)

        assert ImageShow.show(slide.thumbnail)
예제 #13
0
def addDataToTable(table, headers, data):
    table.setRowCount(0)
    table.setColumnCount(0)

    for i in range(len(headers)):
        table.insertColumn(i)
    table.setHorizontalHeaderLabels(headers)

    j = 0
    for row in data:
        table.insertRow(j)
        i = 0
        for x in row:
            table.setItem(j, i, QTableWidgetItem(x))
            i += 1
        j += 1


if __name__ == "__main__":
    from PIL import ImageShow
    data = {
        "First Name": "Monish",
        "Last Name": "Sudhagar",
        "Gender": "Male",
        "Date of Joining": "2020/11/01",
        "Role": "Librarian"
    }
    ID = createQrId("c3f9d130-8524-4699-9b40-4e0f7d5bd4f5", data)
    ImageShow.show(ID)
예제 #14
0
def _showxv(image, title=None, **options):
    from PIL import ImageShow
    ImageShow.show(image, title, **options)    
예제 #15
0
 def test_show(self):
     for mode in ("1", "I;16", "LA", "RGB", "RGBA"):
         im = hopper(mode)
         self.assertTrue(ImageShow.show(im))
예제 #16
0
 def Display(self):
     return ImageShow.show(self.picture)
예제 #17
0
from PIL import ImageShow, Image
import pandas as pd


print("截止到2020/02/20 软件测试无误,由于学校登录系统有个登录状态码是加密的,所以可能随时失败,软件不兼容的联系班里最帅的那个帮忙导吧。。\n我已人品担保不会上传你的账号密码\n", "_"*30)
username = int(input("学号:"))
password = str(input("密码:"))
image_url = "http://jwgls.jmu.edu.cn/Common/CheckCode.aspx"
headers = {"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.100 Safari/537.36 Edg/80.0.361.53"}
s = requests.Session()
response = s.get(image_url, headers=headers)
with open(r"check.jpg", "wb") as f:
    f.write(response.content)
try:
    check_image = Image.open(r"check.jpg")
    ImageShow.show(check_image, title="验证码")
except:
    print("抱歉显示验证码失败,请直接退出")
code = input("验证码:")
# plt.show()
data = {
    "__VIEWSTATE":"/wEPDwUKMTA4MDEzMTMyOQ9kFgICAw9kFgICDw8PFgIeBFRleHQFATBkZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAgUNQnRuTG9naW5JbWFnZQUNQnRuUmVzZXRJbWFnZcH71Q3NhGesjfuvAIN4VJIH4TsM",
    "TxtUserName": username,
    "TxtPassword": password,
    "TxtVerifCode": int(code),
    "BtnLoginImage.x":33,
    "BtnLoginImage.y":7
    }
login_url = "http://jwgls.jmu.edu.cn/login.aspx"
# print(data)
response = s.post(login_url, headers=headers, data=data)