I'm doing a computer vision simulation in blender game engine, so I need to make screenshots that will give me an array/numpy of pixels to do image processing on at each frame. Saving it as PNG through bge.render.makeScreenshot(path) and then reading values through there won't work since that will be very slow for this task.


you might try something like this:

import bge

source = texture.ImageRender(world,sensorView_Cam) 

source.capsize = [640,480]

imageArray = texture.imageToArray(source, 'RGB') 

charArray = imageArray.to_list()

works ok for me (Although, i dont know if it is fast enough for you and if there are faster ways)

| improve this answer | |
  • $\begingroup$ It did give me some numbers but it has several problems. It's one dimensional so how do I check whether it displays what it should. It also doesn't work when sensorView_Cam is set to active, it says "'NoneType' object has no attribute 'to_list''". What can be done about it? Should I try to recombine the 1D vector into R G and B matrices? Because 2Dness of it is essential for some image processing algorithms like convolution (conv neural nets) $\endgroup$ – Alex Azazel May 13 '16 at 9:49
  • $\begingroup$ For your first question: Yes, you need to use the camera image of a non-active camera (can't tell you why, but i remember that i stumbled across the same problem). For your second question: Yes, you need to rearange the data according to the setup of your image (R,G,B in your case). $\endgroup$ – Alexander Gatter May 13 '16 at 10:41
  • $\begingroup$ Well than Ok. Non of them seem as a problem because I always can add another camera on top of it, parent to it and make that one active. Thank you very much. $\endgroup$ – Alex Azazel May 13 '16 at 15:10
  • 1
    $\begingroup$ on your example, texture refers to bge.texture, but what do (world,sensorView_Cam) refer to? The value of these variables is not defined. $\endgroup$ – ntg May 19 '17 at 9:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.