What do you mean by "doesn't detect"?
Depending on the os, on linux it is often enough to add e.g.
`pkg-config opencv4 --cflags`
under Project options | other compiler options and
`pkg-config opencv4 --libs`
under other linker options. Then the compiler can find the includes and the linker the libraries.
Code completion might be a different story. I do not care a lot about it.