Commit 633f57b8 authored by Gaurav Arora (gaa721)'s avatar Gaurav Arora (gaa721)
Browse files

Importing to git for the first time

parents
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9BA81346-7892-448B-B562-3B1F9F2A3CF7}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FaceDetectionApp</RootNamespace>
<AssemblyName>FaceDetectionApp</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UDP.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\FaceDetectionMain2\FaceDetectionMain.csproj">
<Project>{1b9679b2-5d28-4451-9538-671f32d3a4bd}</Project>
<Name>FaceDetectionMain</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
namespace FaceDetectionApp
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.lblFace = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.lblAtt = new System.Windows.Forms.Label();
this.button2 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(12, 12);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(496, 355);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// lblFace
//
this.lblFace.AutoSize = true;
this.lblFace.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.lblFace.Location = new System.Drawing.Point(514, 12);
this.lblFace.Name = "lblFace";
this.lblFace.Size = new System.Drawing.Size(66, 24);
this.lblFace.TabIndex = 1;
this.lblFace.Text = "label1";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(518, 91);
this.textBox1.Multiline = true;
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(331, 276);
this.textBox1.TabIndex = 2;
//
// lblAtt
//
this.lblAtt.AutoSize = true;
this.lblAtt.Location = new System.Drawing.Point(515, 57);
this.lblAtt.Name = "lblAtt";
this.lblAtt.Size = new System.Drawing.Size(35, 13);
this.lblAtt.TabIndex = 3;
this.lblAtt.Text = "label1";
//
// button2
//
this.button2.Location = new System.Drawing.Point(763, 52);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 4;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(861, 379);
this.Controls.Add(this.button2);
this.Controls.Add(this.lblAtt);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.lblFace);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Label lblFace;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label lblAtt;
private System.Windows.Forms.Button button2;
}
}
\ No newline at end of file
using FaceDetectionMain;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace FaceDetectionApp
{
public partial class Form1 : Form
{
public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
//Declare the mouse hook constant.
//For other hook types, you can obtain these values from Winuser.h in the Microsoft SDK.
public const int WH_MOUSE = 7;
private System.Windows.Forms.Button button1;
static int hHook = 0;
//Declare MouseHookProcedure as a HookProc type.
HookProc MouseHookProcedure;
//Declare the wrapper managed POINT class.
[StructLayout(LayoutKind.Sequential)]
public class POINT
{
public int x;
public int y;
}
//Declare the wrapper managed MouseHookStruct class.
[StructLayout(LayoutKind.Sequential)]
public class MouseHookStruct
{
public POINT pt;
public int hwnd;
public int wHitTestCode;
public int dwExtraInfo;
}
//This is the Import for the SetWindowsHookEx function.
//Use this function to install a thread-specific hook.
[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn,
IntPtr hInstance, int threadId);
//This is the Import for the UnhookWindowsHookEx function.
//Call this function to uninstall the hook.
[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern bool UnhookWindowsHookEx(int idHook);
//This is the Import for the CallNextHookEx function.
//Use this function to pass the hook information to the next hook procedure in chain.
[DllImport("user32.dll", CharSet = CharSet.Auto,
CallingConvention = CallingConvention.StdCall)]
public static extern int CallNextHookEx(int idHook, int nCode,
IntPtr wParam, IntPtr lParam);
public Form1()
{
InitializeComponent();
FaceDetector.Instance.FrameCapturedEvent += FrameCallback;
FaceDetector.Instance.FaceDetectedEvent += FaceDetectedCallback;
FaceDetector.Instance.FaceLostEvent += FaceLostCallback;
FaceDetector.Instance.ActiveWindowChanged += F_ActiveWindowChanged;
FaceDetector.Instance.AttentionChecker += AttentoinCheck;
textBox1.Text = FaceDetector.Instance.GetActiveWindowTitle().ToString();
button2.Click += button2_Click;
}
private void AttentoinCheck()
{
bool attention = (FaceDetector.Instance.HasFace) && (FaceDetector.Instance.isCurrentWindowTheApp);
lblAtt.Text = "Attention: " + attention.ToString();
}
private void F_ActiveWindowChanged(object sender, WindowTitle windowHeader, string Windows, IntPtr hwnd)
{
textBox1.Text = "CURRENT WINDOW:" + windowHeader.Title + "\r\n\r\nVISIBLE WINDOWS:\r\n" + Windows;
if (!windowHeader.Title.Equals("Form1"))
{
FaceDetector.Instance.isCurrentWindowTheApp = false;
}
else
{
FaceDetector.Instance.isCurrentWindowTheApp = true;
}
AttentoinCheck();
}
private void FaceDetectedCallback()
{
if (lblFace.InvokeRequired)
lblFace.Invoke(new MethodInvoker(FaceDetectedCallback));
lblFace.Text = "Face Detected at " + System.DateTime.Now.ToString();
AttentoinCheck();
}
private void FaceLostCallback()
{
if (lblFace.InvokeRequired)
lblFace.Invoke(new MethodInvoker(FaceLostCallback));
lblFace.Text = "Face Lost at " + System.DateTime.Now.ToString();
AttentoinCheck();
}
private void FrameCallback(Bitmap b, Rectangle[] faces)
{
if (b != null)
pictureBox1.Image = b;
}
private void button2_Click(object sender, System.EventArgs e)
{
if (hHook == 0)
{
// Create an instance of HookProc.
MouseHookProcedure = new HookProc(Form1.MouseHookProc);
hHook = SetWindowsHookEx(WH_MOUSE,
MouseHookProcedure,
(IntPtr)0,
AppDomain.GetCurrentThreadId());
//If the SetWindowsHookEx function fails.
if (hHook == 0)
{
MessageBox.Show("SetWindowsHookEx Failed");
return;
}
button2.Text = "UnHook Windows Hook";
}
else
{
bool ret = UnhookWindowsHookEx(hHook);
//If the UnhookWindowsHookEx function fails.
if (ret == false)
{
MessageBox.Show("UnhookWindowsHookEx Failed");
return;
}
hHook = 0;
button1.Text = "Set Windows Hook";
this.Text = "Mouse Hook";
}
}
public static int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
{
//Marshall the data from the callback.
MouseHookStruct MyMouseHookStruct = (MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(MouseHookStruct));
if (nCode < 0)
{
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
else
{
//Create a string variable that shows the current mouse coordinates.
String strCaption = "x = " +
MyMouseHookStruct.pt.x.ToString("d") +
" y = " +
MyMouseHookStruct.pt.y.ToString("d");
//You must get the active form because it is a static function.
Form tempForm = Form.ActiveForm;
//Set the caption of the form.
tempForm.Text = strCaption;
return CallNextHookEx(hHook, nCode, wParam, lParam);
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>
\ No newline at end of file
using FaceDetectionMain;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
//https://msdn.microsoft.com/en-us/library/bb546085.aspx Named Pipes
//http://www.codeproject.com/Articles/10649/An-Introduction-to-Socket-Programming-in-NET-using
//https://msdn.microsoft.com/en-us/library/system.net.sockets.multicastoption(v=vs.110).aspx
//https://msdn.microsoft.com/en-us/library/zt39148a(v=vs.110).aspx
//https://msdn.microsoft.com/en-us/library/windows/desktop/ms633516(v=vs.85).aspx
namespace FaceDetectionApp
{
static class Program
{
private static FaceDetector f;
private static TcpListener listener;
private const int LIMIT = 6; //6 concurrent clients
private static List<StreamWriter> sw;
public static JSONMessage JSONMessage;
[STAThread]
static void Main()
{
Init();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
#region Callbacks
private static void FaceDetectedCallback()
{
try
{
JSONMessage.CurrectFaceState = FaceState.Face;
JSONMessage.CurrentTitle = FaceDetector.Instance.GetActiveWindowTitle();
JSONMessage.VisibleWindows = FaceDetector.Instance.Windows;
//write out to each connected listener
foreach (var s in sw) s.WriteLine(JSONMessage.ToString());
} catch(Exception e) {
Console.WriteLine(e.Message);
}
}
private static void FaceLostCallback()
{
try
{
JSONMessage.CurrectFaceState = FaceState.NoFace;
JSONMessage.CurrentTitle = FaceDetector.Instance.GetActiveWindowTitle();
JSONMessage.VisibleWindows = FaceDetector.Instance.Windows;
//write out to each connected listener
foreach (var s in sw) s.WriteLine(JSONMessage.ToString());
} catch (Exception e) {
Console.WriteLine(e.Message);
}
}
private static void ActiveWindowChangedCallback(object sender, WindowTitle windowHeader, string Windows, IntPtr hwnd)
{
try
{
//write out to each connected listener
JSONMessage.CurrentTitle = windowHeader;
foreach (var s in sw) s.WriteLine(JSONMessage.ToString());
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}