Skip to content

Commit 8b4218c

Browse files
nnegreyJustinBeckwith
authored andcommitted
docs: improve detect.js samples (#300)
docs: improve detect.js samples
1 parent 7baa84f commit 8b4218c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

vision/samples/detect.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ async function detectFulltextGCS(bucketName, fileName) {
635635
// [END vision_fulltext_detection_gcs]
636636
}
637637

638-
async function detectPdfText(bucketName, fileName) {
638+
async function detectPdfText(bucketName, fileName, outputPrefix) {
639639
// [START vision_text_detection_pdf_gcs]
640640

641641
// Imports the Google Cloud client libraries
@@ -651,9 +651,11 @@ async function detectPdfText(bucketName, fileName) {
651651
// const bucketName = 'my-bucket';
652652
// Path to PDF file within bucket
653653
// const fileName = 'path/to/document.pdf';
654+
// The folder to store the results
655+
// const outputPrefix = 'results'
654656

655657
const gcsSourceUri = `gs://${bucketName}/${fileName}`;
656-
const gcsDestinationUri = `gs://${bucketName}/${fileName}.json`;
658+
const gcsDestinationUri = `gs://${bucketName}/${outputPrefix}/`;
657659

658660
const inputConfig = {
659661
// Supported mime_types are: 'application/pdf' and 'image/tiff'
@@ -870,10 +872,10 @@ require(`yargs`) // eslint-disable-line
870872
opts => detectFulltextGCS(opts.bucketName, opts.fileName)
871873
)
872874
.command(
873-
`pdf <bucketName> <fileName>`,
875+
`pdf <bucketName> <fileName> <outputPrefix>`,
874876
`Extracts full text from a pdf file`,
875877
{},
876-
opts => detectPdfText(opts.bucketName, opts.fileName)
878+
opts => detectPdfText(opts.bucketName, opts.fileName, opts.outputPrefix)
877879
)
878880
.command(
879881
`localize-objects <fileName>`,
@@ -909,7 +911,7 @@ require(`yargs`) // eslint-disable-line
909911
.example(`node $0 web-geo-gcs my-bucket your-image.jpg`)
910912
.example(`node $0 fulltext ./resources/wakeupcat.jpg`)
911913
.example(`node $0 fulltext-gcs my-bucket your-image.jpg`)
912-
.example(`node $0 pdf my-bucket my-pdf.pdf`)
914+
.example(`node $0 pdf my-bucket my-pdf.pdf results`)
913915
.example(`node $0 localize-objects ./resources/duck_and_truck.jpg`)
914916
.example(`node $0 localize-objects-gcs gs://bucket/bucketImage.png`)
915917
.wrap(120)

vision/samples/system-test/detect.test.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const client = new vision.ImageAnnotatorClient();
2727

2828
const storage = new Storage();
2929
const bucketName = `nodejs-docs-samples-test-${uuid.v4()}`;
30+
const prefix = 'results';
3031
const cmd = `node detect.js`;
3132
const files = [
3233
`face_no_surprise.jpg`,
@@ -250,8 +251,10 @@ describe(`detect`, () => {
250251
});
251252

252253
it(`should extract text from pdf file`, async () => {
253-
const output = await exec(`${cmd} pdf ${bucketName} ${files[7].name}`);
254-
assert.match(output, /pdf-ocr.pdf.json/);
254+
const output = await exec(
255+
`${cmd} pdf ${bucketName} ${files[7].name} ${prefix}`
256+
);
257+
assert.match(output, /results/);
255258
});
256259

257260
it(`should detect objects in a local file`, async () => {

0 commit comments

Comments
 (0)