wxWidgets + OpenCV 矩形崩溃 OnButtonClick()
我试图在单击 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 );
}
我已经在控制台应用程序中尝试过这段代码并且工作正常。我还尝试将此代码放入 wxFrame 构造函数中,并且也可以正常工作。如果我评论矩形函数一切正常(它显示黑色图像)。
我已经遇到这个问题两天了,我最初的问题是我无法扭曲仿射图像,因为它也崩溃了。
我可以在图像中绘制
A.at<uchar>(0,0)=255
,并且我知道我可以执行 for 循环来绘制矩形。
我的环境是 Windows 7 64 位、OpenCv 2.3.1、wxWidgets 2.8.12 和 CodeBlocks 10.05
感谢任何帮助和想法, 谢谢。
---edit----
我尝试过矩形、warpAffine 和 putText 函数,这三个函数在 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.
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. 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.
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.
My environment is Windows 7 64-bit, OpenCv 2.3.1, wxWidgets 2.8.12 and 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. The functions line and circle work fine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来问题出在矩形例程中。 OpenCV 中有这个东西吗?或者wxFrameFrame的方法?
我要尝试的第一件事是查看矩形是否存在传递自动值的问题,一旦调用它就会超出范围。
试试这个
It looks like the problem is in the rectangle routine. Is this something in OpenCV? or a method of 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