Simple OpenCV program crashes
Hello community,
I am currently having a problem. I am following the instructions given in this book "OpenCV 2 Computer Vison Application Programming Cookbook" for creating a simple image display program in OpenCV (2.4.10-1) using Qt 5.4, QtCreator in Ubuntu 14.04.
The code is as follows:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
int main() {
// read an image
cv::Mat image = cv::imread("${PATH_TO_HOME}/Pictures/bottle_label.jpg");
if ( image.data == NULL ) {
std::cout << "no data loaded" << std::endl;
return -1;
}
else {
// create image window named "My image"
cv::namedWindow("My Image", 1);
// show the image on window
std::cout << "Image loaded" << std::endl;
cv::imshow("My Image", image);
// wait key for 5000 ms
cv::waitKey(5000);
return 0;
}
}
And the contents in the .pro file are
# Standard .pro content for qt console application #
INCLUDEPATH += /usr/local/include/
LIBS += -L/usr/local/lib \
-lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_features2d -lopencv_calib3d
The code compiles, but when I run it the program crashes immediately. The debuger points a SIGSEGV occurring in line 17: cv::namedWindow("My Image", 1)
I don't know what to do. I have other programs that use qt and opencv libraries in the same computer but used cmake to build them and they run fine. Could someone please point out where the problem is?
Thank you in advance
The code compiles in qt creator. The problem is during the execution SIGSEGV. I compiled the same code under qt creator using cmake to build it and the program executes without a problem.
I tried what you recommended and I got this output: g
Which I can also not understad, because I installed OpenCV WITH_CUDA=ON after installing cuda 6.5. I checked my opencv.pc file and the flags mentioned in the output don't point where the .so file actually are.
Did you check it with cv::namedWindow("My Image"); by removing 1
Yes, the original code does no use the second parameter. Both variants generate the same problem. The code compiles, but I get a direct crash.
did you check the path by making it simple like cv::Mat image = cv::imread(C://bottle_label.jpg"); ?
Yes, the path is correct and also tried your suggestion. The console ouput give me a "realloc(): invalid pointer" I have also tried to run it in another machine with opencv 2.4.8 an Qt 4 same problem there.
Did you by any chance compiled OpenCV against a different version of QT than the one you are using in your test program?
I had initially openCV 2.4.9 along with qt4 . I deinstalled both and installed afterwards (in the following order) cuda 6.5, qt 5.4 and openCV 2.4.10-1. (In cmake build directory) cmake - D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_CUBLAS=ON -D WITH_CUFFT=ON -D WITH_EIGEN=ON -D WITH_OPENGL=ON -D WITH_QT=ON -D WITH_TBB=ON -D BUILD_DOCS=ON -D BUILD_EXAMPLES=ON -D BUILD_TESTS=ON -D CUDA_ARCH_BIN="3.0" ..
@wagp11 Same problem here. Have you figure it out by now? If so could you please share your solution here? Thanks