从视频中检测过渡帧

时间:2015-11-24 21:57:34

标签: python arrays list python-2.7 if-statement

我想在计算机上添加一组图片到列表中。如果构成图像的像素的r,g和b值大于20,那么我想计算像素。如果特定图像的计数像素数大于20000,我想将该图像的位置添加到列表(trans_frames)。我想我的问题与#34;如果trans_check> 20000"声明。我也对如何将该列表保存到文件感兴趣。有什么建议?谢谢你提前。

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

0 个答案:

没有答案