2016-04-28 7 views
0

Ich codiere eine WindowsForm-Anwendung in C# mit OpenCV. Ich möchte Video von der Webcam erfassen und es in einem Fenster zeigen, und ich möchte es mit P/Invoke machen, ich habe C++ Code, aber ich kann nicht, wie ich es in C# mache.Capturing Video mit opencv mit Pinovke in 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; 
} 

ich einen Link in Github gefunden, die hilfreich sein wird Face Detect

genau gleiche Art, wie ich das Video von webcam.any Referenz Link aufnehmen mag Gesicht von Bild erkennen.?

Antwort

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 

Quelle: Codeproject

+0

ich will nicht Emgucv verwenden ich es durch OpenCV erhalten möchten –