Recent Posts

2D perspective projection could introduce systematic error

1 minute read

If the camera is placed arbitrarily but always to the left, then approximating the hit position as the centroid of the puck could introduce small but consistent skewing to the right.

Examples of perspective errors for different hit points when camera is aligned with the lower left of the canvas. Note reference centroid marked in blue. Personal illustration by author. September 2018.

From the above figure, it can be seen that the camera perspective and 2D projection make more of the flat sides of the pucks on the right visible, causing the 2D centroid to move to the right. On the left side, due to the camera angle being more head-on, the centroid will be a better approximation to the actual position. Note also that the centroid of upper pucks also skew up due to the camera being placed low.

It should be mentioned that the pucks usually has some spin and will hits the canvas less clean than in the above case. If it hits broad side first, the skewing is much less pronounced.

The effect can also be seen in the following figure

Front and side view of canvas in windy conditions. The left side is aligned with the camera and therefore looks straight while the right side is curved due to the camera perspective. The side view shows that both sides curve approximately as much. Personal illustration by author. September 2018.

One could argue that pucks hitting the canvas on the right comes in at an angle, assuming the player is centered, and thus the puck would have moved more to the right if the canvas had not stopped it early. However, assuming this is a valid argument, the reverse would hold for the left side and then the centroid would consistently skew to the right.

The best option is probably to alternate sides for the camera in order to average it out over time.

Building OpenCV on MacOSX High Sierra with Python3, QT and contrib

1 minute read

At the time of writing this, I had actually successfully built and installed OpenCV earlier but after havimg upgraded brew packages at some time or other, the version I had built stopped working due to no longer having access to an old version of libhdf5.

I have cloned the OpenCV and OpenCV contrib repos. In this particular case, I also want to go from version 3.4.2 to 3.4.3.

First, make sure we have the necessary dependencies, although I’m not quite sure the below covers everything we need.

brew install eigen ffmpeg harfbuzz hdf5 lapack libpng libsvg libtiff numpy
     openblas openjpg python qt tbb

Now, retrieve and checkout the 3.4.3 branch in the opencv repo

cd opencv
git checkout master
git pull
git checkout 3.4.3
git checkout -b my-3.4.3

Then we do the same thing for contrib

cd ../opencv_contrib
git checkout master
git pull
git checkout 3.4.3
git checkout -b my-3.4.3
cd ../opencv

I have previously setup a virtualenv with pyenv for Python 3.7.0 and pip installed numpy, imutils and pyyaml

pyenv activate opencv

In the opencv repo, if this is not an upgrade

mkdir build
cd build
vim build.sh

where build.sh should contain

PREFIX_MAIN=`pyenv virtualenv-prefix`
PREFIX=`pyenv prefix`
cmake .. \
    -DCMAKE_BUILD_TYPE=RELEASE \
    -DCMAKE_INSTALL_PREFIX="$PREFIX" \
    -DOPENCV_ENABLE_NONFREE=ON \
    -DWITH_OPENGL=ON \
    -DWITH_OPENVX=ON \
    -DWITH_QT=ON \
    -DWITH_OPENCL=ON \
    -DBUILD_PNG=ON \
    -DBUILD_TIFF=ON \
    -DOPENCV_EXTRA_MODULES_PATH=~/src/opencv_root/opencv_contrib/modules \
    -DWITH_1394=OFF \
    -DWITH_AVFOUNDATION=ON \
    -DWITH_QUICKTIME=OFF \
    -DWITH_CUDA=OFF \
    -DBUILD_opencv_python2=OFF \
    -DBUILD_opencv_python3=ON \
    -DPYTHON3_EXECUTABLE="$PREFIX"/bin/python3.7 \
    -DPYTHON3_PACKAGES_PATH="$PREFIX"/lib/python3.7/site-packages \
    -DPYTHON3_LIBRARY="$PREFIX_MAIN"/lib/libpython3.7m.dylib \
    -DPYTHON3_INCLUDE_PATH="$PREFIX_MAIN"/include/python3.7m \
    -DPYTHON3_NUMPY_INCLUDE_DIRS="$PREFIX"/lib/python3.7/site-packages/numpy/core/include
\
    -DINSTALL_C_EXAMPLES=OFF \
    -DINSTALL_PYTHON_EXAMPLES=OFF \
    -DINSTALL_NAME_DIR="${CMAKE_INSTALL_PREFIX}/lib"

Now, better be safe than sorry (external dependencies might have changed since we built last time)

rm CMakeCache.txt
make clean

and then

./build.sh
make install

Test the install by running

$ python
Python 3.7.0 (default, Jul 31 2018, 23:01:49)
[Clang 6.0.1 (tags/RELEASE_601/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> import numpy as np
>>> cv2.namedWindow("image", cv2.WINDOW_NORMAL)
>>> cv2.imshow("image", np.array([0, 128, 255]))
>>> cv2.waitKey(0)

If the QT window shows up – success!

Autumn storm so no practice

less than 1 minute read

The last week has given Sweden far too much wind for me to be able to practice using the canvas. This is a problem I did not really foresee and since autumn means wind pretty much every day, this is something we need to work with in the long run. Perhaps one could use some kind of dense netting instead?

Seventh shot session. How dark is too dark?

less than 1 minute read

I have a few different video sets I want to generate in order to be able to test for invariance to various conditions, one of which is low light. When I started shooting, it was not that dark and I continued shooting rounds of pucks as the sun set.

I stopped when it got too dark to find the pucks around the canvas, not because it was too dark to practice. Looking at the videos afterward, the later ones were too dark to use even for manual analysis. Unfortunately enough, it felt like it was going really well during some of those rounds.

275 recorded shots, I think.

One of the middle rounds in the dark test set. Personal photo by author. September 2018.

Sixth shot session

less than 1 minute read

225 recorded shots. Still windy.

Harry has taken a keen and active interest in the research. Personal photo by author. September 2018.