python生成测试图片

直接代码

 1 import cv2.cv as cv
 2 saveImagePath = E:/ScreenTestImages/
 3 
 4 colorRed = [0,0,255]
 5 colorGreen = [0,255,0]
 6 colorBlue = [255,0,0]
 7 colorWhite = [255,255,255]
 8 colorBlack = [0,0,0]
 9 colorAqua = [255,255,0]
10 colorFuchsia = [255,0,255]
11 colorYellow = [0,255,255]
12 
13 stardardColors = [colorBlue,colorGreen,colorAqua,colorRed,colorFuchsia,colorYellow,colorWhite]
14 
15 def createImg(depth=3):
16     return cv.CreateImage((800,480),8,depth)
17 
18 def saveImageFile(typeName,img):
19     filename = saveImagePath + typeName + .png
20     cv.SaveImage(filename,img)
21     print typeName+.png,\t\t...\tok
22 
23 def createOneColorImage(color):
24     img = createImg()
25     cv.Set(img,color)
26     return img
27 
28 def create64GrayImage():
29     img = createImg(1)
30     cv.SetZero(img)
31     for xPos in range(0,64):
32         cv.SetImageROI(img,(int(12.5*xPos),0,800,480))
33         cv.Set(img,xPos*255/63)
34         cv.ResetImageROI(img)
35     return img
36 
37 def createCheckBoardPattern(isReserved=False):
38     img = createImg(1)
39     boolColor = True
40     numsX = 4
41     numsY = 4
42     pixsX = 800/numsX
43     pixsY = 480/numsY
44     for x in range(0,numsX):
45         for y in range(0,numsY):
46             cv.SetImageROI(img,(x*pixsX,y*pixsY,(x+1)*pixsX,(y+1)*pixsY))
47             boolColor = not (x%2) ^ (y%2) ^ isReserved            
48             cv.Set(img,255*boolColor)
49             cv.ResetImageROI(img)           
50     return img
51 
52 def createStardardImage():
53     img = createImg()
54     pixs = 800./7
55     for i in range(0,7):
56         cv.SetImageROI(img,(int(i*pixs),0,int(i*pixs+pixs),480))
57         cv.Set(img,stardardColors[i])
58         cv.ResetImageROI(img)
59     return img
60 
61 if __name__ == __main__:
62     print Start Gen Test Screen Files ...
63     saveImageFile(red,createOneColorImage(colorRed))
64     saveImageFile(green,createOneColorImage(colorGreen))
65     saveImageFile(blue,createOneColorImage(colorBlue))    
66     saveImageFile(white,createOneColorImage(colorWhite))
67     saveImageFile(black,createOneColorImage(colorBlack))
68     saveImageFile(64gray,create64GrayImage())
69     saveImageFile(checkboard Pattern,createCheckBoardPattern())
70     saveImageFile(checkboard Pattern(inverted),createCheckBoardPattern(True))
71     saveImageFile(standard,createStardardImage())
72     print Generate Success!
73     

贴上非单色图片的样子:

64 gray:

python生成测试图片

checkboard pattern:

python生成测试图片

checkboard pattern(inverted):

python生成测试图片

 

standard:

python生成测试图片

python生成测试图片,布布扣,bubuko.com

python生成测试图片

上一篇:Anaconda+django写出第一个web app(十)


下一篇:[C#] C# 知识回顾 - 你真的懂异常(Exception)吗?