ID Card Agent
The ID Card Agent is smart AI-powered solution that extracts important key-value information from an image. The agent is also capable of computing bounding box coordinates for important information like Photo of the cardholder, signature of the cardholder etc. Currently a single version of the agent is available. More Agent Versions coming soon.
1. Agents Input Dictionary
Firstly an Agents-input Dictionary has to be defined. For a ID card agent, the agent input dictionary is of the format :
inputs_dict = {
"base64_image" : img_processed,
}
2. Agent's Process Functionality
After setting an inputs dictionary, Set up the agent name and process the query.
agent_name = latentforce/id_card_agent
res = agent.process(agent_name = agent_name, agent_inputs = inputs_dict)
print(res)
Note
Only one id_card_agent is available currently. More agent versions coming soon.
3. Plotting Bounding Boxes
To plot an extracted bounding box on the image :
from PIL import Image
from matplotlib import pyplot as plt
def plot_bbox_check(image, data):
# Create a figure and axes
fig, ax = plt.subplots()
# Display the image
ax.imshow(image)
cropped_regions = []
# Plot each bounding box
for label, bbox in data.items():
# Unpack the bounding box coordinates
x1, y1, x2, y2 = bbox
# Create a Rectangle patch
rect = patches.Rectangle(
(x1, y1),
x2 - x1,
y2 - y1,
linewidth = 1,
edgecolor = 'r',
facecolor = 'none'
)
# Add the rectangle to the Axes
ax.add_patch(rect)
# Annotate the label
plt.text(
x1,
y1,
label,
color = 'white',
fontsize = 8,
bbox = dict(facecolor = 'red', alpha = 0.5)
)
cropped_region = image.crop((x1, y1, x2, y2))
cropped_regions.append(cropped_region)
# Remove the axis ticks and labels
ax.axis('off')
# Show the plot
plt.show()
return cropped_regions
image = Image.open(image_path)
plot_bbox_check(image, res['results']['bbox'])