Click here to Skip to main content
15,789,698 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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");

And this is showImage function:

private: System::Void showImage(IplImage *img,
System::Windows::Forms::PictureBox^ picturebox){
    IntPtr ip(new unsigned


    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!
Updated 1-Feb-13 0:21am

1 solution

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.
Share this answer
pheajcon 1-Feb-13 11:01am    
i have no idea how to make it... can you teach me?
Matthew Faithfull 1-Feb-13 11:05am    
I've no idea I'm afraid, have never used OpenCV. Beside which I cost £40 per hour you'd be better off with a book. :-)
H.Brydon 3-Feb-13 22:59pm    
You don't necessarily have to write a separate unmanaged app. If you use C++/CLI you can write a mixed mode app that has both managed and unmanaged components.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900