/// <summary> /// 點選開始的動作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStart_Click(object sender, EventArgs e) { oWebCam.Container.Height = picWebCam.Height; oWebCam.Container.Width = picWebCam.Width; oWebCam.OpenConnection(); tiCapture.Enabled = true; }
/// <summary> /// 攝影機畫面讀取的動作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmCam_Load(object sender, EventArgs e) { new CognitiveUtility().BindPersonGroup(cbxPersonGroup, face, ""); oWebCam = new WebCam(); oWebCam.Container = picRender; tiCapture.Interval = 5000; objPlUtil.TargetPanel = plCam; plCam.Paint += objPlUtil.OnPaint; oWebCam.OpenConnection(); }
/// <summary> /// 點選透過WebCam照像的動作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnCam_Click(object sender, EventArgs e) { // 打開WebCam oWebCam = new WebCam(); oWebCam.Container = picImage; oWebCam.Container.Height = picImage.Height; oWebCam.Container.Width = picImage.Width; oWebCam.OpenConnection(); string strTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string strFileFolder = ConfigurationManager.AppSettings["FileFolder"].ToString(); string strFileName = strFileFolder + strTime + ".jpg"; Image objImg = oWebCam.CaptureImage(); objImg.Save(strFileName); plTag.BackgroundImage = Bitmap.FromFile(strFileName); Face[] faces = await face.DetectAsync(File.OpenRead(strFileName), true, true); await this.DetectFace(faces); }
/// <summary> /// 點選透過WebCam照像的動作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnCam_Click(object sender, EventArgs e) { // 打開WebCam oWebCam = new WebCam(); oWebCam.Container = picImage; oWebCam.Container.Height = picImage.Height; oWebCam.Container.Width = picImage.Width; oWebCam.OpenConnection(); Image img = oWebCam.CaptureImage(); picImage.Image = img; MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); oWebCam.Dispose(); HttpResponseMessage response = await new CognitiveUtility().FaceDetect(ms, base.SetupConfig.FaceApiKey); string strContent = await response.Content.ReadAsStringAsync(); Face[] faces = JsonConvert.DeserializeObject <Face[]>(strContent); await this.DetectFace(faces); }