【问题标题】:converting images between opencv and wxwidgets在 opencv 和 wxwidgets 之间转换图像
【发布时间】:2011-11-18 04:23:17
【问题描述】:

我有一个大问题。在网上搜索后,我没有找到一个好的解决方案。我通过opencv(2.3)从文件中读取图像并对其进行操作。之后我想在我用 wxwidgets (2.9.3) 编写的应用程序中展示结果。主要问题是,我的图像是灰度的,所以我只有一个数据指针,但 wxwidgets 只使用 RGB。只是一个小例子:

cv::imread(filename,CV_LOAD_IMAGE_GRAYSCALE).convertTo(pictureMatrix,CV_32F,(float)(1/2.0f),0);
// here are some more floating point calculations
cv::Mat output;
pictureMatrix.convertTo(output,CV_8U);
wxImage test(output.rows, output.cols, output.data, true);
wxInitAllImageHandlers();
// saving the picture is just for testing, if it works
test.SaveFile("test.png", wxBITMAP_TYPE_PNG);

【问题讨论】:

    标签: c++ opencv wxwidgets


    【解决方案1】:

    您需要做的就是从灰度转换为 RGB(实际上,如果您使用的是 Windows,则转换为 BGR)。

    cv::Mat grayOutput, rgbOutput;
    pictureMatrix.convertTo(grayOutput,CV_8U);
    cvtColor(grayOutput, rgbOutput, CV_GRAY2BGR); // note the BGR here. 
    //If on Linux, set as RGB
    wxImage test(rgbOutput.cols, rgbOutput.rows,  rgbOutput.data, true);
    ...
    

    【讨论】:

      【解决方案2】:

      您始终可以为每个像素设置R=G=B=<your grayscale value>。如果图像像素的格式不匹配,您可以按照wxImage 预期的格式分配一个新数组,并用这些 RGB 值填充它。

      您也可以查看this link。它看起来与您需要做的相似。

      【讨论】:

      • 此解决方案也有效,但不需要逐像素访问。 THX
      猜你喜欢
      • 1970-01-01
      • 2014-11-02
      • 2017-01-10
      • 1970-01-01
      • 1970-01-01
      • 2018-10-03
      • 2018-06-15
      • 2011-12-27
      • 2013-05-01
      相关资源
      最近更新 更多