Gtk-Message: 14:47:21.541: Failed to load module “canberra-gtk-module“ 的处理方法

1 篇文章 0 订阅
1 篇文章 0 订阅

最近研究读取Elekta加速器XVI产生的his格式的数据读取,利用OpenCV 进行显示时,发现了一个错误(Ubuntu20)如下:Gtk-Message: 14:47:21.541: Failed to load module "canberra-gtk-module"

这个提示可能是缺少canberra-gtk-module模块没有安装。作为新一代青年,上网搜索才是解决方法。

上网搜索得知,我的判断是对的,于是

sudo apt-get install libcanberra-gtk*

 神奇的是,我的显示模式也瞬间变得清晰了,太神奇了。

可能会有小伙伴们想知道怎样读取HIS格式的文件了,告诉大家,很简单的。(文件在这里)文件的大小为524388个字节,前100个字节是文件的文件头信息,

28672    #文件的ID

68          #文件头大小

0            #版本

100        #

8            #文件的大小,这里使用了4个字节表示,读取错误

32          #图像信息的大小

1            #X方向坐上

1            #  Y方向,左上

512        #X右下   也可以理解成row

512        #Y右下                         column

1            # 不解释了,后面的没有用了

0

0

0

0

0

4           #使用16位数据进行存储

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

61784

65446

46682

65504

64609

65525

65534

65535

41560

65455

1888

638

46661

65455

1888

638

从第101个字节开始,到512×512×2结束,是数据部分。

代码如下:

#include <iostream>
#include <opencv2/opencv.hpp>
#include <fstream>
#include <vector>
#include <string>
 
using namespace std;
 
int main(int,char**)
{
    string fileName="../data/test.his";
 
    fstream reader;
    reader.open(fileName.c_str(),ios::in|ios::binary); //read file as binary
    if(!reader.is_open()){
        cout<<"read file failed."<<endl;
        return -1;
    }
 
 
 
    reader.seekg(0,ios::end);
    cout<<"File size is: "<<reader.tellg()<<endl;  // determin the file size.
 
    reader.seekg(0,ios::beg);    //pointer come back to the initial position.
    vector<unsigned short> header;
    char buffer[100];
    reader.read(buffer,100);    // read 1 byte every time.
    for(int i=0;i<50;i++){
        unsigned short p=buffer[2*i+1]<<8|buffer[2*i+0];   //little endiant
        header.push_back(p);
    }
 
    for(vector<unsigned short>::iterator it=header.begin();it!=header.end();++it){
        cout<<*it<<endl;
    }  //display the header information
    int row,col;
    row=header[8];
    col=header[9];
 
    // Reade the pixel data
 
    reader.seekg(100,ios::beg);
    int m=512*512;
    char data[m*2];
    reader.read(data,m*2);  //read the pixel data
 
    unsigned short pixel[m];
    for(int i=0;i<m;++i){
        pixel[i]=data[2*i+1]<<8|data[2*i+0];  //little endiant
    }
 
    reader.close();
    // display the image using OpenCV
    cv::Mat image=cv::Mat(col,row,CV_16UC1,pixel);
    cv::normalize(image,image,0,255,cv::NORM_MINMAX,CV_8UC1);
    cv::imshow("",image);
    cv::waitKey(0);
    return 0;
}

 

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用\[1\]中提供的信息,如果在Ubuntu安装Matlab后运行时报错"Failed to load module 'canberra-gtk-module'",可能是由于未安装Matlab所需的依赖项导致的。你可以尝试执行以下命令来安装缺失的依赖项: ``` sudo apt-get install libcanberra-gtk-module ``` 如果已经安装了这个依赖项但仍然报错,可能是由于GTK版本的问题。Ubuntu默认安装的是GTK 3.0,而Matlab需要的是GTK 2.0版本。你可以尝试安装GTK 2.0+版本的canberra来解决这个问题,运行以下命令: ``` sudo apt-get install libcanberra-gtk-module -y ``` 此外,你还需要添加一个软连接,运行以下命令: ``` sudo ln -s /usr/lib/x86_64-linux-gnu/gtk-2.0/modules/libcanberra-gtk-module.so /usr/lib/libcanberra-gtk-module.so ``` 如果你仍然无法定位到"libcanberra-gtk-module",你可以尝试使用strace命令来查看系统调用过程,以找到出错的位置。根据引用\[3\]中提供的信息,你可以运行以下命令: ``` strace -e trace=file sudo apt-get install libcanberra-gtk-module ``` 这将显示系统调用过程中访问的文件路径,帮助你找到问题所在。 #### 引用[.reference_title] - *1* *2* [Failed to load module “canberra-gtk-module“ 或 Using GTK+ 2.x and GTK+ 3 in the same process is ...](https://blog.csdn.net/qq_46304090/article/details/126572231)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [解决 canberra-gtk-module 加载失败的问题](https://blog.csdn.net/Longyu_wlz/article/details/85254588)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值