Adjust color of the annotation text according to background color
When the color chosen for an annotation is too dark, the label text is barely visible, because it is show in black color. The color of the text must be changed to white for dark backgrounds.
There are several formulae to compute the relative luminance of an RGB color, for instance the L component of the CIELAB color space or the formula from ITU-R BT.709.
There is a Python module for manipulating color spaces that might be of help: colour. This page contains a simple solution for the present issue: How to calculate contrast color in Python