我正在开发一个带有面部检测功能的 mp3 播放器。我有两种形式。
第一种形式是媒体播放器和面部检测代码,第二种形式是用于创建播放列表的代码。
我希望当我单击创建按钮时,播放列表的名称应该显示在第一种形式的列表框中。
这是我对 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");
}
这是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";
}
当我使用此代码在按钮单击事件上访问 form1 的列表框时
new Form1().playlistviewbar.items.add(playlistname);
但这不显示播放列表的名称。有什么解决办法吗?