标签:
直接上源码,例子:
1 # -*- coding: utf-8 -*- 2 3 import numpy as np 4 import cv2 5 6 # 黑色的图片 7 img=np.zeros((512,512,3), np.uint8) 8 9 # 一条线 10 cv2.line(img,(0,0),(511,511),(255,0,0),5) 11 # 画一个矩形(左上角顶点和右下角顶点的坐标) 12 cv2.rectangle(img,(384,0),(510,128),(0,255,0),3) 13 # 画一个圆(中心点坐标和半径) 14 cv2.circle(img,(447,63), 63, (0,0,255), -1) 15 # 画一个椭圆 (0,180代表半个椭圆,0,360整个) 16 cv2.ellipse(img,(256,256),(100,50),0,0,360,255,-1) 17 # 具有四个顶点的多边形 18 # pts=np.array([[10,5],[20,30],[70,20],[50,10]], np.int32) 19 # pts=pts.reshape((-1,1,2)) 20 21 # 添加文字 22 font=cv2.FONT_HERSHEY_SIMPLEX 23 cv2.putText(img,‘OpenCV‘,(10,500), font, 4,(255,255,255),2) 24 25 #显示图片,最终的绘图结果 26 winname = ‘example‘ 27 cv2.namedWindow(winname) 28 cv2.imshow(winname, img) 29 cv2.waitKey(0) 30 cv2.destroyWindow(winname)
标签:
原文地址:http://www.cnblogs.com/jerrybaby/p/5848939.html