pkg-config can't find opencv
You have to put pkg-config --cflags --libs opencv
at the end of your g++ line. For example :
g++ test.cpp -o test `pkg-config --cflags --libs opencv`
Compiles
g++ `pkg-config --cflags --libs opencv` test.cpp -o test
Doesn't compile and have undefined reference.