To combine WPF,cameraCapture and faceDetection
1. WPF example (Key function)
public static BitmapSource ToBitmapSource(IImage image)
2. CameraCapture acquires images in windowform control, it may be converted into WPF image by the previous method.
3. Get the image and detect face and eyes, passing it into WPF image.
Notes: Add System.Drawing for some of items such as Size ==> System.Drawing.Size,
Color -> System.Drawing.Color ... etc.
public Window1()
{
InitializeComponent();
this.Dispatcher.Hooks.DispatcherInactive += new EventHandler(ProcessFrame);
_capture = new Capture();
}
private Capture _capture;
private bool _captureInProgress;
private void ProcessFrame(object sender, EventArgs arg)
{
Image<Bgr, Byte> frame = _capture.QueryFrame();
Image<Gray, Byte> gray = frame.Convert<Gray, Byte>(); //Convert it to Grayscale
//Stopwatch watch = Stopwatch.StartNew();
this.Dispatcher.Hooks.DispatcherInactive -= new EventHandler(ProcessFrame);
//normalizes brightness and increases contrast of the image
gray._EqualizeHist();
//Read the HaarCascade objects
HaarCascade face = new HaarCascade("haarcascade_frontalface_alt_tree.xml");
HaarCascade eye = new HaarCascade("haarcascade_eye.xml");
//Detect the faces from the gray scale image and store the locations as rectangle
//The first dimensional is the channel
//The second dimension is the index of the rectangle in the specific channel
MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(
face,
1.1,
10,
Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new System.Drawing.Size(20, 20));
foreach (MCvAvgComp f in facesDetected[0])
{
//draw the face detected in the 0th (gray) channel with blue color
//image.Draw(f.rect, new Bgr(Color.Blue), 2);
frame.Draw(f.rect, new Bgr(System.Drawing.Color.Blue), 2);
//Set the region of interest on the faces
gray.ROI = f.rect;
MCvAvgComp[][] eyesDetected = gray.DetectHaarCascade(
eye,
1.1,
10,
Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new System.Drawing.Size(20, 20));
gray.ROI = System.Drawing.Rectangle.Empty;
foreach (MCvAvgComp e in eyesDetected[0])
{
System.Drawing.Rectangle eyeRect = e.rect;
eyeRect.Offset(f.rect.X, f.rect.Y);
frame.Draw(eyeRect, new Bgr(System.Drawing.Color.Red), 2);
}
}
image1.Source = ToBitmapSource(frame);
this.Dispatcher.Hooks.DispatcherInactive += new EventHandler(ProcessFrame);
}
4. 下載。
2012年7月3日 星期二
2012年7月2日 星期一
Emgu x64 FaceDetection
Ref: http://lucas-0706.blogspot.tw/2012/02/emgu-cv-on-visual-c-2010.html
電腦 ASUS A43S, OS: Windows 7 x64
1. 加入參考路徑 C:\Users\csjou\Downloads\emgux64\libemgucv-windows-x64-2.2.1.1150\libemgucv-windows-x64-2.2.1.1150\bin\
2. 重新加入 Emgu.DLL, Emgu.CV.DLL, Emgu.Util
3. 重新加入既有項目
CommonAssemblyInfo.cs
haarcascade_eye.xml
haarcascade_frontalface_alt_tree.xml
4. 變更檔案屬性為永遠複製
haarcascade_eye.xml
haarcascade_frontalface_alt_tree.xml
5. 變更輸出bin位置
6. 變更我的電腦 環境變數 Path 加入 C:\Users\csjou\Downloads\emgux64\libemgucv-windows-x64-2.2.1.1150\libemgucv-windows-x64-2.2.1.1150\bin\
7. 結果:
電腦 ASUS A43S, OS: Windows 7 x64
1. 加入參考路徑 C:\Users\csjou\Downloads\emgux64\libemgucv-windows-x64-2.2.1.1150\libemgucv-windows-x64-2.2.1.1150\bin\
2. 重新加入 Emgu.DLL, Emgu.CV.DLL, Emgu.Util
3. 重新加入既有項目
CommonAssemblyInfo.cs
haarcascade_eye.xml
haarcascade_frontalface_alt_tree.xml
4. 變更檔案屬性為永遠複製
haarcascade_eye.xml
haarcascade_frontalface_alt_tree.xml
5. 變更輸出bin位置
6. 變更我的電腦 環境變數 Path 加入 C:\Users\csjou\Downloads\emgux64\libemgucv-windows-x64-2.2.1.1150\libemgucv-windows-x64-2.2.1.1150\bin\
7. 結果:
2012年6月29日 星期五
Google Street View Application -- 3 (中文也通)
1. http://maps.googleapis.com/maps/api/streetview?size=600x300&location=%E7%B4%90%E7%B4%84%E6%99%82%E4%BB%A3%E5%BB%A3%E5%A0%B4&heading=100&fov=150&pitch=20&sensor=false
2. http://maps.googleapis.com/maps/api/streetview?size=600x300&location=%E5%80%AB%E6%95%A6%E5%A4%A7%E7%AC%A8%E9%90%98&heading=150&fov=120&pitch=35&sensor=false
3. http://maps.googleapis.com/maps/api/streetview?size=600x300&location=%E5%B7%B4%E9%BB%8E%E5%87%B1%E6%97%8B%E9%96%80&heading=150&fov=120&pitch=35&sensor=false
2. http://maps.googleapis.com/maps/api/streetview?size=600x300&location=%E5%80%AB%E6%95%A6%E5%A4%A7%E7%AC%A8%E9%90%98&heading=150&fov=120&pitch=35&sensor=false
3. http://maps.googleapis.com/maps/api/streetview?size=600x300&location=%E5%B7%B4%E9%BB%8E%E5%87%B1%E6%97%8B%E9%96%80&heading=150&fov=120&pitch=35&sensor=false
2012年6月28日 星期四
Google Street View Application (kinect) -- 2
Ref:
a. kinect SDK for windows v1.5 Green Screen -WPF
b. Google street view api
1. Green Screen WPF application
2. Add .NET Reference
System.Drawing
System.Windows.Forms
3. Add 3 methods (2 event methods) as follows
3-1 SaveWebPage2Image was used to convert google street view as a bitmap
3-2 Mouse_Up was used to replace the background image as a pre-defined street view
3-3 Mouse_Wheel was used to change the heading angle of the previous street view
public System.Drawing.Bitmap SaveWebPage2Image(string url)
{
// Load the webpage into a WebBrowser control
System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete) { System.Windows.Forms.Application.DoEvents(); }
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
// Take Screenshot of the web pages full height
wb.Height = wb.Document.Body.ScrollRectangle.Height;
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new System.Drawing.Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
return bitmap;
}
int angle1 = 120;
private void Window_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
this.Title = "Headingangle : " + angle1.ToString();
System.Drawing.Bitmap bmp = SaveWebPage2Image(@"http://maps.googleapis.com/maps/api/streetview?size=600x300&location=25.080067,121.397699&heading=" + angle1.ToString() + @"&fov=90&pitch=-10&sensor=false");
IntPtr hBitmap = bmp.GetHbitmap();
System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
Backdrop.Source = WpfBitmap;
}
private void Window_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
{
angle1 += 20;
this.Title = "Headingangle : " + angle1.ToString();
System.Drawing.Bitmap bmp = SaveWebPage2Image(@"http://maps.googleapis.com/maps/api/streetview?size=600x300&location=25.080067,121.397699&heading=" + angle1.ToString() + @"&fov=90&pitch=-10&sensor=false");
IntPtr hBitmap = bmp.GetHbitmap();
System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
Backdrop.Source = WpfBitmap;
}
4. 下載
a. kinect SDK for windows v1.5 Green Screen -WPF
b. Google street view api
1. Green Screen WPF application
2. Add .NET Reference
System.Drawing
System.Windows.Forms
3. Add 3 methods (2 event methods) as follows
3-1 SaveWebPage2Image was used to convert google street view as a bitmap
3-2 Mouse_Up was used to replace the background image as a pre-defined street view
3-3 Mouse_Wheel was used to change the heading angle of the previous street view
public System.Drawing.Bitmap SaveWebPage2Image(string url)
{
// Load the webpage into a WebBrowser control
System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete) { System.Windows.Forms.Application.DoEvents(); }
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
// Take Screenshot of the web pages full height
wb.Height = wb.Document.Body.ScrollRectangle.Height;
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new System.Drawing.Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
return bitmap;
}
int angle1 = 120;
private void Window_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
this.Title = "Headingangle : " + angle1.ToString();
System.Drawing.Bitmap bmp = SaveWebPage2Image(@"http://maps.googleapis.com/maps/api/streetview?size=600x300&location=25.080067,121.397699&heading=" + angle1.ToString() + @"&fov=90&pitch=-10&sensor=false");
IntPtr hBitmap = bmp.GetHbitmap();
System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
Backdrop.Source = WpfBitmap;
}
private void Window_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
{
angle1 += 20;
this.Title = "Headingangle : " + angle1.ToString();
System.Drawing.Bitmap bmp = SaveWebPage2Image(@"http://maps.googleapis.com/maps/api/streetview?size=600x300&location=25.080067,121.397699&heading=" + angle1.ToString() + @"&fov=90&pitch=-10&sensor=false");
IntPtr hBitmap = bmp.GetHbitmap();
System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
Backdrop.Source = WpfBitmap;
}
4. 下載
2012年6月27日 星期三
Google Street View WPF Application -- 1
將Google 街景圖以WPF之Image控制項展示。
1. 加入WIndowForm元件。
// Add ref System.Drawing
// System.Windows.Forms
2. 加入html2bitmap方法
public System.Drawing.Bitmap SaveWebPage2Image(string url)
{
// Load the webpage into a WebBrowser control
System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete) { System.Windows.Forms.Application.DoEvents(); }
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
// Take Screenshot of the web pages full height
wb.Height = wb.Document.Body.ScrollRectangle.Height;
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new System.Drawing.Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
return bitmap;
}
3. 初始設定
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//convert System.Drawing.Image to WPF image
System.Drawing.Bitmap bmp = SaveWebPage2Image(@"http://maps.googleapis.com/maps/api/streetview?size=600x300&location=25.080067,121.397699&heading=300&fov=90&pitch=-10&sensor=false");
IntPtr hBitmap = bmp.GetHbitmap();
System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
im.Source = WpfBitmap;
}
4. MouseUp Event 改辦視角
int angle1 = 120;
private void Window_MouseUp(object sender, MouseButtonEventArgs e)
{
angle1 += 20;
this.Title = "Headingangle : " + angle1.ToString();
System.Drawing.Bitmap bmp = SaveWebPage2Image(@"http://maps.googleapis.com/maps/api/streetview?size=600x300&location=25.080067,121.397699&heading=" + angle1.ToString() + @"&fov=90&pitch=-10&sensor=false");
IntPtr hBitmap = bmp.GetHbitmap();
System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
im.Source = WpfBitmap;
}
}
}
1. 加入WIndowForm元件。
// Add ref System.Drawing
// System.Windows.Forms
2. 加入html2bitmap方法
public System.Drawing.Bitmap SaveWebPage2Image(string url)
{
// Load the webpage into a WebBrowser control
System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete) { System.Windows.Forms.Application.DoEvents(); }
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
// Take Screenshot of the web pages full height
wb.Height = wb.Document.Body.ScrollRectangle.Height;
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new System.Drawing.Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
return bitmap;
}
3. 初始設定
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//convert System.Drawing.Image to WPF image
System.Drawing.Bitmap bmp = SaveWebPage2Image(@"http://maps.googleapis.com/maps/api/streetview?size=600x300&location=25.080067,121.397699&heading=300&fov=90&pitch=-10&sensor=false");
IntPtr hBitmap = bmp.GetHbitmap();
System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
im.Source = WpfBitmap;
}
4. MouseUp Event 改辦視角
int angle1 = 120;
private void Window_MouseUp(object sender, MouseButtonEventArgs e)
{
angle1 += 20;
this.Title = "Headingangle : " + angle1.ToString();
System.Drawing.Bitmap bmp = SaveWebPage2Image(@"http://maps.googleapis.com/maps/api/streetview?size=600x300&location=25.080067,121.397699&heading=" + angle1.ToString() + @"&fov=90&pitch=-10&sensor=false");
IntPtr hBitmap = bmp.GetHbitmap();
System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
im.Source = WpfBitmap;
}
}
}
5. 下載
Convert url to bitmap and then WPF(Image)
Ref: Wait to add
1. There are some examples to save webpage into bitmap.
public System.Drawing.Bitmap SaveWebPage2Image(string url)
{
// Load the webpage into a WebBrowser control
System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete) { System.Windows.Forms.Application.DoEvents(); }
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
// Take Screenshot of the web pages full height
wb.Height = wb.Document.Body.ScrollRectangle.Height;
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new System.Drawing.Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
return bitmap;
}
1. There are some examples to save webpage into bitmap.
public System.Drawing.Bitmap SaveWebPage2Image(string url)
{
// Load the webpage into a WebBrowser control
System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
wb.ScrollBarsEnabled = false;
wb.ScriptErrorsSuppressed = true;
wb.Navigate(url);
while (wb.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete) { System.Windows.Forms.Application.DoEvents(); }
// Take Screenshot of the web pages full width
wb.Width = wb.Document.Body.ScrollRectangle.Width;
// Take Screenshot of the web pages full height
wb.Height = wb.Document.Body.ScrollRectangle.Height;
// Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(wb.Width, wb.Height);
wb.DrawToBitmap(bitmap, new System.Drawing.Rectangle(0, 0, wb.Width, wb.Height));
wb.Dispose();
return bitmap;
}
2. xaml file
<Grid>
<Image Name="im" />
</Grid>
3. Add System.Drawing and System.Windows.Forms
4. Window_Loaded
private void Window_Loaded(object sender, RoutedEventArgs e)
{
//convert System.Drawing.Image to WPF image
System.Drawing.Bitmap bmp = SaveWebPage2Image(@"http://www.google.com.tw");
IntPtr hBitmap = bmp.GetHbitmap();
System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
im.Source = WpfBitmap;
}
5.
2012年6月26日 星期二
Speech SDK 11 -- 2
中文語音辨識 (ASUS A43S with Windows 7 x64)
1) Re-Install Speech SDK
1-1 Repair speeh platform runtime
http://www.microsoft.com/en-us/download/details.aspx?id=27225
1-2 Repair Speech SDK
http://www.microsoft.com/en-us/download/details.aspx?id=27226
1-3 Install speech runtime Language (zh-TW)
http://www.microsoft.com/en-us/download/details.aspx?id=27224#instructions
2) Add Ref :C:\Program Files\Microsoft SDKs\Speech\v11.0\Assembly\Microsoft.Speech.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Speech.Recognition;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
// Create a new SpeechRecognitionEngine instance.
SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("zh-TW"));
// Create a simple grammar that recognizes "red", "green", or "blue".
Choices colors = new Choices();
colors.Add("向上");
colors.Add("向下");
colors.Add("左");
colors.Add("右");
colors.Add("前");
colors.Add("後");
GrammarBuilder gb = new GrammarBuilder();
gb.Append(colors);
// Create the actual Grammar instance, and then load it into the speech recognizer.
Grammar g = new Grammar(gb);
sre.LoadGrammar(g);
// Register a handler for the SpeechRecognized event.
sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
while (true)
{ }
}
static void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine(e.Result.Text);
}
}
}
1) Re-Install Speech SDK
1-1 Repair speeh platform runtime
http://www.microsoft.com/en-us/download/details.aspx?id=27225
1-2 Repair Speech SDK
http://www.microsoft.com/en-us/download/details.aspx?id=27226
1-3 Install speech runtime Language (zh-TW)
http://www.microsoft.com/en-us/download/details.aspx?id=27224#instructions
2) Add Ref :C:\Program Files\Microsoft SDKs\Speech\v11.0\Assembly\Microsoft.Speech.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Speech.Recognition;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
// Create a new SpeechRecognitionEngine instance.
SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("zh-TW"));
// Create a simple grammar that recognizes "red", "green", or "blue".
Choices colors = new Choices();
colors.Add("向上");
colors.Add("向下");
colors.Add("左");
colors.Add("右");
colors.Add("前");
colors.Add("後");
GrammarBuilder gb = new GrammarBuilder();
gb.Append(colors);
// Create the actual Grammar instance, and then load it into the speech recognizer.
Grammar g = new Grammar(gb);
sre.LoadGrammar(g);
// Register a handler for the SpeechRecognized event.
sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
sre.SetInputToDefaultAudioDevice();
sre.RecognizeAsync(RecognizeMode.Multiple);
while (true)
{ }
}
static void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
Console.WriteLine(e.Result.Text);
}
}
}
訂閱:
文章 (Atom)