Skip to content

Commit fd72345

Browse files
committed
Added information about base64 import/export
1 parent 38f395f commit fd72345

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,17 @@ cv.imwriteAsync('./path/img.jpg', mat,(err) => {
252252
cv.imshow('a window name', mat);
253253
cv.waitKey();
254254

255+
// load base64 encoded image
256+
const base64text='data:image/gif;base64,R0lGO..';//Base64 encoded string
257+
const base64data =base64text.replace('data:image/jpeg;base64','')
258+
.replace('data:image/png;base64','');//Strip image type prefix
259+
const buffer = Buffer.from(base64data,'base64');
260+
const image = cv.imdecode(buffer); //Image is now represented as Mat
261+
262+
// convert Mat to base4 encoded jpg image
263+
const outBase64 = cv.imencode('.jpg', croppedImage).toString('base64'); // Perform base64 encoding
264+
const htmlImg='<img src='data:image/jpeg;base64,"+outBase64 + "'>'; //Create insert into HTML compatible <img> tag
265+
255266
// open capture from webcam
256267
const devicePort = 0;
257268
const wCap = new cv.VideoCapture(devicePort);

0 commit comments

Comments
 (0)