pyphon 根据数据将图片分割成小片

 

import string
import cv2
f=open("Data.txt","r")

a = []
b = []
for eachline in f:
    eachline = eachline.strip()
    eachline = eachline.split("   ") 
    for i in eachline:        
        i = string.atof(i)
        i = str(i)
        b.append(i)
        if len(b) == 4:
            a.append(b)
            b = []

i_mg = cv2.imread("orz3s.BMP")
i=0
for data in a :
    
    x = float(data[0])
    y = float(data[1])
    w = float(data[2])
    h = float(data[3])
    i+=1
    I_mg = i_mg[y:h,x:w]
    
    
    c = cv2.imwrite(str(i)+".BMP", I_mg)
    #d.append(c)
    #c = []
    cv2.waitKey(0)
cv2.destroyAllWindows()

 

 

posted @ 2014-01-14 11:53  黑仔啊哈  阅读(304)  评论(0)    收藏  举报