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()