从图片框中的摄像头显示图像 [英] display image from webcam in picturebox

查看:169
本文介绍了从图片框中的摄像头显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个表格,包括一个按钮和一个显示网络摄像头的图片框。当我按下按钮时,图片框将开始显示图像。



这是按钮的代码:



hi all,
I have a form including a button and a picture box to display the webcam. When i press the button, the picture box will start to display the image.

This is the code of the button:

private: System::Void btnCapture_Click(System::Object^ sender,
System::EventArgs^ e) {
    CvCapture * pCapture = cvCaptureFromCAM(0);
    IplImage *image = 0;
    cvNamedWindow ("Demo",CV_WINDOW_AUTOSIZE); // <--- Main Problem

    while (1)
    {
        image = cvQueryFrame (pCapture);
        showImage (image, pictureBox1);
        if (cvWaitKey (1) == 27) break;
    }

    cvReleaseCapture (&pCapture);
    cvDestroyWindow ("Demo");
}



这是showImage功能:




And this is showImage function:

private: System::Void showImage(IplImage *img,
System::Windows::Forms::PictureBox^ picturebox){
    IntPtr ip(new unsigned
    char[img->widthStep*img->height]);

    memcpy(ip.ToPointer(),img->imageData,img->widthStep*img->height);

    picturebox->Image = gcnew Bitmap(img->width,
    img->height, img->widthStep,

    System::Drawing::Imaging::PixelFormat::Format24bppRgb, ip);

    //delete (bmp);
}



但编译时出错




but there is an error when compile

Inline native assembly not supported in managed code

c:\opencv\build\include\opencv2/core/types_c.h(289): error C3862: 'cvRound': cannot compile an unmanaged function with /clr:pure or /clr:safe
1>          Inline native assembly not supported in managed code
1>c:\opencv\build\include\opencv2/core/types_c.h(289): error C3645: 'cvRound' : __clrcall cannot be used on functions compiled to native code
1>c:\opencv\build\include\opencv2/core/mat.hpp(115): error C3861: '_InterlockedExchangeAdd': identifier not found
1>c:\opencv\build\include\opencv2/core/mat.hpp(305): error C3861: '_InterlockedExchangeAdd': identifier not found
1>c:\opencv\build\include\opencv2/core/mat.hpp(377): error C3861: '_InterlockedExchangeAdd': identifier not found
1>c:\opencv\build\include\opencv2/core/mat.hpp(381): error C3861: '_InterlockedExchangeAdd': identifier not found
1>c:\opencv\build\include\opencv2/core/mat.hpp(2064): error C3861: '_InterlockedExchangeAdd': identifier not found
1>c:\opencv\build\include\opencv2/core/mat.hpp(2092): error C3861: '_InterlockedExchangeAdd': identifier not found
1>c:\opencv\build\include\opencv2/core/mat.hpp(2096): error C3861: '_InterlockedExchangeAdd': identifier not found
1>c:\opencv\build\include\opencv2/flann/flann.hpp(233): warning C4996: 'cv::flann::Index_<t>': was declared deprecated
1>          c:\opencv\build\include\opencv2/flann/flann.hpp(278) : see reference to class template instantiation 'cv::flann::Index_<t>' being compiled
1>C:\Program Files\Microsoft Visual Studio 10.0\VC\include\emmintrin.h(27): fatal error C1189: #error :  ERROR: EMM intrinsics not supported in the pure mode!

推荐答案

看起来你试图从托管代码中使用OpenCV而OpenCV头文件/ SDK是非托管代码。这意味着你将不得不编写一个非托管应用程序来使用它。

他们将使用非托管,因为他们正在使用汇编语言函数来加快速度。如果你使用他们的代码,最好遵循他们的模式,除非你想用托管代码重写它。
It look like you''re trying to use OpenCV from managed code and the OpenCV headers/SDK is unmanaged code. That means you''ll have to write an unmanaged application to use it.
They''ll be using unmanaged because they''re using assembly language functions to speed things up no doubt. Best to follow their pattern if you''re using their code unless you''re up for rewriting it in managed code.


这篇关于从图片框中的摄像头显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆