Webcam player

hi i have update the web camera script for blender 2.63

it work on linux and windows

press return for play

have fun

edit:

I have corrected the errors I had committed in the script

a thank you for helping me serge3576

new blend:

Sorry supernova, but, what exactly his script does?

it replaces the texture by video from the webcam default

Cool supermoaa, very cool!

Awsome! the only thing is when i start the game once and hit enter then exit the game and try it again it doesnt work the spot that says video just turns white?
Some times it does work thow but most of the time it wont.

Also would it be possible for it to detect sertan things from your camera say you hold u a phone and it pops out a phone on the game?

can you tell me what OS you use

and that said your console?

for your question I think this is possible by installing opencv
http://www.neuroforge.co.uk/index.php/getting-started-with-python-a-opencv

but it may be slow

This Thread is missing a Screenshot, … A LOT

EDIT: i’ve downloaded it, great Python there.

ok ill look at that thanks!

im running win7

and the console doesnt say anything also sometimes when i hit enter to start the webcam it comes up with a windows menu box saying to pick a camera device?

trying to reinstall the driver of your camera

saw that you said to me,
you do not have a camera by default defined in your system

otherwise it is possible that your camera is not recognized by ffmpeg

well it only comes up with that window maybe 1 in 10 tries and 5 out of 10 it works and the other 5 it doesnt.

unfortunately I know that python code

if you did well is that I told you
and that it does not work

you should post a bug report

http://projects.blender.org/tracker/?atid=306&group_id=9&func=browse

First pb:
a = 10
b = 3

Bad

if a == 1 or 2: # 2 is always True
print (“ok”)
elif a == 3 or 4:
print (“bad”)

Good

if b == 1 or b == 2:
print (“ok”)
elif b == 3 or b == 4:
print (“bad”)

So, the script find always win !!

Second pb:
File “videoStart_etude.py”, line 20, in <module>
bge.logic.vidSrc = texture.VideoFFmpeg("", pathCam, 5, 640, 480)
TypeError: an integer is required

Webcam on Linux

For a Minority Report Game :yes: , I need a Webcam in Game Engine on linux:

No problem on Lucid and Blender 2.49b, but nothing on Xubuntu 12.04 and blender2.6x

All files to test in blender 2.63: http://wiki.labomedia.org/index.php/Fichier:Ba.zip
VideoPlayback.blend runs with a script from
http://www.blender.org/documentation…e.texture.html
No problem with movie, but webcam doesn’t work

I always set in terminal
export LD_PRELOAD=/usr/lib/i386-linux-gnu/libv4l/v4l1compat.so
blender
or
./blender

OK with 2.62 from repository:
Playing Movies
http://www.tutorialsforblender3d.com…e_Movie_1.html

OK only with 2.63 from blender.org, but failed with 2.62 from repository:
Render to Texture
http://www.tutorialsforblender3d.com…_Render_1.html

Real Time Mirror
http://www.tutorialsforblender3d.com…_Mirror_7.html

What are the differences between repository and directory from blender.org ?

The script:

“”"
Basic Video Playback
++++++++++++++++++++++
Example of how to replace a texture in game with a video. It needs to run everyframe
“”"
import bge
from bge import texture
from bge import logic

cont = logic.getCurrentController()
obj = cont.owner

the creation of the texture must be done once: save the

texture object in an attribute of bge.logic module makes it persistent

if not hasattr(logic, ‘video’):

# identify a static texture by name
matID = texture.materialID(obj, 'IMMovie_Curtain.JPG')

# create a dynamic texture that will replace the static texture
logic.video = texture.Texture(obj, matID)

# define a source of image for the texture, here a webcam
logic.video.source = texture.VideoFFmpeg('/dev/video0', 0, 30.0, 640, 480)
logic.video.source.scale = True

# quick off the movie, but it wont play in the background
logic.video.source.play()

you need to call this function every frame to ensure update of the texture.

logic.video.refresh(True)

See http://wiki.labomedia.org/index.php/Webcam_dans_Blender

"""
Basic Video Playback
++++++++++++++++++++++
Example of how to replace a texture in game with a video. It needs to run everyframe
"""
import bge
from bge import texture
from bge import logic

cont = logic.getCurrentController()
obj = cont.owner

# the creation of the texture must be done once: save the
# texture object in an attribute of bge.logic module makes it persistent
if not hasattr(logic, 'video'):

    # identify a static texture by name
    matID = texture.materialID(obj, 'IMMovie_Curtain.JPG')

    # create a dynamic texture that will replace the static texture
    logic.video = texture.Texture(obj, matID)

    # define a source of image for the texture, here a webcam
    logic.video.source = texture.VideoFFmpeg('/dev/video0', 0, 30.0, 640, 480)
    logic.video.source.scale = True

    # quick off the movie, but it wont play in the background
    logic.video.source.play()

# you need to call this function every frame to ensure update of the texture.
logic.video.refresh(True)

Great script,

Is it possible to take a picture and save it to your harddisk?

Meaning:
It is just filming and when I press a button it takes the current frame and saves it in a folder.

Hi, I have the same problem I think you had with the webcam: using your script, only the first frame from the webcam is shown, then it does not get updated. I works flawlessly if I replace the video source with a movie. Any idea on how to fix that?
Im on ubuntu 14.04, blender 2.76b and using a cheap usb webcam that is recognized by smile.

@amoniak:
Works for me on Archlinux. You could try replacing the last code ‘block’ with


if contr.sensors[0].positive:
        bge.logic.video.source = bge.logic.vidSrc
        bge.logic.vidSrc.play()
        bge.logic.video.refresh(True)

Hello - when I run the blend i’m getting a GPU latency of 90%! It’s so laggy…

… any ideas why?

webcam.blend (477 KB) - сome on man, keep working version of Web camera in BGE