首页 > 代码库 > python生成测试图片

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 + .png20     cv.SaveImage(filename,img)21     print typeName+.png,\t\t...\tok22 23 def createOneColorImage(color):24     img = createImg()25     cv.Set(img,color)26     return img27 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 img36 37 def createCheckBoardPattern(isReserved=False):38     img = createImg(1)39     boolColor = True40     numsX = 441     numsY = 442     pixsX = 800/numsX43     pixsY = 480/numsY44     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 img51 52 def createStardardImage():53     img = createImg()54     pixs = 800./755     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 img60 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:

checkboard pattern:

checkboard pattern(inverted):

 

standard: