2010-05-19 7 views
6

im Allgemeinen liefern wir Webcam oder Video-Motion in opencv Fenster mit:OpenCV: Wie Webcam Capture in Windows-Formular-Anwendung anzeigen?

 CvCapture* capture = cvCreateCameraCapture(0); 
      cvNamedWindow("title", CV_WINDOW_AUTOSIZE); 
    cvMoveWindow("title",x,y); 
    while(1) 
    { 
    frame = cvQueryFrame(capture); 
    if(!frame) 
    { 
    break; 
    } 
    cvShowImage("title", frame); 
    char c = cvWaitKey(33); 
    if(c == 27) 
    { 
    break; 
    } 
    } 

ich versuchte PictureBox zu verwenden, die erfolgreich Bild anzuzeigen mit dieser in den Fenstern bilden:

pictureBox1->Image = gcnew System::Drawing::Bitmap(image->width,image->height,image->widthStep,System::Drawing::Imaging::PixelFormat::Undefined, (System::IntPtr) image-> imageData); 

aber wenn im Versuch zu aufgenommenes Bild von Video-anzeigen werden nicht funktioniert es, hier ist die Quelle:

  CvCapture* capture = cvCreateCameraCapture(0); 
    while(1) 
    { 
    frame = cvQueryFrame(capture); 
    if(!frame) 
    { 
    break; 
    } 
    pictureBox1->Image = gcnew System::Drawing::Bitmap(frame->width,frame->height,frame->widthStep,System::Drawing::Imaging::PixelFormat::Undefined, (System::IntPtr) frame-> imageData); 
    char c = cvWaitKey(33); 
    if(c == 27) 
    { 
    break; 
    } 
    } 

ist es trotzdem Fenster Form statt opencv Fenster zu verwenden s um Video oder Webcam zu zeigen?

oder stimmt etwas mit meinem Code nicht? danke für Ihre Hilfe .. :)

Antwort

1

Hinweis: Verwenden Sie VideoInput anstelle von CvCapture (CvCapture ist ein Teil von Highgui eine Bibliothek, die nicht für den Produktionseinsatz gedacht ist, sondern nur für schnelle Tests). Ja die VideoInput Homepage sieht seltsam aus, aber die Bibliothek ist sehr lohnenswert.

Hier ist eine schnelle Probe für die Nutzung von Videoeingang (von der VideoInput.h Datei extrahierte):

//create a videoInput object 
videoInput VI; 

//Prints out a list of available devices and returns num of devices found 
int numDevices = VI.listDevices(); 

int device1 = 0; //this could be any deviceID that shows up in listDevices 
int device2 = 1; //this could be any deviceID that shows up in listDevices 

//if you want to capture at a different frame rate (default is 30) 
//specify it here, you are not guaranteed to get this fps though. 
//VI.setIdealFramerate(dev, 60);  

//setup the first device - there are a number of options: 

VI.setupDevice(device1);       //setup the first device with the default settings 
//VI.setupDevice(device1, VI_COMPOSITE);    //or setup device with specific connection type 
//VI.setupDevice(device1, 320, 240);     //or setup device with specified video size 
//VI.setupDevice(device1, 320, 240, VI_COMPOSITE); //or setup device with video size and connection type 

//VI.setFormat(device1, VI_NTSC_M);     //if your card doesn't remember what format it should be 
                //call this with the appropriate format listed above 
                //NOTE: must be called after setupDevice! 

//optionally setup a second (or third, fourth ...) device - same options as above 
VI.setupDevice(device2);       

//As requested width and height can not always be accomodated 
//make sure to check the size once the device is setup 

int width = VI.getWidth(device1); 
int height = VI.getHeight(device1); 
int size = VI.getSize(device1); 

unsigned char * yourBuffer1 = new unsigned char[size]; 
unsigned char * yourBuffer2 = new unsigned char[size]; 

//to get the data from the device first check if the data is new 
if(VI.isFrameNew(device1)){ 
    VI.getPixels(device1, yourBuffer1, false, false); //fills pixels as a BGR (for openCV) unsigned char array - no flipping 
    VI.getPixels(device1, yourBuffer2, true, true);  //fills pixels as a RGB (for openGL) unsigned char array - flipping! 
} 

//same applies to device2 etc 

//to get a settings dialog for the device 
VI.showSettingsWindow(device1); 


//Shut down devices properly 
VI.stopDevice(device1); 
VI.stopDevice(device2); 
+0

Beeinflusst die simultane Videoausgabe und die Hintergrundbildverarbeitung der gleichen Informationen die Leistung erheblich? –

+0

Ich bin mir nicht sicher, ob ich Ihre Frage richtig verstanden habe. Soweit ich mich erinnere, wird das aufgenommene Bild nicht direkt in den Bildschirmpuffer kopiert. VideoInput basiert jedoch auf DirectShow, was zwei Dinge impliziert: Es ist wirklich schnell und es ist ein PITA zu kompilieren (Sie müssen die entsprechende DirectShow-Implementierung von Microsoft bekommen). Das letzte Mal, als ich es versuchte, musste ich eine ältere Version der DirectShow-Bibliothek bekommen. Eine kompilierte Version der VideoInput-Bibliothek wird jedoch im Download bereitgestellt. –

1

Das Pixelformat bekannt sein sollte, wenn Sie Bilder von einer Kamera erfassen, ist es sehr wahrscheinlich, dass das Format von 24-Bit-BGR. System::Drawing::Imaging::PixelFormat::Format24bppRgb wird das nächste Format sein, aber Sie könnten seltsame Farbanzeige erhalten. Eine Neuanordnung der Farbkomponente wird dieses Problem lösen.

Tatsächlich gibt es .net Version opencv Bibliothek finden Sie hier: http://code.google.com/p/opencvdotnet/ und hier: http://www.emgu.com/wiki/index.php/Main_Page

Hoffe, es hilft!

1

Ich weiß nicht, ob Ihnen das gefallen wird, aber Sie könnten OpenGL verwenden, um den Video-Stream in anderen Fenstern als denen anzuzeigen, die mit opencv bereitgestellt werden. (Erfassen Sie den Rahmen und zeigen Sie ihn auf einem Rechteck .. oder so ähnlich an.)

0

Eine weitere Option, die Sie in Betracht ziehen sollten, ist die Verwendung von emgu. Dies ist ein .Net-Wrapper für opencv mit winforms-controlls.

Verwandte Themen