Skip to content

Commit

Permalink
first commit, V1.05
Browse files Browse the repository at this point in the history
Here we go... (Project ready to compile/run. Tested on Win7/Win 8.1, x64
and x86)
  • Loading branch information
A9T9 committed Dec 22, 2014
1 parent 7e8b51f commit d45435f
Show file tree
Hide file tree
Showing 46 changed files with 314,462 additions and 0 deletions.
34 changes: 34 additions & 0 deletions Face(andmore)Tracker.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Face(andmore)Tracker", "Face(andmore)Tracker\Face(andmore)Tracker.csproj", "{4704C95D-2D13-4F45-8095-F107BA12199D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4704C95D-2D13-4F45-8095-F107BA12199D}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{4704C95D-2D13-4F45-8095-F107BA12199D}.Debug|Any CPU.Build.0 = Release|Any CPU
{4704C95D-2D13-4F45-8095-F107BA12199D}.Debug|x64.ActiveCfg = Debug|x64
{4704C95D-2D13-4F45-8095-F107BA12199D}.Debug|x64.Build.0 = Debug|x64
{4704C95D-2D13-4F45-8095-F107BA12199D}.Debug|x86.ActiveCfg = Debug|x86
{4704C95D-2D13-4F45-8095-F107BA12199D}.Debug|x86.Build.0 = Debug|x86
{4704C95D-2D13-4F45-8095-F107BA12199D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4704C95D-2D13-4F45-8095-F107BA12199D}.Release|Any CPU.Build.0 = Release|Any CPU
{4704C95D-2D13-4F45-8095-F107BA12199D}.Release|x64.ActiveCfg = Release|x64
{4704C95D-2D13-4F45-8095-F107BA12199D}.Release|x64.Build.0 = Release|x64
{4704C95D-2D13-4F45-8095-F107BA12199D}.Release|x86.ActiveCfg = Release|x86
{4704C95D-2D13-4F45-8095-F107BA12199D}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions Face(andmore)Tracker/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
8 changes: 8 additions & 0 deletions Face(andmore)Tracker/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Application x:Class="FaceFinderDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
17 changes: 17 additions & 0 deletions Face(andmore)Tracker/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace FaceFinderDemo
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
79 changes: 79 additions & 0 deletions Face(andmore)Tracker/Camera/CameraDevice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using Emgu.CV;
using FaceFinderDemo.ImageProcessing;

namespace FaceFinderDemo.Camera
{
public class CameraDevice : ImageProcessor, IDisposable
{
public bool IsCapturing { get { return isCapturing; }}

Mat capturedImage;
Capture camera;
bool disposed;
int frameRate;
int frameCount;
bool isCapturing;

public CameraDevice()
{
capturedImage = new Mat();
}

public void StartCamera(int cameraIndex)
{
if (isCapturing)
{
return;
}
CvInvoke.UseOpenCL = false;
camera = new Capture(cameraIndex);
camera.ImageGrabbed += CapOnImageGrabbed;
camera.Start();
isCapturing = true;
}

public void StopCamera()
{
if (!isCapturing)
{
return;
}

camera.ImageGrabbed -= CapOnImageGrabbed;
camera.Stop();
camera.Dispose();
isCapturing = false;
}

private void CapOnImageGrabbed(object sender, EventArgs e)
{
frameCount++;
//Debug.WriteLine("Frames: " + frameCount);
camera.Retrieve(capturedImage);
OnImageAvailable(capturedImage);
}

public void Dispose()
{
if (disposed)
{
return;
}

capturedImage.Dispose();

if (isCapturing)
{
StopCamera();
}

disposed = true;
}

protected override void OnImageReceived(Mat image)
{

}
}
}
26 changes: 26 additions & 0 deletions Face(andmore)Tracker/Camera/DeviceEnumerator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using AForge.Video.DirectShow;

namespace FaceFinderDemo.Camera
{
/// <summary>
/// EMGU CV doesn't support detecting available cameras, so we use directshow for it.
/// </summary>
public static class DeviceEnumerator
{
public static List<string> GetDeviceNames()
{
var devices = new List<string>();
FilterInfoCollection videoDevices = new FilterInfoCollection(
FilterCategory.VideoInputDevice);
for (int i = 0; i != videoDevices.Count; i++)
{
var dev = videoDevices[i];
devices.Add(dev.Name);
}
// OpenCV seems to handle the order in the other direction
devices.Reverse();
return devices;
}
}
}
105 changes: 105 additions & 0 deletions Face(andmore)Tracker/Camera/ImageDevice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
using System;
using System.Timers;
using Emgu.CV;
using Emgu.CV.CvEnum;
using FaceFinderDemo.ImageProcessing;

namespace FaceFinderDemo.Camera
{
public class ImageDevice : ImageProcessor, IDisposable
{
public bool IsSending { get { return isSending; } }

public int FrameRate { get; set; }

bool disposed;
Mat image;
bool isSending;
Timer sendTimer;
object sync = new object();

public ImageDevice()
{
sendTimer = new Timer();
sendTimer.Interval = 100;
sendTimer.Elapsed += SendTimerOnElapsed;
}

void SendTimerOnElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
{
if (image == null)
return;

sendTimer.Stop();
lock (elapsedEventArgs)
{
OnImageAvailable(image.Clone());
}
sendTimer.Start();
}

public void StartSending()
{
if (isSending)
return;

sendTimer.Start();

isSending = true;
}

public void StopSending()
{
if (!isSending)
return;

sendTimer.Stop();

isSending = false;
}

public bool LoadFromFile(string imageFile)
{
lock (sync)
{
if (image != null)
{
image.Dispose();
}
try
{
var imageLoaded = new Mat(imageFile, LoadImageType.Color);
if (imageLoaded.IsEmpty)
return false;

image = imageLoaded;
return true;
}
catch
{
return false;
}
}
}

public void Dispose()
{
if (disposed)
{
return;
}

if (image != null)
{
image.Dispose();
}

disposed = true;
}

protected override void OnImageReceived(Mat image)
{

}
}
}
28 changes: 28 additions & 0 deletions Face(andmore)Tracker/Converters/InverseBooleanConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Windows.Data;

namespace FaceFinderDemo.Converters
{
[ValueConversion(typeof(bool), typeof(bool))]
public class InverseBooleanConverter : IValueConverter
{
#region IValueConverter Members

public object Convert(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
if (targetType != typeof(bool))
throw new InvalidOperationException("The target must be a boolean");

return !(bool)value;
}

public object ConvertBack(object value, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}

#endregion
}
}
34 changes: 34 additions & 0 deletions Face(andmore)Tracker/Converters/VisibilityConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;

namespace FaceFinderDemo.Converters
{
[ValueConversion(typeof(bool), typeof(Visibility))]
public class VisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool flag = false;
if (value is bool)
{
flag = (bool)value;
}
else if (value is bool?)
{
bool? nullable = (bool?)value;
flag = nullable.HasValue ? nullable.Value : false;
}
return (flag ? Visibility.Visible : Visibility.Hidden);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}
Loading

0 comments on commit d45435f

Please sign in to comment.