Video texture using webcam or internet source

Hello,

I’m working on a project for a larp (a live action roleplaying game). At a moment in the game (which is IRL), players will have to monitor a bot that is supposed to be in a remote location. They will control it with a computer. I’m trying to do that with the BGE.

To enhance the feeling of reality, we’d like to put the the bot (that will be a prop) in the hands of the players before it began its journey (then we will drop it in a tube supposedly linked to the remote room). My plan was to put a webcam on the prop and link it to the computer. The BGE would already be on and would play the video from the webcam. But of course after we dropped the bot, we will replace the videotexture from the webcam by the 3d environment (and basically it becomes a FPS game).

I hope i’m clear enough (english is not my mother tongue).

So my question is how can i use a webcam to play video in realtime in the BGE. I’ve found the code for an AVI video stored on the computer (on the blender wiki) but not for a webcam feed. I’m also interested by doing the same thing with a video from the internet.

I’m using Blender 2.49 on Windows XP.

Thanks !

You have to use an external library that will give you access to the webcam.

With python-opencv, you could do something like this:


#Do this once (at init):

import GameLogic as GL
from opencv import highgui

GL.video_texture.source = VideoTexture.ImageBuff()
GL.webcam = highgui.cvCreateCameraCapture(0)


# Do this at the rate of webcam framerate

frame = highgui.cvQueryFrame(GL.webcam)

# convert to proper format for blender texture:
highgui.cvConvertImage(frame, frame, highgui.CV_CVTIMG_SWAP_RB | highgui.CV_CVTIMG_FLIP)

GL.video_texture.source.load(frame.imageData, frame.width, frame.height)
GL.video_texture.refresh(True)

How do I know that ImageBuff.load takes exactly 3 arguments (image_string, image_width, image_height), even though there is no documentation that lists this information? -> I read the source code.

Why is there no documentation -> I don’t know.

Anyway: You don’t have to use opencv. As long as you can derive the 3 required arguments from some webcam handler, you’ll have everything you need.

In the end, it’s all just data.

Thank you for your answer Social. :slight_smile:

So, i’m getting closer but there’s still a long way to go because - i should have said that in my previous post - i know almost nothing about python (I use scripts by copying them from blend files and looking how they are summoned through logic bricks).

I don’t want you to loose your time explaining me all the stuff (what is an external library, opencv, and so on) because i guess it’s a lot of time. But if you have some hints to give (where i should begin for instance, what my blend should look like) that would be really appreciated :slight_smile:

(I’ve ordered a book about Processing, i’ve seen on the net a guy that use sounds from a mp3 to make change in objects in the BGE, and the communication between the sound which is external to the BGE and the BGE is made through Processing, so maybe i will find also a solution for the video too whith this software).

Thanks !

Needless to say, you’ll need to learn python before any of this makes sense.

I don’t want you to loose your time explaining me all the stuff (what is an external library, opencv, and so on) because i guess it’s a lot of time. But if you have some hints to give (where i should begin for instance, what my blend should look like) that would be really appreciated :slight_smile:
I could give you the .blend I used to test the concept (attached), but you’ll still need to install python-opencv yourself, and even if it all works flawlessly on your system, you won’t be able to modify it for your specific purposes if you don’t know python.

The core problem here: you don’t know python.

Solve that problem first, and then worry about how to make the webcam work.

Attachments

VidTest.blend (140 KB)

Thanks for the .blend.

The core problem here: you don’t know python.

Solve that problem first, and then worry about how to make the webcam work.
You’re right. I need to learn python but it will take some time and I wanted to implement that soon.

Hmmm … I will learn the basics then will focus on the functions useful for the script you gave me.

I’ll be back in some time :wink: