Making Maps, Version 2.1: Recognizing location by pixel color

Map of the travels on Day 66

Map of the travels on Day 66

So it turns out now the most tedious thing to do when creating the maps is renaming the files with their tile position information.  I’m not a fan of tedious.

I figured Imagemagick’s -subimage recognition might be the way to go and went as far as writing a script that could pull out the maps from screenshots and (assuming I only ever fed it properly named files) snag off the 6 character file prefix to preserve as the file name.

Once I had some example subimages to compare my screen shots to, I ran a test of the compare.

compare -metric MAE -subimage-search 29-12-2014_08.52.24.png ./cnrkeys/07y07x_cnrkey.png null: 2>&1

After 10 minutes of letting that process run in the background I did some more research on subimage-search and why it might be sooooooo sloooowwwwww. It turns out compare is trying to find all best possible matches. I can’t limit where ImageMagick will to look without cropping the main image in the exactly same way. Another recommendation beside croping would be to downsample them both. A combination downsample and crop would be the fastest of all.

Since that kind of multistep processing seemed like overkill for my problem, I changed tactics. I just need to know if a certain spot on the screen is green. If the pixel is green then I am in the corresponding location.

#What color on the legend indicates where I am. 
#This result will be based on the formatting used below.
TRUECOLOR="136,216,0"

#Get one pixel XCORD,YCORD in from the top left and spit out its
#color information in the format requested. 
mycolor=$(convert $p[1x1+${XCORD}+${YCORD}] -format "%[fx:floor(255*u.r)],%[fx:floor(255*u.g)],%[fx:floor(255*u.b)]" info:-)

#An example of what to do with the information
if [ "$mycolor" == "$TRUECOLOR" ]; then
    found=1
fi

Took a little doing, but I got it working with a row-column scan (gist shown at the end). With a few changes I can use a very similar script to see if Link is dead, what weapon is enabled… it all depends on figuring out a unique pixel color at a unique location.  It is still slow, about 2 to 10 seconds per image depending on its position. To recognize location 07y15x  convert will be called 128 times. It would be faster processing time wise to figure out a way to load a pixel array, but not, it think, faster in people time. I’m not doing millions of these suckers.

As a bonus I can have the script generate my travel route. Seems handy. Not sure how I’ll use it yet.

Current Process

  1. Organize the potential images I want to use for the map (include duplicates if I went through and area twice) in iPhoto or in Finder.
  2. Run the rename script on the folder
  3. Cull the duplicates for any tile position
  4. Run the map-making script on the folder

I do the rename script after organizing now because it changes the order they get processed in and I am thinking about how to preserve route information.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s