2010-05-19 25 views
6

आम तौर पर हम साथ opencv खिड़कियों में वेब कैमरा या वीडियो गति प्रदर्शित:ओपनसीवी: विंडोज़ फॉर्म एप्लिकेशन में वेबकैम कैप्चर कैसे प्रदर्शित करें?

 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; 
    } 
    } 

मैं Picturebox खिड़कियों में छवि प्रदर्शित करने सफल हुआ है कि उपयोग करने का प्रयास इस के साथ फार्म:

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

लेकिन जब im की कोशिश कर रहा

  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; 
    } 
    } 

, खिड़कियाँ उपयोग करने के लिए प्रपत्र बजाय opencv खिड़की वैसे भी है: वीडियो यह अभ्यस्त काम करता है से कब्जा कर लिया छवि प्रदर्शित, यहाँ स्रोत है वीडियो या वेब कैमरा दिखाने के लिए?

या मेरे कोड में कुछ गड़बड़ है? आपकी मदद के लिए धन्यवाद .. :)

उत्तर

1

सलाह का टुकड़ा: VideoInput का उपयोग CvCapture के बजाय (CvCapture highgui का एक हिस्सा एक पुस्तकालय है कि उत्पादन उपयोग के लिए नहीं है, लेकिन सिर्फ त्वरित परीक्षण के लिए)। हां VideoInput मुखपृष्ठ अजीब लग रहा है, लेकिन पुस्तकालय काफी सार्थक है।

//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

क्या एक ही जानकारी के साथ-साथ वीडियो आउटपुट और पृष्ठभूमि छवि प्रसंस्करण प्रदर्शन को प्रभावित करता है? –

+0

सुनिश्चित नहीं है कि मैं आपके प्रश्न को सही ढंग से समझता हूं। जहां तक ​​मुझे याद है, हथियार वाली छवि सीधे स्क्रीन बफर पर कॉपी नहीं की जाती है। हालांकि वीडियो इनपुट डायरेक्टशो पर आधारित है, जो दो चीजों का तात्पर्य है: यह वास्तविक तेज़ है, और यह संकलन करने के लिए एक पिटा है (आपको माइक्रोसॉफ्ट से संबंधित डायरेक्टशो कार्यान्वयन की आवश्यकता है)। आखिरी बार मैंने कोशिश की, मुझे डायरेक्टशो लाइब्रेरी का पुराना संस्करण प्राप्त करना पड़ा। हालांकि, वीडियो इनपुट लाइब्रेरी का एक संकलित संस्करण डाउनलोड में प्रदान किया गया है। –

1

पिक्सेल प्रारूप है जब आप एक कैमरे से छवियों पर कब्जा पता होना चाहिए, तो बहुत संभव प्रारूप है:

यहाँ VideoInput के उपयोग के लिए एक त्वरित नमूना (VideoInput.h फ़ाइल से निकाले) है 24-बिट बीजीआर का। System::Drawing::Imaging::PixelFormat::Format24bppRgb निकटतम प्रारूप होगा लेकिन आपको अजीब रंग का डिस्प्ले मिल सकता है। रंग घटक की पुन: व्यवस्था इस समस्या को हल करेगी।

वास्तव में, .net संस्करण opencv पुस्तकालय यहां उपलब्ध हैं: http://code.google.com/p/opencvdotnet/ और यहाँ: http://www.emgu.com/wiki/index.php/Main_Page

आशा है कि यह मदद करता है!

1

मुझे नहीं पता कि आपको यह पसंद आएगा, लेकिन आप ओपनजीएल के साथ प्रदान की गई अन्य विंडो में वीडियो स्ट्रीम दिखाने के लिए ओपनजीएल का उपयोग कर सकते हैं। (फ्रेम को कैप्चर करें और इसे आयताकार पर प्रदर्शित करें .. या ऐसा कुछ ..)

0

एक अन्य विकल्प जिसे आप विचार करना चाहते हैं वह इमू का उपयोग कर रहा है। यह Winforms नियंत्रण के साथ opencv के लिए एक नेट रैपर है।