I am developing a mp3 player with face detection. I have two forms.
In first form there is media player and face detection code and in second form code for creating playlist.
I want that when i click on create button the name of playlist should be display in listbox of first form.
This is some of my code for form1
private Capture cap;
public Form1()
{
InitializeComponent();
cap = new Capture(0);
_dataBasePath = Directory.GetCurrentDirectory() + @"db1.mdb";
// adjust path to find your xml
haar = new HaarCascade("haarcascade_frontalface_alt_tree.xml");
mouth = new HaarCascade("Mouth.xml");
lefteye = new HaarCascade("eye_left.xml");
righteye = new HaarCascade("haarcascade_righteye_2splits.xml");
}
public void DataBasePath(string path)
{
_dataBasePath = path;
}
private void timer1_Tick(object sender, EventArgs e)
{
using (Image<Bgr, byte> nextFrame = cap.QueryFrame())
{
if (nextFrame != null)
{
// there's only one channel (greyscale), hence the zero index
//var faces = nextFrame.DetectHaarCascade(haar)[0];
Image<Gray, byte> grayframe = nextFrame.Convert<Gray, byte>();
Image<Gray, Byte> gray = nextFrame.Convert<Gray, Byte>();
Image<Gray, Byte> gray1 = nextFrame.Convert<Gray, Byte>();
Image<Gray, Byte> gray2 = nextFrame.Convert<Gray, Byte>();
var faces = grayframe.DetectHaarCascade(
haar, 1.4, 4,
HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new Size(nextFrame.Width / 8, nextFrame.Height / 8)
)[0];
foreach (MCvAvgComp f in faces)
{
//draw the face detected in the 0th (gray) channel with blue color
nextFrame.Draw(f.rect, new Bgr(Color.Blue), 2);
facesnap = f.rect;
int halfheight = facesnap.Height/2;
int start = facesnap.X;
int start1 = facesnap.Y;
Rectangle top = new Rectangle(start,start1,facesnap.Width,halfheight);
int start2 = top.Bottom;
Rectangle bottom = new Rectangle(start, start2, facesnap.Width, halfheight);
//Set the region of interest on the faces
gray.ROI = bottom;
MCvAvgComp[][] mouthsDetected = gray.DetectHaarCascade(mouth,
1.1, 10,
Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
new Size(40,30));
gray.ROI = Rectangle.Empty;
foreach (MCvAvgComp m in mouthsDetected[0])
{
Rectangle mouthRect = m.rect;
mouthRect.Offset(bottom.X, bottom.Y);
nextFrame.Draw(mouthRect, new Bgr(Color.Red), 2);
Rectangle mouthphoto = new Rectangle(mouthRect.X - 5, mouthRect.Y - 10, mouthRect.Width + 5, mouthRect.Height +10);
detectedmouth = mouthphoto;
}
int halfwidth =facesnap.Width/2;
Rectangle toprighteye =new Rectangle(start,start1,halfwidth,halfheight);
int leftx = toprighteye.Right;
Rectangle toplefteye = new Rectangle(leftx, start1, halfwidth, halfheight);
gray1.ROI =toplefteye;
MCvAvgComp[][] detectedlefteye = gray1.DetectHaarCascade(lefteye, 1.1, 1, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(30,10));
gray1.ROI = Rectangle.Empty;
foreach (MCvAvgComp eyesnapleft in detectedlefteye[0])
{
Rectangle eyeRectleft = eyesnapleft.rect;
eyeRectleft.Offset(toplefteye.X, toplefteye.Y);
nextFrame.Draw(eyeRectleft, new Bgr(Color.Green), 2);
lefteyesnap = eyeRectleft;
}
gray2.ROI = toprighteye;
MCvAvgComp[][] detectedrighteye = gray2.DetectHaarCascade(righteye, 1.1, 1, Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(30, 10));
gray2.ROI = Rectangle.Empty;
foreach (MCvAvgComp eyesnapright in detectedrighteye[0])
{
Rectangle eyeRectright = eyesnapright.rect;
eyeRectright.Offset(toprighteye.X, toprighteye.Y);
nextFrame.Draw(eyeRectright, new Bgr(Color.Yellow), 2);
righteyesnap = eyeRectright;
}
}
pictureBox1.Image = nextFrame.ToBitmap();
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
_dataBasePath = Directory.GetCurrentDirectory() + @"db1.mdb";
// adjust path to find your xml
haar = new HaarCascade("haarcascade_frontalface_alt_tree.xml");
mouth = new HaarCascade("Mouth.xml");
lefteye = new HaarCascade("eye_left.xml");
righteye = new HaarCascade("haarcascade_righteye_2splits.xml");
}
this is some of the code for form2
namespace Face_Detection_Concept
{
public partial class Form2 : Form
{
#region Global Variables
public const string Separator = ",";
public static ArrayList searchAudio = new ArrayList();
public static ArrayList searchVideo = new ArrayList();
public static StreamWriter sw;
public string fnm;
#endregion
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
// Set default values
cmbType.SelectedIndex = 0;
chkIncSubDir.Checked = true;
LoadFormats();
txtFilename.Text = "PlayList1.wpl";
}
when i m use this code for accessing listbox of form1 on button click event
new Form1().playlistviewbar.items.add(playlistname);
but this is not displaying the name of the playlist.is there any solution?
See Question&Answers more detail:
os