hi every one,
i m developing an app for symbian OS which use the camera and i m mixing openCv and Qt.
heres my codes:
main.cpp:
mainWindow.CPP:Code:#include "mainwindow.h" #include "MyCameraWindow.h" #include <QtGui/QApplication> #include <opencv/cv.h> #include <opencv/highgui.h> int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow mainWindow; mainWindow.setOrientation(MainWindow::ScreenOrientationAuto); mainWindow.showExpanded(); int retval = app.exec(); return retval; }
mainWindow.hCode:#include "mainwindow.h" #include <QtCore/QCoreApplication> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { CvCapture *cam = cvCaptureFromCAM(0); IplImage *img = cvQueryFrame(cam); MyCameraWindow *mainWin = new MyCameraWindow(cam); mainWin->setWindowTitle("OpenCV --> QtImage"); mainWin->showMaximized(); } MainWindow::~MainWindow() { } void MainWindow::setOrientation(ScreenOrientation orientation) { #if defined(Q_OS_SYMBIAN) // If the version of Qt on the device is < 4.7.2, that attribute won't work if (orientation != ScreenOrientationAuto) { const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.')); if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) { qWarning("Screen orientation locking only supported with Qt 4.7.2 and above"); return; } } #endif // Q_OS_SYMBIAN Qt::WidgetAttribute attribute; switch (orientation) { #if QT_VERSION < 0x040702 // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes case ScreenOrientationLockPortrait: attribute = static_cast<Qt::WidgetAttribute>(128); break; case ScreenOrientationLockLandscape: attribute = static_cast<Qt::WidgetAttribute>(129); break; default: case ScreenOrientationAuto: attribute = static_cast<Qt::WidgetAttribute>(130); break; #else // QT_VERSION < 0x040702 case ScreenOrientationLockPortrait: attribute = Qt::WA_LockPortraitOrientation; break; case ScreenOrientationLockLandscape: attribute = Qt::WA_LockLandscapeOrientation; break; default: case ScreenOrientationAuto: attribute = Qt::WA_AutoOrientation; break; #endif // QT_VERSION < 0x040702 }; setAttribute(attribute, true); } void MainWindow::showExpanded() { #ifdef Q_OS_SYMBIAN showFullScreen(); #elif defined(Q_WS_MAEMO_5) || defined(Q_WS_MAEMO_6) showMaximized(); #else show(); #endif }
Mycamera.Cpp:Code:#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QtGui/QMainWindow> #include <QtGui> #include "MyCameraWindow.h" #include <opencv/cv.h> #include <opencv/highgui.h> #include <assert.h> class MainWindow : public QMainWindow { Q_OBJECT public: enum ScreenOrientation { ScreenOrientationLockPortrait, ScreenOrientationLockLandscape, ScreenOrientationAuto }; explicit MainWindow(QWidget *parent = 0); virtual ~MainWindow(); void setOrientation(ScreenOrientation orientation); void showExpanded(); private: }; #endif
Mycamera.h:Code:#include "MyCameraWindow.h" MyCameraWindow::MyCameraWindow(CvCapture *cam) { camera = cam; QHBoxLayout *layout = new QHBoxLayout; cvwidget = new QOpenCVWidget(this); layout->addWidget(cvwidget); setLayout(layout); startTimer(0.1);// 0.1-second timer } MyCameraWindow::~MyCameraWindow(){} void MyCameraWindow::timerEvent(QTimerEvent*) { IplImage *image = cvQueryFrame(camera); cvwidget->putImage(image); }
QOpenCVWidget.cpp::Code:#ifndef MYCAMERAWINDOW_H_ #define MYCAMERAWINDOW_H_ #include <QWidget> #include <QVBoxLayout> #include "QOpenCVWidget.h" #include <opencv/cv.h> #include <opencv/highgui.h> #include <QtGui> class MyCameraWindow : public QWidget { Q_OBJECT public: MyCameraWindow(CvCapture *cam); ~MyCameraWindow(); protected: void timerEvent(QTimerEvent*); private: QOpenCVWidget *cvwidget; CvCapture *camera; }; #endif
QOpenCVWidget.h:Code:#include "QOpenCVWidget.h" // Constructor QOpenCVWidget::QOpenCVWidget(QWidget *parent) : QWidget(parent) { //setFixedSize(300, 300); layout = new QVBoxLayout; imagelabel = new QLabel; QImage dummy(100,100,QImage::Format_RGB32); image = dummy; layout->addWidget(imagelabel); for (int x = 0; x < 100; x ++) { for (int y =0; y < 100; y++) { image.setPixel(x,y,qRgb(x, y, y)); } } imagelabel->setPixmap(QPixmap::fromImage(image)); setLayout(layout); } QOpenCVWidget::~QOpenCVWidget(void) { } void QOpenCVWidget::putImage(IplImage *cvimage) { int cvIndex, cvLineStart; // switch between bit depths switch (cvimage->depth) { case IPL_DEPTH_8U: switch (cvimage->nChannels) { case 3: if ( (cvimage->width != image.width()) || (cvimage->height != image.height()) ) { QImage temp(cvimage->width, cvimage->height, QImage::Format_RGB32); image = temp; } cvIndex = 0; cvLineStart = 0; for (int y = 0; y < cvimage->height; y++) { unsigned char red,green,blue; cvIndex = cvLineStart; for (int x = 0; x < cvimage->width; x++) { // DO it red = cvimage->imageData[cvIndex+2]; green = cvimage->imageData[cvIndex+1]; blue = cvimage->imageData[cvIndex+0]; image.setPixel(x,y,qRgb(red, green, blue)); cvIndex += 3; } cvLineStart += cvimage->widthStep; } break; default: //cout<<"This number of channels is not supported\n"; break; } break; default: //printf("This type of IplImage is not implemented in QOpenCVWidget\n"); break; } imagelabel->setPixmap(QPixmap::fromImage(image)); } QImage QOpenCVWidget::getImageLabel() { return imagelabel->pixmap()->toImage(); }
when i compile my code it is compiled with 0 errors but when i execute my app it crash, i run it in debug mode:Code:#ifndef QOPENCVWIDGET_H #define QOPENCVWIDGET_H #include <opencv/cv.h> #include <QPixmap> #include <QLabel> #include <QWidget> #include <QVBoxLayout> #include <QImage> class QOpenCVWidget : public QWidget { private: QLabel *imagelabel; QVBoxLayout *layout; QImage image; public: QOpenCVWidget(QWidget *parent = 0); ~QOpenCVWidget(void); void putImage(IplImage *); QImage getImageLabel(); }; #endif
thanks for your help!Code:Starting program: C:\appTir\tirFeu-build-simulator/debug/tirFeu.Exe [New thread 4256.0x1360] [New thread 4256.0x12c8] warning: Lowest section in C:\WINDOWS\system32\mfc42loc.dll is .rsrc at 61d71000 [New thread 4256.0x15ec] [New thread 4256.0x16d0] [New thread 4256.0x1548] BFD: C:\Program Files\Fichiers communs\Nero\DSFilter\NeVideo.ax (.nepku): Section flag IMAGE_SCN_MEM_NOT_CACHED (0x4000000) ignored BFD: C:\Program Files\Fichiers communs\Nero\DSFilter\NeVideo.ax: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .nepku Error while mapping shared library sections: "C:\Program Files\Fichiers communs\Nero\DSFilter\NeVideo.ax": not in executable format: File format not recognized. BFD: C:\Program Files\Fichiers communs\Nero\DSFilter\NeVideo.ax (.nepku): Section flag IMAGE_SCN_MEM_NOT_CACHED (0x4000000) ignored BFD: C:\Program Files\Fichiers communs\Nero\DSFilter\NeVideo.ax: Warning: Ignoring section flag IMAGE_SCN_MEM_NOT_PAGED in section .nepku Error while reading shared library symbols: "C:\Program Files\Fichiers communs\Nero\DSFilter\NeVideo.ax": can't read symbols: File format not recognized. Program exited normally.



