-
Notifications
You must be signed in to change notification settings - Fork 27
how to generate IBufferImage in pure javascript ? #15
Comments
For some detail information , my data flow is like this: This chain was broken when I pass base64 data to daknent, I use new Buffer.form(base64imgData, 'base64') to generate a new Buffer and sent it to daknent, but the result is an empty array. |
Hi @liuxinqiang! You can get pixel data for a base64 url using the const fs = require('fs');
const { Darknet } = require('../darknet');
const { PNG } = require('pngjs');
const darknet = new Darknet({
weights: 'yolov3-tiny.weights',
config: 'yolov3-tiny.cfg',
namefile: 'coco.names'
});
// Include your method of creating a buffer from base64 here
const dataURL = fs.readFileSync('./dog-base64-dataURL.txt', { encoding: 'utf8' });
const dataString = dataURL.replace(/^data:image\/(png|jpg);base64,/, "")
const buffer = Buffer.from(dataString, 'base64');
// Read the PNG in the buffer. Get the width, height and pixel data.
const png = PNG.sync.read(buffer);
// Run the original detection
console.log("Dog:", darknet.detect('./dog.jpg'));
// Run the new detection
console.log("Dog base64:", darknet.detect({
w: png.width,
h: png.height,
c: 4,
b: png.data
})); Let me know if this helps! |
Feel free to "@" me on this issue if you need help, but I'm going to close it now. |
@bennetthardwick
but i get
|
here is a more complete example:
|
Hey @celevra, thanks for finding that bug! It's now been fixed in |
As in your readme, there is an example like this:
Now, I want to detect a single image ,but for some reason , I don't have opencv4nodejs installed, I just want to pass a IBufferImage to Darknet, the question is, how can I generate IBufferImage in pure javascript ?
The text was updated successfully, but these errors were encountered: