#!/usr/bin/env python #-*- coding: utf-8 -*- import cv2 import numpy as np fn="test2.jpg" if __name__ == '__main__': print 'http://blog.csdn.net/myhaspl' print 'myhaspl@qq.com' print print 'loading %s ...' % fn img = cv2.imread(fn) sp=img.shape print sp #height sz1=sp[0] #width sz2=sp[1] print 'width:%d\nheight:%d'%(sz2,sz1) #创建一个窗口并显示图像 cv2.namedWindow('img') cv2.imshow('img', img) #创建原图像大小相同的空白图像,然后画线 myimg1=np.zeros((sz1,sz2), np.uint8) track = np.cumsum(np.random.rand(500000, 2)-0.5, axis=0) track = np.int32(track*10 + (sz1/2, sz2/2)) cv2.polylines(myimg1, [track], 0, 255, 1, cv2.CV_AA) cv2.namedWindow('myimg1') cv2.imshow('myimg1', myimg1) cv2.waitKey() cv2.destroyAllWindows()
opencv读取图像,获取图像大小,创建图像