-
Notifications
You must be signed in to change notification settings - Fork 0
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
45 additions
and
127 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,33 +1,33 @@ | ||
import os | ||
import select | ||
import sys | ||
import json | ||
import asyncio | ||
from datamatrixRecognizer import DatamatrixRecognizer | ||
import warnings | ||
|
||
warnings.filterwarnings("ignore", category=DeprecationWarning) | ||
|
||
async def main(): | ||
paths = sys.argv[1] | ||
|
||
def read_stdin(): | ||
if os.name == 'nt': | ||
j_doc = json.load(sys.stdin) | ||
return json.load(sys.stdin) | ||
else: | ||
if select.select([sys.stdin], [], [], 0.0)[0]: | ||
j_doc = json.load(sys.stdin) | ||
else: | ||
raise Exception('Pipe is empty.') | ||
|
||
recognizer = DatamatrixRecognizer() | ||
return json.loads(sys.stdin.read()) | ||
|
||
tasks = [recognizer.magick(path, j_doc) for path in paths.split(",")] | ||
|
||
result = {"files": await asyncio.gather(*tasks)} | ||
def sync_main(): | ||
paths = sys.argv[1] | ||
j_doc = read_stdin() | ||
|
||
return result | ||
recognizer = DatamatrixRecognizer() | ||
results = [] | ||
for path in paths.split(","): | ||
result = recognizer.magick(path, j_doc) | ||
results.append(result) | ||
|
||
return {"files": results} | ||
|
||
loop = asyncio.get_event_loop() | ||
results = loop.run_until_complete(main()) | ||
loop.close() | ||
|
||
results = sync_main() | ||
print(json.dumps({"results": results})) | ||
|
||
warnings.resetwarnings() |
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 |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import asyncio | ||
import json | ||
import warnings | ||
|
||
from datamatrixRecognizer import DatamatrixRecognizer | ||
warnings.filterwarnings("ignore", category=DeprecationWarning) | ||
|
||
|
||
async def main(pdf_path, params): | ||
@asyncio.coroutine | ||
def main(pdf_path, params): | ||
recognizer = DatamatrixRecognizer() | ||
return recognizer.magick(pdf_path, params) | ||
|
||
return await recognizer.magick(pdf_path, params) | ||
|
||
|
||
results = asyncio.run(main("images/23.jpg", { | ||
loop = asyncio.get_event_loop() | ||
results = loop.run_until_complete(main("images/23.jpg", { | ||
"type": "IDENTICAL", | ||
"segment": {"x": 1, "y": 6} | ||
})) | ||
|
||
print(json.dumps({"results": results})) | ||
|
||
warnings.resetwarnings() |