fletch27502
04-06-2010 15:54:50
I need to capture the webcam image to a windows bmp, so I can apply the bmp as a texture to a billboard. Does anyone have a link to the C# Theora add on, or have any other suggestions on how to capture the image?
TIA,
Scott
smiley80
04-06-2010 19:15:25
You can do that with
DirectShowNet.
Base DirectShow capture class:
http://miyagi.hg.sourceforge.net/hgweb/ ... Capture.cs
Webcam capture:
http://miyagi.hg.sourceforge.net/hgweb/ ... Capture.cs
Usage:
private object padLock = new object();
private Bitmap bitmap;
private WebcamCapture webCam;
private void Setup(int deviceNum)
{
this.webCam = new WebcamCapture(deviceNum);
this.webCam.NewBitmap += this.OnNewBitmap;
}
private void OnNewBitmap(object sender, EventArgs e)
{
lock (this.padLock)
{
this.bitmap = (Bitmap)sender;
}
}
private void Update()
{
lock (this.padLock)
{
if (this.bitmap != null)
{
ConvertBitmapToTexture(this.bitmap, "MyWebCamTexture", this.bitmap.Size);
this.bitmap = null;
}
}
}
'Update' has to be called regularly, e.g. from a frame event handler.
"MyWebCamTexture" is the name of a manually created Texture with the size of the webcam bitmap.
Converting bitmap to texture:
viewtopic.php?f=8&t=11761#p70117
Beauty
04-06-2010 23:15:12
Nice would be to add this code to the Ogre wiki.
In the new wiki (tiki wiki) it's also possible to attach files (e.g. your cs files).
fletch27502
07-06-2010 15:10:47
thanks, this looks very promising. I'll be working to implement the code today, and I'll let you know how it goes.
Scott
fletch27502
08-06-2010 13:25:00
Thanks so much, this was very easy to incorporate into our software and works great.
I do have one question though: Is there a way to get sound from the webcam? We're currently using the FSLOgreCS sound library.
TIA,
Scott
Beauty
08-06-2010 14:09:03
It would be nice if you publish a useful code snippet for other users.
Great would be when you create / publish a tiny application which shows the webcam picture stream in a simple Ogre scene (e.g. projected to a flat cube). This we could add to the MogreSDK.
fletch27502
09-06-2010 13:16:41
I pretty much used the code above without any changes. The only code I wrote was in our layer onto of Mogre that no one here would be interested in. I can try to do something in my free time to incorporate the code into a sample project however. I'll see what I can do in the next couple of weeks.
Scott
smiley80
09-06-2010 23:57:20
I do have one question though: Is there a way to get sound from the webcam? We're currently using the FSLOgreCS sound library.
Don't know if it's possible with FSLOgreCS and with DirectShow I've only looked into getting the audio from a video file.
But with
FMOD it's pretty straighforward to capture audio from a webcam mic.
smiley80
16-06-2010 22:03:10
It would be nice if you publish a useful code snippet for other users.
Great would be when you create / publish a tiny application which shows the webcam picture stream in a simple Ogre scene (e.g. projected to a flat cube). This we could add to the MogreSDK.
Your wish is my command:
removed
Beauty
17-06-2010 01:49:56
Thanks
I added the embedding task to the
Mogre SDK development thread.
It would be good if some other people try this sample application on different systems.
Unfortunately I have no webcam.
smiley80
17-06-2010 15:25:40
Unfortunately I have no webcam.
There's also a videofile playback example.
The codec of the sample video is Xvid, so it only works when you have a DirectShow filter installed which can handle that.
Beauty
17-06-2010 22:29:57
Nice to have a webcam simulator
After adding the files Mogre.dll and OgreMain.dll from the SVN of MogreSDK I could compile and run it (in Visual Studio 2008 with SP1 on WinXP 32bit).
But at runtime I got an error ... see attached file.
Maybe something on my system is out of date?
By the way - I made a tiny addition to your demo:
When it doesn't detect a webcam, it shows a notice about.
And the for loof I changed from 9 to 7, because the number will be increased before display and 10 and 11 can't read by one singe ReadKey()
Here is the new code:
static void Main(string[] args)
{
try
{
var devices = Capture.CaptureDeviceNames; // moved
if (devices.Count == 0) // new
Console.WriteLine("\nNote: No webcam was found.\n\n"); // new
Console.WriteLine("Select capture source:");
Console.WriteLine("1) Sample video");
for (int i = 0; i < devices.Count && i < 7; i++) // changed 9 to 7, because 10 and 11 can't read by ReadKey()
{
Console.WriteLine((i + 2) + ") " + devices[i]);
}
DSDemoApp app = new DSDemoApp(int.Parse(Console.ReadKey().KeyChar.ToString()));
}
catch (System.Runtime.InteropServices.SEHException)
{
throw;
}
}
And I want to say - your sample application is a nice pattern for other demos
smiley80
17-06-2010 23:17:52
After adding the files Mogre.dll and OgreMain.dll from the SVN of MogreSDK I could compile and run it (in Visual Studio 2008 with SP1 on WinXP 32bit).
But at runtime I got an error ... see attached file.
You have to add both rendersystem dlls, too.
And the for loof I changed from 9 to 7, because the number will be increased before display and 10 and 11 can't read by one singe ReadKey()
Oops. Fixed in the attached file. Plus the user input is checked for sanity, and it just plays the videofile if no video input device has been found.
Beauty
18-06-2010 12:26:55
Oh yes of course - the renderfiles
Without webcam I have a little Problem:
The (very short) video will be displayed in a window, which is behind the commandline shell window. When the user put the focus to the background window, then the video is nearly ready.
I tried to put the focus to the renderwindow, but I don't know how to do without Windows.Forms.
Also maybe it's possible to auto restart the video playback? If not, maybe we could use a longer video file? (Yes, your avi file size is nice!)
smiley80
23-06-2010 01:43:25
Accidentally deleted my post.
Reup.
Beauty
23-06-2010 09:30:00
The new video is very dark.
I made changes:
* used the old video and cut of the end of the file (where was no motion)
* changed the camera position (to fit the cube to the window - it was very small)
* when there is no webcam, this text will be displayed: "No webcam detected ... play video file instead."
* added the source code to the MogreSDK SVN (maybe it's better for teamwork)
* tried to embed it there (changed ressources.cfg; linked to Mogre.dll; changed Mogre.dll property "local copy" to false)
But I couldn't get it work. I suppose the application wants to have all dll files in its own directory. Mogre.dll I can link to the SDK binary path, but OgreMain.dll and the Rendersystem dlls can't be found (I suppose). Any idea how to get it work without local copy of the dll files?
The path is:
sdk_fs\Samples\WebcamDemo
Here you can get access in online SVN:
http://code.google.com/p/mogresdk/sourc ... WebcamDemo
CodeKrash
02-01-2011 13:19:33
I have an implementation to extract the images from the "preview pin" of video input devices. It uses DirectShowLib-2008 I can throw together an example project if you wish. You may find something good in it?
Beauty
02-01-2011 15:03:59
Demo applications are always welcome!
We could add it to the Mogre SDK to help newcomers by showing examples.
If you created a demo, just post it in the forum topic
Mogre SDK development.
For quick prototyping or demos with a good overview you can use our new Tutorial Framework.
http://www.ogre3d.org/tikiwiki/tiki-ind ... +Framework