I'm working on a simple OpenCV (v3.1) video capture application using gtkmm 3, and right now I'm trying to load a jpg image into a DrawingArea
by way of taking a Mat
object into a Cairo::Context
. The program is as follows below:
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); }
When I compile the program using: g++ -std=c++11 -Wall -I/usr/local/include/opencv -I/usr/local/include/opencv2 -L/usr/local/lib -g OSDDrawingWindow.cpp -o drawing -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs pkg-config gtkmm-3.0 gtk+-3.0 --cflags --libs
I receive no warnings, but running the program immediately results in a segfault. Why is this?
Aucun commentaire:
Enregistrer un commentaire