-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"axios": "*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const util = require('util'); | ||
const fs = require('fs/promises'); | ||
const exec = util.promisify(require('child_process').exec); | ||
const axios = require('axios'); | ||
|
||
(async () => { | ||
// capture frame | ||
// await exec( | ||
// 'ffmpeg -y -f video4linux2 -s 1280x720 ' + | ||
// '-i /dev/video1 -frames 1 code.jpg' | ||
// ); | ||
|
||
// convert to base 64 | ||
const image = await fs.readFile('code.jpg'); | ||
const base64 = image.toString('base64'); | ||
|
||
const url = | ||
`https://vision.googleapis.com/v1/images:annotate` + | ||
`?key=${process.env.gkey}`; | ||
|
||
// send to vision api | ||
const results = await axios | ||
.post(url, { | ||
requests: [{ | ||
image: { | ||
content: base64 | ||
}, | ||
features: [{ | ||
type: 'DOCUMENT_TEXT_DETECTION' | ||
}] | ||
}] | ||
}); | ||
|
||
const code = results.data.responses[0].fullTextAnnotation.text; | ||
|
||
console.log(code); | ||
//eval(code); | ||
})(); |