私は顔検出機能を備えたmp3プレーヤーを開発しています。私には2つの形式があります。
最初の形式にはメディアプレーヤーと顔検出コードがあり、2番目の形式にはプレイリストを作成するためのコードがあります。
作成ボタンをクリックすると、プレイリストの名前が最初のフォームのリストボックスに表示されるようにしたいと思います。
これは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);
しかし、これはプレイリストの名前を表示していません。解決策はありますか?