PDA

View Full Version : [OpenCV]Seg fault



Vicolaships
13th April 2013, 13:09
Hello, I would like to compile a simple OpenCV application in Qt.

I already looked at Qt-OpenCV-simple-example (http://www.qtcentre.org/threads/43056-Qt-OpenCV-simple-example) topic but its too complicated for me at the moment. I followed a great tutorial on YouTube (https://www.youtube.com/watch?v=0ONxIy8itRA).
Unfortunately I can't get it working, that's why I'm asking for help.

Miscellaneous information :
Ubuntu 13.04 (64 bits)

Qt Creator 2.7.0
Qt framework 5.0.1 (64 bits)

OpenCV 2.4.4

rc libopencv-calib3d2.3 2.3.1-11ubuntu2 amd64 computer vision Camera Calibration library
ii libopencv-calib3d2.4 2.4.2+dfsg-0exp2ubuntu1 amd64 computer vision Camera Calibration library
rc libopencv-contrib2.3 2.3.1-11ubuntu2 amd64 computer vision contrib library
rc libopencv-core2.3 2.3.1-11ubuntu2 amd64 computer vision core library
ii libopencv-core2.4 2.4.2+dfsg-0exp2ubuntu1 amd64 computer vision core library
rc libopencv-features2d2.3 2.3.1-11ubuntu2 amd64 computer vision Feature Detection and Descriptor Extraction library
ii libopencv-features2d2.4 2.4.2+dfsg-0exp2ubuntu1 amd64 computer vision Feature Detection and Descriptor Extraction library
rc libopencv-flann2.3 2.3.1-11ubuntu2 amd64 computer vision Clustering and Search in Multi-Dimensional spaces library
ii libopencv-flann2.4 2.4.2+dfsg-0exp2ubuntu1 amd64 computer vision Clustering and Search in Multi-Dimensional spaces library
rc libopencv-gpu2.3 2.3.1-11ubuntu2 amd64 computer vision GPU Processing library
rc libopencv-highgui2.3 2.3.1-11ubuntu2 amd64 computer vision High-level GUI and Media I/O library
ii libopencv-highgui2.4 2.4.2+dfsg-0exp2ubuntu1 amd64 computer vision High-level GUI and Media I/O library
rc libopencv-imgproc2.3 2.3.1-11ubuntu2 amd64 computer vision Image Processing library
ii libopencv-imgproc2.4 2.4.2+dfsg-0exp2ubuntu1 amd64 computer vision Image Processing library
rc libopencv-legacy2.3 2.3.1-11ubuntu2 amd64 computer vision legacy library
ii libopencv-legacy2.4 2.4.2+dfsg-0exp2ubuntu1 amd64 computer vision legacy library
rc libopencv-ml2.3 2.3.1-11ubuntu2 amd64 computer vision Machine Learning library
ii libopencv-ml2.4 2.4.2+dfsg-0exp2ubuntu1 amd64 computer vision Machine Learning library
rc libopencv-objdetect2.3 2.3.1-11ubuntu2 amd64 computer vision Object Detection library
ii libopencv-objdetect2.4 2.4.2+dfsg-0exp2ubuntu1 amd64 computer vision Object Detection library
rc libopencv-video2.3 2.3.1-11ubuntu2 amd64 computer vision Video analysis library
ii libopencv-video2.4 2.4.2+dfsg-0exp2ubuntu1 amd64 computer vision Video analysis library


The Youtube tutorial is for Windows, I modified the .pro file and it looks like this :


QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = QtTracker3
TEMPLATE = app


SOURCES += main.cpp\
dialog.cpp

HEADERS += dialog.h

FORMS += dialog.ui


# Show Qt where OpenCV is :
INCLUDEPATH += /usr/local/include/opencv #/usr/local/include/opencv2

LIBS += -L/usr/local/lib \
-lopencv_calib3d \
-lopencv_contrib \
-lopencv_core \
-lopencv_features2d \
-lopencv_flann \
-lopencv_gpu \
-lopencv_highgui \
-lopencv_imgproc \
-lopencv_legacy \
-lopencv_ml \
-lopencv_objdetect \
-lopencv_ts \
-lopencv_video

The project builds successfuly but the program exits at start.


Debugging starts
&"warning: GDB: Failed to set controlling terminal: Ioctl() inappropr\303\251 pour un p\303\251riph\303\251rique\n"
no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000


0 ?? /usr/lib/x86_64-linux-gnu/libQtTest.so.4 0x7fffeff97d3c
1 ?? /lib64/ld-linux-x86-64.so.2 0x7ffff7de9876
2 ?? /lib64/ld-linux-x86-64.so.2 0x7ffff7de9930
3 ?? /lib64/ld-linux-x86-64.so.2 0x7ffff7ddb68a
4 ?? 0x1
5 ?? 0x7fffffffe920
6 ??


The arrow points this line

0x7fffeff97d3c <+0x0000> lock incl (%rbx)

The whole project is enclosed in this post (8934). Thanks in advance for your precious help :D

ChrisW67
14th April 2013, 06:10
Miscellaneous information :
Ubuntu 13.04 (64 bits)

Qt Creator 2.7.0
Qt framework 5.0.1 (64 bits)



0 ?? /usr/lib/x86_64-linux-gnu/libQtTest.so.4 0x7fffeff97d3c

You claim to be using Qt5 but the program is clearly linked, or wanting to link, against Qt4. Your PRO file does not indicate that you are building a QTestLib test and yet your error output (is that a stack trace?) directly references it.

At the very least you need to do a clean build and make sure you use the correct QMake version and the program is run in an environment where the matching Qt version libraries can be found. If the pre-packaged OpenCV is dependent on Qt4 then you will need to use Qt4 or rebuild your own OpenCV.

Vicolaships
15th April 2013, 21:44
NB : The enclosed file in the first post is wrong, this is the good one : 8950
Thanks for your reply. I switched to my Ubuntu 12.04 to simplify the problem.

So now the config is :
Qt Creator 2.4.1
Qt framework 4.8.0 (64 bits)

I built my own OpenCV 2.4.4a with the following CMAKE :

cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_FFMPEG=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..

I deleted the .pro.user file and launched the .pro file. Qt gave me no other option than "Desktop"
When I try to compile I get the following errors :


22:41:05: Exécution des étapes de compilation pour le projet QtTracker3...
22:41:05: Configuration inchangée, étape QMake sautée.
22:41:05: Débute : "/usr/bin/make" -w
make: Entering directory `/home/victor/Documents/Projets/FZ200/QtTracker3'
/usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ -o Makefile QtTracker3.pro
make: Leaving directory `/home/victor/Documents/Projets/FZ200/QtTracker3'
make: Entering directory `/home/victor/Documents/Projets/FZ200/QtTracker3'
g++ -Wl,-O1 -o QtTracker3 main.o dialog.o moc_dialog.o -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_imgproc /usr/local/lib/libopencv_calib3d.so /usr/local/lib/libopencv_contrib.so /usr/local/lib/libopencv_core.so /usr/local/lib/libopencv_features2d.so /usr/local/lib/libopencv_flann.so /usr/local/lib/libopencv_gpu.so /usr/local/lib/libopencv_highgui.so /usr/local/lib/libopencv_imgproc.so /usr/local/lib/libopencv_legacy.so /usr/local/lib/libopencv_ml.so /usr/local/lib/libopencv_nonfree.so /usr/local/lib/libopencv_objdetect.so /usr/local/lib/libopencv_photo.so /usr/local/lib/libopencv_stitching.so /usr/local/lib/libopencv_ts.so /usr/local/lib/libopencv_video.so /usr/local/lib/libopencv_videostab.so -lQtGui -lQtCore -lpthread
/usr/local/lib/libavcodec.so.54: undefined reference to `av_bprint_finalize@LIBAVUTIL_51'
/usr/local/lib/libavformat.so.54: undefined reference to `av_timecode_make_smpte_tc_string@LIBAVUTIL_51'
/usr/local/lib/libavformat.so.54: undefined reference to `av_timecode_make_string@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_realloc_f@LIBAVUTIL_51'
/usr/local/lib/libavformat.so.54: undefined reference to `av_timecode_get_smpte_from_framenum@LIBAVUTIL_51'
make: Leaving directory `/home/victor/Documents/Projets/FZ200/QtTracker3'
/usr/local/lib/libavformat.so.54: undefined reference to `av_timecode_init@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_samples_set_silence@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_calloc@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_get_media_type_string@LIBAVUTIL_51'
/usr/local/lib/libavformat.so.54: undefined reference to `av_dynarray_add@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_bprint_init@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_asprintf@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_timecode_make_mpeg_tc_string@LIBAVUTIL_51'
/usr/local/lib/libavformat.so.54: undefined reference to `av_rescale_q_rnd@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_bprintf@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_samples_copy@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_get_default_channel_layout@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_timecode_init_from_string@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_bprint_chars@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_timecode_adjust_ntsc_framenum@LIBAVUTIL_51'
/usr/local/lib/libavcodec.so.54: undefined reference to `av_tempfile@LIBAVUTIL_51'
collect2: ld returned 1 exit status
make: *** [QtTracker3] Error 1
22:41:05: Le processus "/usr/bin/make" s'est terminé avec le code 2.
Erreur à la compilation du projet QtTracker3 (cible : Desktop)
Lors de l'exécution de l'étape "Make""

I did not find much answers for this problem on the web :

Osman Eralp
September 12, 2012 at 10:38 am · Reply

You would get an undefined reference if you forgot to include the include paths in the g++ command. Please use this syntax:
g++ `pkg-config opencv --cflags` my_code.cpp -o my_code `pkg-config opencv --libs`

Let me know if you still are having problems.


How do I do the equivalent in Qt ? I tried by adding the following two lines in the .pro file :

CONFIG += link_pkgconfig
PKGCONFIG += opencv

I really appreciate your help :)

amleto
15th April 2013, 23:53
How do I do the equivalent in Qt ? I tried by adding the following two lines in the .pro file :

CONFIG += link_pkgconfig
PKGCONFIG += opencv

I really appreciate your help :)

http://qt-project.org/doc/qt-4.8/qmake-project-files.html

ChrisW67
16th April 2013, 00:26
Your program is expecting to be linked against libavutil also; is it on your machine?

The code you posted builds just fine on my machine.

Vicolaships
16th April 2013, 10:40
Hello,

Here are my libav* libraries :

/usr/local/lib$ ls -al libavcodec*
-rw-r--r-- 1 root root 90588642 mars 25 15:32 libavcodec.a
lrwxrwxrwx 1 root root 23 mars 25 15:32 libavcodec.so -> libavcodec.so.54.23.100
lrwxrwxrwx 1 root root 23 mars 25 15:32 libavcodec.so.54 -> libavcodec.so.54.23.100
-rwxr-xr-x 1 root root 7527520 mars 25 15:32 libavcodec.so.54.23.100
lrwxrwxrwx 1 root root 22 mars 24 15:12 libavcodec.so.55 -> libavcodec.so.55.1.100
-rwxr-xr-x 1 root root 7692608 mars 24 15:12 libavcodec.so.55.1.100

/usr/local/lib$ ls -al libavformat*
-rw-r--r-- 1 root root 22319750 mars 25 15:32 libavformat.a
lrwxrwxrwx 1 root root 23 mars 25 15:32 libavformat.so -> libavformat.so.54.6.100
lrwxrwxrwx 1 root root 23 mars 25 15:32 libavformat.so.54 -> libavformat.so.54.6.100
-rwxr-xr-x 1 root root 1192224 mars 25 15:32 libavformat.so.54.6.100
lrwxrwxrwx 1 root root 23 mars 24 15:12 libavformat.so.55 -> libavformat.so.55.0.100
-rwxr-xr-x 1 root root 1455456 mars 24 15:12 libavformat.so.55.0.100

I tried to run sudo apt-get update && sudo apt-get upgrade but it didn't solve the problem.
I guess my version of livav* is wrong, which one should I use ?

Vicolaships
28th April 2013, 15:18
After a new installation of Ubuntu 13.04 and installation of OpenCV using :

sudo apt-get install -y libopencv-dev libcv-dev libhighgui-dev

The project compiles /run fine.

Problem solved :D