简体   繁体   English

如何在opencv中使用阈值获取白色字母

[英]how to get white letters using threshold in opencv

I'm following this tutorial: https://www.smartspate.com/how-to-write-a-bot-in-python-for-online-games/ 我正在关注本教程: https : //www.smartspate.com/how-to-write-a-bot-in-python-for-online-games/

but I'm at the first part. 但我是第一部分。 He seems to threshold the image and get the white letters in the picture, but my thresholding does jack and I can't seem to get simple white letters without getting alot of the backround. 他似乎对图像进行阈值处理并获得图片中的白色字母,但是我的阈值处理却千真万确,而且我似乎在没有大量背景知识的情况下也无法获得简单的白色字母。

img = cv2.imread('bot_color.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
x, img = cv2.threshold(img, 150,255, cv2.THRESH_BINARY)
cv2.imshow('img', img)
cv2.waitKey(0)

My result with 252 threshold (exactly as his): 我的结果是252个阈值(恰好是他的):

My result with a 127 threshold: 我的结果是127阈值:

The pic I snipped from the site (original) 我从网站上窃取的图片(原始)

I snipped his pics using snippet. 我用片段摘了他的照片。 But even with other pics, I don't understand why I can't get simple white letters to appear (say for example, another game) 但是即使有其他图片,我也不明白为什么我无法让简单的白色字母出现(例如,另一款游戏)

Like mentioned before, you likely do not have the "original photo" if it was not available for download from the site. 如前所述,如果您无法从网站上下载“原始照片”,则可能没有。 This, however should not alter the way you detect the letters any more than simply adjusting your threshold values. 但是,这不应该仅仅改变阈值而改变您检测字母的方式。 Try adjusting the values to a very broad range before narrowing the range to cherrypick letters. 在将范围缩小到小写字母之前,请尝试将值调整到非常宽的范围。 Try something like this first: 首先尝试这样的事情:

    x, img = cv2.threshold(img, 75,255, cv2.THRESH_BINARY)

Then raise the 75 value or lower the 255 value to narrow the threshold. 然后提高75值或降低255值以缩小阈值。

As I looked at the site it seems that the original image is copyrighted and you cannot download the original. 当我浏览该网站时,原始图片似乎已受版权保护,您无法下载原始图片。 If you made a screenshot of the picture online a lot of information is probably lost and hence the difference in result. 如果您在线制作了图片的屏幕截图,则可能会丢失很多信息,因此结果会有所不同。 Open the image in paint and zoom in on the text and you will see the problem. 用油漆打开图像并放大文本,您将看到问题。 Try doing the same with an image you make on your own. 尝试对自己制作的图像进行相同的处理。 Cheers! 干杯!

The mega pixel count is the total number of pixels in the image and is related to the number of pixels in the width and the height of the image. 百万像素计数是图像中像素的总数,并且与图像宽度和高度中的像素数有关。 By resizing the size of the image reduce the mega pixel count of the photo so the PC can't store all the detail any more (there simply aren't enough pixels to do so). 通过调整图像大小,可以减少照片的大像素数,因此PC无法再存储所有细节(根本没有足够的像素可以存储)。 Thus removing details from the image. 因此从图像中删除细节。

EDIT: 编辑:

I searched online for a screenshot of the same game and the threshold works okay. 我在网上搜索了同一游戏的屏幕截图,阈值正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用opencv轨道栏限制三种颜色? - How to threshold three colours using opencv trackbars? 使用opencv阈值图像以获得与imagemagick相同的结果 - Threshold an image using opencv to get same result as imagemagick 如何在 opencv 中使用自适应阈值设置阈值为零? - How do I threshold to zero using adaptive thresholding in opencv? 给定形成网格的白线图像,如何使用opencv获取内部形状的蒙版? - Given a image of white lines forming a grid, how to get masks of the interior shapes using opencv? 如何在opencv中自动化下限阈值? - How to automate the low end threshold value in opencv? 如何使用openCV-python识别白色背景上的多张照片? - How to recognize multiple photos on a white background using openCV-python? 如何使用 OpenCV2 在带有黑色边框的图像上显示白色文本? - How to show white text on an image with black border using OpenCV2? 如何使用 opencv 将具有透明背景的图像更改为白色背景 - How to change an image with a transparent background to white background using opencv 如何在opencv中改变轮廓形成的面积(阈值) - how to change area of contours formation in opencv (threshold) 如何用opencv自动调整模板匹配的阈值? - How to automatically adjust the threshold for template matching with opencv?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM