问题
I'm making an image recognition program in python 3, I've got as far as getting the name of the item if it isn't recognised, the path of the image to search, and I've used PIL to return the RGB values of each pixel. However: now that I've actually got to the pattern recognition, I have no idea how to attempt it. It's not a problem of errors in the code, or a lack of understanding to attempt this (this is the best way for me to learn programming languages), it's that I don't know what to program (the logic behind it, if you will).
Please note: I'm not looking for any code, purely just an explanation of the logic behind it. (I know that this may not be the right place to ask, but since it was sort of a programming question, I decided it was ok)
This has been puzzling me and my programming friends for a few days now, so any help would be greatly appreciated.
回答1:
The logic behind this is actually quite simple. I googled a bit around and I found out it works like this:
You need to compare all pixels to the pixels in the pattern you need to compare, then just create a var which is set to False when a pixel doesn't match. As soon as this happens, the comparing function is stopped(You could use a while True:
function with a break statement in it) and returnes False then. If it matches, there will be no set to 'False' and the variable of the beginning will stay True.
I hope I could give you an Idea of what to do.
Sincerely, heureka
回答2:
You should give a try to OpenCV and Template Matching approach. There are more sophisticated algorithms such Feature Matching. It depends on the situation.
回答3:
Try using OpenCV. An example algorithm can be:
- Extract keypoints and features from your template using feature detector (ORB, Sift, Surf)
- Do the same for the image
- Compare keypoint descriptors (e.g. for ORB using
BFMatcher
) - Compare count of matched keypoints with your selected threshold
来源:https://stackoverflow.com/questions/35944922/how-could-i-search-for-patterns-in-a-image-in-python-3