def test_overlay03():
    """Test draw image command"""

    fname = base + '03.png'
    tname = os.path.join(tdir, fname)
    rname = os.path.join(refd, fname)

    image_link = 'https://s.hdnux.com/photos/51/23/24/10827008/3/920x920.jpg'
    path = Path('memes/lan/landrew.png')
    origin = overlay.landrew_origin

    output = overlay.overlay_image(overlay.url_to_image(image_link), path,
                                   origin)
    output.save(tname)

    tsize = os.path.getsize(tname)
    print(glob.glob(tname), '[', tsize, 'bytes', ']')

    rsize = os.path.getsize(rname)
    print(glob.glob(rname), '[', rsize, 'bytes', ']')

    result = compare_images(rname, tname, tol=TOLERANCE)
    if result is not None:
        print('result=', result)
    assert result is None
Пример #2
0
def make_draw_gif(frameList, num):
    imageClipLists = []
    frameLength = 1.0 / 24.0
    for frame in frameList:
        if num == 0:
            frame = overlay_image(frame, Path("memes/barrington/bdraw.png"),
                                  barr_origin)
        elif num == 1:
            frame = overlay_image(frame, Path("memes/marius/draw.png"),
                                  marius_origin)
        elif num == 2:
            frame = overlay_image(frame, Path("memes/tim/tdraw.png"),
                                  tim_origin)
        elif num == 3:
            frame = overlay_image(frame, Path("memes/sheldraw.png"),
                                  shel_origin)
        elif num == 4:
            frame = overlay_image(frame, Path("memes/lan/lan-draw.png"),
                                  lan_origin)
        elif num == 5:
            frame = overlay_image(frame, Path("memes/hand.png"), hand_origin)
        elif num == 6:
            frame = overlay_image(frame, Path("memes/lan/landrew.png"),
                                  landrew_origin)
        arr = np.array(frame)
        clip = mp.ImageClip(arr)
        clip = clip.set_duration(frameLength)
        imageClipLists.append(clip)
    #print(imageClipLists)
    concatClip = mp.concatenate_videoclips(imageClipLists, method="compose")
    return concatClip
Пример #3
0
async def draw_universal(ctx, path, command_end_index, origin, name):
    """Universal function which is called by draw command with the following arguments

       Args:
        - ctx: context that the command occured use this to access the message and other attributes
        - path: path to the drawing image (ie memes/lan/landrew.png)
        - command_end_index: index the end of the command (ie. for bdraw its 7 for '$' 'b' 'd' 'r' 'a' 'w' ' ')
        - origin: pixel origin imported from overlay.py
        - name: output file name
    """
    channel = ctx.channel
    async with channel.typing():
        url = over.get_image_url(ctx.message, command_end_index)
        if url == 0:  # no url, hand should write the inputed text
            if len(ctx.message.content[command_end_index:].strip()) == 0:
                # no input given, try to use previous bot output
                if bot_last_command[ctx.author.id] is not None:
                    message = bot_last_command[ctx.author.id]
                    url = over.get_image_url(message, 0)
                    output = over.overlay_image(over.url_to_image(url),
                                                Path(path), origin)
                else:
                    await channel.send(embed=discord.Embed(
                        description=
                        "No previous bot command to pull from. Please specify text or an image.",
                        color=discord.Color.red()))
                    return
            else:
                output = over.draw_text(
                    ctx.message.content[command_end_index:], Path(path),
                    origin)
        else:  # url inputed, hand should draw on the image
            output = over.overlay_image(over.url_to_image(url), Path(path),
                                        origin)
        output.save(name + '.png')
        try:
            message = await channel.send(file=discord.File(name + '.png'))
        except:
            message = await channel.send(embed=discord.Embed(
                description="Image too large", color=discord.Color.red()))
        track_command(ctx.author.id,
                      message)  # tracks the most recent command of a user
    os.remove(name + '.png')
async def draw_universal(ctx, path, command_end_index, origin, name):
    """Universal function which is called by draw command with the following arguments

       Args:
        - ctx: context that the command occured use this to access the message and other attributes
        - path: path to the drawing image (ie memes/lan/landrew.png)
        - command_end_index: index the end of the command (ie. for bdraw its 7 for '$' 'b' 'd' 'r' 'a' 'w' ' ')
        - origin: pixel origin imported from overlay.py
        - name: output file name
    """
    channel = ctx.channel
    #in case of gif
    url = over.get_gif_url(ctx, command_end_index)
    if url != 0:
        #get list of frames
        imgList = over.gif_url_to_image_list(url, 1)
        if imgList == 0:
            #if invalid list return
            await channel.send(embed=discord.Embed(description="invalid image",
                                                   color=discord.Color.red()))
            return
            #get list of image clips
        gifClip = make_draw_gif(imgList, 0)
        gifClip.write_gif(name + '.gif', 24, program='imageio')
        try:
            #check if message is <8 mb
            message = await channel.send(file=discord.File(name + '.gif'))
        except:
            #random color cause why not
            randRGB = lambda: random.randint(0, 255)
            randColor = int('%02X%02X%02X' % (randRGB(), randRGB(), randRGB()),
                            16)
            os.remove(name + '.gif')
            await channel.send(embed=discord.Embed(
                description="GIF + image becomes too large to send, sorry :(",
                color=randColor))
            return
        track_command(ctx.author.id, message)
        os.remove(name + '.gif')
        return
    url = over.get_image_url(ctx, command_end_index)
    if url == 0:  # no url, hand should write the inputed text
        output = over.draw_text(ctx.message.content[command_end_index:],
                                Path(path), origin)
    else:  # url inputed, hand should draw on the image
        output = over.overlay_image(over.url_to_image(url), Path(path), origin)
    output.save(name + '.png')
    try:
        message = await channel.send(file=discord.File(name + '.png'))
    except:
        message = await channel.send(embed=discord.Embed(
            description="Image too large", color=discord.Color.red()))
    track_command(ctx.author.id,
                  message)  # tracks the most recent command of a user
    os.remove(name + '.png')
Пример #5
0
async def bdraw(ctx):
    url = get_image_url(ctx)
    if url == 0:
        output = draw_text(ctx.message.content[7:],
                           Path('memes/barrington/bdraw.png'))
    else:
        output = overlay_image(url_to_image(url),
                               Path('memes/barrington/bdraw.png'))
    output.save('barrington-drawing.png')
    await client.send_file(ctx.message.channel, 'barrington-drawing.png')
    os.remove('barrington-drawing.png')
Пример #6
0
async def mdraw(ctx):
    url = get_image_url(ctx)
    if url == 0:
        output = draw_text(ctx.message.content[7:],
                           Path('memes/marius/draw.png'))
    else:
        output = overlay_image(url_to_image(url),
                               Path('memes/marius/draw.png'))
    name = 'marius-drawing.png'
    output.save(name)
    await client.send_file(ctx.message.channel, name)
    os.remove(name)
Пример #7
0
async def bdraw(ctx):
    url = get_image_url(ctx)
    if url == 0:
        output = draw_text(ctx.message.content[7:],
                           Path('memes/barrington/bdraw.png'), barr_origin)
    else:
        output = overlay_image(url_to_image(url),
                               Path('memes/barrington/bdraw.png'), barr_origin)
    output.save('barrington-drawing.png')
    message = await client.send_file(ctx.message.channel,
                                     'barrington-drawing.png')
    track_command(ctx.message.author.id, message)
    os.remove('barrington-drawing.png')
Пример #8
0
async def mdraw(ctx):
    url = get_image_url(ctx)
    if url == 0:
        output = draw_text(ctx.message.content[7:],
                           Path('memes/marius/draw.png'), marius_origin)
    else:
        output = overlay_image(url_to_image(url),
                               Path('memes/marius/draw.png'), marius_origin)
    name = 'marius-drawing.png'
    output.save(name)
    message = await client.send_file(ctx.message.channel, name)
    track_command(ctx.message.author.id, message)
    os.remove(name)
Пример #9
0
        lm = cv2.threshold(lm.copy(), 0, 255, cv2.THRESH_BINARY)[1]
        lm = imutils.rotate_bound(lm, le_angle)
        lm = imutils.resize(lm, width=ear_width, inter=cv2.INTER_NEAREST)

        rm = cv2.cvtColor(r_ear_mask, cv2.COLOR_BGR2GRAY)
        rm = cv2.threshold(rm.copy(), 0, 255, cv2.THRESH_BINARY)[1]
        rm = imutils.rotate_bound(rm, re_angle)
        rm = imutils.resize(rm, width=ear_width, inter=cv2.INTER_NEAREST)

        nm = cv2.cvtColor(nossy_mask, cv2.COLOR_BGR2GRAY)
        nm = cv2.threshold(nm.copy(), 0, 255, cv2.THRESH_BINARY)[1]
        nm = imutils.rotate_bound(nm, nose_angle)
        nm = imutils.resize(nm, width=nose_width, inter=cv2.INTER_NEAREST)

        nh = width(shape[30], shape[33])

        output = overlay_image(output, left_ear, lm,
                               (int(x + 0.7 * w), int(y - h / 2.2)))
        output = overlay_image(output, right_ear, rm, (x, int(y - h / 2.2)))
        output = overlay_image(
            output, Nose, nm,
            (int(nose[0][0] - nose_width * 0.2), int(shape[30][1] - nh * 1.3)))

    cv2.imshow("image", output)
    key = cv2.waitKey(1) & 0xFF

    # if the `q` key was pressed, break from the loop
    if key == ord("q"):
        break
cv2.destroyAllWindows()
        dx = re_center[0] - le_center[0]
        angle = np.degrees(np.arctan2(dy, dx)) - 180

        # print(angle)

        glass1 = imutils.rotate_bound(glass, angle)

        glass1 = imutils.resize(glass1, width=g_width)

        glass_height = glass1.shape[0]

        mask1 = cv2.cvtColor(mask, cv2.COLOR_BGR2GRAY)
        mask1 = cv2.threshold(mask1.copy(), 0, 255, cv2.THRESH_BINARY)[1]
        mask1 = imutils.rotate_bound(mask1, angle)

        mask1 = imutils.resize(mask1, width=g_width, inter=cv2.INTER_NEAREST)

        output = overlay_image(
            output, glass1, mask1,
            shift(g_width, glass_height, angle, re_center[0], re_center[1]))

# cv2.imwrite(f"Results/result{sys.argv[2]}.jpg",output)
# print("Boom! Boom! Done!")
    cv2.imshow("image", output)
    key = cv2.waitKey(1) & 0xFF

    # if the `q` key was pressed, break from the loop
    if key == ord("q"):
        break
cv2.destroyAllWindows()