#include "opencv2/core.hpp" should be moved to the external header, otherwise #include "opencv2/optim.hpp" in user's code will fail.