123456789101112131415161718192021222324252627 |
- from array import array
- import numpy as np
- import cv2 as cv
- # 加载图片到灰度图像
- img = cv.imread('C:\TSP\png.png', cv.IMREAD_GRAYSCALE)
- h,w = img.shape
- print(h,w)
- print(img.size)
- f = open('C:\TSP\BITMAP', 'w')
- line = '%d %d %d\n' % (h,w, img.size)
- f.write(line)
- lst = ['0'] * w
- for m in range(h):
- for n in range(w):
- if img[m,n] == 0:
- lst[n] = '1'
- else:
- lst[n] = '0'
- line = ' '.join(lst)
- f.write(line+'\n')
- # cv.imshow('image',img)
- # cv.waitKey(5000)
- # cv.destroyAllWindows()
|