在c#中使用Pinovke使用opencv捕获视频

时间:2016-04-28 05:35:19

标签: c# c++ opencv video

我使用openCV在C#中编写WindowsForm应用程序。我想从网络摄像头捕获视频并在窗口中显示它,我想用P / Invoke来做,我得到了c ++代码,但我不知道如何在c#中进行。

#include "opencv2/opencv.hpp"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened())  // check if we succeeded
    return -1;

Mat edges;
namedWindow("edges",1);
for(;;)
{
    Mat frame;
    cap >> frame; // get a new frame from camera
    cvtColor(frame, edges, COLOR_BGR2GRAY);
    GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
    Canny(edges, edges, 0, 30, 3);
    imshow("edges", edges);
    if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}

我在github中找到了一个链接,它将检测来自图像Face Detect

的脸部

我想从网络摄像头捕获视频的方式完全相同。任何参考链接都会有帮助。?

1 个答案:

答案 0 :(得分:0)

#region cameracapture
   if (comboBox1.Text == "Capture From Camera")
   {
     try
     {
       _capture = null;
       _capture = new Capture(0);
       _capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FPS, 30);
       _capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_HEIGHT, 240);
       _capture.SetCaptureProperty(Emgu.CV.CvEnum.CAP_PROP.CV_CAP_PROP_FRAME_WIDTH, 320);
       Time_Label.Text = "Time: ";
       Codec_lbl.Text = "Codec: ";
       Frame_lbl.Text = "Frame: ";
       webcam_frm_cnt = 0;
       cam = 1;
       Video_seek.Value = 0;
       Application.Idle += ProcessFrame;
       button1.Text = "Stop";
       comboBox1.Enabled = false;
     }
     catch (NullReferenceException excpt)
     {
        MessageBox.Show(excpt.Message);
     }
   }
#endregion cameracapture 

来源:Codeproject