async def ify(ctx, scale, path, file_name, *args):
    """Command to paste a face on top of faces in an inputed image using facial recognition

       Args:
        - ctx: context that the command occured use this to access the message and other attributes
        - args: arguments of the message
        - scale: specified scale for the faces
        - path: face image path
        - file_name: output file name
    """
    channel = ctx.channel
    url = over.get_image_url_args(ctx, args[0], 1, 0)
    if url == 0:  # invalid image
        await channel.send(embed=discord.Embed(description="Invalid image",
                                               color=discord.Color.red()))
        return
    else:
        output = paste_on_face(Path(path), url, scale)
    # if there were no faces found then send error
    if output == 0:
        await channel.send(embed=discord.Embed(
            description='No faces found, please input another image',
            color=discord.Color.red()))
        return

    output.save(file_name)
    try:
        message = await channel.send(file=discord.File(file_name))
        track_command(ctx.author.id, message)
    except:
        await channel.send(embed=discord.Embed(description="Image too large",
                                               color=discord.Color.red()))
    os.remove(file_name)
Exemplo n.º 2
0
async def barrify(ctx):
    url = get_image_url(ctx)
    if url == 0:  # invalid image
        await client.send_message(ctx.message.channel,
                                  embed=discord.Embed(
                                      description="Invalid image",
                                      color=discord.Color.red()))
        return
    else:
        output = paste_on_face(Path('memes/barrington/barr-face.png'), url)
    output.save('barrify.png')
    message = await client.send_file(ctx.message.channel, 'barrify.png')
    track_command(ctx.message.author.id, message)
    os.remove('barrify.png')
Exemplo n.º 3
0
async def ify(ctx, scale, path, file_name, *args):
    """Command to paste a face on top of faces in an inputed image using facial recognition

       Args:
        - ctx: context that the command occured use this to access the message and other attributes
        - args: arguments of the message
        - scale: specified scale for the faces
        - path: face image path
        - file_name: output file name
    """
    channel = ctx.channel
    async with channel.typing():
        url = over.get_image_url_args(ctx.message, args[0], 1, 0)
        if url == 0:  # invalid image
            # 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)
            else:
                await channel.send(embed=discord.Embed(
                    description=
                    "No previous bot command to pull from. Please specify a valid image.",
                    color=discord.Color.red()))
                return
        try:
            output = paste_on_face(Path(path), url, scale)
        except:
            await channel.send(embed=discord.Embed(
                description='Unidentified Image, try a different image',
                color=discord.Color.red()))
        # if there were no faces found then send error
        if output == 0:
            await channel.send(embed=discord.Embed(
                description='No faces found, please input another image',
                color=discord.Color.red()))
            return

        output.save(file_name)
        try:
            message = await channel.send(file=discord.File(file_name))
            track_command(ctx.author.id, message)
        except:
            await channel.send(embed=discord.Embed(
                description="Image too large", color=discord.Color.red()))
    os.remove(file_name)
def test_facedetection02():
    """Test pasting on face with multiple faces"""

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

    image_link = 'https://p1.pxfuel.com/preview/133/768/57/sikhs-india-indians-people-turban-sikhism-smile.jpg'
    scale = face_detection.mar_scale
    path = Path('memes/marius/marius-face.png')

    output = face_detection.paste_on_face(path, image_link, scale)
    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
def test_facedetection01():
    """Test pasting on face with one face"""

    fname = base + '01.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'
    scale = face_detection.barr_scale
    path = Path('memes/barrington/barr-face.png')

    output = face_detection.paste_on_face(path, image_link, scale)
    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