/// <summary> /// 播放摄像头线程 /// </summary> private void Play_Camera() { while (bPlayflag) { //Thread.Sleep(40); Mat cFrame = new Mat(); m_vCapture.Read(cFrame); int sleepTime = (int)Math.Round(1000 / m_vCapture.Fps); Cv2.WaitKey(sleepTime); if (cFrame.Empty()) { continue; } Cv2.Flip(cFrame, cFrame, OpenCvSharp.FlipMode.Y); Rect cMaxrect = new Rect(170, 90, 150, 150); if (bTakePicture)//拍照,截取指定区域 { Mat cHead = new Mat(cFrame, cMaxrect); Cv2.ImWrite(PicSavePath, cHead); SetPictureBoxImage(pic_head, cHead.ToBitmap()); cHead.Release(); bTakePicture = false; } //绘制指定区域(人脸框) Scalar color = new Scalar(0, 100, 0); Cv2.Rectangle(cFrame, cMaxrect, color, 2); SetPictureBoxImage(pic_cam, cFrame.ToBitmap()); cFrame.Release();//释放 } }
/// <summary> /// 深度表示PictureBoxを更新 /// <param name="image">表示画像。depthBitmapと同じサイズ・色深度でなければならない /// Kinectから得られる16bitの深度ではないので注意。</param> /// </summary> private void UpdateDepthPictureBox(Mat image) { // 指定された画像でBitmapを更新 image.ToBitmap(this.depthBitmap); // PictureBoxの描画を要求 this.pictureBoxDepth.Invalidate(); }
/// <summary> /// カラー表示PictureBoxの表示を更新 /// <param name="image">表示画像。colorBitmapと同じサイズ・色深度でなければならない</param> /// </summary> private void UpdatePictureBox(Mat image) { // 指定された画像でBitmapを更新 image.ToBitmap(this.colorBitmap); // PictureBoxの描画を要求 this.pictureBoxColor.Invalidate(); }
public void ToMatGrayScale() { Mat img = new Mat(FilePath.Image.Lenna511, ImreadModes.GrayScale); Bitmap bitmap = img.ToBitmap(); Mat converted = BitmapConverter.ToMat(bitmap); //Mat converted = Mat.FromBitmap(bitmap); using (new Window("Grayscale Bitmap to Mat test", converted)) { Cv2.WaitKey(); } }