0

I am getting this error trying to convert an image into a CvMat:

Error: Imencode - expected arg 0 to be a Buffer of Uint8 Values

This seems easy enough to fix, although I don't know how to convert an image into a Uint8Array, which is what the function is asking for. Here's my code so far:

request(url, function (error, response, body) {
    let uint8Array = new Uint8Array(body);
    let imageCvMat = cv.imdecode(uintArray)
})

2 Answers 2

1

I think you are opencv4nodejs for implementing your solution. I would like to direct your attention to a few aspects.

You can check it out here that imdecode & imencode accept buffers as input opencv4nodejs imdecode

So basically the issue that I have faced as well is that you are not converting your image into Mat using imdecode in first place. Kindly check the input you are providing & try fixing it.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah that’s my question - how do I convert it to the necessary input?
1

My original goal was to be able to pass an image from a URL into cv.imdecode(). Turns out the way to do this is with a Buffer, and this works like a charm:

request(url, function (error, response, body) {
    let buffer = Buffer.from(body);
    let imageCvMat = cv.imdecode(buffer);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.