【问题标题】:How to convert Mat to IplImage in Javacv?如何在 Javacv 中将 Mat 转换为 IplImage?
【发布时间】:2017-05-14 02:32:02
【问题描述】:

有人知道如何将 Mat 转换为 IplImage 吗? 为了实现这一点,我已将 Mat 转换为 BufferedImage,但再次无法在 BufferedImage 中找到转换为 IplImage。

有什么方法可以将 Mat 转换为 IplImage?

谢谢

【问题讨论】:

    标签: opencv image-processing javacv face-recognition


    【解决方案1】:

    我相信您可以按如下方式将 BufferedImage 转换为 IplImage。

    public static IplImage toIplImage(BufferedImage src) {
      Java2DFrameConverter bimConverter = new Java2DFrameConverter();
      OpenCVFrameConverter.ToIplImage iplConverter = new OpenCVFrameConverter.ToIplImage();
      Frame frame = bimConverter.convert(src);
      IplImage img = iplConverter.convert(frame);
      IplImage result = img.clone();
      img.release();
      return result;
    }
    

    我是从this 问题中得到的。暂时试试这个。我会检查是否可以直接转换。

    更新: 请看看这个api docs。我没有测试以下内容。刚才写了。请尝试告诉我。

    public static IplImage toIplImage(Mat src) {
     OpenCVFrameConverter.ToIplImage iplConverter = new OpenCVFrameConverter.ToIplImage();
     OpenCVFrameConverter.ToMat  matConverter = new OpenCVFrameConverter.ToMat();
     Frame frame =  matConverter.convert(src);
     IplImage img = iplConverter.convert(frame);
     IplImage result = img.clone();
     img.release();
     return result;
    }
    

    【讨论】:

    • 感谢 rajind 的回复,看来可以了。但现在面临新问题:bytedeco IplImage 到 googlecode IplImage 和 bytedeco Mat 到 googlecode Mat 转换,你能建议我怎么做吗? (实际上有两个独立的模型,一个是在使用更新的 jar 的 bytedeco 中生成 IplImage,第二个模型在使用旧版本 jar 的 googlecode 中接受 IplImage)。希望您了解要达到的目标。
    • @Vicky 你为什么一开始就尝试使用两个不同的版本?
    • @Vicky,既然原始问题已得到回答,您能否考虑接受答案? :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-07
    • 2015-05-13
    • 1970-01-01
    相关资源
    最近更新 更多