xavctn / img2table

img2table is a table identification and extraction Python Library for PDF and images, based on OpenCV image processing
MIT License
581 stars 76 forks source link

How can I import an image which is already read as numpy.ndarray? #174

Closed ibowennn closed 8 months ago

ibowennn commented 9 months ago

Thank you for your work!

Before importing the image into img2table, I need to preprocess it. This involves reading the image as a numpy.ndarray format and split it into several tables. I received a "TypeError: Invalid type <class 'numpy.ndarray'> for src argument" when attempting to pass the images into the Image API. How can I import these numpy.ndarray images into img2table?

xavctn commented 8 months ago

Hello,

You can use an image array as such:

_, buffer = cv2.imencode(".jpg", img)
doc = Image(src=BytesIO(buffer))