Showing
1 changed file
with
18 additions
and
9 deletions
| ... | @@ -5,7 +5,7 @@ var request = require('request'); | ... | @@ -5,7 +5,7 @@ var request = require('request'); |
| 5 | var https=require('https'); | 5 | var https=require('https'); |
| 6 | var http=require('http'); | 6 | var http=require('http'); |
| 7 | var mime=require('mime-types'); | 7 | var mime=require('mime-types'); |
| 8 | - | 8 | +var png=require('png-js'); |
| 9 | var fs = require("fs"); | 9 | var fs = require("fs"); |
| 10 | 10 | ||
| 11 | var httpsOptions = { | 11 | var httpsOptions = { |
| ... | @@ -89,7 +89,17 @@ async function handleEvent(event) { | ... | @@ -89,7 +89,17 @@ async function handleEvent(event) { |
| 89 | await stream.on('data', (chunk) => { | 89 | await stream.on('data', (chunk) => { |
| 90 | console.log(typeof(chunk)); | 90 | console.log(typeof(chunk)); |
| 91 | fs.writeFileSync("./photo/1.png",chunk); | 91 | fs.writeFileSync("./photo/1.png",chunk); |
| 92 | - var cheerio = require('cheerio'); | 92 | + |
| 93 | + var PNG = require('png-js'); | ||
| 94 | + | ||
| 95 | +var myimage = new PNG("./photo/1.png"); | ||
| 96 | + | ||
| 97 | +var width = myimage.width; | ||
| 98 | +var height = myimage.height; | ||
| 99 | + | ||
| 100 | +myimage.decode(function (pixels) { | ||
| 101 | + //Pixels is a 1D array containing pixel data | ||
| 102 | + var cheerio = require('cheerio'); | ||
| 93 | var uriBase = 'https://koreacentral.api.cognitive.microsoft.com/vision/v2.1/ocr'; | 103 | var uriBase = 'https://koreacentral.api.cognitive.microsoft.com/vision/v2.1/ocr'; |
| 94 | var options = { | 104 | var options = { |
| 95 | uri: uriBase, | 105 | uri: uriBase, |
| ... | @@ -101,14 +111,11 @@ async function handleEvent(event) { | ... | @@ -101,14 +111,11 @@ async function handleEvent(event) { |
| 101 | 'Content-Type': 'application/json', | 111 | 'Content-Type': 'application/json', |
| 102 | 'Ocp-Apim-Subscription-Key': '979dc5d63344438fa4701c62feebb7dc' | 112 | 'Ocp-Apim-Subscription-Key': '979dc5d63344438fa4701c62feebb7dc' |
| 103 | }, | 113 | }, |
| 104 | - body: fs.readFileSync("./photo/1.png") | 114 | + body: myimage |
| 105 | }; | 115 | }; |
| 106 | - app.get('/photo',(req,res)=>{ | 116 | + |
| 107 | - res.send(chunk+"png"); | ||
| 108 | - }) | ||
| 109 | - /* | ||
| 110 | request.post(options, function (error, response, body) { | 117 | request.post(options, function (error, response, body) { |
| 111 | - var data=body; | 118 | + var data=options.body; |
| 112 | console.log(data); | 119 | console.log(data); |
| 113 | var text=''; | 120 | var text=''; |
| 114 | while(data.indexOf('text\\')!=-1) | 121 | while(data.indexOf('text\\')!=-1) |
| ... | @@ -140,8 +147,10 @@ async function handleEvent(event) { | ... | @@ -140,8 +147,10 @@ async function handleEvent(event) { |
| 140 | } | 147 | } |
| 141 | client.replyMessage(event.replyToken,result).then(resolve).catch(reject); | 148 | client.replyMessage(event.replyToken,result).then(resolve).catch(reject); |
| 142 | }); | 149 | }); |
| 143 | - });*/ | 150 | + }); |
| 144 | 151 | ||
| 152 | +}); | ||
| 153 | + | ||
| 145 | 154 | ||
| 146 | 155 | ||
| 147 | 156 | ... | ... |
-
Please register or login to post a comment