https://hrubos.tech/blogy/content/images/20260607042030-Snímka obrazovky 2026-06-07 o 4.18.02.png
V jednoduchosti povedané, čo môj algo hľadá? Tvary číslic, toť všetko. Ak nájde pravý uhol, môže povedať je to 5ka, ak nájde uhlopriečku štvorca, môže odhadnúť, je to 7, ak nájde zvislý vektor, môže odhadnúť, je to 1 :) A ták, nó:

Edit2: Prečo nie napr 751? Veď algo môže vidieť napr kde konkrétny tvar je prvej? Hračka.
![]()
extends Node2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
#get_pix_col(10,10)
#pix_dist(0,0,0,1)
max_dist_one_col(Color(0.7843, 0.3412, 0.4118, 1))
nearest_pix_same_col(10,10)
find_rectangle(Color(0.0824, 0.0902, 0.1725, 1))
get_square_diagonal(Color(0.0275, 0.0745, 0.1373, 1))
get_vertical_line(Color(0.0275, 0.0745, 0.1373, 1))
func pix_dist(x1,y1,x2,y2):
var p1 = Vector2i(x1, y1)
var p2 = Vector2i(x2, y2)
var distance = p1.distance_to(p2)
print("dist:["+str(x1)+","+str(y1)+"]=>["+str(x2)+","+str(y2)+"] == " + str(distance))
func get_pix_col(x,y):
var sprite: Sprite2D = $PixelAnalysis
var texture: Texture2D = sprite.texture
var image: Image = texture.get_image()
var sizeh=image.get_height()
var sizew=image.get_width()
var col: Color = image.get_pixel(x, y)
print("pixcol["+str(x)+","+str(y)+"] == "+str(col))
func nearest_pix_same_col(srcx,srcy):
var source = Vector2i(srcx, srcy)
var sprite: Sprite2D = $PixelAnalysis
var texture: Texture2D = sprite.texture
var image: Image = texture.get_image()
var color = image.get_pixelv(source)
var nearest_distance = INF
var nearest_pixel: Vector2i
for y in image.get_height():
for x in image.get_width():
var pos = Vector2i(x, y)
if pos == source:
continue
if image.get_pixel(x, y) == color:
var dist = source.distance_to(pos)
if dist < nearest_distance:
nearest_distance = dist
nearest_pixel = pos
print("Nearest pix of same color: ", nearest_pixel)
print("Dist of nearest pix: ", nearest_distance)
func colors_match(a: Color, b: Color, epsilonr := 0.001,epsilong:=0.001,epsilonb:=0.001) -> bool:
return (
abs(a.r - b.r) < epsilonr &&
abs(a.g - b.g) < epsilong &&
abs(a.b - b.b) < epsilonb &&
abs(a.a - b.a) == 0
)
func max_dist_one_col(target_color:Color):
var left_x = INF
var right_x = -INF
var sprite: Sprite2D = $PixelAnalysis
var texture: Texture2D = sprite.texture
var image: Image = texture.get_image()
var row=0
var col=0
for y in range(image.get_height()):
for x in range(image.get_width()):
if colors_match(image.get_pixel(x, y), target_color,0.3,0.03,0.03):
left_x = min(left_x, x)
right_x = max(right_x, x)
row=y
col=x
if left_x != INF:
print("Max dist one col RED: ", right_x - left_x, " on row ",row, " on col ",col)
else:
print("Defined col not found at this picture!")
func _input(event):
if event is InputEventMouseButton and event.pressed:
var sprite = $PixelAnalysis
# pozícia myši v lokálnom priestore sprite-u
var local_pos = sprite.to_local(event.position)
var image = sprite.texture.get_image()
var tex_size = sprite.texture.get_size()
# ak je sprite centrovaný (default)
var pixel_pos = local_pos + tex_size / 2
if pixel_pos.x >= 0 and pixel_pos.y >= 0 \
and pixel_pos.x < image.get_width() \
and pixel_pos.y < image.get_height():
var color = image.get_pixelv(Vector2i(pixel_pos))
print("Clicked col: "+str(color))
func find_rectangle(target_color: Color):
var sprite: Sprite2D = $PixelAnalysis
var image: Image = sprite.texture.get_image()
var min_x = INF
var min_y = INF
var max_x = -INF
var max_y = -INF
for y in range(image.get_height()):
for x in range(image.get_width()):
if colors_match(image.get_pixel(x, y), target_color):
min_x = min(min_x, x)
min_y = min(min_y, y)
max_x = max(max_x, x)
max_y = max(max_y, y)
if min_x == INF:
print("Number 5 not found!")
return null
print("Found number 5")
func get_square_diagonal(target_color: Color):
var image = $PixelAnalysis.texture.get_image()
for y in range(image.get_height() - 2):
for x in range(image.get_width() - 2):
# \
if (
colors_match(image.get_pixel(x, y), target_color,0.3,0.3,0.3) and
colors_match(image.get_pixel(x + 1, y + 1), target_color,0.3,0.3,0.03) and
colors_match(image.get_pixel(x + 2, y + 2), target_color,0.3,0.3,0.3)
):
print("Found nubmer 7")
return
# /
if (
colors_match(image.get_pixel(x + 2, y), target_color,0.3,0.03,0.03) and
colors_match(image.get_pixel(x + 1, y + 1), target_color,0.3,0.3,0.3) and
colors_match(image.get_pixel(x, y + 2), target_color,0.3,0.3,0.3)
):
print("Found nubmer 7")
return
print("Not found number 7")
func get_vertical_line(target_color: Color) -> bool:
var image = $PixelAnalysis.texture.get_image()
for y in range(image.get_height() - 2):
for x in range(image.get_width()):
if (
colors_match(image.get_pixel(x, y), target_color,0.3,0.3,0.3) and
colors_match(image.get_pixel(x, y + 1), target_color,0.3,0.3,0.3) and
colors_match(image.get_pixel(x, y + 2), target_color,0.3,0.3,0.3)
):
print("Found number 1")
return true
print("Not found number 1")
return false

Comments “Nájdete algoritmus O(N), nie LLMs, aby ste dané číslo našli? Tu je môj v mili sekundách pre 700x700 pixelový obrázok :) Nemožné? Možné! Ak je LLMs štatistický odhadový model, prečo môj nie je?”