Ask Your Question

Pete's profile - activity

2017-02-16 03:03:05 -0500 commented question How to create a cmake project for debug and release

just checked out my link.txt file generated by cmake and it seems that it is working after all..

2017-02-15 13:17:04 -0500 asked a question How to create a cmake project for debug and release

When you build OpenCV v3.2 on ubuntu 16.04 LTS the installation creates several .cmake file. I want to use OpenCVModules-debug.cmake in a debug build and OpenCVModules-release.cmake in a release build of my project. My project CMakeLists.txt file contains:

find_package( OpenCV REQUIRED )
target_link_libraries(main ${OpenCV_LIBS} )

When I run cmake -D CMAKE_BUILD_TYPE=Debug in my project it still links against the release versions of the OpenCV libraries. How to I get cmake to use the libraries specified in OpenCVModules-debug.cmake??

Edit: Just checked the link.txt file generated by cmake and it appears to be working! Still cant step into the library code in gdb but that must be a different issue.

2017-01-24 08:07:19 -0500 received badge  Popular Question (source)
2015-11-04 03:20:16 -0500 received badge  Famous Question (source)
2014-01-03 01:14:34 -0500 received badge  Notable Question (source)
2013-10-22 16:21:39 -0500 answered a question qt and imread -> realloc(): invalid old size: 0x0000000000611a20

This problem was caused on Ubuntu 13.04 where qtcreator does not detect the qt5 installation. When I built OpenCV the OpenCV build correctly picked up the qt5 installation. When I started the Qt project (in my case OpenCVNQt) with qtcreator only qmake-qt4 was detected. So the problem I saw was a result of a mismatch between Qt5 libraries used in OpenCV and Qt4 libraries used in my project. To fix this I had to delete the Qt project file and manual add /usr/lib/x86_64-linux-gnu/qt5/bin/qmake ({Tools->Options; Build & Run; Qt Versions} See Also you have to manual add the Qt5 Kit ({Tools->Options; Build & Run; Kits}). Then I updated the project code, in particular I had to add QT += widgets to the file and change #include <qtgui> to #include <qtwidgets> (see

Now it works!

2013-10-19 17:19:21 -0500 asked a question qt and imread -> realloc(): invalid old size: 0x0000000000611a20


I am using Qt 4.8.4 and opencv- and get an odd error when running the application.

The offending line in the code is

        Mat img1 = imread(name, CV_LOAD_IMAGE_GRAYSCALE);

When I compile a simple test program without Qt libraries then OpenCV works just fine and loads the image. However when built with the Qt libraries the build works just fine but when the program is run I get

$ ./opencvnqt
*** Error in `./opencvnqt': realloc(): invalid old size: 0x00000000006119e0 ***

Does anyone know why this run time error is occuring and how to avoid it or how to debug it? FYI the build and link lines look like this:

g++ -c -m64 -pipe -g -Wall -W -D_REENTRANT -DVERSION=1.0 -DPD_NOT_SERIAL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++-64 -I../OpenCVNQt -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I/usr/local/include/opencv -I. -I. -I../OpenCVNQt -I. -o MainWindow.o MainWindow.cpp

g++ -m64 -o opencvnqt main.o MainWindow.o moc_MainWindow.o  -L/usr/lib/x86_64-linux-gnu -L /usr/local/lib -lopencv_core -lopencv_highgui -lQtGui -lQtCore -lpthread
2013-04-25 07:17:19 -0500 received badge  Popular Question (source)
2012-09-19 06:45:39 -0500 received badge  Student (source)
2012-08-28 09:14:03 -0500 received badge  Self-Learner (source)
2012-08-27 14:30:47 -0500 commented question Camera Not working

I am using SmartQ Ten3 T15 tablet with Android 4.1 Jelly Bean. Now all the OpenCV examples work and a learnt a whole lot about android and OpenCV on Android in the process.

2012-08-26 11:50:42 -0500 answered a question Error building Android OpenCV 2.4.2 Tutorial

See noisecapella's very good answer to the similar question that I asked -

Copy build.xml from a sample (specifically tutorial-2-opencvcamera), only changing the project name to "opencv". Create in that directory with sdk.dir set to my SDK location. After that it worked fine

Also, edit build.xml to run the NDK build for tutorial-3 and 4, as described here:

2012-08-26 02:54:19 -0500 answered a question Camera Not working

I have fix the problem of the camera not working. In brief I moved to latest OpenCV code, installed Android 4.1.1 on my tablet, moved to the latest Android development environment. Then I built OpenCV Manager and the camera wrapper ( is a guide but not complete). I changed the default path in camera_activity.cpp:
#define DEFAULT_WRAPPER_PACKAGE_NAME "org.opencv.lib_v24_armv7a_neon"
After the build I installed my version of the OpenCV binary_pack_armv7a_neon-release.apk and the examples began to work. Then I fixed a problem where OpenCV examples assume a backward facing camera. My tablet only has forward facing camera so 4 of the examples failed till I fixed that example code bug and now all examples work.

As you will know from reading to build modules/androidcamera/camera_wrapper and the binary pack OpenCV binary_pack_armv7a_neon-release.apk you need to have a working build of the android source for your platform. Building on 64bit Linux requires the latest Android source, plus a lot of 32bit libraries as detailed at, then follow the instructions at (I configured and built full-eng that builds the generic/system/lib libraries referenced by camera_wrapper/CMakeLists.txt).
Now the fun started for me because OpenCV does not seem to have been built as a package so here are the fixes that I have used. First I set my path up and ANDROID_NDK
export ANDROID_NDK=~/InstallPackages/android-ndk-r8b
export ANDROID_SDK=~/InstallPackages/android-sdk-linux
export ANDROID_SRC=~/Projects/Android411
export PATH=${PATH}:${ANDROID_SDK}/platform-tools:${ANDROID_SDK}/tools:${ANDROID_SDK}:${ANDROID_NDK}
then in the build folder (android/build) I ran cmake


and built the code

make -j8
make install

I use ANDROID_USE_STLPORT=OFF because various parts of OpenCV include android-ndk-r8b/sources/cxx-stl/gnu-libstdc++/include/ext/atomicity.h that does not exist in the stlport libraries that are described as "experimental" by the Android team. The side effect of this is that rtti is switched on so linking fails. So one of either include atomicity.h or linking have to be fixed. It also has the side effect that the OpenCV Manager is not built, but I have a simple fix for this. The result is that the entire OpenCV code is built and all the .apk files are produced (although OpenCV binary_pack_armv7a_neon-release-unsigned.apk has to be signed (see

Ok so here are my patches:
ERROR from the logcat output "CameraWrapperConnector::connectToLib: folderPath=/data/data/com.NativeCamera/lib/
CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library E/CV_CAP ( 1796): Native_camera returned opening error: 4 E/Sample::SurfaceView( 1796): Failed to open native camera
FIX this is the error that started it all.. fix is to build android and opencv but ... (more)

2012-08-24 17:47:02 -0500 received badge  Scholar (source)
2012-08-24 17:26:50 -0500 commented answer OpenCV-2.4.2-android-sdk missing build.xml?

Thanks that fixed it for me.

2012-08-17 11:29:29 -0500 asked a question Camera Not working

I am using the OpenCV-2.4.2-android-sdk and have problems with the camera on my target. On the emulator the sample color-blob-detection works for me so I know I have the sdk correctly configured. On target the application crashes and in the logs I get
E/CAMERA_ACTIVITY( 1940): Could not read /proc/self/smaps
D/CAMERA_ACTIVITY( 1940): CameraWrapperConnector::connectToLib: folderPath=/data/data/com.NativeCamera/lib/
E/CAMERA_ACTIVITY( 1940): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library
E/CV_CAP ( 1940): Native_camera returned opening error: 4
E/Sample-ImageManipulations::SurfaceView( 1940): Failed to open native camera

I see in the code that this is used in std::string CameraWrapperConnector::getPathLibFolder() as a default when /proc/self/smaps cant be opened. The path /data/data/com.NativeCamera AND /proc/self/smaps do not exist on my target, does this mean that the native camera is not supported on my target? Or do I have to change the name of /proc/self/smaps in the OpenCV code to map to a file that does exist on Android 4.0.3?

looking at the output from dumpsys run on my target ("adb shell dumpsys") I get the following interesting entry:

When I start the camera application on target I get the following in the logs:
I/ActivityManager( 312): START {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000} from pid 525
I/ActivityManager( 312): Start proc for activity pid=2028 uid=10007 gids={1006, 1015}

So it looks like the OpenCV code is trying to find a way to locate the nativeLibraryPath using smaps.. but smaps now does not exist on Android so OpenCV must change to find a new way to locate the correct library. Has this bug already been fixed?

2012-08-17 10:01:18 -0500 commented question OpenCV-2.4.2-android-sdk missing build.xml?

Getting a bit closer to the solution, back with Eclipse. On target I find that the same sample fails with D/CAMERA_ACTIVITY( 1796): CameraWrapperConnector::connectToLib: folderPath=/data/data/com.NativeCamera/lib/ E/CAMERA_ACTIVITY( 1796): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library E/CV_CAP ( 1796): Native_camera returned opening error: 4 E/Sample::SurfaceView( 1796): Failed to open native camera And on my target device there is no /data/data/com.NativeCamera/... And if I start my camera I get} from pid 525 I/ActivityManager( 312): Start proc for activity pid=2028 uid=10007 gids={1006, 1015}

So perhaps my camera does not use the native api

2012-08-17 03:11:31 -0500 received badge  Editor (source)
2012-08-16 16:39:13 -0500 asked a question OpenCV-2.4.2-android-sdk missing build.xml?

I am following the tutorial at and found that I have to work round some odd problems. I am using an Android 4.0.3 target and developing on Ubuntu 12.04, I have android-ndk-r8b and am using Android 4.0.3 API 15. I am using Async initialization OpenCV Manager Android service to get OpenCV libraries on the target device. The NDK samples I have tried seem to work ok but all the OpenCV samples fail on the target with either - E/Sample::SurfaceView(1724): Can't open camera! OR

E/CAMERA_ACTIVITY(2076): Could not read /proc/self/smaps 08-16 21:29:33.817: D/CAMERA_ACTIVITY(2076): CameraWrapperConnector::connectToLib: folderPath=/data/data/com.NativeCamera/lib/ 08-16 21:29:33.817: E/CAMERA_ACTIVITY(2076): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library 08-16 21:29:33.817: E/CV_CAP(2076): Native_camera returned opening error: 4 08-16 21:29:33.825: E/Sample-ImageManipulations::SurfaceView(2076): Failed to open native camera

I dropped back to command line from Eclipse to try and work out what in the environment was failing and I get an error .../android-sdk-linux/tools/ant/build.xml:569: Invalid file: .../OpenCV-2.4.2-android-sdk/sdk/java/build.xml because OpenCV-2.4.2-android-sdk/sdk/java/build.xml does not exist in the released sdk

Following appears to works ok: android update project -p . -s --target 1 ndk-build -B V=1

But then ant debug fails - [dependency] API<=15: Adding annotations.jar to the classpath. [echo] ---------- [echo] Building Libraries with 'debug'...

BUILD FAILED .../android-sdk-linux/tools/ant/build.xml:569: Invalid file: .../OpenCV-2.4.2-android-sdk/sdk/java/build.xml

Eclipse does not show this error so I am not sure what is going on or how best to tackle this problem... Perhaps I should build OpenCV with my environment - that surely would create /OpenCV-2.4.2-android-sdk/sdk/java/build.xml