private void treeView1_DoubleClick(object sender, EventArgs e) { try { if (treeView1.SelectedNode != null) { if (treeView1.SelectedNode.GetNodeCount(true) == 0) { string path = imageDir + "/" + facedata[treeView1.SelectedNode.Parent.Index].name + "/" + (treeView1.SelectedNode.Index + 1) + ".jpg"; feaBox.BackgroundImage = BitmapHelper.ReadImageFile(path); } else { ResetFeaBox(); } } else { ResetFeaBox(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void Matching(object obj) { MatchData matchData = (MatchData)obj; if (matchData.bitmapSource != null) { float[] vec = new float[FaceApi.FeatureVecLen()]; BitmapData bitmapData = matchData.bitmapSource.LockBits(new Rectangle(0, 0, matchData.bitmapSource.Width, matchData.bitmapSource.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); while (isFeaRunning) { Console.WriteLine("Matching is Waitting"); } isFeaRunning = true; bool success = FaceApi.FeatureVecPtr(bitmapData.Scan0, bitmapData.Width, bitmapData.Height, bitmapData.Stride, 3, matchData.landmark, vec); isFeaRunning = false; matchData.bitmapSource.UnlockBits(bitmapData); double maxdata = 0; int maxidx1 = 0; int maxidx2 = 0; int index = 0; foreach (FaceData face in facedata) { for (int idx = 0; idx < face.feavec.Count; ++idx) { double result = FaceApi.Distance(vec, face.feavec[idx]); if (result > maxdata) { maxdata = result; maxidx2 = idx; maxidx1 = index; } Console.WriteLine(result + ""); } index += 1; } if (maxdata > threshold) { if (!closing) { string path = imageDir + "/" + facedata[maxidx1].name + "/" + (maxidx2 + 1) + ".jpg"; SetMatchBox(BitmapHelper.ReadImageFile(path), "匹配ID:" + facedata[maxidx1].name /*maxdata + ""*/); } } else { if (!closing) { SetMatchBox(null, ""); } } } matchData.Dispose(); }
private void button1_Click(object sender, EventArgs e) { string imagePath = FileTools.GetImagePath(); try { if (imagePath != null) { image = new Bitmap(BitmapHelper.ReadImageFile(imagePath)); pictureBox1.BackgroundImage = image.Clone(new Rectangle(0, 0, image.Width, image.Height), PixelFormat.Format24bppRgb); } else { pictureBox1.BackgroundImage = null; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }