Pass (x,y, z) position from outside blender

Hello, this is my first time using blender, lucky me the game I have to do is pretty easy but I’m having some issues. I want to make a game in blender where I could pass a position from another python script outside blender.
What I’m trying to do is something like that shown in the next video:

Where the game is 3D, I mean the squares are cubes in mine, I get the position of the balls using a camera and OpenCV, but I don’t know how to pass that position to the game so the cubes explode.

Why from outside the blend? and why camera+opencv?
ball, collision sensor, throw it to the wall, if it collides with square, end ball, explode the square, add a point or whatever.

Anyway you can import python scripts in the scripts you like with import scriptname

@chinoleveratto: One easy way to do this is to use sockets. This could be used when you’d like to transfer data over the network from another machine, but it works on localhost as well. The “Non BGE”/OpenCV part of your system can open a socket and send some data (your x,y,z position or whatever). Within the BGE, you can check that socket each frame and grab the data (if there is something in your inbox). You can find a useful example here: http://blog.mikepan.com/post/19310460549/very-simple-networking-in-python

This is easily doable via:

  • Networking (nonblocking sockets)
  • pyserial module (if you have a serial port)
  • Shared memory
  • About a dozen other ways.

Be sure to put the python logic brick into module mode to ensure things persist between frames.

Or you can call openCV directly from the python within your BGE game (which is what I would do. Your game “owns” the CV code). Even if your CV code is in C, you can use python’s ctypes interface to run code from shared libraries.