Autoscoring with Matlab

While I qualified a long time ago on the M9, I never really learned to be a good shot. Now, I’m trying to learn to shoot well and wanted to automatically score my targets, keep the data, and get better.

There are apps to do this, but none of them did what I wanted. One app by Thomas Gabrowski and Justa Mili works off a photo of the target to automatically calculate the score. They also have the capability to analyze shooting groups with Windage, Elevation, Mean Radius and Extreme Spread. They have capabilities to keep track of your previous shooting sessions and monitor progress. The App costs $17.

Developing my own costs my time, but gives me flexibility to work with my targets and my system. It’s also a thing I do: grab challenges that will teach me something. It’s served me well and Matlab makes this all accessible and fun. The other thing is that apps never work exactly right. What if I want the raw data so I can calculate if I’m aiming high or low over time? All this code is on github at https://github.com/tbbooher/automatic_target_scoring.

I told my children that two key skills every digital citizen needs are the ability to process text and images. By processing text, I’m able to tell any story from any reports in digital form. This is often bank statements, hotel stays, fitness stuff or uber rides. By processing images, I’m able to understand and report on things that are happening around me.

In looking around, I found this thesis filled with some good ideas. I reached out to the author and discussed the merits of edge detection vs template matching. He didn’t have his code available. There were several papers but none were really that helpful. It was easier to start building than to spend a lot of time reading other’s approaches.

I knew there would be three steps to this: (1) registering all images to the standard, fixed, image for consistent distance, (2) finding the bullet holes/center and (3) measuring the distances from the center each hole.

Image Registration

This was harder than I thought since most registration is for two similar images. I was used to the ease of Photoshop for rapid registration. It turns out it is a hard problem to register images of different pictures of what are really different scenes, even though the structure is common. Most image registration problems are pictures of the same scene that have been taken at different angles or distances. The picture below makes this clear:

Reference and Real Image

I found two approaches that worked for image registration. The first approach was to extract the red circle and then make the circles match. Here I had to calculate and align the centers, and rescale one image to the size of the other. Color thresholding and imfindcircle were quite useful.

For the more general case, I had to use fitgeotrans which takes the pairs of control points, movingPoints and fixedPoints, and uses them to infer the geometric transformation. It does this by taking the pairs of control points, movingPoints and fixedPoints, and uses them to infer the geometric transformation. After doing this I had a set of images that were all the same size, and all in the same orientation — with bullet holes.

Registered Images

Finding the bullet holes

I was able to use this matlab post to learn that I could sample some colors in photoshop, convert the image to HSV and find shades of gray using some code from Theodoros Giannakopoulos.

The next thing I had to do was create the ability to find the center. I did this by recognizing that the center X is red and pretty distinctive — ideal for template matching using normalized cross-correlation matlab has a great description of how this works here. With this accomplished, I can find the center in a few lines, by going off this template:

Template

All together, I’m able to compute the measurements to make a picture like this (note the green circle in the middle on the X):

Result

With the image registered, the center defined and all holes discovered, I could easily calculate a score of a mean distance to the bullseye.

Problems

The problem was that I couldn’t get good consistency. The shadows were a problem on some images, on others, shots very close to one another caused confusion. It turned out that I was really good at quickly seeing the holes, better than a template matching problem. Note that when I saved the image, I updated a xls file and saved the scores as EXIF data so the image had the exact locations of the holes that I could pull out later if needed. The code below works awesome and is ideal for my solution. Best of all, I learned a lot about how to manipulate and extract data from images.

Results

So, is my shooting getting better? Not yet. In the plot below you can see my score is increasing, and the stDev of my shots is increasing as well. Now, the data aren’t uniform since I had the target at 5m and now have it at 6.5m on Oct 8. Sept 12 was with a suppressed 22 at 5m. Oct 8 was 9mm. Anyway, it’s better to know from data than to be guessing. I’m chalking this up to an improved technique that is taking some time to adjust to.

Torsion Table for Shapeoko

I needed a torsion table to make sure my Shapeoko XXL had a solid foundation. Dimensions for the Shapeoko are available here. The basic idea of a torsion table is to use two thin layers of material on either side of a lightweight core, usually a grid of beams. Torsion boxes are used in wings and vertical stabilizers. The final product can resist torsion under an applied load. The torsion box uses the properties of its thin surfaces to carry the imposed loads primarily through tension while the close proximity of the enclosed core material compensates for the tendency of the opposite side to buckle under compression.

I found some great data in the links below:

  • great collection of ideas here
  • and more ideas here
  • This post was great at getting ideas.

Marc Spagnuolo, a.k.a. “The Wood Whisperer,” put together a pretty comprehensive 20-minute-plus video on how he built his. Spagnuolo shows you how to get past the dilemma of building your first torsion box, which is: how do you construct a perfectly flat surface, before you’ve got a perfectly flat surface to assemble it on?

My design was intended to look similar to this, but I didn’t like the idea of making sure all the individual pieces were straight, so I build a design based on half-lap joints.

Example Build

Lining everything up perfectly was super easy after cutting the slots. MDF is an amazing material.

Half Lap Assembly

The end result was intended to look like this by using the Hopkins Mfg Corp Workbench Kit 90158MI.

Shapeoko Table

My end design looked like this (I always use mm for dimensions).

I used my table saw to cut down the core pieces all to the same height. A torsion box is a completely flat, very sturdy and relatively lightweight surface, and anyone designing anything structural and rectilinear should understand its principles. The concept is simple, even if construction can be tedious: Two flat, horizontal surfaces are sandwiched over a grid of crossmembers, and once the sandwich is glued shut, a rigidity much greater than that possessed by the individual parts is achieved.

Pieces Cut

I added shims to the bottom of the saw horses to make sure the base was level. I used lots of glue.

Assembly drying

By using half-lap cuts I was able to get all the spacing right. It was critical to square the boards.

Half-laps cut

Here you can see my use of pocket screws and my testing of the table to ensure it is level.

Inital design

I love using cutlist optimizer to speed up my cuts and optimize the use of the wood. I’ve designed cutting algorithms myself in the past and this online tool is fast, accurate and excellent. (https://www.cutlistoptimizer.com/). I did make a design change by ripping long strips so I could avoid the inaccuracy of all the small cuts.

Cutlist

I made a video of my design process. I made a component with half-laps cut out, replicated it with design tools, flipped a copy that I rotated 90 degrees.

Video of the Design Process