Пример #1
0
    def percentage_missing_data(df: 'DataFrame or Series', in_percentage: 'bool'=True, draw_graph: 'bool'=False):
        """
        Return missing data per column (in percentage, if True)
        input is a pandas dataframe or series
        output is the number of missing rows (in percentage, if specified)
        if draw_graph is false and in_percentage is false, return missing_data
        if draw_graph is false and in_percentage is true, return missing_data_perc
        if draw_graph is true and in_percentage is false, plot graph and return missing_data
        if draw_graph is true and in_percentage is false, plot graph and return missing_data_perc"""

        missing_data = df.isna().sum()[df.isna().sum() > 0].sort_values(ascending=False)
        missing_data_perc = np.round(missing_data/df.shape[0] * 100, 2)

        if not draw_graph and not in_percentage:  # do not plot graph and output number of missing rows
            print(f'Missing rows found in: {tuple(missing_data.index)}')
            return missing_data
        if not draw_graph and in_percentage:  # don't plot graph and output percent of missing rows
            print(f'Percentage number of missing rows for: {tuple(missing_data.index)}')
            return missing_data_perc

        #  plot graph to display info
        sns.set_theme(style='darkgrid')
        fig = plt.figure(figsize=(6, 3), dpi=150)
        ax = fig.add_axes(rect=[0, 0, 1, 1])
        row_lab = "Missing Rows"
        titl = "Missing Rows per Column"

        if not in_percentage:
            sns.barplot(y=missing_data.index, x=missing_data, ax=ax)

        else:
            row_lab = f"{row_lab} (in %)"
            titl = f"{titl} (in %)"
            sns.barplot(y=missing_data_perc.index, x=missing_data_perc, ax=ax)

        ax.set_ylabel("Feature"), ax.set_xlabel(row_lab)
        ax.set_title(titl)

        #  save graph as image
        graph_folder = f'{os.getcwd()}\\DisplayGraphs'
        joblib.os.makedirs(graph_folder, exist_ok=True)  # folder created
        graph_file = f'{graph_folder}\\plot1.png'
        fig.savefig(fname=graph_file, pad_inches=0.25,
                    dpi=200, bbox_inches='tight')

        # display saved figure image
        from PIL import Image, ImageShow
        img = Image.open(graph_file)
        ImageShow.show(img)

        if not in_percentage:  # output number of missing rows
            print('Number of missing rows:')
            return missing_data
        print('Percentage number of missing rows:')
        return missing_data_perc  # output percent of missing rows
Пример #2
0
def position(camera,actual_position,target_position,base,lnk1,lnk2):

	print('Displaying camera.')
	ImageShow.show(camera)
	time = float(prompt('time ->'))
	base = float(prompt('base ->', '%.1f' % base))
	lnk1 = float(prompt('lnk1 ->', '%.1f' % lnk1))
	lnk2 = float(prompt('lnk2 ->', '%.1f' % lnk2))
	reset = False
	
	return time, base, lnk1, lnk2, reset
Пример #3
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)
    def mesh(self, image):
        width = 640
        height = 480
        pose_2d_mpiis = []
        visibilities = []

        # Re-samples the images and perform estimation
        humans = self.args["estimator"].inference(image, resize_to_default=(
                self.args["width"] > 0 and self.args["height"] > 0),
                                                  upsample_size=float(4))
        # creates the body structure containing body points
        structure = TfPoseEstimator.draw_humans(image, humans, imgcopy=False)
        for human in humans:
            pose_2d_mpii, visibility = common.MPIIPart.from_coco(human)
            pose_2d_mpiis.append(
                [(int(y * height + 0.5), int(x * width + 0.5)) for x, y in pose_2d_mpii]
            )
            # Contains the body points. If empty then body not found error encounter
            visibilities.append(visibility)

        # Generate 2D points
        pose_2d_mpiis = np.array(pose_2d_mpiis)
        visibilities = np.array(visibilities)
        # Generate 3D points of 17 joints of body
        transformed_pose2d, weights = self.args["pose"].transform_joints(pose_2d_mpiis, visibilities)
        # pose_3d contains an matrix of size 17(body points)*3(x,y,z)
        pose_3d = self.args["pose"].compute_3d(transformed_pose2d, weights)
        # Take Transpose of the matrix and return a matrix of size 3*17
        keypoints = pose_3d[0].transpose()
        # chaning the color scheme of the image from RGB to BGR
        output=Image.fromarray(cv.cvtColor(structure, cv.COLOR_RGB2BGR))
        # Displaying Image on the frontend
        ImageShow.show(output,title=self.url)

        # window_name = "image " + str(self.window_counter)
        # structure=ResizeWithAspectRatio(image=structure,height=786)
        #
        # cv.imshow(window_name, structure)
        # cv.waitKey(10)
        # thread = myThread(self.window_counter, name=window_name)
        # thread.start()
        # _thread.start_new_thread(create_window(),window_name)

        # keypoints = keypoints

        """
        return 3d keypoints

        """

        return keypoints[13]
Пример #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_showxv_deprecation(self):
        class TestViewer(ImageShow.Viewer):
            def show_image(self, image, **options):
                return True

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

        im = Image.new("RGB", (50, 50), "white")

        with pytest.warns(DeprecationWarning):
            Image._showxv(im)

        # Restore original state
        ImageShow._viewers.pop(0)
Пример #7
0
    def it_can_show_its_thumbnail(self, tmpdir):
        slide, _ = base_test_slide(tmpdir,
                                   PILIMG.RGBA_COLOR_500X500_155_249_240)

        slide.save_thumbnail()

        assert ImageShow.show(PIL.Image.open(slide.thumbnail_path))
Пример #8
0
    def test_viewer(self):
        viewer = ImageShow.Viewer()

        self.assertIsNone(viewer.get_format(None))

        self.assertRaises(NotImplementedError,
                          lambda: viewer.get_command(None))
Пример #9
0
def test_viewer():
    viewer = ImageShow.Viewer()

    assert viewer.get_format(None) is None

    with pytest.raises(NotImplementedError):
        viewer.get_command(None)
Пример #10
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)
Пример #11
0
def test_show_without_viewers():
    viewers = ImageShow._viewers
    ImageShow._viewers = []

    im = hopper()
    assert not ImageShow.show(im)

    ImageShow._viewers = viewers
Пример #12
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)
Пример #13
0
def DrawText(text, bgImage):
    image = Image.new('RGBA', (3 * 24, 24), color=(0, 0, 0, 0))
    draw = ImageDraw.Draw(image)
    font = ImageFont.truetype('C:/Windows/Fonts/simhei.ttf',
                              int(24.0 * 3.0 / len(text)),
                              encoding="unic")
    draw.text((0, 0), text, (0, 0, 0, 160), font)
    ImageShow.show(image)
    image = image.rotate(random.uniform(-5, 5),
                         resample=Image.BICUBIC,
                         expand=1)
    scaleWidth = int(bgImage.height / image.height * image.width)
    image = image.resize((scaleWidth, bgImage.height), resample=Image.BICUBIC)
    bgImageCrop = bgImage.crop(box=(0, 0, scaleWidth, bgImage.height))
    image = Image.alpha_composite(bgImageCrop, image)
    ImageShow.show(image)
    return image.convert(mode='RGB')
Пример #14
0
    def it_can_show_its_thumbnail(self, tmpdir):
        tmp_path_ = tmpdir.mkdir("myslide")
        image = PILIMG.RGBA_COLOR_500X500_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))
Пример #15
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)
Пример #16
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)
Пример #17
0
from PIL import ImageShow
import os
from src.denoiser.mean_pixel import MeanPixel
from src.denoiser.median_pixel import MedianPixel
from src.denoiser.cnn import CnnAutoencoder
import numpy as np
from PIL import ImageFilter


class FehViewer(ImageShow.UnixViewer):
    def show_file(self, filename, **options):
        os.system('feh %s' % filename)
        return 1


ImageShow.register(FehViewer, order=-1)


def load_image(filename):

    img = Image.open(filename)
    img.load()
    data = np.asarray(img, dtype=np.uint8)
    return data.flatten()


def show_image_numpy(im):
    im = Image.fromarray(im.reshape(480, 720, 3))
    im.save("1.png")
    im.show()
Пример #18
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)
Пример #19
0
 def test_register(self):
     # Test registering a viewer that is not a class
     ImageShow.register("not a class")
Пример #20
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()))
Пример #23
0
 def test_show(self):
     for mode in ("1", "I;16", "LA", "RGB", "RGBA"):
         im = hopper(mode)
         self.assertTrue(ImageShow.show(im))
Пример #24
0
  __all__.append('serial')
except ModuleNotFoundError as e:
  pass

# try:
#   # from .video import camera
#   from . import display, rpycs
#   __all__.extend(['display', 'video', 'rpycs', 'camera'])
# except ModuleNotFoundError as e:
#   pass

try:
  from . import nn
  __all__.extend(['nn'])
except ModuleNotFoundError as e:
  pass

try:
  import shutil
  from PIL import ImageShow
  # use fbviewer on linux
  # os.system('ln -s /usr/sbin/fbviewer /usr/sbin/display')
  if shutil.which("fbviewer"):
    class fbViewer(ImageShow.UnixViewer):
      def get_command_ex(self, file, **options):
        command = executable = "fbviewer"
        return command, executable
    ImageShow.register(fbViewer, 0)
except ModuleNotFoundError as e:
  pass
Пример #25
0
class MyPrompts(Prompts):
    def in_prompt_tokens(self, cli=None):
        return [
            (Token.Other, ">>> "),
        ]

    def out_prompt_tokens(self):
        return [
            (Token.Prompt, ""),
        ]


class MyViewer(ImageShow.Viewer):
    format = "png"

    def get_command(self, file, **options):
        w = 1920 // 2
        h = w * 3 // 4
        left = (1920 - w) // 2
        top = (1080 - h) // 2

        return rf'mpv --no-terminal --geometry={w}x{h}+{left}+{top} "{file}"'


ImageShow.register(MyViewer, order=-1)

ip = get_ipython()
ip.prompts = MyPrompts(ip)

os.system("cls")
Пример #26
0
 def test_register(self):
     # Test registering a viewer that is not a class
     ImageShow.register("not a class")
Пример #27
0
def _showxv(image, title=None, **options):
    from PIL import ImageShow
    ImageShow.show(image, title, **options)    
Пример #28
0
    def test_register(self):
        # Test registering a viewer that is not a class
        ImageShow.register("not a class")

        # Restore original state
        ImageShow._viewers.pop()
Пример #29
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)
Пример #30
0
    def test_register(self):
        # Test registering a viewer that is not a class
        ImageShow.register("not a class")

        # Restore original state
        ImageShow._viewers.pop()
Пример #31
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)
Пример #32
0
 def Display(self):
     return ImageShow.show(self.picture)
Пример #33
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)