Sending Batch request to azure cognitive API for TEXT-OCR
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 15/100
Research direction
Start by reviewing the Azure Cognitive API endpoint used in recognise_text, especially the recognizeText request and its Operation-Location polling flow. The issue does not name a repository file or test, and completion is undefined because it asks whether multiple images can be submitted in one request.
Written by the indexing model from the issue text.
Description
I am calling azure cognitive API for OCR text-recognization and I am passing 10-images at the same time simultaneously (as the code below only accepts one image at a time-- that is 10-independent requests in parallel) which is not efficient to me, from processing point of view, as I need to use extra modules i.e: Celery and multiprocessing.
So, is there a way to send all the 10-images in a single request and get the output at once then do post processing?
import time
from io import BytesIO
import cv2
import requests
from PIL import Image as PILImage
from PIL import Image
file_list = []
headers = {
"Ocp-Apim-Subscription-Key": "<API-KEY>",
'Content-Type': 'application/octet-stream'}
p = "symbol_sample.jpg"
print(p,"p")
def recognise_text(p):
p = cv2.imread(p)
cropped_image = PILImage.fromarray(p)
buffer = BytesIO()
cropped_image.save(buffer, format="JPEG")
image_bytes = buffer.getvalue()
try:
response = requests.post(
"https://centralindia.api.cognitive.microsoft.com/vision/v2.0/recognizeText?mode=Printed",
headers=headers,
data=image_bytes
)
header_link = str(response.headers['Operation-Location'])
while (True):
headers_get = {
"Ocp-Apim-Subscription-Key": "<API-KEY>"",
'Content-Type': 'application/json'
}
result = requests.get(
url=header_link,
headers=headers_get
)
response_r = result.json()
if response_r["status"] == "Succeeded":
return response_r
else:
time.sleep(4)
except Exception as e:
print(e)
return ""
image1="symbol_sample.jpg"
o = recognise_text(image1)
print(o)
Any help would be really appreciated.
- Dominant language
- HTML
- Stars
- 241
- Forks
- 279
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Azure-Samples/cognitive-services-REST-api-samples
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
Azure-Samples/cognitive-services-REST-api-samples#139 · 5 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 15/100
-
Difficulty 1/5 Under an hour Newbie friendliness 45/100
Azure-Samples/cognitive-services-REST-api-samples#172 · 1 reaction ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
Azure-Samples/cognitive-services-REST-api-samples#138 · 1 comment ·
All issues in Azure-Samples/cognitive-services-REST-api-samples
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area/profiles comp/cli comp/dashboard P2 sweeper:risk-session-state type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
NousResearch/hermes-agent#122365 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vllm-project/production-stack#1105 ·
-
bug priority:low
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
CyberAgent/psd2svg#430 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100