I am using C# to program face detection using Intel Realsense SR300 camera. Below is windows form application. which includes, just a picture box, one start button and one stop button. I have already added all the necessary libraries. I can start my windows form but when I press the start button, the program just stops there like it's not responding and I had to manually stop the program from Visual studio.
Help me with this. Thanks.
What I have tried:
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.Diagnostics;
namespace _11
{
public partial class Form1 : Form
{
private PXCMSession session;
private PXCMSenseManager senseManager;
private PXCMFaceData faceData;
private PXCMFaceModule facemodule;
private PXCMFaceConfiguration faceConfiguration;
public Form1()
{
InitializeComponent();
}
private void detect()
{
session = PXCMSession.CreateInstance();
senseManager = session.CreateSenseManager();
senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 30);
senseManager.EnableFace();
facemodule = senseManager.QueryFace();
faceConfiguration = facemodule.CreateActiveConfiguration();
faceConfiguration.SetTrackingMode(PXCMFaceConfiguration.TrackingModeType.FACE_MODE_COLOR_PLUS_DEPTH);
faceConfiguration.detection.maxTrackedFaces = 2;
faceConfiguration.detection.isEnabled = true;
faceConfiguration.ApplyChanges();
senseManager.Init();
faceData = facemodule.CreateOutput();
while(true)
{
if(senseManager.AcquireFrame(true) >= pxcmStatus.PXCM_STATUS_NO_ERROR)
{
break;
}
if(faceData != null)
{
faceData.Update();
}
int nfaces = faceData.QueryNumberOfDetectedFaces();
for (int i =0; i < nfaces; i++)
{
PXCMFaceData.Face face = faceData.QueryFaceByIndex(i);
processposition(face);
}
senseManager.ReleaseFrame();
}
if (faceData != null)
{
faceData.Dispose();
}
if (faceConfiguration != null)
{
faceConfiguration.Dispose();
}
facemodule.Dispose();
}
private void processposition(PXCMFaceData.Face face)
{
PXCMFaceData.DetectionData detectionData = face.QueryDetection();
PXCMRectI32 rect;
detectionData.QueryBoundingRect(out rect);
}
private void Start_Click(object sender, EventArgs e)
{
detect();
}
private void Stop_Click(object sender, EventArgs e)
{
senseManager.Close();
senseManager.Dispose();
session.Dispose();
}
}
}