My objective is simple: I want to capture a frame from a random camera in the scene in the form of a bitmap. So the end result should be a 32x32 (maybe less) matrix with rgb color codes.
The scope of all this is to simulate a color sensor on a robot. I am trying to simulate a NXT lego robot.
Until know with i managed (with the help of the community) to make a video texture with the camera as the source and map it on a plane (code below). Everything works well but know i want to capture that texture in some way.
Any ideas? Thank you very much!
from bge import logic as l import bge contr = l.getCurrentController() obj = contr.owner if not hasattr(l, 'video'): # -- Get the material that is using our texture matID = bge.texture.materialID(obj, "IMwebcam.png") # -- Create the video texture l.video = bge.texture.Texture(obj, matID) scene = l.getCurrentScene() objList = scene.objects cam1_Name = objList["Camera"] l.video.source = bge.texture.ImageRender(scene,cam1_Name) # -- scale the video l.video.source.scale = False # -- play the video l.video.source.play()
So…i found a way, it’s really simple (if you know it )
l.video.source.capsize = [3,3] image = l.video.source.image
now image is a 3x3 array composed of RGBA elements (255,255,255,255)