Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.

Conversation

telpirion
Copy link
Contributor

These code samples add the following region tags:

  • video_detect_person_beta
  • video_detect_person_gcs_beta
  • video_detect_faces_beta
  • video_detect_faces_gcs_beta

These code samples will be the canonicals.

@telpirion telpirion requested a review from bcoe February 6, 2020 05:31
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Feb 6, 2020
@codecov
Copy link

codecov bot commented Feb 6, 2020

Codecov Report

Merging #362 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #362   +/-   ##
=======================================
  Coverage   25.65%   25.65%           
=======================================
  Files          38       38           
  Lines        9135     9135           
=======================================
  Hits         2344     2344           
  Misses       6791     6791

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c96b179...2dbd81c. Read the comment docs.

Copy link

@bcoe bcoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is looking reasonable to me, a few stylistic nits.

// const path = 'Local file to analyze, e.g. ./my-file.mp4';

// Reads a local video file and converts it to base64
const file = await util.promisify(fs.readFile)(path);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're blocking any ways, I might be tempted to use fs.readFileSync, avoid the promisify step.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

const personAnnotations =
results[0].annotationResults[0].personDetectionAnnotations;

personAnnotations.forEach(personAnnotation => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid the forEach, and an extra layer of callbacks, you could do this:

for (const {segment, timestampedObjects} of tracks) {
  console.info(segment, timestampedObjects);
}

I've been tending to use this syntax rather than forEach these days, it's also nice because you can break out of the loop with break.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, here and elsewhere.

Thank you for showing me this syntax!

@telpirion
Copy link
Contributor Author

Thank you for the review!

@telpirion telpirion merged commit cff2f36 into master Feb 7, 2020
@telpirion telpirion deleted the face-person-samples branch February 7, 2020 23:47
Copy link
Contributor

@nnegrey nnegrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Region tag fixes

'use strict';

async function detectPerson(path) {
//[START video_detect_person_beta]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// [START

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// [END video_detect_person_beta]
}
async function detectPersonGCS(gcsUri) {
//[START video_detect_person_gcs_beta]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add space // [START

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
}
// [END video_detect_person_beta]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

video_detect_person_gcs_beta

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged.

It's already fixed :).

console.log(`\tAttribute: ${name}; `);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// [END video_detect_faces_beta]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console.log(`\tAttribute: ${name}; `);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// [END video_detect_faces_gcs_beta

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nnegrey
Copy link
Contributor

nnegrey commented Feb 12, 2020

Couple style things:

  1. Each sample should have its own file
  2. async needs to be inside the region tag:
    example: https://github.com/googleapis/nodejs-automl/blob/master/samples/delete_model.js

const results = await operation.promise();
console.log('Waiting for operation to complete...');

// Gets annotations for video
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a note that we get the first result because only 1 video is processed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

videoContext: {
personDetectionConfig: {
// Must set includeBoundingBoxes to true to get poses and attributes.
includeBoundingBoxes: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't use the bounding boxes in the output, is it worth addding?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bounding boxes are necessary to get the person and face detection segments but don't need to be read.

Reading bounding boxes is a pretty common task for the Video Intelligence API. On one hand, developers should be familiar with it already and this sample is really more about the attributes. On the other hand, it is a common task for using the API and maybe a good thing to include anyway.

I don't have a strong feeling one way or the other about bounding boxes, besides that adding them makes this sample longer. What is your preference?

Comment on lines +58 to +69
if (segment.startTimeOffset.seconds === undefined) {
segment.startTimeOffset.seconds = 0;
}
if (segment.startTimeOffset.nanos === undefined) {
segment.startTimeOffset.nanos = 0;
}
if (segment.endTimeOffset.seconds === undefined) {
segment.endTimeOffset.seconds = 0;
}
if (segment.endTimeOffset.nanos === undefined) {
segment.endTimeOffset.nanos = 0;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@telpirion, does this ever happen?
If so, that seems like an issue we need to raise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can happen, yes. Sometimes the result from the API simply doesn't return a value and thus the property is undefined.

TBH, I'm following the pattern demonstrated here (among other places):
https://github.com/googleapis/nodejs-video-intelligence/blob/master/samples/analyze.v1p2beta1.js#L42-L61

@telpirion
Copy link
Contributor Author

Thank you for the review!

A couple follow-up questions:

Couple style things:

  1. Each sample should have its own file

The existing beta samples use just "analyze.v1p2beta1.js.". The file includes multiple samples (and it's what I used as an example).

Does that need to be refactored?

gcf-merge-on-green bot pushed a commit that referenced this pull request Feb 14, 2020
🤖 I have created a release \*beep\* \*boop\* 
---
## [2.7.0](https://www.github.com/googleapis/nodejs-video-intelligence/compare/v2.6.5...v2.7.0) (2020-02-13)


### Features

* face and person detection samples ([#362](https://www.github.com/googleapis/nodejs-video-intelligence/issues/362)) ([cff2f36](https://www.github.com/googleapis/nodejs-video-intelligence/commit/cff2f36a4e6294908a4e26587ed840c1ec1b03f8))


### Bug Fixes

* adds spaces to region tags, other fixes ([#369](https://www.github.com/googleapis/nodejs-video-intelligence/issues/369)) ([2b6943e](https://www.github.com/googleapis/nodejs-video-intelligence/commit/2b6943ee0685761a0076c7b8023eed4f12f93d64))
* fixes face and people detection region tags ([#367](https://www.github.com/googleapis/nodejs-video-intelligence/issues/367)) ([ab039b5](https://www.github.com/googleapis/nodejs-video-intelligence/commit/ab039b56b3bea27edf93c4db7c97241599d38419))
* refactors person and face detection samples into separate files ([#370](https://www.github.com/googleapis/nodejs-video-intelligence/issues/370)) ([eb9b400](https://www.github.com/googleapis/nodejs-video-intelligence/commit/eb9b400c24bdf306d8263ec402922b3235754034))
* updates README file with correct links ([#371](https://www.github.com/googleapis/nodejs-video-intelligence/issues/371)) ([fb2701a](https://www.github.com/googleapis/nodejs-video-intelligence/commit/fb2701a81c7476ef06ab279a8d4572f006abe831))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants