从opencv读取时,gtkmm DrawingArea分段错误

时间:2017-02-24 19:39:33

标签: c++ opencv c++11 gtk gtkmm

我正在使用gtkmm 3开发一个简单的OpenCV(v3.1)视频捕获应用程序,现在我正试图通过{{1}将jpg图像加载到DrawingArea将对象转换为Mat。该计划如下:

Cairo::Context

当我使用:int main(int argc, char *argv[]){ Gtk::Window* mainWindow; Gtk::DrawingArea* videoBackground; auto app = Gtk::Application::create(argc, argv, "com.twallis.OSD"); Mat inImage, outImage; inImage = cv::imread("blackbackground.jpg", IMREAD_COLOR); cvtColor(inImage, outImage, CV_BGR2RGB); /*LOAD WIDGETS FROM BUILDER FILE*/ Glib::RefPtr<Gtk::Builder> builder = Gtk::Builder::create(); try{ builder->add_from_file("OSD_drawing_background1.glade"); } catch(const Glib::FileError& ex){ std::cerr << "fileError: " << ex.what() << endl; return 1; } catch(const Glib::MarkupError& ex){ std::cerr << "MarkupError: " << ex.what() << endl; return 1; } catch(const Gtk::BuilderError& ex){ std::cerr << "BuilderError " << ex.what() << endl; return 1; } builder->get_widget("mainWindow", mainWindow); builder->get_widget("videoBackground", videoBackground); Cairo::RefPtr<Cairo::Context> cairoContext = videoBackground- >get_window()->create_cairo_context(); Gdk::Cairo::set_source_pixbuf(cairoContext, Gdk::Pixbuf::create_from_data(outImage.data, Gdk::COLORSPACE_RGB, false, 8, outImage.cols, outImage.rows, outImage.step)); mainWindow->add(*videoBackground); videoBackground->queue_draw(); return app->run(*mainWindow); }

编译程序时

我没有收到任何警告,但立即运行该程序会导致段错误。这是为什么?

1 个答案:

答案 0 :(得分:0)

if(!outImage.empty()) {
   ...
}