/// <summary> /// 激活过滤器 /// </summary> /// <param name="bActive"></param> public void ActiveFilter(bool bActive = true) { active = bActive; if (active) { // 向各个频道监听“新聊天”事件 foreach (var channel in showingChannel) { channel.OnNewChat += AddChatText; } } else // 过滤器失效 { foreach (var channel in showingChannel) { channel.OnNewChat -= AddChatText; OnRefreshOutput = null; OnAddOutput = null; } } }
private void ImageGrabbedProcess(object sender, EventArgs arg) { try { Mat mat = new Mat(); DateTime now = DateTime.Now; capture.Retrieve(mat); // 捕获摄像头图片 Bitmap bitmap = mat.Bitmap; detectfacefeature = GetDetectFaceFeature(bitmap, pictureBox0, false); if (detectfacefeature.faceflag) { //人脸识别 if (checkflag) { float similar = 0.0f; int num = 0; for (int i = 0; i < listface.Count; i++) { float facesimilar = recogitionAndFacePairMatching(listface[i].face_Feature, detectfacefeature.face_Feature); Console.WriteLine("编号: " + i + " -- " + "人脸姓名: " + listface[i].face_name + " -- " + "相似度: " + facesimilar); if (facesimilar > similar) { similar = facesimilar; num = i; } } //刷新进度条 refresh = new Refresh(refreshprogressbar); Invoke(refresh, (similar * 100), listface[num].face_name); if (similar > changecheckvalue) { setControlText(label1, "识别结果: " + listface[num].face_name); bool sendflag = false; if (radioButton1.Checked) { sendflag = Serial_Device_API.GateAPI.GateSendData(Serial_Device_API.DeviceSerialPort.GateSerialPort, Serial_Device_API.GateAPI.gateleft); } else if (radioButton2.Checked) { sendflag = Serial_Device_API.GateAPI.GateSendData(Serial_Device_API.DeviceSerialPort.GateSerialPort, Serial_Device_API.GateAPI.gateright); } if (sendflag) { Console.WriteLine("数据发送成功!"); } else { Console.WriteLine("数据发送失败!"); } } else { setControlText(label1, "识别结果: " + "无此人"); } } else { setControlText(label1, "识别结果: " + "未开启人脸识别"); //刷新进度条 refresh = new Refresh(refreshprogressbar); Invoke(refresh, 0.00f, ""); } //添加人脸 if (addflag) { pictureBox0.Image = null; facelibrary = new FaceLibrary(); facelibrary.face_name = textBox1.Text.Trim(); detectfacefeature = GetDetectFaceFeature(bitmap, pictureBox0, true); facelibrary.face_Feature = detectfacefeature.face_Feature; if (currentfacenum > -1) //覆盖当前人脸信息 { listface[currentfacenum] = facelibrary; } else { listface.Add(facelibrary); } addflag = false; currentfacenum = -1; string listfacelibrary = JsonListToString(listface); FileWrite(filepath, listfacelibrary); MessageBox.Show("人脸注册成功!"); //清除人脸用户名 refreshtext = new RefreshText(refreshTextbox); Invoke(refreshtext, textBox1, ""); } } else { if (checkflag) { setControlText(label1, "识别结果: " + "未检测到人脸"); } if (addflag) { MessageBox.Show("未检测到人脸,人脸注册失败!"); addflag = false; } } //设置显示图片 imageBox0.Image = mat; } catch (Exception ex) { Console.WriteLine(ex.Message); } }