def loadSphereTexture (filename):
    
    global textureLoaderTextures
    
    # if texture already loaded return its id
    if filename in textureLoaderTextures:
        return textureLoaderTextures[filename]
    
    # load image
    image = open(filename)
    ix = image.size[0]
    iy = image.size[1]
    image = image.tostring("raw", "RGBX", 0, -1)
    
    # Create Texture
    textureId = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, textureId)
    
    glPixelStorei(GL_UNPACK_ALIGNMENT,1)
    glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)
    
    # save and return texture id
    textureLoaderTextures[filename] = textureId
    return textureId
示例#2
0
def RecebePoliedroDoArquivo(argv):
    global facesDoPoliedro, objetosADesenhar
    if len(argv) < 2:
        return None

    arquivoEntrada = open(argv[1])
    linhasDoArquivo = arquivoEntrada.readlines()

    linha = linhasDoArquivo[3].split(" ")
    numeroVertices = int(linha[2])

    linha = linhasDoArquivo[7].split(" ")
    numeroFaces = int(linha[2])

    indiceVertice = 0
    vertices = []
    while indiceVertice < numeroVertices:
        vertice = linhasDoArquivo[10 + indiceVertice].split(" ")
        vertices.append(
            Point(float(vertice[0]), float(vertice[1]), float(vertice[2])))
        indiceVertice += 1

    indiceFaces = 0
    faces = []
    while indiceFaces < numeroFaces:
        face = linhasDoArquivo[10 + indiceVertice + indiceFaces].split(" ")
        faces.append([int(fac) for fac in face[1:] if str.isdigit(fac)])
        indiceFaces += 1

    arquivoEntrada.close()
    return vertices, faces
示例#3
0
def loadBindTex( tex_list):
    glEnable( GL_TEXTURE_2D)
    tex = glGenTextures( len( tex_list))

    for i, path in enumerate( tex_list):
        try:
            im = open(path)
            ix = im.size[0]
            iy = im.size[1]
            try:
                image = im.tostring("raw", "RGBA", 0, -1)
            except SystemError:
                image = im.tostring("raw", "RGBX", 0, -1)
            glBindTexture( GL_TEXTURE_2D, tex[i])
            glPixelStorei( GL_UNPACK_ALIGNMENT,1)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)

            #glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER  )
            #glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER  )
            #glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER  )

            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE) # GL_ADD, GL_MODULATE, GL_DECAL, GL_BLEND, GL_REPLACE, GL_COMBINE.
            glTexImage2D( GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
        except:
            print "Textur kann nicht erstellt werden"
            pass
    return tex
def loadTexture (filename):
    
    global textureLoaderTextures
    
    # if texture already loaded return its id
    if filename in textureLoaderTextures:
        return textureLoaderTextures[filename]
    
    # load image
    image = open(filename)
    ix = image.size[0]
    iy = image.size[1]
    image = image.tostring("raw", "RGBX", 0, -1)
    
    # Create Texture
    textureId = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, textureId)
    glPixelStorei(GL_UNPACK_ALIGNMENT,1)
    
    if config.textureMode == config.textureMode_nearest:
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
        glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
    elif config.textureMode == config.textureMode_linear:
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
        glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
    elif config.textureMode == config.textureMode_mipmap:
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST)
        gluBuild2DMipmaps(GL_TEXTURE_2D, 3, ix, iy, GL_RGBA, GL_UNSIGNED_BYTE, image)
    
    # save and return texture id
    textureLoaderTextures[filename] = textureId
    return textureId
示例#5
0
文件: text.py 项目: nosuchtim/MMTT1
	def loadImage( self, imageName ):
		"""Load an image file as a 2D texture using PIL

		This method combines all of the functionality required to
		load the image with PIL, convert it to a format compatible
		with PyOpenGL, generate the texture ID, and store the image
		data under that texture ID.

		Note: only the ID is returned, no reference to the image object
		or the string data is stored in user space, the data is only
		present within the OpenGL engine after this call exits.
		"""
		im = open(imageName)
		try:
			ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGB", 0, -1)
			debug("Able to use tostring RGB")
		except SystemError:
			debug("Unable to use tostring RGB?")
			return -1
		# generate a texture ID
		ID = glGenTextures(1)
		# make it current
		glBindTexture(GL_TEXTURE_2D, ID)
		glPixelStorei(GL_UNPACK_ALIGNMENT,1)
		# copy the texture into the current texture ID
		debug("TEXTURE ix,iy=%f,%f" % (ix,iy))
		glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGB, GL_UNSIGNED_BYTE, image)
		# return the ID for use
		return ID
示例#6
0
文件: swingo.py 项目: jeska/swingo
def fillin(card):
   spaces_dir = "swingo_spaces"
   spaces = getfiles(spaces_dir)
   for x in range(5):
      for y in range(5):
         index = 5*x+y
         if index != 12: # ignores the middle square
            space = open(path.join(spaces_dir, spaces[index]))
            card.paste(space, (10 + 210*x, 232 + 210*y))
示例#7
0
def recognition():
	from os import chdir,environ
	from tesseract import image_to_string
	from Image import open
	path = environ.get("HOME")
	im = open("blob.jpg")	
	text = image_to_string(im)
	chdir(path+"/alpr/latest/")
	return text
示例#8
0
def recognition():
    from os import chdir, environ
    from tesseract import image_to_string
    from Image import open
    path = environ.get("HOME")
    im = open("blob.jpg")
    text = image_to_string(im)
    chdir(path + "/alpr/latest/")
    return text
示例#9
0
    def initializeImages(self):
        # create arrays
        self.imgOff = []
        self.lblOff = []
        self.lblUser = []
        self.imgUser = []
        self.imgUser2 = []
        self.drawUser = []
        for i in range(0, len(c.DRUMS)):
            self.imgOff.append("")
            self.lblOff.append("")
            self.imgUser.append("")
            self.lblUser.append("")
            self.imgUser2.append("")
            self.drawUser.append("")

            # create the "on" image as a background
        self.imgBg = PhotoImage(file="images/drums_on.gif")
        self.lblBg = self.canvas.create_image(0, 0, anchor=NW, image=self.imgBg)

        # create the regular "off" images on top of the "on" images
        for i in c.DRUMS:
            self.imgOff[i] = PhotoImage(file="images/drum" + str(i) + "_off.gif")
            self.lblOff[i] = self.canvas.create_image(
                c.POS_LEFT[i], c.POS_TOP[i], anchor=NW, image=self.imgOff[i], tags="off" + str(i)
            )

            # create the key labels overlay
        self.imgLabels1 = open(r"images/labels.png")
        self.drawLabels = Draw(self.imgLabels1)
        self.imgLabels = PhotoImage(self.imgLabels1)
        self.lblLabels = self.canvas.create_image(0, 0, anchor=NW, image=self.imgLabels)

        # create the "user on" images offscreen
        for i in c.DRUMS:
            self.imgUser[i] = open(r"images/drum" + str(i) + "_user.png")
            self.drawUser[i] = Draw(self.imgUser[i])
            self.imgUser2[i] = PhotoImage(self.imgUser[i])
            self.lblUser[i] = self.canvas.create_image(
                c.POS_LEFT[i], c.POS_TOP[i] + c.CANVAS_HEIGHT, anchor=NW, image=self.imgUser2[i], tags="user" + str(i)
            )

        return
示例#10
0
文件: cam.py 项目: wipxj3/EventTicket
 def __init__(self, imageIndex):
     pil = open(imageIndex + ".png").convert("L")
     width, height = pil.size
     raw = pil.tostring()
     image = zbar.Image(width, height, "Y800", raw)
     scanner = zbar.ImageScanner()
     scanner.scan(image)
     for symbol in image:
         # do something useful with results
         self.info = symbol.data
     self.data = str(self.info)
示例#11
0
def load_texture(self, image_name):
		im = open(image_name)
		try:
			ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBA", 0, -1)
		except SystemError:
			ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBX", 0, -1)

		ID = glGenTextures(1)
		glBindTexture(GL_TEXTURE_2D, ID)
		glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
		return ID
def loadTexture(filename, ident):
    global texture_planete
    image = open(filename)  # retourne une PIL.image si import Image (!)
    
    ix = image.size[0]
    iy = image.size[1]
    image = image.tostring("raw", "RGBX", 0, -1)
    
    # 2d texture (x and y size)
    # BUG (?)
    #glBindTexture(GL_TEXTURE_2D, glGenTextures(1, texture_planete[ident]))
    texture_planete[ident] = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, int(texture_planete[ident]))

    glPixelStorei(GL_UNPACK_ALIGNMENT,1)
    glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
示例#13
0
    def load_image(self, filename):
        # global media_folder
        # if not os.path.isabs(filename):
        #    filename = media_folder + filename

        # fail if file does not exist

        if not os.path.isfile(filename):
            raise ValueError("load_image(" + filename +
                             "): No such file")
        else:
            from Image import open
            mode = "RGB"
            image = open(filename).convert(mode)
            size = image.size
            data = image.tostring()

            # initialize this picture with new properties

            self.__initialize_picture(image, filename, get_short_path(filename))
示例#14
0
文件: utils.py 项目: skerrj/jarl
def pil_loader(path):
    """Load an image file as a 2D texture using PIL"""
    from Image import open, NEAREST
    im = open(path).resize((256,256), NEAREST)
    
    texid = glGenTextures(1)
    
    try:
        # get image meta-data (dimensions) and data
        ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBA", 0, -1)
    except SystemError:
        # has no alpha channel, synthesize one, see the
        # texture module for more realistic handling
        ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBX", 0, -1)
            
    glBindTexture(GL_TEXTURE_2D, texid)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
    glPixelStorei(GL_UNPACK_ALIGNMENT,1)
    # copy the texture into the current texture ID
    glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
    # return the ID for use
    return (texid, pygame.Rect(0, 0, ix, iy))
示例#15
0
文件: swingo.py 项目: jeska/swingo
def main(num_cards):
   for card_num in range(1, num_cards + 1):
      card = open("full_blank.png")
      fillin(card)
      card.save("dancecard" + str(card_num) + ".png")
示例#16
0
from Image import open

maze = open("maze.png")
dest = (1, 640)
(x, y) = (639, 1)
stack = []


def tryMove(dx, dy):
    return (maze.getpixel((x + dx, y + dy))[2] == 0 and (x + dx, y + dy, 0))


while (x, y) != dest:
    maze.putpixel((x, y), (maze.getpixel((x, y))[0], 0, 255, 255))
    stack.append((x, y, maze.getpixel((x, y))[0]))
    x, y, tmp = tryMove(-1, 0) or tryMove(1, 0) or tryMove(0, 1) or tryMove(
        0, -1) or (stack.pop() and stack.pop())
print(stack[:100])
file("maze.zip", "wb").write("".join(
    map(lambda (x, y, r): chr(r),
        filter(lambda (x, y, r): (x ^ y) & 1 == 0, stack))))
示例#17
0
def initData():
    global rP

    #load texture
    im = open(sys.argv[1])
    try:
        ix, iy, image = im.size[0], im.size[1], im.tostring(
            "raw", "RGBA", 0, -1)
    except SystemError:
        ix, iy, image = im.size[0], im.size[1], im.tostring(
            "raw", "RGBX", 0, -1)

    rP.texID = glGenTextures(1)
    glBindTexture(GL_TEXTURE_2D, rP.texID)
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
    glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                 image)

    texl, text, texr, texb = 0.0, 1.0, 1.0, 0.0
    left, top, right, bottom = -1.0, 1.0, 1.0, -1.0

    vtxs = np.array([(left, top, 0.0), (right, top, 0.0), (right, bottom, 0.0),
                     (left, bottom, 0.0)], 'f')
    triang = Delaunay(vtxs[:, 0:2])

    interleaved = np.array([
        texl,
        text,
        left,
        top,
        0.0,
        texr,
        text,
        right,
        top,
        0.0,
        texr,
        texb,
        right,
        bottom,
        0.0,
        texl,
        text,
        left,
        top,
        0.0,
        texr,
        texb,
        right,
        bottom,
        0.0,
        texl,
        texb,
        left,
        bottom,
        0.0,
    ], 'f')

    print interleaved

    norms = np.array([(0.0, 0.0, 1.0) for _ in vtxs], dtype=np.float32)
    rP.points = vbo.VBO(interleaved)
    rP.indices = np.array(triang.vertices, dtype=np.ubyte).flatten()
    #print len(vtxs),len(rP.indices)

    rP.normals = vbo.VBO(norms)
    rP.cnt = len(vtxs)
from Image import open
import matplotlib as mpl
mpl.use('Agg')
import pylab as plt

mpl.rc('text', usetex=True)
plt.figure()
y=[1,2,3,4,5,4,3,2,1,1,1,1,1,1,1,1]
col_labels=['col1','col2','col3']
row_labels=['row1','row2','row3']
table_vals=[11,12,13,21,22,23,31,32,33]
table = r'''\begin{tabular}{ c | c | c | c } & col1 & col2 & col3 \\\hline row1 & 11 & 12 & 13 \\\hline row2 & 21 & 22 & 23 \\\hline row3 & 31 & 32 & 33 \end{tabular}'''
plt.text(9, 3.4, table, size=12)
plt.plot(y)
plt.savefig("./table_demo.ps") 

# convert ps image to png
open("./table_demo.ps").save("./table_demo.png")