gpt4 book ai didi

c++ - 从opencv读取时gtkmm DrawingArea分割错误

转载 作者:行者123 更新时间:2023-12-02 16:38:21 27 4
gpt4 key购买 nike

我正在使用gtkmm 3开发一个简单的OpenCV(v3.1)视频捕获应用程序,现在我正尝试通过将DrawingArea对象转换为Mat将jpg图像加载到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); }

当我使用以下命令编译程序时: 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
我没有收到任何警告,但是立即运行该程序会导致segfault。为什么是这样?

最佳答案

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

关于c++ - 从opencv读取时gtkmm DrawingArea分割错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42446971/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com