PixelSearch return 可以使用相同颜色的多个坐标吗?
Can PixelSearch return multiple coords with the same color?
函数 PixelSearch returns 匹配特定颜色的第一个像素。问题是我需要找到更多颜色相同但坐标不同的像素。
例如,如果我在 420x689
和 864x1022
中都有一个红色像素,PixelSearch 仅 returns 第一个坐标。我怎样才能同时识别第二个红色像素坐标?
我的代码是:PixelSearch, Sx, Sy, 380, 80, 1550, 900, 0xFFA004, 1, Fast RGB
但只有 returns 1 个像素。我可以使用其他 function/approach 吗?
以下有效,尽管它可能不是解决此问题的最佳/最有效的方法。
您可以尝试遍历给定的像素范围,并将与指定颜色匹配的像素添加到数组中。
这是我得到的:
#SingleInstance Force
xStorage:=[]
yStorage:=[]
startX:=380
startY:=80
endX:=1550
endY:=900
TargetColor:=0xFFA004
iterX:=startX
iterY:=startY
while(iterX<=endX)
{
while(iterY<=endY)
{
PixelGetColor, currentColor, %iterX%, %iterY%
if(currentColor==TargetColor){
xStorage.Push(iterX)
yStorage.Push(iterY)
;MsgBox %iterX% %iterY% %currentColor%
}
iterY++
}
iterY=0
iterX++
}
for index, element in xStorage
{
MsgBox % "Element number " . index . " of the X-cood is " . element
}
for index, element in yStorage
{
MsgBox % "Element number " . index . " of the Y-cood is " . element
}
esc::ExitApp
编辑:修复了阻止 y 迭代器在每次 line/cycle 后重置的错误代码。
花了一段时间,但我过去遇到过这个问题并首先解决了它扫描主要区域,如果它找到一个像素,那么它会在该像素之后搜索该行的其余部分(如果它找到它搜索)越过那个像素到线的末尾,然后一旦它到达线的末尾,就会搜索扫描线下方区域中的所有内容,并重复测试和工作。这对我想要这个有一段时间的许多脚本很有用。它在大面积上可能会很慢,但这可能是您可以获得的最快速度。
CoordMode, mouse, Screen
multipixelsearch(colour, x1, y1, x2, y2) {
varx1 := x1
vary1 := y1
varx2 := x2
vary2 := y2
loop
{
PixelSearch, x, y, varx1, vary1, varx2, vary2, colour, 0, RGB Fast
if (ErrorLevel) {
return
}
yfound := y
forcoord(x, y)
loop {
PixelSearch, x, y, x, y, x2, y, colour, 0, RGB Fast
if (ErrorLevel) {
vary1 := yfound + 1
Break
} else {
x := x+1
forcoord(x, y)
}
}
}
}
forcoord(x, y) {
;what it does for every coord goes here
}
return
Esc::ExitApp
函数 PixelSearch returns 匹配特定颜色的第一个像素。问题是我需要找到更多颜色相同但坐标不同的像素。
例如,如果我在 420x689
和 864x1022
中都有一个红色像素,PixelSearch 仅 returns 第一个坐标。我怎样才能同时识别第二个红色像素坐标?
我的代码是:PixelSearch, Sx, Sy, 380, 80, 1550, 900, 0xFFA004, 1, Fast RGB
但只有 returns 1 个像素。我可以使用其他 function/approach 吗?
以下有效,尽管它可能不是解决此问题的最佳/最有效的方法。
您可以尝试遍历给定的像素范围,并将与指定颜色匹配的像素添加到数组中。
这是我得到的:
#SingleInstance Force
xStorage:=[]
yStorage:=[]
startX:=380
startY:=80
endX:=1550
endY:=900
TargetColor:=0xFFA004
iterX:=startX
iterY:=startY
while(iterX<=endX)
{
while(iterY<=endY)
{
PixelGetColor, currentColor, %iterX%, %iterY%
if(currentColor==TargetColor){
xStorage.Push(iterX)
yStorage.Push(iterY)
;MsgBox %iterX% %iterY% %currentColor%
}
iterY++
}
iterY=0
iterX++
}
for index, element in xStorage
{
MsgBox % "Element number " . index . " of the X-cood is " . element
}
for index, element in yStorage
{
MsgBox % "Element number " . index . " of the Y-cood is " . element
}
esc::ExitApp
编辑:修复了阻止 y 迭代器在每次 line/cycle 后重置的错误代码。
花了一段时间,但我过去遇到过这个问题并首先解决了它扫描主要区域,如果它找到一个像素,那么它会在该像素之后搜索该行的其余部分(如果它找到它搜索)越过那个像素到线的末尾,然后一旦它到达线的末尾,就会搜索扫描线下方区域中的所有内容,并重复测试和工作。这对我想要这个有一段时间的许多脚本很有用。它在大面积上可能会很慢,但这可能是您可以获得的最快速度。
CoordMode, mouse, Screen
multipixelsearch(colour, x1, y1, x2, y2) {
varx1 := x1
vary1 := y1
varx2 := x2
vary2 := y2
loop
{
PixelSearch, x, y, varx1, vary1, varx2, vary2, colour, 0, RGB Fast
if (ErrorLevel) {
return
}
yfound := y
forcoord(x, y)
loop {
PixelSearch, x, y, x, y, x2, y, colour, 0, RGB Fast
if (ErrorLevel) {
vary1 := yfound + 1
Break
} else {
x := x+1
forcoord(x, y)
}
}
}
}
forcoord(x, y) {
;what it does for every coord goes here
}
return
Esc::ExitApp