Obtained position of tables in pdf and plot the bounding box on the image - python

Following this script, I could know the bounding box of the tables in my e-pdf:
tabula.read_pdf(file, stream=True,guess=True,lattice=False,multiple_tables=True, output_format="json", pages=pg_num)
However, I want to plot the bounding boxes detected on the image. I realised that pixels or locations changed from x,y,w,h from the tabula bounding boxes are different from the images converted from the pdf using this script:
from pdf2image import convert_from_path
pages = convert_from_path(file)
open_cv_image = np.array(pages[pg_num - 1])
Any thoughts on how to synchronise location in the tabula pdf vs location from the image exported?

Related

How to open a one band tif / tiff picture with python?

I'm trying to load, resize and show a one band tif picture.
The band is a greyscaled band.
Here you can download the picture in question from google drive :
https://drive.google.com/file/d/171b2FDOCVrBQKtJ3oZQoxJjVce2ODfLQ/view?usp=sharing
I've tryed the following code but when i display the picture, i've a full black image.
from PIL import Image
im = Image.open(My_Tif_File_Path)
im.show()

When loading and writing a PNG image to PDF using Pillow (PIL), how do I fix the size of the image in the PDF?

I am reading in a list of PNG images from a directory and I want to maintain the image sizes.
However, when I go to save them, each image is automatically resized to fit the entire page AND it automatically rotates the images to landscape rather than keeping them portrait.
Example of what I am doing below:
from PIL import Image
x = []
# get list of images
for i in [list of image files in my directory]:
im = Image.open(i)
im = im.convert('RGB') # will not save as RGBA
x.append(im)
im.save('my_doc.pdf', save_all=True, append_images=x)
Yet, the images which are all the same dimensions and sized to fit neatly onto a single page in portrait orientation, are being rotated to landscape orientation and stretched to the limits of the page making them blurry as a result.
I want one image per page, using the native dimensions of the images, and in portrait.
Is there a way to prevent PIL from doing this?
Thanks in advance!

Extracting Images from a pdf file of Engineering Drawings in python

this is the first time I am trying this,
I have a PDF file which is basically a 2D Engineering drawing eg: as given here
All drawings are very similar in nature,
I need to find out the centre circular drawings area covered by black ink. I want to find out in the central circular image, what portion of the area is having black ink, and what portion has white dots.
My problem starts with loading the pdf file in python for which I used this code:
import os
os.chdir("E:\WorkStation Laptop\Projects\Shirwal\Printing\PDF Images")
from pdf2image import convert_from_path
images = convert_from_path('06561 ALKEM LABORATORIES LIMITED mm.pdf')
for img in images:
img.save('output.jpg', 'JPEG')
But this isn't working and giving me this error
PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?
My 2nd step is to extract that area having a circular image and then calculating the black dots area and white dots area
How should I do it?

How to label image without using bounding box?

I'm trying to create custom dataset using my own images. This images I cropped from logs data such as below:
https://drive.google.com/open?id=1x0oWiVZ9KOw5P0gIMxQNxO-ajdrGy7Te
I want it to be able to detect the high vibration such as below:
https://drive.google.com/open?id=1tUjthjGG1c23kTCQZOgedcsx99R_a_z3
I have around 300 image of the High Vibration in one folder. the picture is like below:
https://drive.google.com/open?id=1IG_-wRJxe-_TOYfSxHjRq5UBWMn9mO1k
I wanted to do exactly like https://towardsdatascience.com/how-to-train-your-own-object-detector-with-tensorflows-object-detector-api-bec72ecfe1d9. IN this example image dataset was hand-labeled manually with LabelImg.
However I don't see why I need to draw box for images that only have one object in it and can have the frame of the image as the bounding box.
Please advice how I can create data set and processing the images without manually drawing the bounding box (since the images consist of one object), and how to draw bounding boxes in batch for image that contain one object(i.e. having the frame of the image as the bounding box)?
It sounds like you want to do 'image classification' as opposed to 'object detection' -- it may be easier to make a script that generates xml files, containing the image's width and height as bounding box dimensions, as opposed to using labelImg.

Using Contour Detection to extract required data from image

I have been trying to extract text from a document by utilizing the coordinates obtained from boundingRect function. While these coordinates work when trying to draw the contours i cant seem to extract the individual characters onto a temporary image file.
This is the code i used
[x,y,w,h] = cv2.boundingRect(contour)
roi = image[y:y+h,x:x+w]
m[y:y+h, x:x+w]=roi
and i've also tried
cv2.drawContours(m,[c],-1,0,1)
image = cv2.bitwise_and(image,image, mask=m)

Categories