As the message says, you need to rebuild the library using gtk. Go into your OpenCV folder and create a new folder called Release.
cd ~/OpenCV mkdir Release cd Release
Now you need to rebuild OpenCV. Use the following command
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_GTK=ON -D WITH_OPENGL=ON ..
Remember to use WITH_GTK=ON
when building. After that, enter the following command
make sudo make install
Now run your code. This should make it work. You can delete the old folder.
source share