在Windows窗体应用程序中创建opencv程序 [英] Create opencv program in windows forms application

查看:289
本文介绍了在Windows窗体应用程序中创建opencv程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个程序,使用打开的

 FileDialog1 

控件将图像加载到图片框,并在该图像上标记一些点。我能够将图像加载到pictureBox。我已经声明了一个名为CvCreatePoints的类来标记点uisng CvPoint()函数。但我不知道如何将该pictureBox图像传递给

 CvCreatePoints 

类。



以下是我的代码



在Form1.h内部按钮点击事件



 openFileDialog1->过滤器=   Jpeg | * .Jpg; 
openFileDialog1-> FilterIndex = 1 ;
if (openFileDialog1-> ShowDialog()== System :: Windows :: Forms :: DialogResult :: OK)
{
pictureBox1-> Image = Image :: FromFile(openFileDialog1-> FileName);
}







然后我有mouse_down事件,我试图获得积分用户单击并将它们传递给CvCreatePoints类。我有一个名为DrawPoints的方法



 CvCreatePoints cp; 
点xy;
xy = Control :: MousePosition :: get();

int xVal = xy.X;
int yVal = xy.Y;
cp.DrawPoints(pictureBox1-> Image,xVal,yVal);





在我的CvCreatePoints.hi中有DrawPoints方法



 CvCreatePoints( void ); 
void DrawPoints(IplImage * img, int x, int y);






CvCreatePoints.cpp类中的




  void  CvCreatePoints :: DrawPoints(IplImage * image, int  x, int  y)
{

}





编译时,


无法从''System ::转换参数1绘图::图像^''到''IplImage *''

给出了错误。那么如何将

 System :: Drawing :: Image转换为''IplImage 





另外



 1> E:\Softwarez \ OPENCV_DIR \Opencv243 \ build \ include \opencv2 / core / types_c.h(305):错误C3862:''cvRound'':无法使用/ clr编译非托管函数:pure或/ clr:safe 
1>托管代码中不支持内联本机程序集
1> E:\Softwarez \OPENCV_DIR \Opencv243 \ build \ include \opencv2 / core / types_c.h(305):错误C3645:''cvRound '':__ clrcall不能用于编译为本机代码的函数
1> MatlabToOpenCv.cpp
1> E:\Softwarez \ OPENCV_DIR \Opencv243 \ build \ include \opencv2 / core / types_c.h(305):错误C3862:''cvRound'':无法编译带/ clr:pure或/ clr的非托管函数:safe
1>托管代码中不支持内联本机程序集
1> E:\Softwarez \OPENCV_DIR \Opencv243 \ build \ include \opencv2 / core / types_c.h(305):错误C3645:''cvRound '':__ clrcall不能用于编译为本机代码的函数





我不明白这个错误:(

谢谢

解决方案

你不能将CLR引用转换为本机指针,这两件事情是不一样的。其次你不能直接调用非托管代码在CLR程序中,您需要使用 Platfrom Invoke [ ^ ]功能。

Hi, iam implementig a program to load an image to picture box using open

FileDialog1

control and mark some points on that image. I was able to load the image to the pictureBox.I have declared a class called CvCreatePoints to mark points uisng CvPoint() function. But i dont know how to pass that pictureBox image to

CvCreatePoints

class.

Below is my code

In Form1.h Inside Button click event

openFileDialog1->Filter = "Jpeg |*.Jpg";
                  openFileDialog1->FilterIndex = 1;
                    if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK )
                    {
                     pictureBox1->Image = Image::FromFile(openFileDialog1->FileName);
                    }




Then i have mouse_down event and there i tried to get the points when user clicks and pass them to the CvCreatePoints class. There i have a method called DrawPoints

CvCreatePoints cp;		 
 Point xy;
 xy = Control::MousePosition::get();
			 
 int xVal = xy.X;
 int yVal = xy.Y;
 cp.DrawPoints(pictureBox1->Image,xVal,yVal);



In my CvCreatePoints.h i have DrawPoints method

CvCreatePoints(void);
    void DrawPoints(IplImage *img, int x,int y);




in CvCreatePoints.cpp class

void CvCreatePoints::DrawPoints(IplImage *image, int x,int y)
{

}



When compiled,

cannot convert parameter 1 from ''System::Drawing::Image ^'' to ''IplImage *''

error is given. So how do i cast

System::Drawing::Image to ''IplImage



Also

1>E:\Softwarez\OPENCV_DIR\Opencv243\build\include\opencv2/core/types_c.h(305): error C3862: ''cvRound'': cannot compile an unmanaged function with /clr:pure or /clr:safe
1>          Inline native assembly not supported in managed code
1>E:\Softwarez\OPENCV_DIR\Opencv243\build\include\opencv2/core/types_c.h(305): error C3645: ''cvRound'' : __clrcall cannot be used on functions compiled to native code
1>  MatlabToOpenCv.cpp
1>E:\Softwarez\OPENCV_DIR\Opencv243\build\include\opencv2/core/types_c.h(305): error C3862: ''cvRound'': cannot compile an unmanaged function with /clr:pure or /clr:safe
1>          Inline native assembly not supported in managed code
1>E:\Softwarez\OPENCV_DIR\Opencv243\build\include\opencv2/core/types_c.h(305): error C3645: ''cvRound'' : __clrcall cannot be used on functions compiled to native code



I don''t understand this error :(
Thank you

解决方案

You cannot cast a CLR reference to a native pointer, the two things are not the same. And secondly you cannot call unmanaged code directly in a CLR program, you need to use the Platfrom Invoke[^] feature.


这篇关于在Windows窗体应用程序中创建opencv程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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