python challenge 7

 1 #-*- coding:utf8-*-
2 import time
3 import Image
4 start = time.time()
5 #先将图片 oxygen.png 下载
6 import re, Image
7
8 i = Image.open("oxygen.png") # http://www.pythonchallenge.com/pc/def/oxygen.png
9 row = [i.getpixel((x, 45)) for x in range(0, i.size[0], 7)]
10 print row
11 ords = [r for r, g, b, a in row if r == g == b]
12 print ords
13 print "".join(map(chr, map(int, re.findall("\d+", "".join(map(chr, ords))))))
14 #integrity
15 #if __name__ == '__main__':
16
17 # img = Image.open('oxygen.png')
18 #
19 # #left,top,right,bottom
20 # box = (0, 43, 608, 52)
21 #
22 # belt = img.crop(box)
23 #
24 # #get a sequence object containing pixel values
25 # pixels = belt.getdata()
26 #
27 # print('mode: %s' % img.mode)
28 # print('amount of pixel: %d' % len(pixels))
29 # print(pixels[0])
30 #
31 # #convert mode RGBA to mode L
32 # lBelt = belt.convert('L')
33
34 # #get a sequence object containing pixel values
35 # lPixels = lBelt.getdata()
36 #
37 # #黑白条中的像素点有规律:每一行的像素点都是一样的,并且一行中也有相同的像素。
38 # #但有一点不好处理的是:字母间可以通过能否组成单词来判断是否有重复值,但数字
39 # #就不能通过这种方法来判断了
40 # str = []
41 #
42 # #step 7是通过试验出来的
43 # for i in range(0, 608, 7):
44 # str.append(chr(lPixels[i]))
45 # x = lPixels[i]
46 #
47 # print(''.join(str))
48
49
50 print "耗时:"+str(time.time() - start)
posted @ 2012-02-10 18:26  lcyang  阅读(320)  评论(0编辑  收藏  举报