I have a json file where I have extracted data of some entities including lineitem. And…
- User
I have a json file where I have extracted data of some entities including line_item. And I have a Image(Invoice) and OCR textract output in csv format containing these columns (page_num,block_num,line_num,word_num,left,right,top,bottom,width,height,conf,text,image_height,image_width) . Now I want to map all the line item on image from json using ocr output. And create bounding box for each line_items and Print those bounding box on image. A sample json output : { "invoice_details": { "invoice_number": "2268", "invoice_date": "10-Dec-2020", "invoice_due_date": "None", "order_id": "None", "vendor_name": "", "buyer_name": "", "shipto_name": "None" }, "Payment Details": { "vendor_ifsccode": "", "vendor_bankname": "", "account_number": "" }, "address_details": { "vendor_address": "", "billto_address": "", "shipto_address": "" }, "amounts_and_tax": { "Subtotal_or_taxable_amount": "", "total_sgst_amount": "", "total_cgst_amount": "", "total_igst_amount": "None", "total_amount_after_tax": "", "billto_GSTIN": "", "vendor_GSTIN": "", "shipto_GSTIN": "None" }, "line_items": [ { "hsn_code": "8443", "description": "Hp 1606 Pressure Roller", "unit_of_measurement_or_uom": "NOS", "unit_price": "750.00", "quantity": "3", "sgst_rate": "None", "sgst_amount": "None", "cgst_rate": "None", "cgst_amount": "None", "igst_rate": "None", "igst_amount": "None", "taxable_amount_or_subtotal": "2250.00", "total_amount_or_gross_amount_of_the_item": "None" }, { "hsn_code": "8443", "description": "Teflon 1010 (OG)", "unit_of_measurement_or_uom": "NOS", "unit_price": "800.00", "quantity": "3", "sgst_rate": "None", "sgst_amount": "None", "cgst_rate": "None", "cgst_amount": "None", "igst_rate": "None", "igst_amount": "None", "taxable_amount_or_subtotal": "2400.00", "total_amount_or_gross_amount_of_the_item": "None" }, { "hsn_code": "84439959", "description": "Pick Up Roll 1606", "unit_of_measurement_or_uom": "NOS", "unit_price": "250.00", "quantity": "3", "sgst_rate": "None", "sgst_amount": "None", "cgst_rate": "None", "cgst_amount": "None", "igst_rate": "None", "igst_amount": "None", "taxable_amount_or_subtotal": "750.00", "total_amount_or_gross_amount_of_the_item": "None" }, { "hsn_code": "8443", "description": "Hp 1606 Lower Bush", "unit_of_measurement_or_uom": "NOS", "unit_price": "250.00", "quantity": "2", "sgst_rate": "None", "sgst_amount": "None", "cgst_rate": "None", "cgst_amount": "None", "igst_rate": "None", "igst_amount": "None", "taxable_amount_or_subtotal": "500.00", "total_amount_or_gross_amount_of_the_item": "None" }, { "hsn_code": "8443", "description": "1505 /1606 Fuser Drive Gear", "unit_of_measurement_or_uom": "NOS", "unit_price": "250.00", "quantity": "1", "sgst_rate": "None", "sgst_amount": "None", "cgst_rate": "None", "cgst_amount": "None", "igst_rate": "None", "igst_amount": "None", "taxable_amount_or_subtotal": "250.00", "total_amount_or_gross_amount_of_the_item": "None" } ], "table_column_names_in_reading_order": "Sl No.,Description of Goods,HSN/SAC,Quantity,Rate,per,Disc. %,Amount" } You have to write a dynamic python code to map bounding box.
- Assistant
- User
What are the limitations of this code?
- Assistant
- User
Solve these limitation 2. Simple String Matching: The code uses simple string containment checks (str.contains) for matching descriptions. This approach might not be robust enough for cases where the OCR text slightly differs from the source text due to recognition errors or formatting differences.
-
Fuzzy Matching Requirement: For better results, especially with OCR imperfections, implementing fuzzy string matching could significantly improve the ability to match line items. Libraries like fuzzywuzzy can help but are not considered in the basic implementation.
-
Static and Simplistic Bounding Box Logic: The code assumes that the bounding box for a line item can be determined by the aggregate minimal and maximal coordinates of the OCR text blocks that contain the item description. This approach might not accurately reflect the actual positioning of each line item, especially for multiline descriptions or complex invoice layouts.
-
- Assistant
- User
No this code is not working. Use dynamic programming approaches to solve this problem
- Assistant
- User
give the final code
- Assistant