Fill broken parts of an image using Python, OpenCV - python

I have a Captcha image like this:Captcha image
And Im writing a program to read it. Before any ML work I want to fill the parts where the image is broken. How do I do this?

Related

OpenCV: Stitch with saving warping/arrangement informations and re-stitch with the saved info

First of all, I am a beginner in computer vision field, learning OpenCV from the web.
What I am trying is stitching multispectral (bands > 3) images with OpenCV stitching APIs.
I already know that OpenCV doesn't support multispectral image.
So, the idea I came up with is as follows:
Extract the RGB images from each multispectral image.
Use cv2.Stitcher_create() and stitcher.stitch class to stitch all the RGB images (reference: https://pyimagesearch.com/2018/12/17/image-stitching-with-opencv-and-python/). And save the warping and arrangement informations (ex. Homography, matching keypoints...) in making RGB panorama.
Stitch each remaining bands' image by loading the informations that saved in step 2.
The problem is, I can't find the codes for the saving and loading informations that required in step 2 and 3.
Is the suggested method possible? And if possible, is there any tips or references that I can use?
Yes you can do it (I did it before for my paper on stitching construction plans). You need to save the camera parameters after the feature matching and probably also the seam masks.
Look here (cameras) and here (seam masks)

Magnify image based on rectangle points selected on image

I am working on a code in python and I came across a figure in a report that I would like to replicate.
Basically I would like to create a 'bounding' box onto the original image, and then subsequently crop and display the part of the image that has the bounding box on it. (basically to 'magnify' that section)
I've been googling but I can't seem to find the correct function to use so that I can achieve this. Currently, opencv is used to read my image, but if there is a function in matplotlib that does this, then you can suggest that too.
Thank you for your help!

Ways to clean up photos for Tesseract OCR?

I'm new to Tesseract and wanted to know if there were any ways to clean up photos for a simple OCR program to get better results. Thanks in advance for any help!
The code I am using:
#loads tesseract
tess.pytesseract.tesseract_cmd =
#filepath
file_path =
image = Image.open(file_path)
#processes image
text = tess.image_to_string(image, config='')
print(text)
I've used pytesseract in the past and with the following four modifications, I could read almost anything as long as the text font wasn't too small to begin with. pytesseract seems to struggle with small writing, even after resizing.
- Convert to Black & White -
Converting the images to black and white would frequently improve the recognition of the program. I used OpenCV to do so and got the code from the end of this article.
- Crop -
If all your photos are in similar format, as in the text you need is always in the same spot, I'd recommend cropping your pictures. If possible, pass only the exact part of the photo to pytesseract that you want analyzed, the less the program has to analyze, the better. In my case, I was taking screenshots and would specify the exact region of where to take one.
- Resize -
Another thing you can do is to play with the scaling of the original photo. Sometimes after resizing to almost double it's initial size pytesseract could read the text a lot easier. Generaly, bigger text is better but there's a limit as the photo can become too pixelated after resizing to be recognizable.
- Config -
I've noticed that pytesseract can recognize text a lot easier than numbers. If possible, break the photo down into sections and whenever you have a trouble spot with numbers you can use:
pytesseract.image_to_string(image, config='digits')

Combining two images horizontally in python using OpenCV

I have four images, each slices of a larger image. If I string them together horizontally, then I get the larger image. To complete this task, I'm using python 2.7 and the OpenCV library, specifically the hconcat() function. Here is the code:
with open("tempfds.jpg", 'ab+') as f:
f.write(cv2.hconcat(cv2.hconcat(cv2.imread("491411.jpg"),cv2.imread("491412.jpg")),cv2.hconcat(cv2.imread("491413.jpg"),cv2.imread("491414.jpg"))))
When I run it, everything works fine. But when I try to open the image itself, I get an error: Error interpreting JPEG image file (Not a JPEG file: starts with 0x86 0x7e). All the images I'm using are jpg's, so I don't understand why this error is occurring. Any insight is appreciated.
If you want to write a JPEG, you need:
cv2.imwrite('lovely.jpg', image)
where image is all your images concatenated together.

opencv python- noise in saved image via io.imsave

i am trying to save an image in opencv python. the image that the program is showing via cv2.imshow() is perfectly fine. but when i am saving it using cv2.imwrite() it is saving black image .then i have tried io.imsave for saving but it is also saving my image with some gray small blobs on that.
i am saving it with .png extension.i have also tried to save with other extensions but nothing works fine for me.
cv2.imshow('result',res)
io.imsave('gabor.png',res)
can anyone point out what can be the problem?

Categories

Resources