karanvivekbhargava / obamanet

ObamaNet : Photo-realistic lip-sync from audio (Unofficial port)
MIT License
235 stars 71 forks source link

Release the code about how to get the cropped images #2

Closed JianxiangWang closed 5 years ago

JianxiangWang commented 6 years ago

Copy the patched images into folder a and the cropped images to folder b ==> Could you release the code about how to get the cropped images ?

Thank you ~

karanvivekbhargava commented 6 years ago

I had created a script to do the same. I'll add it to the repository soon. Thanks

karanvivekbhargava commented 5 years ago
import matplotlib.pyplot as plt
from glob import glob

filelist = sorted(glob('testing/*.bmp')) # ('images/*.bmp')

for i in range(len(filelist)):
    img = cv2.imread(filelist[i])
    x = int(np.floor((img.shape[1]-256)/2))
    crop_img = img[0:256, x:x+256]
    # cv2.imshow("cropped", crop_img)
    # cv2.waitKey(1000)
    filename = 'testing_cropped_images/' + str(i) + '.bmp' 
    # filename = 'cropped_images/' + str(i) + '.bmp'
    print(filename)
    cv2.imwrite(filename, crop_img)

You might have to make some changes to this @JianxiangWang . But this should do the trick, or give you an idea on how to do this.

ak9250 commented 5 years ago

@karanvivekbhargava do you need to crop images of the head will https://github.com/leblancfg/autocrop work, also I am looking to turn the whole process in google colab

PMA65 commented 3 years ago

Is this code snippet supposed to crop the mouth region ? If yes, do we tweak it manually to crop the mouth ? Thanks for sharing

import matplotlib.pyplot as plt
from glob import glob

filelist = sorted(glob('testing/*.bmp')) # ('images/*.bmp')

for i in range(len(filelist)):
  img = cv2.imread(filelist[i])
  x = int(np.floor((img.shape[1]-256)/2))
  crop_img = img[0:256, x:x+256]
  # cv2.imshow("cropped", crop_img)
  # cv2.waitKey(1000)
  filename = 'testing_cropped_images/' + str(i) + '.bmp' 
  # filename = 'cropped_images/' + str(i) + '.bmp'
  print(filename)
  cv2.imwrite(filename, crop_img)

You might have to make some changes to this @JianxiangWang . But this should do the trick, or give you an idea on how to do this.

PMA65 commented 3 years ago

Also could you please provide the steps (no code just how you went from images to cropped/patched to end result) it seems your readme file is missing some parts