Switched to AForge.NET because OpenCV has no ability to list the devices and is too big (>200mb)

Cameras can now be selected from video options screen, some tweaking is still to be done
Added preview in video options screen
Some tweaks in sing screen
There might be issues with AForge.NET on x86, please test.
This commit is contained in:
Stephan Sundermann committed 2012-07-06 14:12:17 +02:00
1 parent b93dd532b4
commit 88bacb3e9c
14 files changed
+559 -107

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
+2
View File
@@ -197,5 +197,7 @@
<TR_SCREENOVIDEO_VIDEOPREVIEW>Video-Vorschau</TR_SCREENOVIDEO_VIDEOPREVIEW>
<TR_SCREENOVIDEO_VIDEOINSONGS>Videos während des Singens</TR_SCREENOVIDEO_VIDEOINSONGS>
<TR_SCREENO_VIDEO_VIDEOSTOBACKGROUND>Videos der Hintergrundmusik</TR_SCREENO_VIDEO_VIDEOSTOBACKGROUND>
<TR_SCREENO_VIDEO_WEBCAMDEVICES>Webcams</TR_SCREENO_VIDEO_WEBCAMDEVICES>
<TR_SCREENO_VIDEO_WEBCAMCAPABILITIES>Webcamfähigkeiten</TR_SCREENO_VIDEO_WEBCAMCAPABILITIES>
</Texts>
</root>
+2
View File
@@ -197,5 +197,7 @@
<TR_SCREENOVIDEO_VIDEOPREVIEW>Video Preview</TR_SCREENOVIDEO_VIDEOPREVIEW>
<TR_SCREENOVIDEO_VIDEOINSONGS>Videos while singing</TR_SCREENOVIDEO_VIDEOINSONGS>
<TR_SCREENO_VIDEO_VIDEOSTOBACKGROUND>Display current backgroundmusic video</TR_SCREENO_VIDEO_VIDEOSTOBACKGROUND>
<TR_SCREENO_VIDEO_WEBCAMDEVICES>Webcams</TR_SCREENO_VIDEO_WEBCAMDEVICES>
<TR_SCREENO_VIDEO_WEBCAMCAPABILITIES>Webcamcapabilities</TR_SCREENO_VIDEO_WEBCAMCAPABILITIES>
</Texts>
</root>
@@ -222,6 +222,64 @@
<!-- <Space>: Reflection Space-->
<!-- <Height>: Reflection Height-->
</Text5>
<Text6>
<!--<X>, <Y>: Text position-->
<X>75</X>
<Y>345</Y>
<!--<Z>: Text position-->
<Z>0,00</Z>
<!--<H>: Text height-->
<H>32</H>
<!--<MaxW>: Maximum text width (if exists)-->
<!--<Color>: Text color from ColorScheme (high priority)-->
<!--or <R>, <G>, <B>, <A> (lower priority)-->
<Color>StaticColor</Color>
<!--<SColor>: Selected Text color from ColorScheme (high priority)-->
<!--or <SR>, <SG>, <SB>, <SA> (lower priority)-->
<SColor>TextSColor</SColor>
<!--<Align>: Text align horizontal: Left, Center, Right-->
<Align>Left</Align>
<!--<HAlign>: Text align vertical (on downsizing): Top, Center, Bottom-->
<HAlign>Center</HAlign>
<!--<Style>: Text style: Normal, Italic, Bold, BoldItalic-->
<Style>Bold</Style>
<!--<Font>: Text font name-->
<Font>Normal</Font>
<!--<Text>: Text or translation tag-->
<Text>TR_SCREENO_VIDEO_WEBCAMDEVICES</Text>
<!--<Reflection> If exists:-->
<!-- <Space>: Reflection Space-->
<!-- <Height>: Reflection Height-->
</Text6>
<Text7>
<!--<X>, <Y>: Text position-->
<X>75</X>
<Y>405</Y>
<!--<Z>: Text position-->
<Z>0,00</Z>
<!--<H>: Text height-->
<H>32</H>
<!--<MaxW>: Maximum text width (if exists)-->
<!--<Color>: Text color from ColorScheme (high priority)-->
<!--or <R>, <G>, <B>, <A> (lower priority)-->
<Color>StaticColor</Color>
<!--<SColor>: Selected Text color from ColorScheme (high priority)-->
<!--or <SR>, <SG>, <SB>, <SA> (lower priority)-->
<SColor>TextSColor</SColor>
<!--<Align>: Text align horizontal: Left, Center, Right-->
<Align>Left</Align>
<!--<HAlign>: Text align vertical (on downsizing): Top, Center, Bottom-->
<HAlign>Center</HAlign>
<!--<Style>: Text style: Normal, Italic, Bold, BoldItalic-->
<Style>Bold</Style>
<!--<Font>: Text font name-->
<Font>Normal</Font>
<!--<Text>: Text or translation tag-->
<Text>TR_SCREENO_VIDEO_WEBCAMCAPABILITIES</Text>
<!--<Reflection> If exists:-->
<!-- <Space>: Reflection Space-->
<!-- <Height>: Reflection Height-->
</Text7>
<ButtonExit>
<!--<Skin>: Texture name-->
<Skin>Button</Skin>
@@ -497,13 +555,13 @@
<H>50</H>
<!--<ArrowLeftX>, <ArrowLeftY>, <ArrowLeftZ>, <ArrowLeftW>, <ArrowLeftH>: Left arrow position, width and height-->
<ArrowLeftX>505</ArrowLeftX>
<ArrowLeftY>225</ArrowLeftY>
<ArrowLeftY>285</ArrowLeftY>
<ArrowLeftZ>0,00</ArrowLeftZ>
<ArrowLeftW>40</ArrowLeftW>
<ArrowLeftH>40</ArrowLeftH>
<!--<ArrowRightX>, <ArrowRightY>, <ArrowRightZ>, <ArrowRightW>, <ArrowRightH>: Right arrow position, width and height-->
<ArrowRightX>1170</ArrowRightX>
<ArrowRightY>225</ArrowRightY>
<ArrowRightY>285</ArrowRightY>
<ArrowRightZ>0,00</ArrowRightZ>
<ArrowRightW>40</ArrowRightW>
<ArrowRightH>40</ArrowRightH>
@@ -539,5 +597,151 @@
<!--<NumVisible>: Number of visible elements in the slide-->
<NumVisible>3</NumVisible>
</SelectSlideVideosToBackground>
<SelectSlideWebcamDevices>
<!--<Skin>: Texture name-->
<Skin>Invisible</Skin>
<!--<SkinArrowLeft>: Texture name of left arrow-->
<SkinArrowLeft>SelectSlideArrowLeft</SkinArrowLeft>
<!--<SkinArrowRight>: Texture name of right arrow-->
<SkinArrowRight>SelectSlideArrowRight</SkinArrowRight>
<!--<SkinSelected>: Texture name for selected SelectSlide-->
<SkinSelected>SelectSlide</SkinSelected>
<!--<SkinArrowLeftSelected>: Texture name of selected left arrow-->
<SkinArrowLeftSelected>SelectSlideArrowLeft</SkinArrowLeftSelected>
<!--<SkinArrowRightSelected>: Texture name of selected right arrow-->
<SkinArrowRightSelected>SelectSlideArrowRight</SkinArrowRightSelected>
<!--<SkinHighlighted>: Texture name for highlighted SelectSlide-->
<SkinHighlighted>SelectSlide</SkinHighlighted>
<!--<X>, <Y>, <Z>, <W>, <H>: SelectSlide position, width and height-->
<X>500</X>
<Y>340</Y>
<Z>0,00</Z>
<W>700</W>
<H>50</H>
<!--<ArrowLeftX>, <ArrowLeftY>, <ArrowLeftZ>, <ArrowLeftW>, <ArrowLeftH>: Left arrow position, width and height-->
<ArrowLeftX>505</ArrowLeftX>
<ArrowLeftY>345</ArrowLeftY>
<ArrowLeftZ>0,00</ArrowLeftZ>
<ArrowLeftW>40</ArrowLeftW>
<ArrowLeftH>40</ArrowLeftH>
<!--<ArrowRightX>, <ArrowRightY>, <ArrowRightZ>, <ArrowRightW>, <ArrowRightH>: Right arrow position, width and height-->
<ArrowRightX>1170</ArrowRightX>
<ArrowRightY>345</ArrowRightY>
<ArrowRightZ>0,00</ArrowRightZ>
<ArrowRightW>40</ArrowRightW>
<ArrowRightH>40</ArrowRightH>
<!--<Color>: SelectSlide color from ColorScheme (high priority)-->
<!--or <R>, <G>, <B>, <A> (lower priority)-->
<Color>SelectSlideColor</Color>
<!--<SColor>: Selected SelectSlide color from ColorScheme (high priority)-->
<!--or <SR>, <SG>, <SB>, <SA> (lower priority)-->
<SColor>SelectSlideSColor</SColor>
<!--<HColor>: Highlighted SelectSlide color from ColorScheme (high priority)-->
<!--or <HR>, <HG>, <HB>, <HA> (lower priority)-->
<HColor>SelectSlideHColor</HColor>
<!--<ArrowColor>: Arrow color from ColorScheme (high priority)-->
<!--or <ArrowR>, <ArrowG>, <ArrowB>, <ArrowA> (lower priority)-->
<ArrowColor>ArrowColor</ArrowColor>
<!--<ArrowSColor>: Selected arrow color from ColorScheme (high priority)-->
<!--or <ArrowSR>, <ArrowSG>, <ArrowSB>, <ArrowSA> (lower priority)-->
<ArrowSColor>ArrowSColor</ArrowSColor>
<!--<TextColor>: Text color from ColorScheme (high priority)-->
<!--or <TextR>, <TextG>, <TextB>, <TextA> (lower priority)-->
<TextColor>TextColor</TextColor>
<!--<TextSColor>: Selected text color from ColorScheme (high priority)-->
<!--or <TextSR>, <TextSG>, <TextSB>, <TextSA> (lower priority)-->
<TextSColor>TextSColor</TextSColor>
<!--<TextH>: Text height-->
<TextH>32,00</TextH>
<!--<TextMaxW>: Maximum text width (if exists)-->
<TextMaxW>205,33</TextMaxW>
<!--<TextFont>: Text font name-->
<TextFont>Normal</TextFont>
<!--<TextStyle>: Text style: Normal, Italic, Bold, BoldItalic-->
<TextStyle>Bold</TextStyle>
<!--<NumVisible>: Number of visible elements in the slide-->
<NumVisible>3</NumVisible>
</SelectSlideWebcamDevices>
<SelectSlideWebcamCapabilities>
<!--<Skin>: Texture name-->
<Skin>Invisible</Skin>
<!--<SkinArrowLeft>: Texture name of left arrow-->
<SkinArrowLeft>SelectSlideArrowLeft</SkinArrowLeft>
<!--<SkinArrowRight>: Texture name of right arrow-->
<SkinArrowRight>SelectSlideArrowRight</SkinArrowRight>
<!--<SkinSelected>: Texture name for selected SelectSlide-->
<SkinSelected>SelectSlide</SkinSelected>
<!--<SkinArrowLeftSelected>: Texture name of selected left arrow-->
<SkinArrowLeftSelected>SelectSlideArrowLeft</SkinArrowLeftSelected>
<!--<SkinArrowRightSelected>: Texture name of selected right arrow-->
<SkinArrowRightSelected>SelectSlideArrowRight</SkinArrowRightSelected>
<!--<SkinHighlighted>: Texture name for highlighted SelectSlide-->
<SkinHighlighted>SelectSlide</SkinHighlighted>
<!--<X>, <Y>, <Z>, <W>, <H>: SelectSlide position, width and height-->
<X>500</X>
<Y>400</Y>
<Z>0,00</Z>
<W>700</W>
<H>50</H>
<!--<ArrowLeftX>, <ArrowLeftY>, <ArrowLeftZ>, <ArrowLeftW>, <ArrowLeftH>: Left arrow position, width and height-->
<ArrowLeftX>505</ArrowLeftX>
<ArrowLeftY>405</ArrowLeftY>
<ArrowLeftZ>0,00</ArrowLeftZ>
<ArrowLeftW>40</ArrowLeftW>
<ArrowLeftH>40</ArrowLeftH>
<!--<ArrowRightX>, <ArrowRightY>, <ArrowRightZ>, <ArrowRightW>, <ArrowRightH>: Right arrow position, width and height-->
<ArrowRightX>1170</ArrowRightX>
<ArrowRightY>405</ArrowRightY>
<ArrowRightZ>0,00</ArrowRightZ>
<ArrowRightW>40</ArrowRightW>
<ArrowRightH>40</ArrowRightH>
<!--<Color>: SelectSlide color from ColorScheme (high priority)-->
<!--or <R>, <G>, <B>, <A> (lower priority)-->
<Color>SelectSlideColor</Color>
<!--<SColor>: Selected SelectSlide color from ColorScheme (high priority)-->
<!--or <SR>, <SG>, <SB>, <SA> (lower priority)-->
<SColor>SelectSlideSColor</SColor>
<!--<HColor>: Highlighted SelectSlide color from ColorScheme (high priority)-->
<!--or <HR>, <HG>, <HB>, <HA> (lower priority)-->
<HColor>SelectSlideHColor</HColor>
<!--<ArrowColor>: Arrow color from ColorScheme (high priority)-->
<!--or <ArrowR>, <ArrowG>, <ArrowB>, <ArrowA> (lower priority)-->
<ArrowColor>ArrowColor</ArrowColor>
<!--<ArrowSColor>: Selected arrow color from ColorScheme (high priority)-->
<!--or <ArrowSR>, <ArrowSG>, <ArrowSB>, <ArrowSA> (lower priority)-->
<ArrowSColor>ArrowSColor</ArrowSColor>
<!--<TextColor>: Text color from ColorScheme (high priority)-->
<!--or <TextR>, <TextG>, <TextB>, <TextA> (lower priority)-->
<TextColor>TextColor</TextColor>
<!--<TextSColor>: Selected text color from ColorScheme (high priority)-->
<!--or <TextSR>, <TextSG>, <TextSB>, <TextSA> (lower priority)-->
<TextSColor>TextSColor</TextSColor>
<!--<TextH>: Text height-->
<TextH>32,00</TextH>
<!--<TextMaxW>: Maximum text width (if exists)-->
<TextMaxW>205,33</TextMaxW>
<!--<TextFont>: Text font name-->
<TextFont>Normal</TextFont>
<!--<TextStyle>: Text style: Normal, Italic, Bold, BoldItalic-->
<TextStyle>Bold</TextStyle>
<!--<NumVisible>: Number of visible elements in the slide-->
<NumVisible>3</NumVisible>
</SelectSlideWebcamCapabilities>
<StaticWebcamOutput>
<!--<Skin>: Texture name-->
<Skin>CoverBackground</Skin>
<!--<X>, <Y>, <Z>, <W>, <H>: Static position, width and height-->
<X>50</X>
<Y>450</Y>
<Z>0,00</Z>
<W>320</W>
<H>240</H>
<!--<Color>: Static color from ColorScheme (high priority)-->
<!--or <R>, <G>, <B>, <A> (lower priority)-->
<Color>Visible</Color>
<!--<Reflection> If exists:-->
<!-- <Space>: Reflection Space-->
<!-- <Height>: Reflection Height-->
</StaticWebcamOutput>
</ScreenOptionsVideo>
</root>
+23 -7
View File
@@ -11,6 +11,7 @@ using System.Xml.XPath;
using OpenTK.Platform;
using Vocaluxe.Lib.Sound;
using Vocaluxe.Lib.Webcam;
namespace Vocaluxe.Base
{
@@ -89,7 +90,8 @@ namespace Vocaluxe.Base
public enum EWebcamLib
{
OpenCV
OpenCV,
AForgeNet
}
public enum ERecordLib
@@ -261,6 +263,7 @@ namespace Vocaluxe.Base
public static SMicConfig[] MicConfig;
public static int MicDelay = 300; //[ms]
public static EWebcamLib WebcamLib = EWebcamLib.OpenCV;
public static SWebcamConfig WebcamConfig;
//Lists to save parameters and values
private static List<string> _Params = new List<string>();
@@ -433,6 +436,13 @@ namespace Vocaluxe.Base
CHelper.TryGetEnumValueFromXML<EOffOn>("//root/Video/VideoPreview", navigator, ref VideoPreview);
CHelper.TryGetEnumValueFromXML<EOffOn>("//root/Video/VideosInSongs", navigator, ref VideosInSongs);
CHelper.TryGetEnumValueFromXML<EOffOn>("//root/Video/VideosToBackground", navigator, ref VideosToBackground);
CHelper.TryGetEnumValueFromXML<EWebcamLib>("//root/Video/WebcamLib", navigator, ref WebcamLib);
WebcamConfig = new SWebcamConfig();
CHelper.GetValueFromXML("//root/Video/WebcamConfig/MonikerString", navigator, ref WebcamConfig.MonikerString, String.Empty);
CHelper.TryGetIntValueFromXML("//root/Video/WebcamConfig/Framerate", navigator, ref WebcamConfig.Framerate);
CHelper.TryGetIntValueFromXML("//root/Video/WebcamConfig/Width", navigator, ref WebcamConfig.Width);
CHelper.TryGetIntValueFromXML("//root/Video/WebcamConfig/Height", navigator, ref WebcamConfig.Height);
#endregion Video
#region Record
@@ -453,9 +463,6 @@ namespace Vocaluxe.Base
MicDelay = 0;
if (MicDelay > 500)
MicDelay = 500;
CHelper.TryGetEnumValueFromXML<EWebcamLib>("//root/Record/WebcamLib", navigator, ref WebcamLib);
#endregion Record
return true;
@@ -676,6 +683,18 @@ namespace Vocaluxe.Base
writer.WriteComment("Show backgroundmusic videos as background: " + ListStrings(Enum.GetNames(typeof(EOffOn))));
writer.WriteElementString("VideosToBackground", Enum.GetName(typeof(EOffOn), VideosToBackground));
writer.WriteComment("WebcamLib: " + ListStrings(Enum.GetNames(typeof(EWebcamLib))));
writer.WriteElementString("WebcamLib", Enum.GetName(typeof(EWebcamLib), WebcamLib));
writer.WriteStartElement("WebcamConfig");
writer.WriteElementString("MonikerString", WebcamConfig.MonikerString);
writer.WriteElementString("Framerate", WebcamConfig.Framerate.ToString());
writer.WriteElementString("Width", WebcamConfig.Width.ToString());
writer.WriteElementString("Height", WebcamConfig.Height.ToString());
writer.WriteEndElement();
writer.WriteEndElement();
#endregion Video
@@ -700,9 +719,6 @@ namespace Vocaluxe.Base
writer.WriteComment("Mic delay in ms. 0, 20, 40, 60 ... 500");
writer.WriteElementString("MicDelay", MicDelay.ToString());
writer.WriteComment("WebcamLib: " + ListStrings(Enum.GetNames(typeof(EWebcamLib))));
writer.WriteElementString("WebcamLib", Enum.GetName(typeof(EWebcamLib), WebcamLib));
writer.WriteEndElement();
#endregion Record
+22 -3
View File
@@ -15,15 +15,19 @@ namespace Vocaluxe.Base
{
switch (CConfig.WebcamLib)
{
case EWebcamLib.OpenCV:
_Webcam = new COpenCV();
case EWebcamLib.AForgeNet:
_Webcam = new CAForgeNet();
break;
default:
_Webcam = new COpenCV();
_Webcam = new CAForgeNet();
break;
}
_Webcam.Init();
_Webcam.Select(CConfig.WebcamConfig);
CConfig.WebcamConfig = _Webcam.GetConfig();
CConfig.SaveConfig();
}
public static bool GetFrame(ref STexture tex)
@@ -46,5 +50,20 @@ namespace Vocaluxe.Base
{
_Webcam.Start();
}
public static void Stop()
{
_Webcam.Stop();
}
public static void Select(SWebcamConfig c)
{
_Webcam.Select(c);
}
public static SWebcamDevice[] GetDevices()
{
return _Webcam.GetDevices();
}
}
}
+167
View File
@@ -0,0 +1,167 @@
using System;
using System.Collections.Generic;
using System.Text;
using Vocaluxe.Base;
using AForge.Video;
using System.Drawing;
using AForge.Video.DirectShow;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using Vocaluxe.Lib.Draw;
using System.Threading;
namespace Vocaluxe.Lib.Webcam
{
class CAForgeNet : IWebcam
{
private Bitmap _CurrentFrame = new Bitmap(1, 1);
private List<SWebcamDevice> _Devices = new List<SWebcamDevice>();
private bool _Paused;
private VideoCaptureDevice _Webcam;
private FilterInfoCollection _WebcamDevices;
private SWebcamConfig _Config;
public void Close()
{
if (_Webcam != null)
{
_Webcam.SignalToStop();
_Webcam.NewFrame -= new NewFrameEventHandler(OnFrame);
}
}
public bool GetFrame(ref STexture Frame)
{
if ((_CurrentFrame != null) && (_Webcam != null))
{
lock (_CurrentFrame)
{
BitmapData bitmapdata = _CurrentFrame.LockBits(new Rectangle(0, 0, _CurrentFrame.Width, _CurrentFrame.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
byte[] data = new byte[4 * _CurrentFrame.Width * _CurrentFrame.Height];
Marshal.Copy(bitmapdata.Scan0, data, 0, data.Length);
_CurrentFrame.UnlockBits(bitmapdata);
if (((Frame.index == -1) || (_CurrentFrame.Width != Frame.width)) || (_CurrentFrame.Height != Frame.height))
{
CDraw.RemoveTexture(ref Frame);
Frame = CDraw.AddTexture(_CurrentFrame.Width, _CurrentFrame.Height, ref data);
}
else
{
CDraw.UpdateTexture(ref Frame, ref data);
}
}
}
return false;
}
public bool Init()
{
_WebcamDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
int num = 0;
foreach (FilterInfo info in _WebcamDevices)
{
SWebcamDevice device = new SWebcamDevice {
ID = num,
Name = info.Name,
MonikerString = info.MonikerString,
Capabilities = new List<SCapabilities>()
};
num++;
VideoCaptureDevice tmpdev = new VideoCaptureDevice(info.MonikerString);
for (int i = 0; i < tmpdev.VideoCapabilities.Length; i++ )
{
SCapabilities item = new SCapabilities
{
Framerate = tmpdev.VideoCapabilities[i].FrameRate,
Height = tmpdev.VideoCapabilities[i].FrameSize.Height,
Width = tmpdev.VideoCapabilities[i].FrameSize.Width
};
device.Capabilities.Add(item);
}
_Devices.Add(device);
}
return true;
}
private void OnFrame(object sender, NewFrameEventArgs e)
{
if (!_Paused)
{
lock (_CurrentFrame)
{
_CurrentFrame = (Bitmap) e.Frame.Clone();
}
}
}
public void Pause()
{
if (_Webcam != null)
{
_Paused = true;
}
}
public void Start()
{
if (_Webcam != null)
{
_Webcam.NewFrame -= new NewFrameEventHandler(OnFrame);
//Subscribe to NewFrame event
_Webcam.NewFrame += new NewFrameEventHandler(OnFrame);
_Webcam.Start();
_Paused = false;
}
}
public void Stop()
{
if (_Webcam != null)
{
_Webcam.SignalToStop();
}
}
public SWebcamDevice[] GetDevices()
{
return _Devices.ToArray();
}
public bool Select(SWebcamConfig Config)
{
//Close old camera connection
Close();
if (_WebcamDevices == null)
return false;
//No MonikerString found, try first webcam
if (Config.MonikerString == String.Empty)
_Webcam = new VideoCaptureDevice(_WebcamDevices[0].MonikerString);
else //Found MonikerString
_Webcam = new VideoCaptureDevice(Config.MonikerString);
if (_Webcam == null)
return false;
if (Config.Framerate != 0 && Config.Height != 0 && Config.Width != 0)
{
_Webcam.DesiredFrameRate = Config.Framerate;
_Webcam.DesiredFrameSize = new Size(Config.Width, Config.Height);
}
_Config.Framerate = _Webcam.DesiredFrameRate;
_Config.Height = _Webcam.DesiredFrameSize.Height;
_Config.Width = _Webcam.DesiredFrameSize.Width;
_Config.MonikerString = _Webcam.Source;
return true;
}
public SWebcamConfig GetConfig()
{
return _Config;
}
}
}
-80
View File
@@ -1,80 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using Vocaluxe.Base;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
namespace Vocaluxe.Lib.Webcam
{
class COpenCV : IWebcam
{
Image<Bgr, Byte> _CurrentFrame;
Capture _CaptureDevice;
Object Mutex = new Object();
public bool Init()
{
//Create a new default Capture
_CaptureDevice = new Capture();
if (_CaptureDevice != null)
_CaptureDevice.ImageGrabbed += OnImageGrabbed;
return true;
}
public void Start()
{
if (_CaptureDevice != null)
_CaptureDevice.Start();
}
public void Pause()
{
if (_CaptureDevice != null)
_CaptureDevice.Pause();
}
public void Close()
{
if(_CaptureDevice != null)
_CaptureDevice.Dispose();
}
public bool GetFrame(ref Draw.STexture Frame)
{
if (_CurrentFrame != null)
{
Bitmap b = _CurrentFrame.ToBitmap();
BitmapData bd = b.LockBits(new Rectangle(0, 0, _CurrentFrame.Width, _CurrentFrame.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
byte[] data = new byte[4 * _CurrentFrame.Width * _CurrentFrame.Height];
Marshal.Copy(bd.Scan0, data, 0, data.Length);
if (Frame.index == -1 || _CurrentFrame.Width != Frame.width || _CurrentFrame.Height != Frame.height)
{
CDraw.RemoveTexture(ref Frame);
Frame = CDraw.AddTexture(_CurrentFrame.Width, _CurrentFrame.Height, ref data);
}
else
{
CDraw.UpdateTexture(ref Frame, ref data);
}
b.UnlockBits(bd);
b.Dispose();
return true;
}
return false;
}
public void OnImageGrabbed(object sender, EventArgs e)
{
_CurrentFrame = _CaptureDevice.RetrieveBgrFrame();
}
}
}
+28
View File
@@ -5,14 +5,42 @@ using Vocaluxe.Lib.Draw;
namespace Vocaluxe.Lib.Webcam
{
struct SWebcamDevice
{
public int ID;
public string Name;
public string MonikerString;
public List<SCapabilities> Capabilities;
}
struct SCapabilities
{
public int Framerate;
public int Width;
public int Height;
}
struct SWebcamConfig
{
public string MonikerString;
public int Framerate;
public int Width;
public int Height;
}
interface IWebcam
{
bool Init();
void Start();
void Pause();
void Stop();
void Close();
bool GetFrame(ref STexture Frame);
SWebcamConfig GetConfig();
SWebcamDevice[] GetDevices();
bool Select(SWebcamConfig sWebcamConfig);
}
}
+93 -1
View File
@@ -5,6 +5,7 @@ using System.Windows.Forms;
using Vocaluxe.Base;
using Vocaluxe.Menu;
using Vocaluxe.Lib.Webcam;
namespace Vocaluxe.Screens
@@ -18,9 +19,16 @@ namespace Vocaluxe.Screens
private const string SelectSlideVideoPreview = "SelectSlideVideoPreview";
private const string SelectSlideVideosInSongs = "SelectSlideVideosInSongs";
private const string SelectSlideVideosToBackground = "SelectSlideVideosToBackground";
private const string SelectSlideWebcamDevices = "SelectSlideWebcamDevices";
private const string SelectSlideWebcamCapabilities = "SelectSlideWebcamCapabilities";
private const string StaticWebcamOutput = "StaticWebcamOutput";
private const string ButtonExit = "ButtonExit";
private SWebcamConfig _Config;
Lib.Draw.STexture _WebcamTexture = new Lib.Draw.STexture(-1);
public CScreenOptionsVideo()
{
Init();
@@ -33,8 +41,9 @@ namespace Vocaluxe.Screens
_ThemeName = "ScreenOptionsVideo";
_ScreenVersion = ScreenVersion;
_ThemeStatics = new string[] { StaticWebcamOutput };
_ThemeButtons = new string[] { ButtonExit };
_ThemeSelectSlides = new string[] { SelectSlideVideoBackgrounds, SelectSlideVideoPreview, SelectSlideVideosInSongs, SelectSlideVideosToBackground };
_ThemeSelectSlides = new string[] { SelectSlideVideoBackgrounds, SelectSlideVideoPreview, SelectSlideVideosInSongs, SelectSlideVideosToBackground, SelectSlideWebcamDevices, SelectSlideWebcamCapabilities };
}
public override void LoadTheme()
@@ -45,6 +54,23 @@ namespace Vocaluxe.Screens
SelectSlides[htSelectSlides(SelectSlideVideoPreview)].SetValues<EOffOn>((int)CConfig.VideoPreview);
SelectSlides[htSelectSlides(SelectSlideVideosInSongs)].SetValues<EOffOn>((int)CConfig.VideosInSongs);
SelectSlides[htSelectSlides(SelectSlideVideosToBackground)].SetValues<EOffOn>((int)CConfig.VideosToBackground);
SWebcamDevice[] dev = CWebcam.GetDevices();
foreach(SWebcamDevice d in dev)
{
SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].AddValue(d.Name);
}
int deviceNr = SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection;
for (int i = 0; i < dev[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities.Count; i++)
{
SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].AddValue(dev[deviceNr].Capabilities[i].Width.ToString() + " x " + dev[deviceNr].Capabilities[i].Height.ToString() + " @ " + dev[deviceNr].Capabilities[i].Framerate.ToString());
}
SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection = 0;
_Config.MonikerString = dev[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].MonikerString;
_Config.Width = dev[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Width;
_Config.Height = dev[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Height;
_Config.Framerate = dev[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Framerate;
}
public override bool HandleInput(KeyEvent KeyEvent)
@@ -78,10 +104,18 @@ namespace Vocaluxe.Screens
break;
case Keys.Left:
if (SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selected)
OnDeviceEvent();
if (SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selected)
OnCapabilitiesEvent();
SaveConfig();
break;
case Keys.Right:
if (SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selected)
OnDeviceEvent();
if (SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selected)
OnCapabilitiesEvent();
SaveConfig();
break;
}
@@ -101,6 +135,10 @@ namespace Vocaluxe.Screens
if (MouseEvent.LB && IsMouseOver(MouseEvent))
{
if (SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selected)
OnDeviceEvent();
if (SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selected)
OnCapabilitiesEvent();
SaveConfig();
if (Buttons[htButtons(ButtonExit)].Selected)
{
@@ -112,6 +150,8 @@ namespace Vocaluxe.Screens
public override bool UpdateGame()
{
CWebcam.GetFrame(ref _WebcamTexture);
Statics[htStatics(StaticWebcamOutput)].Texture = _WebcamTexture;
SelectSlides[htSelectSlides(SelectSlideVideosToBackground)].Selection = (int)CConfig.VideosToBackground;
return true;
}
@@ -119,18 +159,70 @@ namespace Vocaluxe.Screens
public override bool Draw()
{
base.Draw();
return true;
}
public override void OnClose()
{
CWebcam.Close();
base.OnClose();
}
public override void OnShow()
{
CWebcam.Close();
CWebcam.Select(_Config);
CWebcam.Start();
base.OnShow();
}
private void SaveConfig()
{
CConfig.VideoBackgrounds = (EOffOn)SelectSlides[htSelectSlides(SelectSlideVideoBackgrounds)].Selection;
CConfig.VideoPreview = (EOffOn)SelectSlides[htSelectSlides(SelectSlideVideoPreview)].Selection;
CConfig.VideosInSongs = (EOffOn)SelectSlides[htSelectSlides(SelectSlideVideosInSongs)].Selection;
CConfig.VideosToBackground = (EOffOn)SelectSlides[htSelectSlides(SelectSlideVideosToBackground)].Selection;
CConfig.WebcamConfig = _Config;
CBackgroundMusic.VideoEnabled = true;
CConfig.SaveConfig();
}
private void OnDeviceEvent()
{
int deviceNr = SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection;
SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Clear();
SWebcamDevice[] d = CWebcam.GetDevices();
for (int i = 0; i < d[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities.Count; i++)
{
SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].AddValue(d[deviceNr].Capabilities[i].Width.ToString() + " x " + d[deviceNr].Capabilities[i].Height.ToString() + " @ " + d[deviceNr].Capabilities[i].Framerate.ToString());
}
SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection = 0;
_Config.MonikerString = d[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].MonikerString;
_Config.Width = d[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Width;
_Config.Height = d[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Height;
_Config.Framerate = d[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Framerate;
CWebcam.Close();
CWebcam.Select(_Config);
CWebcam.Start();
}
private void OnCapabilitiesEvent()
{
SWebcamDevice[] d = CWebcam.GetDevices();
_Config.MonikerString = d[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].MonikerString;
_Config.Width = d[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Width;
_Config.Height = d[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Height;
_Config.Framerate = d[SelectSlides[htSelectSlides(SelectSlideWebcamDevices)].Selection].Capabilities[SelectSlides[htSelectSlides(SelectSlideWebcamCapabilities)].Selection].Framerate;
CWebcam.Close();
CWebcam.Select(_Config);
CWebcam.Start();
}
}
}
+5 -1
View File
@@ -207,7 +207,7 @@ namespace Vocaluxe.Screens
if (_Webcam)
CWebcam.Start();
else
CWebcam.Pause();
CWebcam.Stop();
break;
case Keys.Enter:
@@ -621,6 +621,8 @@ namespace Vocaluxe.Screens
PrepareTimeLine();
CSound.Play(_CurrentStream);
CSound.RecordStart();
if(_Webcam)
CWebcam.Start();
}
private void Stop()
@@ -629,6 +631,8 @@ namespace Vocaluxe.Screens
CGraphics.FadeTo(EScreens.ScreenScore);
_FadeOut = true;
if (_Webcam)
CWebcam.Close();
}
private void UpdateLyrics()
+11 -13
View File
@@ -141,21 +141,19 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="AForge.Video, Version=2.2.4.0, Culture=neutral, PublicKeyToken=cbfb6e07d173c401, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Output\AForge.Video.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="AForge.Video.DirectShow, Version=2.2.4.1, Culture=neutral, PublicKeyToken=61ea4348d43881b7, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Output\AForge.Video.DirectShow.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Community.CsharpSqlite">
<HintPath>..\Output\Community.CsharpSqlite.dll</HintPath>
</Reference>
<Reference Include="Emgu.CV, Version=2.4.0.1717, Culture=neutral, PublicKeyToken=7281126722ab4438, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Output\Emgu.CV.dll</HintPath>
</Reference>
<Reference Include="Emgu.CV.UI, Version=2.4.0.1717, Culture=neutral, PublicKeyToken=7281126722ab4438, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Output\Emgu.CV.UI.dll</HintPath>
</Reference>
<Reference Include="Emgu.Util, Version=2.4.0.1717, Culture=neutral, PublicKeyToken=7281126722ab4438, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Output\Emgu.Util.dll</HintPath>
</Reference>
<Reference Include="OpenTK">
<HintPath>..\Output\OpenTK.dll</HintPath>
</Reference>
@@ -219,7 +217,7 @@
<Compile Include="Lib\Video\CVideoDecoder.cs" />
<Compile Include="Lib\Video\CVideoDecoderFFmpeg.cs" />
<Compile Include="Lib\Video\IVideoDecoder.cs" />
<Compile Include="Lib\Webcam\COpenCV.cs" />
<Compile Include="Lib\Webcam\CAForgeNet.cs" />
<Compile Include="Lib\Webcam\IWebcam.cs" />
<Compile Include="Menu\CBackground.cs" />
<Compile Include="Menu\CButton.cs" />