Logo detection with OpenCV on python - python

I want to detect excel logo in this kind of image :
!Edited Image where I want to detect excel logo.
So I extracted each logo and used them as "training" set.
I tried by using Brute-Force Matching with ORB Descriptors and Brute-Force Matching with SIFT Descriptors and Ratio Test as you can find here : https://docs.opencv.org/4.x/dc/dc3/tutorial_py_matcher.html.
I never had any matches. I thought I was doing it wrong so I use the exact same code but on the same kind of images you can see in the example and it works correctly.
My two hypothesis are : Excel logo is too simple so not easy to recognize. The logo in the image are too small. Maybe I'm wrong and someone here could help me.
Maybe I'm not using the best method or the best parameters but I don't have any idea to improve my researches.

Related

Detect (and maybe decode) PDF417 barcodes using python

I am trying to detect the pdf417 barcode (2D barcode) from an image using python.
I will be receiving images of IDs where there is a barcode in them but it might not always be straight. So I am looking for an effective way to DETECT the pdf417 barcode using Python.
I tried all of the available methods that I could find (that uses python)
e.g.,
pdf417decoder: requires the image to be cut exactly around the barcode just like in the image below:
pyzbar: only detects 1D barcodes
python-zxing and zxing: didn't detect any of the pdf417 barcodes that I tried (around 10 different IDs - different country)
Barcode-detection: this is a DL approach that uses YOLO-V3 to detect barcodes, but again (after trying it), it only detects 1D barcodes...
Is there a method that I missed?
Am I using a wrong approach towards this problem?
Possible solution that I am thinking of: using computer vision (some filters and transformations) to detect a box that has black and white dots... Something similar to this.
Thanks!
After various trials, I ended up using an approach of template matching by OpenCV.
You need to precisely choose your template image that will be the search reference of your algorithm. You need to feed it some grayscaled images.
Then, you need to choose the boxes that have a result higher than a certain threshold (for me 0.55). Then apply NMS (non max suppression) to filter out the noisy boxes.
But keep in mind that there are many edge cases to encounter. If someone is interested to see the complete solution, please let me know.

Extract text from light text on withe background image

I have an image like the following:
and I would want to extract the text from it, that should be ws35, I've tried with pytesseract library using the method :
pytesseract.image_to_string(Image.open(path))
but it returns nothing... Am I doing something wrong? How can I get back the text using the OCR ? Do I need to apply some filter on it ?
You can try the following approach:
Binarize the image with a method of your choice (Thresholding with 127 seems to be sufficient in this case)
Use a minimum filter to connect the lose dots to form characters. Thereby, a filter with r=4 seems to work quite good:
If necessary the result can be further improved via application of a median blur (r=4):
Because i personally do not use tesseract i am not able to try this picture, but online ocr tools seem to be able to identify the sequence correctly (especially if you use the blurred version).
Similar to #SilverMonkey's suggestion: Gaussian blur followed by Otsu thresholding.
The problem is that this picture is low quality and very noisy!
even proffesional and enterprisal programs are struggling with this
you have most likely seen a capatcha before and the reason for those is because its sent back to a database with your answer and the image and then used to train computers to read images like these.
short answer is: pytesseract cant read the text inside this image and most likely no module or proffesional programs can read it either.
You may need apply some image processing/enhancement on it. Look at this post read suggestions and try to apply.

Python - reading characters from tyre image opencv

I am having to solve the problem where I have to detect the tire dot code in a given tire image and recognize the characters in the tire.
Sample :-
https://www.tirerack.com/images/tires/tiretech/determining_age/Post_2000_Full_Dot.jpg
I am using OPENCV to perform this task and referred the following link for reference https://github.com/schollz/python-ocr.
I have also used a Canny Edge and SWT detection to perform the task, but it has also not helped. I used the libpillowfight library for the same.
This approach is able to contrast the image but not able to extract the characters efficiently.
Can anyone suggest a better way to achieve this. Help appreciated.

CAPTCHAs Image Manipulation using Pillow

As an exercise, I'm attempting to break the following CAPTCHA:
It doesn't seem like it would be too difficult to break as the edges seems to fairly solid and noise should be relatively easy to remove. Problem is, I have very little experience with image manipulation. Currently I'm using Python with the Pillow library to manipulate the CAPTCHA image, after which it will be passed into Tesseract for OCR.
In the following code I attempt to bring out the edges by sharpening the image and the convert the image to black and white
from PIL import Image, ImageFilter
try:
img = Image.open("Captcha.jpg")
except:
print("Can't load captcha.")
exit()
# Bring out the edges by sharpening.
out = img.filter(ImageFilter.SHARPEN)
out = out.convert("L")
out = out.point(lambda x: 0 if x<136 else 255, "1")
width, height = out.size
out = out.resize((width*5, height*5), Image.NEAREST)
out.save("captcha_modified.png")
At this point I see the following:
However, Tesseract is still unable to read the characters. As an experiment, I used good ol' mspaint to manually modify the image to a point to where it could be read by Tesseract:
So if can get the image to that point, I think Tesseract will do a fairly good job at detecting characters. So my current thoughts are that I need to enhance the edges and reduce the noise the image. Also, I imagine it would be easier for Tesseract to detect the letters if the letters will filled in rather than outlined, but I have not idea how I'd do this.
Any suggestions on how to go about this? Is there a better way to process the images?
I am short on time so this answer may not be incredibly useful but goes over my own 2 algorithms exactly. There isn't much code but a few method reccomendations. It is a good idea to use code rather than MS Paint.With code its actually really easy to break a captcha and achieve above 50% success rate. Behavioral recognition may be a better security mechanism or may be an additional one.
A. Edge Detection Method you use:
Edge detection really isn't necessary. In this case, just use the getpixel((x,y)) function and fill in the area between the bounding lines, recognizing to fill at lines 1,3,5;etc. and turn off the fill after intersection 2,4,6;etc. Luckilly, you chose an easy Captcha so edge detection is a decent solution without decluttering,rotating, and re-alignment.
B. Manipulation Method:
Another method I use utilizes OpenCV and pillow as well. I am really busy but am posting a blog article on this later at druid5.wordpress.com/ which will contain code examples of this method. Since it isn't illegal to get through them, at least I am told, I use the method I will post to collect data all the time. Mostly, contrast and detail from pillow, some basic clutter removal with stats, re-alignment with a basic dfs, and rotation (performable with opencv or easily with a kernal). Tesseract is a good choice for open source but it isn't too hard to create an OCR with opencv either.
This exercies is a decent introduction to OpenCV, PIL (pillow), image manipulation with math, and some other things that help with everything from robotics to AI.
Using flow control to find the failed conditions and try different routes may be necessary but the aim should always be a generic solution.

Best Method for Identifying Broken Ellipses

I've been trying to identify ellipses in these pictures for a long time now for a project I'm working on. At the moment I'm trying a new method with a bit of success. I blur the image then subtract the original from it. After that I threshold that image which is how I get this: http://imgur.com/gIkv30A
I've been trying a few methods but have had pretty much no success with any of them. I can't get any more of the noise removed without compromising the quality of the ellipses I have found, but the ellipses I want to find seem to be decently defined.
If anyone has an idea on where I can go now I'd love to hear it.
Thanks,
Andy
edit:
Original Image: http://imgur.com/3ttIFiz
The main method I've tried so far using an adaptive threshold on the image then fitting an ellipse around each of the contours I find after that. It works quite well in one set of images, but performs very poorly in this set. I can see my current method working well in both I get it right.
How well it works with old images: http://imgur.com/eUYiYNa
How well it works with the new (more relevant to the program) images: http://imgur.com/1UXxXAp

Categories

Resources