Posts: 726
 
	
		
		
		05-06-2019, 10:00 PM 
(This post was last modified: 05-06-2019, 10:42 PM by win .) 
  
		
	 
	
		php code: 
 
PHP Code:
  =  'https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=xxxxxxx' ; $header  = [ 'Content-Length: multipart/form-data' ]; $file  =  '/data/image/a.png' ;  // Local image path $image  =  base64_encode ( file_get_contents ( $file )); $post  = [   'image'  =>  $image , $res  =  request_post ( $api ,  $post ,  $header );  
The garbled problem of unicode characters is still not solved   Can someone provide some methods? thanks 
	 
	
	
	
	
 
 
	
	
	
		
	Posts: 726
 
	
		
		
		05-06-2019, 11:03 PM 
(This post was last modified: 05-06-2019, 11:13 PM by win .) 
  
		
	 
	
		@redbull2k    @Kevin   Do not use ResponseText ResponseBody , there is no garbled  
Macro 
Macro8  typelib  WinHttp  {662901FC-6951-4854-9EB2-D9A2570F2B2E}  5.1 WinHttp. WinHttpRequest  r._create Open ( "POST"  F "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic" ) setRequestHeader ( "content-type" ,  "application/x-www-form-urlencoded" ) SetRequestHeader ( "cache-control"  ,  "no-cache" ) str  access=  "access_token=24.b305c9822131e65eda05e29c157dd719.2592000.1559103982.282335-16139329&image=" str  sFile.getfile ( "$desktop$\3.png" ) ;; change to file location encrypt ( 4  sFile ""  2 ) escape ( 9 ) Send ( F "{ access}{ _s}" ) ARRAY ( byte )  a= r.ResponseBody str  s.fromn ( & a[0 ] a.len ) out  sIXml  x= JsonToXml ( s) ARRAY ( IXmlNode )  a1;  x.Path ( "root/words_result/item/words"  a1 1 ) int  i;  for ( i 0  a1.len )  out  a1[i].Value 
 
	
	
	
	
 
 
	
	
	
		
	Posts: 229
 
	
	
		sometimes all it takes is a little longer patience and will you will find the answer.
	
	
	
	
	
 
 
	
	
	
		
	Posts: 1,344
 
	
		
		
		05-06-2019, 11:40 PM 
(This post was last modified: 05-06-2019, 11:41 PM by Kevin .) 
  
		
	 
	
		make code shorter no i don't think so, make it less lines yes .
for example
typelib  WinHttp  {662901FC-6951-4854-9EB2-D9A2570F2B2E}  5.1 ;  WinHttp. WinHttpRequest  r._create ;  r.Open ( "POST"  F "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic" );  r.setRequestHeader ( "content-type" ,  "application/x-www-form-urlencoded" );  r.SetRequestHeader ( "cache-control"  ,  "no-cache" ) str  access=  "access_token=24.b305c9822131e65eda05e29c157dd719.2592000.1559103982.282335-16139329&image=" str  sFile.getfile ( "$desktop$\3.png" ) ;; change to file location encrypt ( 4  sFile ""  2 );  _s.escape ( 9 );  r.Send ( F "{ access}{ _s}" ) ARRAY ( byte )  a= r.ResponseBody ;  str  s.fromn ( & a[0 ] a.len ) IXml  x= JsonToXml ( s);  ARRAY ( IXmlNode )  a1;  x.Path ( "root/words_result/item/words"  a1 1 ) int  i;  for ( i 0  a1.len )  out  a1[i].Value 
 could be even less lines but there really is no point. Code could be all in 1 line if you really wanted but like i said what's the point.
	
 
 
	
	
	
		
	Posts: 229
 
	
	
		and here is my crack at making it shorter
Function 
Function18  typelib  WinHttp  {662901FC-6951-4854-9EB2-D9A2570F2B2E}  5.1 WinHttp. WinHttpRequest  r._create Open ( "POST"  "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=24.b305c9822131e65eda05e29c157dd719.2592000.1559103982.282335-16139329" ) setRequestHeader ( "content-type" ,  "application/x-www-form-urlencoded" )  ; r.SetRequestHeader ( "language_type"  ,  "CHN_ENG" ) str  sFile.getfile ( "$desktop$\3.png" ) ;; change to file location str  base64.encrypt ( 4  sFile ""  2 )  ; base64.escape ( 9 ) Send ( F "&image={ base64}" )  ; ARRAY ( byte )  by=  r.ResponseBody str  json.fromn ( & by[0 ] by.len )  ; out  json
 
 
	
	
	
		
	Posts: 726
 
	
		
		
		05-07-2019, 12:07 AM 
(This post was last modified: 05-07-2019, 12:19 AM by win .) 
  
		
	 
	
		Wow!
I think, is the code shorter and it runs faster? 
Maybe what I think is wrong. 
I think using external components may make the code run longer.
I am experiencing a problem with VBS code outputWscript.Echo r.ResponseBody     All are garbledWscript.Echo r.ResponseText     Unicode characters are garbled 
 
 
 
 
	
	
	
		
	Posts: 1,344
 
	
	
		The code itself  is fast enough.  What varies is the server response  time. Which  you have no control  of. Code for me takes maybe 1 second or less to get a response.
	
	
	
	
	
 
 
	
	
	
		
	Posts: 229
 
	
	
		this so far has no error protection so when it errors it fails. the idea is to make it robust and catch potential errors
something like this
Function 
Function18  typelib  WinHttp  {662901FC-6951-4854-9EB2-D9A2570F2B2E}  5.1 WinHttp. WinHttpRequest  r._create Open ( "POST"  "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token=24.b305c9822131e65eda05e29c157dd719.2592000.1559103982.282335-16139329" ) setRequestHeader ( "content-type" ,  "application/x-www-form-urlencoded" )  ; r.SetRequestHeader ( "language_type"  ,  "CHN_ENG" ) str  sFile.getfile ( "$desktop$\100jhkjghjkg0.png" ) ;; change to file location err  goto  endofstr  base64.encrypt ( 4  sFile ""  2 )  ; base64.escape ( 9 ) Send ( F "&image={ base64}" )  err  goto  endofARRAY ( byte )  by=  r.ResponseBody out  r.Status sel  r.Status , case  200  ;;The request completed successfully. , str  json.fromn ( & by[0 ] by.len )  ; out  json, case  404  ;;The server has not found anything that matches the requested URI. , out  "error" , case  else  out  "Fail" ret ;endof out  _error.descriptionret 
 
 
	
	
	
		
	Posts: 726
 
 
	
	
	
		
	Posts: 1,344
 
	
	
		one tip use a jpg instead of a png the documentation recommends jpg over other types
	
	
	
	
	
 
 
	
	
	
		
	Posts: 726
 
	
		
		
		05-07-2019, 01:11 AM 
(This post was last modified: 05-07-2019, 01:12 AM by win .) 
  
		
	 
	
		I think the best is PNG, because JPG is sometimes very blurry, affecting the recognition effect, I sent a code (screenshot + text recognition) 
http://www.quickmacros.com/forum/showthr...4#pid33604 
	 
	
	
	
	
 
 
	
	
	
		
	Posts: 1,344
 
	
	
		from the api documentation
 
 
	
	
	
		
	Posts: 726
 
	
		
		
		05-07-2019, 03:00 AM 
(This post was last modified: 05-07-2019, 03:10 AM by win .) 
  
		
	 
	
		JPG ? Why not PNG?  For text, I think GIF is the best, small, and very clear. 
This is currently the most popular free OCR software in China, it integrates many OCR engines, it is open source 
https://github.com/AnyListen/tianruoocr 
	 
	
	
	
	
 
 
	
	
	
		
	Posts: 726
 
	
	
		@kevinIn VBS, using the following com object, the output will not be garbled, but I did not find it in QM's class library.MSXML2.ServerXMLHTTP ") ResponseText  
	
	
	
	
	
 
 
	
	
	
		
	Posts: 726
 
	
	
		How does QM create an MSXML2.ServerXMLHTTP object?    
	
	
	
	
 
 
	
	
	
		
	Posts: 229
 
	
		
		
		05-08-2019, 12:45 AM 
(This post was last modified: 05-08-2019, 12:49 AM by redbull2k .) 
  
		
	 
	
		you can find a lot of useful info in tools> com libraries
Function 
Function21  typelib  MSXML2  {F5078F18-C551-11D3-89B9-0000F81FE221}  3.0 MSXML2. ServerXMLHTTP  b._create 
 
 
	
	
	
		
	Posts: 726
 
	
	
		Thank you for your help, what method did you find for it?
	
	
	
	
	
 
 
	
	
	
		
	Posts: 229
 
	
	
		i Just found it for you. All typelib can be found in Tools>Com Libraries, once your there just find microsoft xml find the newest version which will be v6.0. double click it to isert it in current function/macro there are also controls that you can attach to dialog.
	
	
	
	
	
 
 
	
	
	
		
	Posts: 726
 
	
		
		
		05-08-2019, 01:01 AM 
(This post was last modified: 05-08-2019, 01:14 AM by win .) 
  
		
	 
	
		This is my new code, it is better understood 
Macro 
Macro8  typelib  MSXML2  {F5078F18-C551-11D3-89B9-0000F81FE221}  3.0 MSXML2. ServerXMLHTTP  r._create Open ( "POST"  F "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic" ) setRequestHeader ( "content-type" ,  "application/x-www-form-urlencoded" ) SetRequestHeader ( "cache-control"  ,  "no-cache" ) str  access=  "access_token=24.b305c9822131e65eda05e29c157dd719.2592000.1559103982.282335-16139329&image=" str  sFile.getfile ( "$desktop$\1.png" ) ;; change to file location encrypt ( 4  sFile ""  2 ) escape ( 9 ) Send ( F "{ access}{ _s}" ) IXml  x= JsonToXml ( r.ResponseText ) ARRAY ( IXmlNode )  aPath ( "root/words_result/item/words"  a 1 ) str  dfor ( int ' i 0  a.len ) , d.addline ( a[i].Value ) mes  d.trim 
Thank you for your help, I just learned that it is an xml component.  
@Kevin
I feel using the current components(MSXML2.ServerXMLHTTP), the response is faster  
Attached Files Image(s)  
	
	
	
 
 
	
	
	
		
	Posts: 229
 
	
	
		test for yourself
Function 
Function21  long  t1= perf typelib  MSXML2  {F5078F18-C551-11D3-89B9-0000F81FE221}  3.0 MSXML2. ServerXMLHTTP  r._create Open ( "POST"  F "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic" ) setRequestHeader ( "content-type" ,  "application/x-www-form-urlencoded" ) SetRequestHeader ( "cache-control"  ,  "no-cache" ) str  access=  "access_token=24.b305c9822131e65eda05e29c157dd719.2592000.1559103982.282335-16139329&image=" str  sFile.getfile ( "$desktop$\2.png" ) ;; change to file location encrypt ( 4  sFile ""  2 ) escape ( 9 ) Send ( F "{ access}{ _s}" ) long  t2= perf  ;;get time after out  t2- t1 ;;display the difference IXml  x= JsonToXml ( r.ResponseText ) ARRAY ( IXmlNode )  aPath ( "root/words_result/item/words"  a 1 ) str  dfor ( int ' i 0  a.len ) , d.addline ( a[i].Value ) mes  d.trim 
 
 
	
	
	
		
	Posts: 726
 
	
		
		
		05-08-2019, 01:42 AM 
(This post was last modified: 05-08-2019, 01:47 AM by win .) 
  
		
	 
	
		127648
 
 
	
	
	
		
	Posts: 229
 
	
	
		that value is in milliseconds its just like a stopwatch,we tell it to start we tell it to end. its just telling you the result from start to finish.
	
	
	
	
 
 
	
	
	
		
	Posts: 726
 
	
	
		indeed so  
 
 
	
	
	
		
	Posts: 726
 
	
	
		It can also be implemented using powershell code, see the link below
http://www.quickmacros.com/forum/showthr...1#pid33661