wxWidgets + OpenCV 矩形崩溃 OnButtonClick()

发布于 2025-01-05 11:53:37 字数 819 浏览 0 评论 0原文

我试图在单击 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本宫微胖 2025-01-12 11:53:37

看起来问题出在矩形例程中。 OpenCV 中有这个东西吗?或者wxFrameFrame的方法?

我要尝试的第一件事是查看矩形是否存在传递自动值的问题,一旦调用它就会超出范围。

试试这个

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);

    ...

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

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);

    ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文