一个弱爆的google 翻译客户端
如何获取京东商品价格和商品评分

01图

xhSong posted @ 2012年11月03日 19:12 in python with tags python bit map , 2449 阅读

事情很多,就是不想干。之前看到贴吧上一些帖子用字符做画,感觉挺好玩的。于是试着用python写一个用0和1以及作画的程序。先上几个作品吧!

            01                                                              
           01  1111111111111                                                
       11111   1111111    11111                                             
     0 111111 111111111   11111 1                                           
   1  1111111111111111111111111   1                                         
  0 11111111111111111111111111111110                                        
 1111  111111111 1 111111111111111111                                       
 1 1    111111    1111111111111111111                                       
011111111111111111111111111    1111111                                      
111111111111111111111111111   111111                                        
  111111111111111111111111111111111                                         
  111111111111    11111111111111   111                                      
 11111111111111  11111111111  1                                             
111      111111 1111110          111111111                                  
1111   11111 1   11  1          11111111111    11111111111       1111       
 1111111111 1      0           1111111111111               1  11111111111   
 1  1               11         1111111111                    1111111111111  
                     11         111111                         11111111111  
       0             1 1           1                            1111111111  
      01 0            0 0         1                              11111111   
     01 01             1        0 11111                           1         
      11 1             1 0     1 111111           1111111          1        
   0    1               1 1   1    1              11111111         1        
        1               11   0                       01111          1       
                        11100       111 1111                        1       
                  1 10111 111                                        1      
                    00101  1                                         1      
                          1                                          1      
                          1                                          1      
                          1                                  1 1     1      
                          1                                1  1      011    
                          1                               1110      11      
                          1                                         1       
                           1                                       1       1
                            0                                     1         
                              11                               11           
                                  011                    1111               
                                           1111111101                       

源图片:

萌1

 

                               1111             1111                            
          00000000000001 11                            11100000000000001        
       1000000000000001                                     10000000000000      
       0000000000000                                          1000000000000     
      10000000001                                                10000000001    
      100000000                                                    100000001    
       000000                                                        100000     
        001                                                            000      
         1                                                              0       
       00000000000000000000001                      0000000000000000000000      
      100000001        1000000001               0000000001        1100000001    
     0000001              100000000           100000001               0000001   
    000000        11110       0000001        0000001      011011       100000   
   100000   111     001        0000001      0000001       1001     111  100001  
   00000011                 100000000       1000000011                 1000000  
  1000000              0000000000001         10000000000001             1000000 
 100000000        1000000000001                   1000000000001        000000001
 10000000001   100000000001                            00000000001    1000000000
 000000000000000000001                                     110000000000000000000
 000000000000000001                                            10000000000000000
10000000000001                                                     1000000000000
11  100000                                                             100001  1
 1                                                                             0
 11                                                                            1
  0                                                                           1 
  11                                                                         11 
                                                                             1  
    11                                                                      1   
      0                                                                    0    
       11                                                                 1     
          1                                                            10       
           10                                                         1         
              11                                                   1            
                 111                                            11              
                      1111                                111                   
                              1000011111111111111111100000                      

源图片:

萌2

原理很简单,也没有什么技术含量,就是那个图片变换一下,定两个0和1的阀值,然后就ok了。

 

#!/usr/bin/python
# coding=utf-8
from Tkinter import *
from FileDialog import *
import Image

file_name = 'a.jpg'

def getFileName():
    file_dialog = LoadFileDialog(frame)
    global file_name
    file_name = file_dialog.go()
    try:
        img = Image.open(file_name)
    except:
        print 'openfile error'
    show_img.image = img
    show_img.pack()


def gen():
    try:
        img_o = Image.open(file_name)
    except:
        print 'openfile error'
    img_L = img_o.convert('L')
    size_x, size_y = img_o.size
    size_y = size_y * 80 / size_x / 2
    size_x = 80
#img_L.resize((size_x, size_y)).show()
    data = list(img_L.resize((size_x, size_y)).getdata())

    min_x, min_y = size_x, size_y
    max_x, max_y = 0, 0

    for i in range(0, size_y):
        for j in range(0, size_x):
            index = i * size_x + j
            if data[index] <= 170:
                min_x, min_y = min(min_x, j), min(min_y, i)
                max_x, max_y = max(max_x, j), max(max_y, i)
    genText.delete('1.0', 'end')
    for i in range(min_y, max_y + 1):
        for j in range(min_x, max_x + 1):
            index = i * size_x + j
            if data[index] > 170:
                to = ' '
            elif data[index] > 85:
                to = '1'
            else:
                to = '0'
            genText.insert('end', to)
        #print
        genText.insert('end', '\n')



if __name__ == "__main__":
     
    mainWindow = Tk()
    mainWindow.title()
    #mainWindow.geometry('640x480+0+0')
    
    frame = Frame(mainWindow)
    frame.pack()
    
    fileBotton = Button(frame, text =u"打开文件", command = getFileName)
    fileBotton.pack(side = LEFT)
    
    genBotton = Button(frame, text = u"生成", command = gen)
    genBotton.pack(side = LEFT)
    
    genText = Text(frame, height = 40)
    genText.pack(fill = BOTH, padx = 10, pady = 10)
    
    show_img = Label(frame)
    show_img.pack()
    mainWindow.mainloop()
Avatar_small
25penny.com 说:
2023年4月23日 14:31

During your visit to our website, there are chances to collect more information without making you directly acknowledged. Website does collect your personal information such as name, identity, Gender and would also collect the geographic location. During your visit to our website, there are chances to collect more information without 25penny.com making you directly acknowledged. Website does collect your personal information such as name, identity, Gender and would also collect the geographic location.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter