Пример #1
0
def load_image_points(path, size):
  print 'in load image points'
  img = scipy.ndimage.imread(path)[..., :3]
  points = locator.face_points(path)
  if len(points) == 0:
    print 'No face in %s' % path
    return None, None
  else:
    # print 'Face landmark points : ',points
    # for i in range (0,71):
    #   cv2.line(img, (points[i][0],points[i][1]), (points[i][0],points[i][1]), (0,255,0),5)
    # cv2.imshow('original points',img)
    # cv2.waitKey(0)

    cv2.line(img, (points[18][0],points[18][1]), (points[18][0],points[18][1]), (255,224,0),5)
    cv2.line(img, (points[21][0],points[21][1]), (points[21][0],points[21][1]), (255,224,0),5)
    cv2.line(img, (points[22][0],points[22][1]), (points[22][0],points[22][1]), (255,224,0),5)
    cv2.line(img, (points[25][0],points[25][1]), (points[25][0],points[25][1]), (255,224,0),5)

    cv2.line(img, (points[30][0],points[30][1]), (points[30][0],points[30][1]), (255,0,0),5)
    cv2.line(img, (points[40][0],points[40][1]), (points[40][0],points[40][1]), (255,0,0),5)

    cv2.line(img, (points[54][0],points[54][1]), (points[54][0],points[54][1]), (0,255,0),5)
    cv2.line(img, (points[56][0],points[56][1]), (points[56][0],points[56][1]), (0,255,0),5)
    cv2.line(img, (points[58][0],points[58][1]), (points[58][0],points[58][1]), (0,255,0),5)

    cv2.line(img, (points[59][0],points[59][1]), (points[59][0],points[59][1]), (0,0,255),5)
    cv2.line(img, (points[65][0],points[65][1]), (points[65][0],points[65][1]), (0,0,255),5)
    cv2.imshow("img",img)
    cv2.waitKey(0)
    return aligner.resize_align(img, points, size)
Пример #2
0
def load_image_points(path, size):
    # print 'in load image points'
    # img = scipy.ndimage.imread(path)[..., :3]
    img = cv2.imread(path)[..., :3]
    # print 'in load image points'
    # img = scipy.ndimage.imread(path)[..., :3]
    points = locator.face_points(path)
    if len(points) == 0:
        print 'No face in %s' % path
        return None, None
    else:
        # print 'Face landmark points : ',points
        # for i in range (0,71):
        #   cv2.line(img, (points[i][0],points[i][1]), (points[i][0],points[i][1]), (0,255,0),5)
        # cv2.imshow('original points',img)
        # cv2.waitKey(0)

        # cv2.line(img, (points[18][0],points[18][1]), (points[18][0],points[18][1]), (255,224,0),5)
        # cv2.line(img, (points[21][0],points[21][1]), (points[21][0],points[21][1]), (255,224,0),5)
        # cv2.line(img, (points[22][0],points[22][1]), (points[22][0],points[22][1]), (255,224,0),5)
        # cv2.line(img, (points[25][0],points[25][1]), (points[25][0],points[25][1]), (255,224,0),5)
        #
        # cv2.line(img, (points[30][0],points[30][1]), (points[30][0],points[30][1]), (255,0,0),5)
        # cv2.line(img, (points[40][0],points[40][1]), (points[40][0],points[40][1]), (255,0,0),5)
        #
        # cv2.line(img, (points[54][0],points[54][1]), (points[54][0],points[54][1]), (0,255,0),5)
        # cv2.line(img, (points[56][0],points[56][1]), (points[56][0],points[56][1]), (0,255,0),5)
        # cv2.line(img, (points[58][0],points[58][1]), (points[58][0],points[58][1]), (0,255,0),5)
        #
        # cv2.line(img, (points[59][0],points[59][1]), (points[59][0],points[59][1]), (0,0,255),5)
        # cv2.line(img, (points[65][0],points[65][1]), (points[65][0],points[65][1]), (0,0,255),5)
        # cv2.imshow("img",img)
        # cv2.waitKey(0)
        # return aligner.resize_align(img, points, size)
        return aligner.resize_align(img, points, size)
Пример #3
0
def load_image_points(path, size):
  img = scipy.ndimage.imread(path)[..., :3]
  points = locator.face_points(path)

  if len(points) == 0:
    return None, None
  else:
    return aligner.resize_align(img, points, size)
Пример #4
0
def load_image_points(path, size):
    img = scipy.ndimage.imread(path)[..., :3]
    points = locator.face_points(path)

    if len(points) == 0:
        return None, None
    else:
        return aligner.resize_align(img, points, size)
Пример #5
0
def load_image_points(path, size):
    img = cv2.imread(path)
    points = locator.face_points(img)

    if len(points) == 0:
        print('No face in %s' % path)
        return None, None
    else:
        return aligner.resize_align(img, points, size)
Пример #6
0
def test_local():
    from functools import partial
    import cv2
    import scipy.misc
    import locator
    import aligner
    from matplotlib import pyplot as plt

    # Load source image
    face_points_func = partial(locator.face_points, '../data')
    base_path = '../females/Screenshot 2015-03-04 17.11.12.png'
    src_path = '../females/BlDmB5QCYAAY8iw.jpg'
    src_img = cv2.imread(src_path)

    # Define control points for warps
    src_points = face_points_func(src_path)
    base_img = cv2.imread(base_path)
    base_points = face_points_func(base_path)

    size = (600, 500)
    src_img, src_points = aligner.resize_align(src_img, src_points, size)
    base_img, base_points = aligner.resize_align(base_img, base_points, size)
    result_points = locator.weighted_average_points(src_points, base_points,
                                                    0.2)

    # Perform transform
    dst_img1 = warp_image(src_img, src_points, result_points, size)
    dst_img2 = warp_image(base_img, base_points, result_points, size)

    import blender
    ave = blender.weighted_average(dst_img1, dst_img2, 0.6)
    mask = blender.mask_from_points(size, result_points)
    blended_img = blender.poisson_blend(dst_img1, dst_img2, mask)

    plt.subplot(2, 2, 1)
    plt.imshow(ave)
    plt.subplot(2, 2, 2)
    plt.imshow(dst_img1)
    plt.subplot(2, 2, 3)
    plt.imshow(dst_img2)
    plt.subplot(2, 2, 4)

    plt.imshow(blended_img)
    plt.show()
Пример #7
0
def test_local():
  from functools import partial
  import scipy.ndimage
  import scipy.misc
  import locator
  import aligner
  from matplotlib import pyplot as plt

  # Load source image
  face_points_func = partial(locator.face_points, '../data')
  base_path = '../females/Screenshot 2015-03-04 17.11.12.png'
  src_path = '../females/BlDmB5QCYAAY8iw.jpg'
  src_img = scipy.ndimage.imread(src_path)[:, :, :3]

  # Define control points for warps
  src_points = face_points_func(src_path)
  base_img = scipy.ndimage.imread(base_path)[:, :, :3]
  base_points = face_points_func(base_path)

  size = (600, 500)
  src_img, src_points = aligner.resize_align(src_img, src_points, size)
  base_img, base_points = aligner.resize_align(base_img, base_points, size)
  result_points = locator.weighted_average_points(src_points, base_points, 0.2)

  # Perform transform
  dst_img1 = warp_image(src_img, src_points, result_points, size)
  dst_img2 = warp_image(base_img, base_points, result_points, size)

  print 'blending'
  import blender
  ave = blender.weighted_average(dst_img1, dst_img2, 0.6)
  mask = blender.mask_from_points(size, result_points)
  blended_img = blender.poisson_blend(dst_img1, dst_img2, mask)

  plt.subplot(2, 2, 1)
  plt.imshow(ave)
  plt.subplot(2, 2, 2)
  plt.imshow(dst_img1)
  plt.subplot(2, 2, 3)
  plt.imshow(dst_img2)
  plt.subplot(2, 2, 4)

  plt.imshow(blended_img)
  plt.show()
Пример #8
0
def load_image_points(path, size):
    img = scipy.ndimage.imread(path)[..., :3]
    points = locator.face_points(path)
    ## Add image boundary points
    #x,y = np.meshgrid([0,size[0]/2,size[0]],[0,size[1]/2,size[1]])
    #im_edge_points = np.vstack((y.flatten(),x.flatten())).T
    #points = np.vstack((points,im_edge_points))

    if len(points) == 0:
        print('No face in %s' % path)
        return None, None
    else:
        return aligner.resize_align(img, points, size)
Пример #9
0
def load_image_points(path, size, fromDb=False):
  img = scipy.ndimage.imread(path)[..., :3]
  if fromDb:
    with con:
      cur = con.cursor()
      data = cur.execute("SELECT points FROM entries WHERE name=?", ([os.path.basename(path)]))
      points = convert_array(cur.fetchone()[0])
  else:
    points = locator.face_points(path)

  if len(points) == 0:
    return None, None
  else:
    return aligner.resize_align(img, points, size)