Skip to content

Commit

Permalink
Image dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
OrKoN committed Mar 10, 2017
1 parent 807e405 commit 7cef2c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 6 additions & 1 deletion darknet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ImageDetectionWorker : public AsyncWorker {
// so it is safe to use V8 again
void HandleOKCallback () {
HandleScope scope;
const int argc = 3;
const int argc = 4;
v8::Local<v8::Array> results = Nan::New<v8::Array>();
for(int i = 0; i < output->numberOfResults; i++) {
RecognitionResult result = output->recognitionResults[i];
Expand All @@ -87,10 +87,15 @@ class ImageDetectionWorker : public AsyncWorker {
i++;
}

v8::Local<v8::Object> dimensions = Nan::New<v8::Object>();
dimensions->Set(Nan::New("width").ToLocalChecked(), Nan::New<v8::Number>(output->frameWidth));
dimensions->Set(Nan::New("height").ToLocalChecked(), Nan::New<v8::Number>(output->frameHeight));

v8::Local<v8::Value> argv[argc] = {
Nan::NewBuffer(output->modifiedFrame, output->modifiedFrameSize).ToLocalChecked(),
Nan::NewBuffer(output->originalFrame, output->originalFrameSize).ToLocalChecked(),
results,
dimensions
};

callback->Call(argc, argv);
Expand Down
3 changes: 3 additions & 0 deletions src/demo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ WorkerData* start_image_demo(InputOptions opts) {
progressState->numberOfResults = current_results.size();
progressState->recognitionResults = new RecognitionResult[progressState->numberOfResults];

progressState->frameWidth = original.w;
progressState->frameHeight = original.h;

int i = 0;
for(auto const& result: current_results) {
progressState->recognitionResults[i] = result;
Expand Down
4 changes: 2 additions & 2 deletions test/darknetImageTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ darknet.detectImage({
weights: './yolo.weights',
data: './cfg/coco.data',
image: './data/dog.jpg',
}, function(modified, original, detections) {
console.log(modified.length, original.length, detections);
}, function(modified, original, detections, dimensions) {
console.log(modified.length, original.length, detections, dimensions);
fs.writeFileSync('./data.modified.raw', modified);
// ffmpeg -f rawvideo -s 768x576 -pix_fmt bgr24 -i data.raw data.jpg
fs.writeFileSync('./data.raw', original);
Expand Down

0 comments on commit 7cef2c5

Please sign in to comment.