Opencv Undefined symbols for architecture cv:imwrite Mac osX high Sierra - c++

I downloaded GCC and opencv(3.4.1_2) in my Mac OS X high Sierra(10.13.3) through homebrew.
$ g++ --version
g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
In my "opencvtest.cpp", cv::imwrite was seen as undefined symbols for architecture but other functions such as cv::imread, cv::namedWindow worked perfectly.
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgcodecs.hpp"
#include <iostream>
using namespace cv;
int main( int argc, char** argv ) {
Mat img = imread( argv[1], -1 );
if( img.empty() ) return -1;
namedWindow( "Example1", cv::WINDOW_AUTOSIZE );
imshow( "Example1", img );
imwrite("Example1.jpg", img); //<-- error
waitKey( 0 );
destroyWindow( "Example1" );
}
Makefile was written as:
CC = g++
CFLAGS = -g -Wall -std=c++11
OPENCV = `pkg-config --cflags --libs opencv`
test: opencvtest.o
$(CC) -o $# opencvtest.o $(CFLAGS) $(OPENCV)
opencvtest.o: opencvtest.cpp
$(CC) -c opencvtest.cpp $(CFLAGS) $(OPENCV)
Compilation using g++ in terminal yielded:
In file included from /usr/local/Cellar/opencv/3.4.1_2/include/opencv2/core.hpp:54:0,
from /usr/local/Cellar/opencv/3.4.1_2/include/opencv2/highgui.hpp:46,
from /usr/local/Cellar/opencv/3.4.1_2/include/opencv2/highgui/highgui.hpp:48,
from opencvtest.cpp:2:
/usr/local/Cellar/opencv/3.4.1_2/include/opencv2/core/base.hpp:381:35: warning:unknown option after '#pragma GCC diagnostic' kind [-Wpragmas]
# pragma GCC diagnostic ignored "-Winvalid-noreturn"
^~~~~~~~~~~~~~~~~~~~
g++ -o test opencvtest.o -g -Wall -std=c++11 `pkg-config --cflags --libs opencv`
Undefined symbols for architecture x86_64:
"cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator<int> > const&)", referenced from:
_main in opencvtest.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make: *** [test] Error 1
If I commented the problematic imwrite("Example1.jpg", img);, the program worked perfectly and the image can be shown. I had reinstalled opencv3 for many times and this problem seemed to be unsolvable. Can any clever people tell me what should I do next?
Edit:Here is my opencv profile. It said that the default C++ compiler was clang++ but not g++-7.
$opencv_version -v
General configuration for OpenCV 3.4.1 =====================================
Version control: unknown
Extra modules:
Location (extra): /tmp/opencv-20180307-60086-ryy1b3/opencv-3.4.1/opencv_contrib/modules
Version control (extra): unknown
Platform:
Timestamp: 2018-03-07T08:15:55Z
Host: Darwin 17.3.0 x86_64
CMake: 3.10.2
CMake generator: Unix Makefiles
CMake build tool: /usr/local/Homebrew/Library/Homebrew/shims/super/gmake
Configuration: Release
CPU/HW features:
Baseline: SSE SSE2 SSE3
requested: SSE3
disabled: SSE4_1 SSE4_2 AVX AVX2
Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
SSE4_1 (3 files): + SSSE3 SSE4_1
SSE4_2 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2
FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
AVX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
AVX2 (9 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
AVX512_SKX (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_SKX
C/C++:
Built as dynamic libs?: YES
C++11: YES
C++ Compiler: /usr/local/Homebrew/Library/Homebrew/shims/super/clang++ (ver 9.0.0.9000039)
C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-implicit-fallthrough -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-implicit-fallthrough -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: /usr/local/Homebrew/Library/Homebrew/shims/super/clang
C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-implicit-fallthrough -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-implicit-fallthrough -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release):
Linker flags (Debug):
ccache: NO
Precompiled headers: NO
Extra dependencies: /usr/local/lib/libtbb.dylib
3rdparty dependencies:
OpenCV modules:
To be built: aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann fuzzy hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python2 python3 python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
Disabled: js world
Disabled by dependency: -
Unavailable: cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv dnn_modern freetype hdf java matlab ovis sfm ts viz
Applications: apps
Documentation: NO
Non-free algorithms: YES
GUI:
Cocoa: YES
Media I/O:
ZLib: /usr/lib/libz.dylib (ver 1.2.11)
JPEG: build (ver 90)
WEBP: build (ver encoder: 0x020e)
PNG: /usr/local/lib/libpng.dylib (ver 1.6.34)
TIFF: /usr/local/lib/libtiff.dylib (ver 42 / 4.0.9)
OpenEXR: /usr/local/lib/libImath.dylib /usr/local/lib/libIlmImf.dylib /usr/local/lib/libIex.dylib /usr/local/lib/libHalf.dylib /usr/local/lib/libIlmThread.dylib (ver 2.2.0)
Video I/O:
FFMPEG: YES
avcodec: YES (ver 57.107.100)
avformat: YES (ver 57.83.100)
avutil: YES (ver 55.78.100)
swscale: YES (ver 4.8.100)
avresample: YES (ver 3.7.0)
AVFoundation: YES
Parallel framework: TBB (ver 2018.0 interface 10002)
Trace: YES (with Intel ITT)
Other third-party libraries:
Intel IPP: 2017.0.3 [2017.0.3]
at: /tmp/opencv-20180307-60086-ryy1b3/opencv-3.4.1/build/3rdparty/ippicv/ippicv_mac
Intel IPP IW: sources (2017.0.3)
at: /tmp/opencv-20180307-60086-ryy1b3/opencv-3.4.1/build/3rdparty/ippicv/ippiw_mac
Lapack: YES (/System/Library/Frameworks/Accelerate.framework /System/Library/Frameworks/Accelerate.framework)
Eigen: YES (ver 3.3.4)
Custom HAL: NO
Protobuf: build (3.5.1)
OpenCL: YES (no extra features)
Include path: NO
Link libraries: -framework OpenCL
Python 2:
Interpreter: /usr/local/opt/python#2/libexec/bin/python (ver 2.7.14)
Libraries: /usr/local/Cellar/python#2/2.7.14_1/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib (ver 2.7.14)
numpy: /usr/local/lib/python2.7/site-packages/numpy/core/include (ver 1.14.1)
packages path: lib/python2.7/site-packages
Python 3:
Interpreter: /usr/local/opt/python/bin/python3 (ver 3.6.4)
Libraries: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-darwin/libpython3.6.dylib (ver 3.6.4)
numpy: /usr/local/lib/python3.6/site-packages/numpy/core/include (ver 1.14.1)
packages path: lib/python3.6/site-packages
Python (for build): /usr/local/opt/python#2/libexec/bin/python
Java:
ant: NO
JNI: /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/include /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/include/darwin /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/include
Java wrappers: NO
Java tests: NO
Matlab: NO
Install to: /usr/local/Cellar/opencv/3.4.1_2
-----------------------------------------------------------------
Thus one only used clang++ instead of g++ with or without CFLAG = -g and compilation worked well. I wondered if one can change opencv default compiler from clang++ to g++?

As I suggested in the comments, this is likely to work if you use the clang++ compiler in place of GNU g++, which is why I suggested you run:
opencv_version -v
If you look at the output, specifically the line that starts C++ Compiler: you can see that OpenCV was compiled with a derivative of clang++.
I have generally "just gone with flow" and used the same compiler as OpenCV was built with, but I guess there are other options.
I guess you could either:
force OpenCV to compile with g++, or
force g++ to compile your application such that it can link with OpenCV compiled with clang++.
I have tested the first suggestion above, namely compiling OpenCV with the GNU compiler and that works like this:
cmake -D CMAKE_CXX_COMPILER=/usr/local/bin/g++-7 -D CMAKE_C_COMPILER=/usr/local/bin/gcc-7 ...
make -j8
make install
I guess the latter is done with something like:
g++ YourApp.cpp -std=C++11 -stdlib=libstdc++ $(pkg-config ...) -o YourApp
But if anyone knows better, PLEASE COMMENT and I'll update the advice!

Almost is because not link the proper library. Find by yourself is difficult.
I solve that by
g++ HelloWorld.cpp -o hello `pkg-config --cflags --libs opencv`
My source file is HelloWorld.cpp, and you can run pkg-config --cflags --libs opencv alone. It just print the params about include header and link library:
$ pkg-config --cflags --libs opencv
-I/usr/local/include/opencv -I/usr/local/include -L/usr/local/lib -lopencv_dnn -lopencv_ml -lopencv_objdetect -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_video -lopencv_photo -lopencv_imgproc -lopencv_flann -lopencv_core
My source file is
#include <iostream>
#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
And i test the really problem by put params that pkg-config --cflags --libs opencv product one by one. Finally I find my problem is not set
-I/usr/local/include/opencv -I/usr/local/include
. That really killing me. I forget to set header directory......

Related

Opencv on MacOS Xcode can not use imread to read image based on C++

I am not sure why I cannot read an image by using imread function and the details about my code are as the following.
#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
int main(int argc, const char * argv[])
{
cv::Mat scrImage = cv::imread("/Users⁩/zsk⁩/Downloads⁩/zsk.JPEG", CV_LOAD_IMAGE_COLOR);
if(scrImage.empty())
{
std::cout << "something wrong" << std::endl;
return -1;
}
cv::Mat scrGray;
cv::cvtColor(scrImage, scrGray, CV_RGB2GRAY);
cv::imshow("scrGray", scrGray);
cv::Mat blurDstImage;
blur(scrGray, blurDstImage, cv::Size(5, 5), cv::Point(-1, 1));
cv::imshow("blurDstImage", blurDstImage);
cv::imwrite("/Users⁩/zsk⁩/Downloads⁩/blurgirl.jpg", blurDstImage);
cv::waitKey(0);
return 0;
}
General configuration for OpenCV 3.4.3 =====================================
Version control: unknown
Extra modules:
Location (extra): /tmp/opencv-20181001-83194-s618mv/opencv-3.4.3/opencv_contrib/modules
Version control (extra): unknown
Platform:
Timestamp: 2018-10-01T12:58:23Z
Host: Darwin 18.0.0 x86_64
CMake: 3.12.2
CMake generator: Unix Makefiles
CMake build tool: /usr/local/Homebrew/Library/Homebrew/shims/mac/super/gmake
Configuration: Release
CPU/HW features:
Baseline: SSE SSE2 SSE3 SSSE3
requested: DETECT
disabled: SSE4_1 SSE4_2 AVX AVX2
Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
SSE4_1 (3 files): + SSE4_1
SSE4_2 (1 files): + SSE4_1 POPCNT SSE4_2
FP16 (1 files): + SSE4_1 POPCNT SSE4_2 FP16 AVX
AVX (5 files): + SSE4_1 POPCNT SSE4_2 AVX
AVX2 (9 files): + SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
AVX512_SKX (1 files): + SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_SKX
C/C++:
Built as dynamic libs?: YES
C++11: YES
C++ Compiler: /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang++ (ver 10.0.0.10001145)
C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -msse -msse2 -msse3 -mssse3 -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -msse -msse2 -msse3 -mssse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: /usr/local/Homebrew/Library/Homebrew/shims/mac/super/clang
C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -msse -msse2 -msse3 -mssse3 -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Winconsistent-missing-override -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -ffunction-sections -fdata-sections -msse -msse2 -msse3 -mssse3 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release):
Linker flags (Debug):
ccache: NO
Precompiled headers: NO
Extra dependencies:
3rdparty dependencies:
OpenCV modules:
To be built: aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann fuzzy hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python2 python3 python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching tracking video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
Disabled: js text world
Disabled by dependency: -
Unavailable: cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java matlab ovis sfm ts viz
Applications: apps
Documentation: NO
Non-free algorithms: YES
GUI:
Cocoa: YES
Media I/O:
ZLib: /usr/lib/libz.dylib (ver 1.2.11)
JPEG: build-libjpeg-turbo (ver 1.5.3-62)
WEBP: build (ver encoder: 0x020e)
PNG: /usr/local/lib/libpng.dylib (ver 1.6.35)
TIFF: /usr/local/lib/libtiff.dylib (ver 42 / 4.0.9)
OpenEXR: /usr/local/lib/libImath.dylib /usr/local/lib/libIlmImf.dylib /usr/local/lib/libIex.dylib /usr/local/lib/libHalf.dylib /usr/local/lib/libIlmThread.dylib (ver 2.2.0)
HDR: YES
SUNRASTER: YES
PXM: YES
Video I/O:
FFMPEG: YES
avcodec: YES (ver 58.18.100)
avformat: YES (ver 58.12.100)
avutil: YES (ver 56.14.100)
swscale: YES (ver 5.1.100)
avresample: YES (ver 4.0.0)
AVFoundation: YES
Parallel framework: TBB (ver 2018.0 interface 10005)
Trace: YES (with Intel ITT)
Other third-party libraries:
Intel IPP: 2017.0.3 [2017.0.3]
at: /tmp/opencv-20181001-83194-s618mv/opencv-3.4.3/build/3rdparty/ippicv/ippicv_mac
Intel IPP IW: sources (2017.0.3)
at: /tmp/opencv-20181001-83194-s618mv/opencv-3.4.3/build/3rdparty/ippicv/ippiw_mac
Lapack: YES (/System/Library/Frameworks/Accelerate.framework /System/Library/Frameworks/Accelerate.framework)
Eigen: YES (ver 3.3.5)
Custom HAL: NO
Protobuf: build (3.5.1)
OpenCL: YES (no extra features)
Include path: NO
Link libraries: -framework OpenCL
Python 2:
Interpreter: /usr/local/opt/python#2/bin/python (ver 2.7.15)
Libraries: /usr/local/Cellar/python#2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib (ver 2.7.15)
numpy: /usr/local/lib/python2.7/site-packages/numpy/core/include (ver 1.15.1)
packages path: lib/python2.7/site-packages
Python 3:
Interpreter: /usr/local/opt/python/bin/python3 (ver 3.7)
Libraries: /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/config-3.7m-darwin/libpython3.7.dylib (ver 3.7.0)
numpy: /usr/local/lib/python3.7/site-packages/numpy/core/include (ver 1.15.1)
packages path: lib/python3.7/site-packages
Python (for build): /usr/local/opt/python#2/bin/python
Java:
ant: NO
JNI: /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home/include /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home/include/darwin /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home/include
Java wrappers: NO
Java tests: NO
Matlab: NO
Install to: /usr/local/Cellar/opencv/3.4.3
Finally, I find that the problem is that Opencv is header only which needs to special compile.

cv::parallel_for_ not very big improvement

I'm testing the class cv::ParallelLoopBody for image processing code.
I first started implementing the normalization, where I've to divide all the pixels with certain values for each channel, which is an easy nice parallelized code.
However, when testing it, I don't see any difference.
Am I doing something wrong here?
This is my class:
class Parallel_process : public cv::ParallelLoopBody
{
private:
cv::Mat img; //my image to normalize
std::vector<int> A;
int diff;
public:
Parallel_process(cv::Mat inputImage, std::vector<int> AA, int diffVal)
: img(inputImage), A(AA), diff(diffVal){}
virtual void operator()(const cv::Range& range) const
{
for(int i = range.start; i < range.end; i++)
{
//in is a patch of my original image
cv::Mat in(img, cv::Rect(0, (img.rows/diff)*i, img.cols, img.rows/diff));
std::vector<int> AAA (A);
in.forEach<cv::Vec3f>
(
[&AAA](cv::Vec3f &pixel, const int* po) -> void
{
pixel[0]/=AAA[0];
pixel[1]/=AAA[1];
pixel[2]/=AAA[2];
}
);
}
}
};
and in main() function I'm calling my operator like so:
cv::parallel_for_(cv::Range(0, 91), Parallel_process(img, AA, 91)); //my image is 1288*728 size so 728/91=8
EDIT
This my OpenCV configuation:
General configuration for OpenCV 3.3.1 =====================================
Version control: unknown
Extra modules:
Location (extra): /home/jrsros/opencv_contrib-3.3.1/modules
Version control (extra): unknown
Platform:
Timestamp: 2017-12-14T13:05:47Z
Host: Linux 4.10.0-40-generic x86_64
CMake: 3.5.1
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/make
Configuration: Release
CPU/HW features:
Baseline: SSE SSE2 SSE3
requested: SSE3
Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2
requested: SSE4_1 SSE4_2 AVX FP16 AVX2
SSE4_1 (3 files): + SSSE3 SSE4_1
SSE4_2 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2
FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
AVX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
AVX2 (8 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
C/C++:
Built as dynamic libs?: YES
C++11: YES
C++ Compiler: /usr/bin/c++ (ver 7.2.0)
C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -Wno-implicit-fallthrough -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -Wno-implicit-fallthrough -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -fopenmp -g -O0 -DDEBUG -D_DEBUG
C Compiler: /usr/bin/gcc-5
C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -msse -msse2 -msse3 -fvisibility=hidden -fopenmp -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffast-math -ffunction-sections -msse -msse2 -msse3 -fvisibility=hidden -fopenmp -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release):
Linker flags (Debug):
ccache: NO
Precompiled headers: NO
Extra dependencies: dl m pthread rt /usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libtbb.so cudart nppc nppial nppicc nppicom nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cufft -L/usr/local/cuda-8.0/lib64
3rdparty dependencies:
OpenCV modules:
To be built: cudev core cudaarithm flann hdf imgproc ml objdetect phase_unwrapping plot reg surface_matching video viz xphoto bgsegm cudabgsegm cudafilters cudaimgproc cudawarping dnn face freetype fuzzy img_hash imgcodecs photo shape videoio xobjdetect cudacodec highgui bioinspired dpm features2d line_descriptor saliency text calib3d ccalib cudafeatures2d cudalegacy cudaobjdetect cudaoptflow cudastereo datasets rgbd stereo structured_light superres tracking videostab xfeatures2d ximgproc aruco optflow stitching python2
Disabled: js world contrib_world
Disabled by dependency: -
Unavailable: java python3 ts cnn_3dobj cvv dnn_modern matlab sfm
GUI:
QT: NO
GTK+ 2.x: YES (ver 2.24.30)
GThread : YES (ver 2.48.2)
GtkGlExt: YES (ver 1.2.0)
OpenGL support: YES (/usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGL.so)
VTK support: YES (ver 6.2.0)
Media I/O:
ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
WEBP: /usr/lib/x86_64-linux-gnu/libwebp.so (ver encoder: 0x0202)
PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)
TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 4.0.6)
JPEG 2000: /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
OpenEXR: build (ver 1.7.1)
GDAL: NO
GDCM: NO
Video I/O:
DC1394 1.x: NO
DC1394 2.x: NO
FFMPEG: YES
avcodec: YES (ver 56.60.100)
avformat: YES (ver 56.40.101)
avutil: YES (ver 54.31.100)
swscale: YES (ver 3.1.101)
avresample: NO
GStreamer:
base: YES (ver 1.8.3)
video: YES (ver 1.8.3)
app: YES (ver 1.8.3)
riff: YES (ver 1.8.3)
pbutils: YES (ver 1.8.3)
OpenNI: NO
OpenNI PrimeSensor Modules: NO
OpenNI2: NO
PvAPI: NO
GigEVisionSDK: NO
Aravis SDK: NO
UniCap: NO
UniCap ucil: NO
V4L/V4L2: NO/YES
XIMEA: NO
Xine: NO
Intel Media SDK: NO
gPhoto2: NO
Parallel framework: TBB (ver 4.4 interface 9002)
Trace: YES (with Intel ITT)
Other third-party libraries:
Use Intel IPP: 2017.0.3 [2017.0.3]
at: /home/jrsros/opencv-3.3.1/build/3rdparty/ippicv/ippicv_lnx
Use Intel IPP IW: sources (2017.0.3)
at: /home/jrsros/opencv-3.3.1/build/3rdparty/ippicv/ippiw_lnx
Use VA: NO
Use Intel VA-API/OpenCL: NO
Use Lapack: NO
Use Eigen: YES (ver 3.2.92)
Use Cuda: YES (ver 8.0)
Use OpenCL: YES
Use OpenVX: NO
Use custom HAL: NO
NVIDIA CUDA
Use CUFFT: YES
Use CUBLAS: YES
USE NVCUVID: NO
NVIDIA GPU arch: 20 30 35 37 50 52 60 61
NVIDIA PTX archs:
Use fast math: YES
OpenCL: <Dynamic loading of OpenCL library>
Include path: /home/jrsros/opencv-3.3.1/3rdparty/include/opencl/1.2
Use AMDFFT: NO
Use AMDBLAS: NO
Python 2:
Interpreter: /usr/bin/python2.7 (ver 2.7.12)
Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.12)
numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.11.0)
packages path: lib/python2.7/dist-packages
Python 3:
Interpreter: /usr/bin/python3 (ver 3.5.2)
Python (for build): /usr/bin/python2.7
Java:
ant: NO
JNI: NO
Java wrappers: NO
Java tests: NO
Matlab:
mex: /usr/local/MATLAB/R2017b/bin/mex
Compiler/generator: Not working (bindings will not be generated)
Documentation:
Doxygen: NO
Tests and samples:
Tests: NO
Performance tests: NO
C/C++ Examples: NO
Install path: /usr/local
cvconfig.h is in: /home/jrsros/opencv-3.3.1/build
-----------------------------------------------------------------
An example of code I'm using to test my parallelism:
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/core/utility.hpp>
#include <iostream>
#include <sys/time.h>
class Parallel_process : public cv::ParallelLoopBody
{
private:
cv::Mat img;
std::vector<int> A;
int diff;
public:
Parallel_process(cv::Mat inputImgage, std::vector<int> AA, int diffVal)
: img(inputImgage), A(AA), diff(diffVal){}
virtual void operator()(const cv::Range& range) const
{
for(int i = range.start; i < range.end; i++)
{
cv::Mat in(img, cv::Rect(0, (img.rows/diff)*i, img.cols, img.rows/diff));
std::vector<int> AAA (A);
in.forEach<cv::Vec3f>
(
[&AAA](cv::Vec3f &pixel, const int* po) -> void
{
pixel[0]/=AAA[0];
pixel[1]/=AAA[1];
pixel[2]/=AAA[2];
}
);
}
}
};
int main(int argc, char* argv[])
{
cv::Mat src=cv::imread(argv[1]);
std::vector<std::vector<int> > AA;
//compute AA here
double timeStart=tic(), timeEnd=0;
//Normalize the image /AA
cv::parallel_for_(cv::Range(0, 91), Parallel_process(src, AA, 91));
timeEnd = tic() - timeStart;
std::cout << "ALL " <<1/timeEnd << std::endl<< std::endl; //FPS
return 0;
}
I'm compiling my code on linux ubuntu Core i7-2630QM 2Ghz * 8 threads (4 cores):
g++ -std=c++1z -Wall -Weffc++ -Ofast -march=native test4.cpp -o test4 `pkg-config --cflags --libs opencv`
EDIT2
In htop I see that it is using all the threads at the end
1 2 3 4 5 6 7 8
Variant 1
threads,mean(us),min(us),max(us)
1,18798.2,18106,22780
2,9762.84,9427,10397
3,6813.55,6765,9296
4,5317.75,5088,7433
5,5067.11,4931,7552
6,4925.41,4780,9473
7,4797.74,4641,9492
8,4798.18,4504,27244
1 2 3 4 5 6 7 8
Variant 2
threads,mean(us),min(us),max(us)
1,18512.8,17780,20084
2,9788.73,9302,11338
3,6850.47,6671,9765
4,5209.64,5022,8831
5,5052.46,4881,7041
6,6851.99,4762,11422
7,5077.32,4624,9886

C++ openCV - createFisherFaceRecognizer was not declared in this scope

I am trying to make a facerecognizer in C++ using openCV. But keep getting the following errors:
1) cv::face::createFisherFaceRecognizer(int, double), but this gives:
main.cpp:(.text+0x6a8): undefined reference to`cv::face::createFisherFaceRecognizer(int, double)'
2)face::FisherFaceRecognizer::create(), but this gives:
error: ‘cv::face::FisherFaceRecognizer’ has not been declared
None of those work, what is the correct way so I can run my code (none of those commented lines worked...)?
I even reinstalled everything, because no one could help me out. This is the current situation:
General configuration for OpenCV 3.2.0 =====================================
Version control: unknown
Extra modules:
Location (extra): /home/yalishanda/Downloads/opencv_contrib-3.2.0/modules
Version control (extra): unknown
Platform:
Timestamp: 2017-07-04T08:29:50Z
Host: Linux 4.8.0-36-generic x86_64
CMake: 3.5.1
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/make
Configuration: Release
C/C++:
Built as dynamic libs?: YES
C++ Compiler: /usr/bin/c++ (ver 5.4.0)
C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: /usr/bin/cc
C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wno-narrowing -Wno-comment -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release):
Linker flags (Debug):
ccache: NO
Precompiled headers: YES
Extra dependencies: /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/x86_64-linux-gnu/libz.so gtk-x11-2.0 gdk-x11-2.0 pangocairo-1.0 atk-1.0 cairo gdk_pixbuf-2.0 gio-2.0 pangoft2-1.0 pango-1.0 gobject-2.0 fontconfig freetype gthread-2.0 glib-2.0 dl m pthread rt
3rdparty dependencies: libjpeg libwebp libtiff libjasper IlmImf libprotobuf
OpenCV modules:
To be built: core flann imgproc ml photo reg surface_matching video dnn freetype fuzzy imgcodecs shape videoio highgui objdetect plot superres ts xobjdetect xphoto bgsegm bioinspired dpm face features2d line_descriptor saliency text calib3d ccalib datasets rgbd stereo tracking videostab xfeatures2d ximgproc aruco optflow phase_unwrapping stitching structured_light
Disabled: world contrib_world
Disabled by dependency: -
Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java python2 python3 viz cnn_3dobj cvv hdf matlab sfm
GUI:
QT: NO
GTK+ 2.x: YES (ver 2.24.30)
GThread : YES (ver 2.48.2)
GtkGlExt: NO
OpenGL support: NO
VTK support: NO
Media I/O:
ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
JPEG: libjpeg (ver 90)
WEBP: build (ver 0.3.1)
PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)
TIFF: build (ver 42 - 4.0.2)
JPEG 2000: build (ver 1.900.1)
OpenEXR: build (ver 1.7.1)
GDAL: NO
GDCM: NO
Video I/O:
DC1394 1.x: NO
DC1394 2.x: NO
FFMPEG: NO
avcodec: NO
avformat: NO
avutil: NO
swscale: NO
avresample: NO
GStreamer: NO
OpenNI: NO
OpenNI PrimeSensor Modules: NO
OpenNI2: NO
PvAPI: NO
GigEVisionSDK: NO
Aravis SDK: NO
UniCap: NO
UniCap ucil: NO
V4L/V4L2: NO/YES
XIMEA: NO
Xine: NO
gPhoto2: NO
Parallel framework: pthreads
Other third-party libraries:
Use IPP: 9.0.1 [9.0.1]
at: /home/yalishanda/Downloads/opencv-3.2.0/build/3rdparty/ippicv/ippicv_lnx
Use IPP Async: NO
Use VA: NO
Use Intel VA-API/OpenCL: NO
Use Lapack: NO
Use Eigen: NO
Use Cuda: NO
Use OpenCL: YES
Use OpenVX: NO
Use custom HAL: NO
OpenCL: <Dynamic loading of OpenCL library>
Include path: /home/yalishanda/Downloads/opencv-3.2.0/3rdparty/include/opencl/1.2
Use AMDFFT: NO
Use AMDBLAS: NO
Python 2:
Interpreter: /usr/bin/python2.7 (ver 2.7.12)
Python 3:
Interpreter: /usr/bin/python3 (ver 3.5.2)
Python (for build): /usr/bin/python2.7
Java:
ant: NO
JNI: NO
Java wrappers: NO
Java tests: NO
Matlab: Matlab not found or implicitly disabled
Documentation:
Doxygen: NO
Tests and samples:
Tests: YES
Performance tests: YES
C/C++ Examples: NO
Install path: /usr/local
cvconfig.h is in: /home/yalishanda/Downloads/opencv-3.2.0/build
-----------------------------------------------------------------
This is the command with which I compile: (https://pastebin.com/raw/1EB7jXZd)
g++ src/faceDetection.cpp src/faceRecognition.cpp main.cpp -L/usr/local/lib -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dpm -lopencv_fuzzy -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_plot -lopencv_dnn -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core -o main
sort of speaking already linking almost every library that exists in openCV.... What else can I add?
createFisherFaceRecognizer() must be declared before being used. Most likely you are missing an header file (.h). I couldn't understand from the doc which one is it. You must find which one declares this function.

OpenCV waitKey() function always returns 255 on mac

I tested the OpenCV waitKey() function on Mac (version 10.12.2) but it didn't seem to work correctly. It always return 255 when no keys pressed as well as any key pressed! I'm wondering whether it's incorrectly installed or it's a bug in OpenCV itself. Any idea to fix it would be appreciated.
Here the source code of my program:
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
int main() {
int ch;
cv::namedWindow("Test waitKey()", cv::WINDOW_AUTOSIZE);
cv::Mat image = cv::Mat(100,100,CV_8U, cv::Scalar(0));
cv::imshow("Test waitKey()", image);
for (;;){
ch = cv::waitKey(1000);
std::cout << ch << std::endl; // always return 255
// and this if statement will never be executed!
if (ch == 'q') break;
}
return 0;
}
And here the output of cv::getBuildInformation() function:
General configuration for OpenCV 3.2.0
=====================================
Version control: unknown
Platform:
Timestamp: 2017-01-14T14:50:25Z
Host: Darwin 16.3.0 x86_64
CMake: 3.7.2
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/make
Configuration: RELEASE
C/C++:
Built as dynamic libs?: YES
C++ Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ (ver 8.0.0.8000042)
C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -fno-omit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -fno-omit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -fno-omit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -fno-omit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release):
Linker flags (Debug):
ccache: NO
Precompiled headers: NO
Extra dependencies: -framework OpenCL -framework Cocoa -framework AVFoundation -framework CoreGraphics -framework CoreMedia -framework CoreVideo -framework QuartzCore -framework Accelerate
3rdparty dependencies: libjpeg libwebp libpng libtiff libjasper IlmImf zlib
OpenCV modules:
To be built: core flann imgproc ml photo video imgcodecs shape videoio highgui objdetect superres ts features2d calib3d stitching videostab python2
Disabled: world
Disabled by dependency: -
Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java python3 viz
GUI:
QT: NO
Cocoa: YES
OpenGL support: NO
VTK support: NO
Media I/O:
ZLib: build (ver 1.2.8)
JPEG: build (ver 90)
WEBP: build (ver 0.3.1)
PNG: build (ver 1.6.24)
TIFF: build (ver 42 - 4.0.2)
JPEG 2000: build (ver 1.900.1)
OpenEXR: build (ver 1.7.1)
GDAL: NO
GDCM: NO
Video I/O:
DC1394 1.x: NO
DC1394 2.x: NO
FFMPEG: NO
avcodec: NO
avformat: NO
avutil: NO
swscale: NO
avresample: NO
GStreamer: NO
OpenNI: NO
OpenNI PrimeSensor Modules: NO
OpenNI2: NO
PvAPI: NO
GigEVisionSDK: NO
Aravis SDK: NO
AVFoundation: YES
V4L/V4L2: NO/NO
XIMEA: NO
gPhoto2: NO
Parallel framework: GCD
Other third-party libraries:
Use IPP: 9.0.1 [9.0.1]
at: /Users/ngoclinhng/opencv/release/3rdparty/ippicv/ippicv_osx
Use IPP Async: NO
Use VA: NO
Use Intel VA-API/OpenCL: NO
Use Lapack: YES (-framework Accelerate)
Use Eigen: NO
Use Cuda: NO
Use OpenCL: YES
Use OpenVX: NO
Use custom HAL: NO
OpenCL: <Link with OpenCL library>
Link libraries: -framework OpenCL
Use AMDFFT: NO
Use AMDBLAS: NO
Python 2:
Interpreter: /usr/bin/python2.7 (ver 2.7.10)
Libraries: /usr/lib/libpython2.7.dylib (ver 2.7.10)
numpy: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include (ver 1.8.0rc1)
packages path: lib/python2.7/site-packages
Python 3:
Interpreter: /Users/ngoclinhng/anaconda/bin/python3 (ver 3.5.2)
Python (for build): /usr/bin/python2.7
Java:
ant: NO
JNI: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/JavaVM.framework/Headers /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/JavaVM.framework/Headers /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/JavaVM.framework/Headers
Java wrappers: NO
Java tests: NO
Matlab: Matlab not found or implicitly disabled
Documentation:
Doxygen: NO
Tests and samples:
Tests: YES
Performance tests: YES
C/C++ Examples: NO
Install path: /usr/local
cvconfig.h is in: /Users/ngoclinhng/opencv/release
-----------------------------------------------------------------
You should use cvWaitKey(n) instead~
After OpenCV 3.1, cv::waitKey(n) return value changed from -1 to 255 when no keydown during the n millis.
You normally have to and the result with 255 to mask extraneous bits out:
key = cv::waitKey(1000) & 255;
Extraneous bits might be the shift or control key etc. They are OS-dependent.
The keypresses being detected also depends on which window you have selected - you need to have the image window selected (having the focus) IIRC for keypresses to be detected - rather than the Terminal window from which you launched your program.

How to know which flags have been set for OpenCV 2.3.1 built on Ubuntu 12.04?

I need to work on a computer, not mine, where OpenCV is already built. However, I would like to know which flags have been set when it was built, e.g. WITH_TBB= , WITH_CUDA= , and so on. Is there a way to get this information from some file?
Just run this:
#include <opencv2/opencv.hpp>
#include <iostream>
int main()
{
// Get build information
std::cout << cv::getBuildInformation();
}
It produces output like this:
General configuration for OpenCV 3.0.0 =====================================
Version control: unknown
Platform:
Host: Darwin 15.0.0 x86_64
CMake: 3.3.2
CMake generator: Unix Makefiles
CMake build tool: /usr/local/Library/ENV/4.3/gmake
Configuration: Release
C/C++:
Built as dynamic libs?: YES
C++ Compiler: /usr/local/Library/ENV/4.3/clang++ (ver 7.0.0.7000176)
C++ flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -fno-omit-frame-pointer -msse -msse2 -mavx -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG
C++ flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -fno-omit-frame-pointer -msse -msse2 -mavx -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
C Compiler: /usr/local/Library/ENV/4.3/clang
C flags (Release): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -fno-omit-frame-pointer -msse -msse2 -mavx -fvisibility=hidden -fvisibility-inlines-hidden -DNDEBUG
C flags (Debug): -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -fno-omit-frame-pointer -msse -msse2 -mavx -fvisibility=hidden -fvisibility-inlines-hidden -g -O0 -DDEBUG -D_DEBUG
Linker flags (Release):
Linker flags (Debug):
Precompiled headers: NO
Extra dependencies: -framework OpenCL -framework Cocoa /usr/local/opt/jpeg/lib/libjpeg.dylib /usr/local/lib/libwebp.dylib /usr/local/lib/libpng.dylib /usr/local/lib/libtiff.dylib /usr/local/lib/libImath.dylib /usr/local/lib/libIlmImf.dylib /usr/local/lib/libIex.dylib /usr/local/lib/libHalf.dylib /usr/local/lib/libIlmThread.dylib /usr/lib/libz.dylib -framework QTKit -framework QuartzCore -framework AppKit
3rdparty dependencies: ippicv
OpenCV modules:
To be built: hal core flann imgproc ml photo video imgcodecs shape videoio highgui objdetect superres ts features2d calib3d stitching videostab python2
Disabled: world
Disabled by dependency: -
Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java python3 viz
GUI:
QT: NO
Cocoa: YES
OpenGL support: NO
VTK support: NO
Media I/O:
ZLib: /usr/lib/libz.dylib (ver 1.2.5)
JPEG: /usr/local/opt/jpeg/lib/libjpeg.dylib (ver 80)
WEBP: /usr/local/lib/libwebp.dylib (ver encoder: 0x0202)
PNG: /usr/local/lib/libpng.dylib (ver 1.6.18)
TIFF: /usr/local/lib/libtiff.dylib (ver 42 - 4.0.6)
JPEG 2000: NO
OpenEXR: /usr/local/lib/libImath.dylib /usr/local/lib/libIlmImf.dylib /usr/local/lib/libIex.dylib /usr/local/lib/libHalf.dylib /usr/local/lib/libIlmThread.dylib (ver 2.2.0)
GDAL: NO
Video I/O:
DC1394 1.x: NO
DC1394 2.x: NO
FFMPEG: NO
codec: NO
format: NO
util: NO
swscale: NO
resample: NO
gentoo-style: NO
GStreamer: NO
OpenNI: NO
OpenNI PrimeSensor Modules: NO
OpenNI2: NO
PvAPI: NO
GigEVisionSDK: NO
QuickTime: NO
QTKit: YES
V4L/V4L2: NO/NO
XIMEA: NO
gPhoto2: NO
Other third-party libraries:
Use IPP: 8.2.1 [8.2.1]
at: /tmp/opencv320151102-4718-8kzykk/opencv-3.0.0/3rdparty/ippicv/unpack/ippicv_osx
Use IPP Async: NO
Use Eigen: YES (ver 3.2.6)
Use TBB: NO
Use OpenMP: NO
Use GCD YES
Use Concurrency NO
Use C=: NO
Use pthreads for parallel for:
NO
Use Cuda: NO
Use OpenCL: YES
OpenCL:
Version: static
libraries: -framework OpenCL
Use AMDFFT: NO
Use AMDBLAS: NO
Python 2:
Interpreter: /usr/bin/python (ver 2.7.10)
Libraries: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib (ver 2.7.10)
numpy: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include (ver 1.8.0rc1)
packages path: lib/python2.7/site-packages
Python 3:
Interpreter: NO
Python (for build): /usr/bin/python
Java:
ant: NO
JNI: /System/Library/Frameworks/JavaVM.framework/Headers /System/Library/Frameworks/JavaVM.framework/Headers /System/Library/Frameworks/JavaVM.framework/Headers
Java wrappers: NO
Java tests: NO
Matlab:
mex: NO
Documentation:
Doxygen: NO
PlantUML: NO
Tests and samples:
Tests: YES
Performance tests: YES
C/C++ Examples: NO
Install path: /usr/local/Cellar/opencv3/3.0.0
cvconfig.h is in: /tmp/opencv320151102-4718-8kzykk/opencv-3.0.0/macbuild
-----------------------------------------------------------------