【问题标题】:Error: Could not find MIME for Buffer <null> while using Jimp to save the buffer of cv.Mat()错误:使用 Jimp 保存 cv.Mat() 的缓冲区时找不到缓冲区 <null> 的 MIME
【发布时间】:2021-06-11 03:29:36
【问题描述】:

这是产生错误的代码的 sn-p:

let mat = cv.Mat.zeros(cnn_size, cnn_size, 3);
savepath = "path/to/saved/image.jpg"
let bf = Buffer.from(mat.data);
Jimp.read(bf).then(data => {
    console.log(data);
    return data.resize(cnn_size, cnn_size).write(savepath);
}).catch(err => {
    console.error(err);
});

运行代码导致了这个错误:(node:2152) UnhandledPromiseRejectionWarning: E​​rror: Could not find MIME for Buffer &lt;null&gt;

【问题讨论】:

    标签: javascript opencv jimp


    【解决方案1】:

    我正在从事的一个项目也遇到了同样的问题。 axios 和 jimp.read 的组合对我有用。

    axios({
    method: 'get',
    url: failingImageUrl,
    responseType: 'arraybuffer'
    })
    .then(function ({data: imageBuffer}) {
     return jimp.read(imageBuffer)
    })
    

    来源https://github.com/oliver-moran/jimp/issues/775#issuecomment-521938738

    【讨论】:

    • 感谢@gbengaoyetade 这对我有用
    猜你喜欢
    • 2020-08-29
    • 2017-05-12
    • 2018-01-14
    • 1970-01-01
    • 2011-03-12
    • 1970-01-01
    • 2019-11-26
    • 1970-01-01
    • 2016-07-17
    相关资源
    最近更新 更多