Ask Your Question
0

reading data uri with opencv.js

asked 2019-07-10 00:32:55 -0600

MaggPI gravatar image

HI , I would like to import an image data uri into opencv.js. Is there a factory function such as cv.imread to do this?

If not, are there any examples javascript routines that can sort the data uri into cv.matFromImageData?

Thank You

edit retag flag offensive close merge delete

Comments

can you show us, what you have, so far ? what are you trying to achieve ? what's the "context" ?

berak gravatar imageberak ( 2019-07-10 01:58:31 -0600 )edit

no js expert, but imho, you should load your image into a canvas, and use cv.matFromImageData from that.

(in the same way, imread() does it, just look at helper.js / utils.js)

berak gravatar imageberak ( 2019-07-10 03:17:52 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-07-12 17:51:13 -0600

MaggPI gravatar image

Berak , thx for your note, I found a great site that explains datauri conversion options with opencv.js https://github.com/justadudewhohacks/...

// load base64 encoded image const base64text='data:image/png;base64,R0lGO..';//Base64 encoded string const base64data =base64text.replace('data:image/jpeg;base64','') .replace('data:image/png;base64','');//Strip image type prefix const buffer = Buffer.from(base64data,'base64'); const image = cv.imdecode(buffer); //Image is now represented as Mat

// convert Mat to base64 encoded jpg image const outBase64 = cv.imencode('.jpg', croppedImage).toString('base64'); // Perform base64 encoding const htmlImg=''; //Create insert into HTML compatible tag

edit flag offensive delete link more

Comments

^^ none of it supported from opencv.

berak gravatar imageberak ( 2019-07-13 03:16:36 -0600 )edit

Hi cv.imencode is undefined. Do you know why?

wwwwwwwwwwww gravatar imagewwwwwwwwwwww ( 2020-10-20 12:45:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-07-10 00:32:55 -0600

Seen: 3,233 times

Last updated: Jul 12 '19