###机器学习和OpenCV for Python操作图形文件和图形操作####
####utf8#####
from nupmy import *
ipmort cv2
win _name = ‘mypicture‘ #窗口名称
#CV2.window_mormal: 调整窗口大小
cv2.namedWindow(win_name,cv2.WINDOW_MORMAL) #0 黑白图片,1原色图片
img = cv2.imread (‘mypicture.jpg‘,1) #显示图片
cv2.waitkey(0)
cv2.destoryAllWindows() #销毁创建的对象
######保存图片:OpenCV 可将图片转换为PGM格式#######
cv2.imwrite("paulwalke.mono.pgm",img)
#######Matplolib显示图片#########
from matplotlib import python as plt
img = cv2.imread(‘paulwalker.mono.pgm’,0)#读取黑白图片
plt.imshow(img,cmap = ‘gray‘ , interpolation = ‘bicubic‘)
plt.xticks({}),plt,yticks({}) #隐藏x,y坐标
############绘制直线and矩形####
img=zeros(512,512,3)
#起点,(0,0)终点(511,511),颜色(0,255,255) 像素:2
cv2.line(img,(0,255),(512,255),(0,255,255),2) #直线
左上角:(150,150);右小角:(350,350) 颜色:(255,255,0) 像素:2
cv2.imshow(‘image’,img)
cv2 .waitKey(0)
cv2.destoryALLindows()
.
本文出自 “honglin” 博客,谢绝转载!
原文地址:http://huanghonglin.blog.51cto.com/11324462/1851770