A Small Tip on CMake and QT Development Environment

OpenCV Version: 4.2.0

OpenCV-Contrib Version: 4.2.0

CMake Version: 3.20.0

When developing image algorithms with OpenCV, being able to display the pixel where the mouse falls on the image can greatly improve development efficiency.

I searched this issue and found that most bloggers use callback functions to solve it, which not only adds extra complexity but may not yield good results.

At this point, we need to use cmake-gui to build the makefile.

Step One:

Click on configure:

A Small Tip on CMake and QT Development Environment

Step Two:

Add the variable QT5_DIR directory, and check the variables and set their values according to your needs:

A Small Tip on CMake and QT Development Environment

Step Three:

Click Generate to create the makefile in the corresponding build directory.

Then, in the current directory, enter: make and sudo make install, which will produce the dynamic library and header files in the corresponding directory.

The effect is shown below:

A Small Tip on CMake and QT Development Environment

In the lower left corner, the mouse position coordinates and corresponding pixel map can be displayed.

I also tried to build the project using the command line and found that cmake could not locate the QT directory. The specific reason is unclear, but using cmake-gui achieves the goal.

For compiling OpenCV source code with cmake, please refer to the article: OpenCV Learning (1) OpenCV Source Code Installation.

A Small Tip on CMake and QT Development Environment

Leave a Comment