mardi 24 novembre 2015

Detection of Transition Frames from Video

I would like to add a set of pictures on my computer to a list. If the r, g and b values of a pixel constituting the image are greater than 20, then I want to count the pixel. If the number of counted pixels is greater than 20000 for a particular image, I want add the location of that image to a list (trans_frames). I think I am having issues with the "if trans_check > 20000" statement. I am also interested in how to save that list to a file. Any suggestions? Thanks in advanced.

from PIL import Image
import glob

all_frames = glob.glob('/Users/isaiahnields/Documents/Code/#g_isaiah/Python/Code/Isaiah/Subtractions/'+'/*.png') #add location of pictures to list
all_frames.sort() #sort pictures in numberical order
trans_frames = [] #transition frames list
for index in range(0, len(all_frames)): #for loop for each picture
    image1_nominal = all_frames[index]
    image1 = Image.open(image1_nominal)
    width, height = image1.size
    trans_check = 0
    for x in range(0 , width):
        for y in range(0 , height):
            r, g, b = image1.getpixel( (x,y))
            if r > 20 and g > 20 and b > 20:
                trans_check = trans_check + 1
                if trans_check > 20000: #I am having issues here
                    trans_check = 0
                    trans_frames.append(image1_nominal)
                    print trans_frames

Aucun commentaire:

Enregistrer un commentaire