How could I search for patterns in a image in python 3 [closed]

廉价感情. 提交于 2020-01-25 23:51:08

问题


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:

  1. Extract keypoints and features from your template using feature detector (ORB, Sift, Surf)
  2. Do the same for the image
  3. Compare keypoint descriptors (e.g. for ORB using BFMatcher)
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!