Click here to Skip to main content
11,702,130 members (66,305 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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
    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!
Posted 31-Jan-13 22:48pm
Edited 31-Jan-13 23:21pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
pheajcon at 1-Feb-13 11:01am
   
i have no idea how to make it... can you teach me?
Matthew Faithfull at 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 at 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)

  Print Answers RSS
0 Maciej Los 420
1 Sergey Alexandrovich Kryukov 355
2 OriginalGriff 314
3 Mika Wendelius 119
4 CHill60 105
0 OriginalGriff 8,344
1 Sergey Alexandrovich Kryukov 7,507
2 CPallini 4,922
3 Maciej Los 4,371
4 Mika Wendelius 3,556


Advertise | Privacy | Mobile
Web02 | 2.8.150819.1 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100