Esempio n. 1
0
def ru_morpher(imgpaths, width=500, height=600, num_frames=20, fps=10, \
               out_frames=None, out_video=None, alpha=False, plot=False,
               obj=None, sessionid=None):
    """
    Create a morph sequence from multiple images in imgpaths
    :param imgpaths: array or generator of image paths
    :param callback: callback function on each point
    """
    oBack = {'status': 'ok', 'msg': ''}
    try:
        video = videoer.Video(out_video, fps, width, height)
        images_points_gen = load_valid_image_points(imgpaths, (height, width))
        src_img, src_points = next(images_points_gen)
        iStep = 0
        for dest_img, dest_points in images_points_gen:

            debugMsg("ru_morpher step {}".format(iStep))

            morph(src_img,
                  src_points,
                  dest_img,
                  dest_points,
                  video,
                  width,
                  height,
                  num_frames,
                  fps,
                  out_frames,
                  out_video,
                  alpha,
                  plot,
                  obj=obj,
                  sessionid=sessionid,
                  result_type="image")

            # Set the new source = old destination
            src_img, src_points = dest_img, dest_points

            iStep += 1

        # Check if any faces could be found in the image
        if iStep == 0:
            # This means that the points could not be found on the image
            print('debug point #3 in: ru_morpher')
            # No points were found
            oBack['status'] = "error"
            oBack['msg'] = "Er kan geen gezicht gevonden worden in dit beeld"
            debugMsg(oBack['msg'])

        debugMsg("ru_morpher video.end")
        video.end()
    except:
        sMsg = get_error_message()
        DoError("ru_morpher: ")
        oBack['status'] = 'error'
        oBack['msg'] = sMsg
    finally:
        return oBack
Esempio n. 2
0
def morph_ani(
    src_imgpaths,
    des_imgpath,
    num_pics,
    width=500,
    height=600,
    fps_in=24,
    slow_rate=5,
    out_frames=None,
    out_video=None,
    plot=False,
):
    num_frames = num_pics * slow_rate
    fps = fps_in * slow_rate

    video = videoer.Video(out_video, fps, width, height)
    plt = plotter.Plotter(plot, num_images=num_frames, out_folder=out_frames)

    dest_img, dest_points = load_image_points(des_imgpath, (height, width))
    images_points_gen = load_valid_image_points(src_imgpaths, (height, width))

    frameCount = 0
    for src_img, src_points in images_points_gen:
        if frameCount == 0:
            p_face = src_img
            p_points = src_points

        avg_face0, avg_points0 = morph_one(
            src_img, src_points, dest_img, dest_points,
            1 - float(frameCount) / (num_frames - 1), width, height)
        for i in range(0, slow_rate):
            avg_face, avg_points = morph_one(avg_face0, avg_points0, p_face,
                                             p_points,
                                             i / float(slow_rate - 1), width,
                                             height)
            mask = blender.mask_from_points(avg_face.shape[:2], avg_points)
            avg_face = np.dstack((avg_face, mask))
            plt.plot_one(avg_face)
            plt.save(avg_face)
            video.write(avg_face)
            frameCount = frameCount + 1
        p_face = avg_face0
        p_points = avg_points0

    video.end()
    plt.show()
Esempio n. 3
0
def morpher(imgpaths,
            width=500,
            height=600,
            num_frames=20,
            fps=10,
            out_frames=None,
            out_video=None,
            alpha=False,
            plot=False):
    """
  Create a morph sequence from multiple images in imgpaths
  :param imgpaths: array or generator of image paths
  """
    video = videoer.Video(out_video, fps, width, height)
    images_points_gen = load_valid_image_points(imgpaths, (height, width))
    src_img, src_points = next(images_points_gen)
    for dest_img, dest_points in images_points_gen:
        morph(src_img, src_points, dest_img, dest_points, video, width, height,
              num_frames, fps, out_frames, out_video, alpha, plot)
        src_img, src_points = dest_img, dest_points
    video.end()