[英]wxWidgets + OpenCV rectangle crash OnButtonClick()
I am trying to draw a simple rectangle in a OpenCV Mat when a wxbutton is clicked, but program crash when calls rectangle function. 我试图单击wxbutton时在OpenCV Mat中绘制一个简单的矩形,但是调用矩形函数时程序崩溃。
void wxFrameFrame::OnButton1Click(wxCommandEvent& event)
{
Mat A(480,640,CV_32F);
Point p1(10, 10);
Point p2(20,200);
rectangle(A, p1, p2, Scalar(255,0,255,0), 0);
// Show what you got
namedWindow( "src", CV_WINDOW_AUTOSIZE );
imshow( "src", A );
}
I have tried this code in a console application and works fine. 我已经在控制台应用程序中尝试了此代码,并且工作正常。 I have also tried to put this code in the wxFrame constructor and works fine too.
我也尝试将这段代码放在wxFrame构造函数中,并且也可以正常工作。 If I comment the rectangle function all is ok (it shows a black image).
如果我评论矩形函数,一切正常(显示黑色图像)。
I have this problem for two days now, my original problem was I couldn't warpAffine an image because it crashed too. 我有两天了这个问题,我原来的问题是我无法warpAffine图像,因为它也崩溃了。
I can draw in the image with 我可以用
A.at<uchar>(0,0)=255
and I know I can do a for loop to draw the rectangle. 而且我知道我可以做一个for循环来绘制矩形。
My environment is Windows 7 64-bit, OpenCv 2.3.1, wxWidgets 2.8.12 and CodeBlocks 10.05 我的环境是Windows 7 64位,OpenCv 2.3.1,wxWidgets 2.8.12和CodeBlocks 10.05
Any help and idea is appreciated, Thanks. 感谢您的任何帮助和想法,谢谢。
---edit---- - -编辑 - -
I have tried the functions rectangle, warpAffine and putText and the three crashed when called inside OnButtonClick. 我已经尝试了矩形函数,warpAffine和putText函数,并且在OnButtonClick内部调用这三个函数时崩溃了。 The functions line and circle work fine.
功能线和圆工作正常。
It looks like the problem is in the rectangle routine. 看来问题出在矩形例程中。 Is this something in OpenCV?
这是OpenCV中的东西吗? or a method of wxFrameFrame?
或wxFrameFrame的方法?
The 1st thing I would try is to see if rectangle is having a problem with being passed automatics that go out of scope as soon as it is called. 我要尝试的第一件事是查看矩形是否在通过自动调用时遇到问题,该自动调用会立即超出范围。
Try this 尝试这个
void wxFrameFrame::OnButton1Click(wxCommandEvent& event)
{
static Mat A(480,640,CV_32F);
static Point p1(10, 10);
static Point p2(20,200);
static Scaler s(255,0,255,0);
static int n = 0;
rectangle(A, p1, p2, s, n);
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.