Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do you make an AI that will recognize pictures
- sp3oni
-
Scratcher
7 posts
How do you make an AI that will recognize pictures
How do I make an AI that will recognize pictures?
_B)_
_B)_- sp3oni
-
Scratcher
7 posts
How do you make an AI that will recognize pictures
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????









Last edited by sp3oni (April 26, 2026 20:17:41)
- RicDiamond1477
-
Scratcher
100+ posts
How do you make an AI that will recognize pictures
How do I make an AI that will recognize pictures?Currently, it is not possible to code AI into Scratch (but you can use ScratchAttach to integrate AI) but you can use the few blocks the Video Sensing extension has to detect motion._B)_
- tinod456
-
Scratcher
9 posts
How do you make an AI that will recognize pictures
the easiest way is to use one big list called all_training_data. every time you scan a new picture, you add those 400 pixels (the 0s and 1s) to the end of that list.
1. set up your lists
current_scan: this holds the 1s and 0s of the picture you just drew.
all_training_data: this is your “brain” that saves every scan you've ever done.
labels: this list remembers what each scan was (e.g., item 1 is “circle,” item 2 is “square”).
2. the “add to training” code
after you draw something, you run this script. it asks you what the shape is, then saves the scan data.
now, when the ai wants to recognize a new drawing, it has to scan through its whole “brain” list, 400 items at a time, to see which past scan looks the most like the new one.
scratch
define find best match
set to (0)
set to
set to (1)
// loop through every scan you've saved
how to use it
1 draw a shape.
2 run the scan block.
3 run the add to training block (do this a few times for circles, squares, etc.).
4 now, draw something new, scan it, and run the find best match block.
1. set up your lists
current_scan: this holds the 1s and 0s of the picture you just drew.
all_training_data: this is your “brain” that saves every scan you've ever done.
labels: this list remembers what each scan was (e.g., item 1 is “circle,” item 2 is “square”).
2. the “add to training” code
after you draw something, you run this script. it asks you what the shape is, then saves the scan data.
define add to training data3. how it recognizes (comparing to everything)
ask [what did you just draw?] and wait
add (answer) to [labels v] // save the name
set [index v] to (1)
repeat (length of [current_scan v])
add (item (index) of [current_scan v]) to [all_training_data v]
change [index v] by (1)
end
now, when the ai wants to recognize a new drawing, it has to scan through its whole “brain” list, 400 items at a time, to see which past scan looks the most like the new one.
scratch
define find best match
set to (0)
set to
set to (1)
// loop through every scan you've saved
repeat (length of [labels v])// compare 400 pixels of the memory to the current drawing
set [current_score v] to (0)
set [scan_pixel v] to (1)
repeat (400)// if this memory is the closest match so far, remember it
if <(item (scan_pixel) of [current_scan v]) = (item (training_index) of [all_training_data v])> then
change [current_score v] by (1)
end
change [training_index v] by (1)
change [scan_pixel v] by (1)
end
if <(current_score) > (best_score)> thensay (join (winner))
set [best_score v] to (current_score)
set [winner v] to (item (iteration) of [labels v])
end
end
how to use it
1 draw a shape.
2 run the scan block.
3 run the add to training block (do this a few times for circles, squares, etc.).
4 now, draw something new, scan it, and run the find best match block.
- Discussion Forums
- » Help with Scripts
-
» How do you make an AI that will recognize pictures