1

I am new in coding and I want to create a chroma key automation for images using python and Pillow (https://pillow.readthedocs.org/en/3.0.x/handbook/tutorial.html). How can I proceed? Do you know other libraries to do this thing in a better way? Thank you for the answers.

Leonardo
  • 43
  • 7
  • Do you want to modify the input image based on the key or do you simply want to dump out the resulting matte to disk or another image object? – eestrada Jan 11 '16 at 18:58
  • I want that the code imports a photo taken with a green background and changes the green background with a random image located in a predefinited folder. Then I insert the code that I have already written to automatically post the output image on a specific facebook page. – Leonardo Jan 11 '16 at 22:25
  • Your SO question should be about one thing: turning 'green' pixels into transparent black (or whatever the pillow overlay function requires). Selecting a random background and posting are different functions. What experiments have you run? – Terry Jan Reedy Jan 12 '16 at 03:25
  • PS After writing the above and and hitting Enter, I googled 'python pillow chroma key' and found an SO question that appears to give an answer. There were non-SO hits also. – Terry Jan Reedy Jan 12 '16 at 03:31
  • I want to use a code like this one https://github.com/sinanm89/greenbox/blob/master/greensc.py but this code gives me some problems with the command numpy.array – Leonardo Jan 12 '16 at 11:41
  • Using Ubuntu instead of Windows, the code seems Ok. Now I have another question: how can I use the output file with the second part of the code that uploads the image on facebook?This is the code http://pastebin.com/dNs4T9TH – Leonardo Jan 12 '16 at 17:25
  • @Leonardo How to upload the image file to facebook should be posted as an altogether separate question. – eestrada Jan 12 '16 at 23:41
  • @eestrada. Ok. About the same code that I have linked I have a question: how can I use image.open() to open a random file from the folder /background ? – Leonardo Jan 13 '16 at 23:29
  • @Leonardo You can do it by importing the `os` and `random` modules. Put all the file paths into a list using `os.listdir`, then choose a random item using `random.choice`. The file path that is returned should then be passed to `Image.open`. – eestrada Jan 13 '16 at 23:49
  • @eestrada i have tried the command:[code] BG = Image.open(random.choice(os.listdir('/home/leonardo/Scrivania/background'))).convert('RGB') [/code] but it gives me this error http://pastebin.com/uZU98jBH – Leonardo Jan 14 '16 at 00:23
  • @Leonardo If you are having this much trouble, then you should open another question about the issue. Stack overflow questions are meant to address one issue at a time so that answers can be useful to others. The fact that this comment thread has gone on for as long as it has is a bad thing. I know it takes longer to open a new question, but that is what you need to do if you want help. I am personally happy to answer your questions, but you need to make a new stack overflow question if you have a separate question from the original one here (which you do). – eestrada Jan 14 '16 at 00:30

0 Answers0