Bonsoir,

j'essaie de faire tourner un code c++/qt/opencv sur mon macbook pro
snow leopard. Ce programme détecte les contours d'un flux vidéo via le filtre canny-edge. J'ai réussi à le compiler mais j'ai une segmentation fault à l'exécution. Ce code compile et marche bien sur une debian lenny. Sur Mac,
j'ai du modifier légèrement le Makefile pour intégrer opencv2 :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
 
CC            = /usr/bin/gcc-4.2 -g
CXX           = /usr/bin/g++-4.2 -g
DEFINES       = -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED
CFLAGS        = -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W $(DEFINES)
CXXFLAGS      = -pipe -g -gdwarf-2 -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5 -Wall -W $(DEFINES)
INCPATH       = -I/opt/local/libexec/qt4-mac/mkspecs/macx-g++ -I. -I/opt/local/libexec/qt4-mac/lib/QtCore.framework/Versions/4/Headers -I/opt/local/libexec/qt4-mac/lib/QtCore.framework/Versions/4/Headers -I/opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/Headers -I/opt/local/libexec/qt4-mac/lib/QtGui.framework/Versions/4/Headers -I/opt/local/libexec/qt4-mac/include -I. -I/opt/local/Library/Frameworks/OpenCV.framework/Headers 
LINK          = /usr/bin/g++-4.2
LFLAGS        = -headerpad_max_install_names -arch x86_64 -Xarch_x86_64 -mmacosx-version-min=10.5
LIBS          = $(SUBLIBS) -F/opt/local/Library/Frameworks -framework QtGui -framework QtCore -L/opt/local/lib -lcv -cvaux -lcxcore -lhighgui
AR            = ar cq
Voici l'erreur et la backtrace obtenue à l'exécution :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
 
(gdb) file Image_capture_QT 
Reading symbols for shared libraries ........ done
Load new symbol table from "/Users/fab/Projets_info/Image_capture_QT/Image_capture_QT.app/Contents/MacOS/Image_capture_QT"? (y or n) y
Reading symbols from /Users/fab/Projets_info/Image_capture_QT/Image_capture_QT.app/Contents/MacOS/Image_capture_QT...done.
(gdb) r
Starting program: /Users/fab/Projets_info/Image_capture_QT/Image_capture_QT.app/Contents/MacOS/Image_capture_QT 
Reading symbols for shared libraries .+++++++................................................................................................warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_archivers_bzip2/work/bzip2-1.0.5/blocksort.o" - no debug information available for "blocksort.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_archivers_bzip2/work/bzip2-1.0.5/huffman.o" - no debug information available for "huffman.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_archivers_bzip2/work/bzip2-1.0.5/crctable.o" - no debug information available for "crctable.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_archivers_bzip2/work/bzip2-1.0.5/randtable.o" - no debug information available for "randtable.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_archivers_bzip2/work/bzip2-1.0.5/compress.o" - no debug information available for "compress.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_archivers_bzip2/work/bzip2-1.0.5/decompress.o" - no debug information available for "decompress.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_archivers_bzip2/work/bzip2-1.0.5/bzlib.o" - no debug information available for "bzlib.c".
 
...........warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/vorbisenc.o" - no debug information available for "vorbisenc.c".
 
.warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/mdct.o" - no debug information available for "mdct.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/smallft.o" - no debug information available for "smallft.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/block.o" - no debug information available for "block.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/envelope.o" - no debug information available for "envelope.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/window.o" - no debug information available for "window.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/lsp.o" - no debug information available for "lsp.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/lpc.o" - no debug information available for "lpc.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/analysis.o" - no debug information available for "analysis.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/synthesis.o" - no debug information available for "synthesis.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/psy.o" - no debug information available for "psy.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/info.o" - no debug information available for "info.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/floor1.o" - no debug information available for "floor1.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/floor0.o" - no debug information available for "floor0.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/res0.o" - no debug information available for "res0.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/mapping0.o" - no debug information available for "mapping0.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/registry.o" - no debug information available for "registry.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/codebook.o" - no debug information available for "codebook.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/sharedbook.o" - no debug information available for "sharedbook.c".
 
warning: Could not find object file "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_audio_libvorbis/work/libvorbis-1.3.1/lib/.libs/bitrate.o" - no debug information available for "bitrate.c".
 
.............. done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries . done
Reading symbols for shared libraries ................... done
 
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x000000000000002c
0x000000010000703a in IplImageWidget::paintEvent (this=0x124411190, e=0x7fff5fbe87f0) at IplImageWidget.cpp:79
79	    painter.drawImage(QRect(0,0,im2->width,im2->height),m_i);
(gdb) back
#0  0x000000010000703a in IplImageWidget::paintEvent (this=0x124411190, e=0x7fff5fbe87f0) at IplImageWidget.cpp:79
#1  0x00000001000e69b6 in QWidget::event ()
#2  0x000000010043866b in QMainWindow::event ()
#3  0x000000010008cfdd in QApplicationPrivate::notify_helper ()
#4  0x0000000100091d0d in QApplication::notify ()
#5  0x0000000100c546bc in QCoreApplication::notifyInternal ()
#6  0x000000010008d1ac in qt_sendSpontaneousEvent ()
#7  0x000000010003b31b in -[QCocoaView drawRect:] ()
#8  0x00007fff81d3b081 in -[NSView _drawRect:clip:] ()
#9  0x00007fff81d39cf4 in -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] ()
#10 0x00007fff81d3a05e in -[NSView _recursiveDisplayAllDirtyWithLockFocus:visRect:] ()
#11 0x00007fff81d383c6 in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#12 0x00007fff81d39292 in -[NSView _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#13 0x00007fff81d37ee8 in -[NSThemeFrame _recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:] ()
#14 0x00007fff81d3479a in -[NSView _displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] ()
#15 0x00007fff81cadff6 in -[NSView displayIfNeeded] ()
#16 0x000000010003f51a in -[QCocoaWindow displayIfNeeded] ()
#17 0x00007fff81ca8ea2 in _handleWindowNeedsDisplay ()
#18 0x00007fff83594077 in __CFRunLoopDoObservers ()
#19 0x00007fff8356fef4 in __CFRunLoopRun ()
#20 0x00007fff8356f84f in CFRunLoopRunSpecific ()
#21 0x00007fff838b091a in RunCurrentEventLoopInMode ()
#22 0x00007fff838b067d in ReceiveNextEventCommon ()
#23 0x00007fff838b05d8 in BlockUntilNextEventMatchingListInMode ()
#24 0x00007fff81c7e29e in _DPSNextEvent ()
#25 0x00007fff81c7dbed in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#26 0x00007fff81c438d3 in -[NSApplication run] ()
#27 0x000000010004b1c5 in QEventDispatcherMac::processEvents ()
#28 0x0000000100d2a1f4 in QEventLoop::processEvents ()
#29 0x0000000100d2a504 in QEventLoop::exec ()
#30 0x0000000100d2bb1c in QCoreApplication::exec ()
#31 0x0000000100007f84 in main (argc=1, argv=0x7fff5fbeb370) at main.cpp:47
Apparemment, il y a un problème au niveau de la méthode IplImageWidget::paintEvent

Voici le source en question où il y a en bas l'appel de cette méthode :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "IplImageWidget.h"


IplImageWidget::IplImageWidget()
{

printf("ici !!! ");

capture = cvCaptureFromCAM(0);

im1 = cvQueryFrame( capture );
 
m_i = QImage(QSize(im1->width,im1->height),QImage::Format_RGB32);
this->setMinimumSize(im1->width,im1->height);
this->setMaximumSize(im1->width,im1->height);

printf("ici !!! "); 
m_timer = new QTimer(this);
connect(m_timer,SIGNAL(timeout()),this,SLOT(queryFrame()));
m_timer->start(0);    
}

IplImageWidget::~IplImageWidget()
{
  cvReleaseImage(&im1 );
  cvReleaseImage(&im2 );
  cvReleaseCapture(&capture);
}

void IplImageWidget::queryFrame() {

IplImage* frame = cvQueryFrame( capture );
im2 = cvCreateImage(cvGetSize(frame),8,1); 

printf("im2 adress =%d",im2);
cvCvtColor(frame,im2,CV_BGR2GRAY);
const int pixels = im2->width * im2->height;
QRgb*imageData = reinterpret_cast<QRgb*> (m_i.bits());
for(int i = 0; i < pixels;++i)
{
 imageData[i] = qRgb (im2->imageData[i],im2->imageData[i],im2->imageData[i]);
 }
this->gaussianfilter();
this->border_detect();
this->repaint();
//cvReleaseImage(&im1);
cvReleaseImage(&im2);
}

void IplImageWidget::gaussianfilter()
    	
{  bool ok;
   int fact=m_i.depth()/8;
   EXIm1=new EXImage(m_i.height(),fact*m_i.width());
   EXIm1->transfert_to_exim(&(this->m_i));
   EXIm1->gaussian(fact);
   EXIm1->transfert_to_qim(&(this->m_i));
   delete EXIm1;    
}

void IplImageWidget::border_detect()
{  int threshold=200;
   bool ok;
   int fact=m_i.depth()/8;
   EXIm1=new EXImage(m_i.height(),fact*m_i.width());
   EXIm1->transfert_to_exim(&(this->m_i));
   EXIm1->normex(fact);
   EXIm1->normey(fact);
   EXIm1->norme(fact);   
   EXIm1->seuil(threshold,fact);
   EXIm1->transfert_to_qim(&(this->m_i));
   delete EXIm1;
}


void IplImageWidget::paintEvent(QPaintEvent* e)
{
    QPainter painter(this); 
    painter.drawImage(QRect(0,0,im2->width,im2->height),m_i);
}
Je crois que sous linux, j'utilise la version 1.0 de opencv et sous mac, c'est la version 2.0. Est ce un problème de compatibilité entre les deux versions ?

Si quelqu'un a une idée ...

Je vous remercie par avance.