python:SampleCV编辑图
本帖最后由 1+1 于 2014-3-9 21:05 编辑我们利用“SimpleCV”库中的相关函数可以轻松的实现很多功能,具体的安装步骤可以点这里。现在我们来具体实现一些例程,将这张图片作为源图片:1、将图片翻转270°:
from SimpleCV import*
myDisplay = Display()
pcDuinoImage = Image("pcDuino.jpg")
while myDisplay.isNotDone():
if myDisplay.mouseLeft :
break
rotated = pcDuinoImage.rotate(270)
rotated.show()
2、剪切图片:
from SimpleCV import*
myDisplay = Display()
pcDuinoImage = Image("pcDuino.jpg")
while myDisplay.isNotDone():
if myDisplay.mouseLeft :
break
warped = pcDuinoImage.warp( ((100,0), (300,0), (450,400), (0,400)) )
warped.show()
3、胶片特效:
from SimpleCV import*
myDisplay = Display()
pcDuinoImage = Image("pcDuino.jpg")
while myDisplay.isNotDone():
if myDisplay.mouseLeft :
break
inverted = pcDuinoImage.invert()
inverted.show()
4、将图片变为灰色:
from SimpleCV import*
myDisplay = Display()
pcDuinoImage = Image("pcDuino.jpg")
while myDisplay.isNotDone():
if myDisplay.mouseLeft :
break
grey = pcDuinoImage.greyscale()
grey.show()
5,在图片上添加自己喜欢的字符串:
from SimpleCV import Image,Display,DrawingLayer,Color
from time import time,sleep
myDisplay = Display()
pcDuinoImage = Image("pcDuino.jpg")
myDrawingLayer = DrawingLayer((pcDuinoImage.width,pcDuinoImage.height))
myDrawingLayer.setFontSize(50)
myDrawingLayer.setFontItalic(True)
myDrawingLayer.text("MiNi PC + Arduino !",(10,20),color=Color.BLACK)
pcDuinoImage.addDrawingLayer(myDrawingLayer)
pcDuinoImage.applyLayers()
myDrawingLayer.setFontSize(50)
myDrawingLayer.setFontItalic(True)
myDrawingLayer.text("pcDuino",(70,70),color=Color.BLACK)
pcDuinoImage.addDrawingLayer(myDrawingLayer)
pcDuinoImage.applyLayers()
myDrawingLayer.rectangle ((430,570),(600,600),color=Color.RED,filled=True)
myDrawingLayer.setFontSize(30)
myDrawingLayer.setFontItalic(False)
myDrawingLayer.text("www.pcduino.org",(430,570),color=Color.WHITE)
pcDuinoImage.addDrawingLayer(myDrawingLayer)
pcDuinoImage.applyLayers()
pcDuinoImage.save(myDisplay)
while not myDisplay.isDone() :
sleep(0.2)
页:
[1]