我如何在python 3中搜索图像中的模式 [英] How could I search for patterns in a image in python 3

查看:80
本文介绍了我如何在python 3中搜索图像中的模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用python 3制作图像识别程序,如果没有识别出该项目的名称,我已经获得了尽可能多的名称,要搜索的图像的路径,并且我已经使用 PIL 以返回每个像素的RGB值.但是:既然我已经真正了解了模式识别,我不知道如何尝试它.这不是代码错误或尝试缺乏理解的问题(这是我学习编程语言的最佳方法),而是我不知道要编程什么(如果您愿意,它背后的逻辑)会).

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.

推荐答案

其背后的逻辑实际上非常简单.我在Google周围搜索了一下,发现它的工作原理如下:

The logic behind this is actually quite simple. I googled a bit around and I found out it works like this:

您需要将所有像素与需要比较的图案中的像素进行比较,然后仅创建一个变量,当像素不匹配时将其设置为False.一旦发生这种情况,比较函数就会停止(您可以在其中使用带有break语句的while True:函数),然后返回False.如果匹配,则不会将其设置为"False",并且开头的变量将保持为True.

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.

此致Heureka

这篇关于我如何在python 3中搜索图像中的模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆