Results 1 to 4 of 4

Thread: OpenCV conflict with QIMage in Ubuntu

  1. #1
    Join Date
    Jan 2011
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Symbian S60 Maemo/MeeGo

    Default OpenCV conflict with QIMage in Ubuntu

    Hello

    I am running a Ubuntu 12.04 installation with the latest Qt SDK. I've compiled OpenCV and imported the libraries into the QtSDK folders.

    Qt recognizes the libraries and allows me to build the project if I include the following:

    Qt Code:
    1. unix: LIBS += -lopencv_core \
    2. -lopencv_highgui \
    3. -lopencv_imgproc \
    4. -lopencv_objdetect \
    5. -lopencv_contrib
    To copy to clipboard, switch view to plain text mode 

    The project runs correctly with no errors from the OpenCV until I try to get it to save an image as QImage.

    If that wasn't enough, I've also got QML files serving as the user interface, and if I include any "Image" element in them, the program "unexpectedly exits". If I remove the OpenCV code, the program runs correctly with the Image element. If I remove the Image element and re-insert the OpenCV code, the program runs correctly (as long as I do not have QImage anywhere in my code).

    I've tried to rebuild OpenCV, and try new Qt projects, but this "conflict" still remains between OpenCV and QImage (and QML Image element).

    My colleagues are able to run the project without problems on their Windows 7 machines.

    Please advise.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: OpenCV conflict with QIMage in Ubuntu

    Thank you for sharing the fact that your program doesn't work. It would help if you shared even the smallest amount of information about how it fails. At the moment all we know is that program fails. We can surmise that your "unexpected exit" problem is your code using an uninitialised or invalid pointer or an uninitialised data structure. Beyond that we could guess all day.

    From the knowledge that many programs use both Qt and OpenCV I can be almost certain this is not a collision between QImage and OpenCV. This, for example, works just fine.
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3.  
    4. #include <opencv/cv.h>
    5. #include <opencv/highgui.h>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication app(argc, argv);
    10.  
    11.  
    12. QImage image("test.jpg");
    13. QLabel label;
    14. label.setPixmap( QPixmap::fromImage(image) );
    15. label.show();
    16.  
    17. // load an image
    18. IplImage* img = cvLoadImage("test.jpg");
    19. if(!img)
    20. qFatal("Could not load image file\n");
    21. cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE | CV_WINDOW_FREERATIO | CV_GUI_NORMAL);
    22. cvMoveWindow("mainWin", 100, 100);
    23. cvShowImage("mainWin", img );
    24.  
    25. int result = app.exec();
    26.  
    27. cvDestroyWindow("mainWin");
    28. cvReleaseImage(&img );
    29.  
    30. return result;
    31. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2011
    Posts
    10
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Symbian S60 Maemo/MeeGo

    Default Re: OpenCV conflict with QIMage in Ubuntu

    Apologies for not sharing any code, I had wrongly assumed that someone else might have had experienced the problem and thus would know the answer.

    The code I have at the moment is confidential, but I will strip it in order to get the bare bones of what's failing and then reply to this thread.

    The code that you have given me does indeed work. We use facial detection and recognition that come with OpenCV 2.4.2, and it strangely works with Windows 7.

    Thank you for taking your time, I'll return with more information

  4. #4
    Join Date
    Feb 2014
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: OpenCV conflict with QIMage in Ubuntu

    Hello, I've just ran into same problem.

    Ubuntu 12.04, Qt 4.8, OpenCv 2.4.3, PCL 1.6. Developing all via Qt Creator 2.5.2. All in 64 bits version.

    I din't faced this issue until now, due to the fact I was dealing with image files in disk via "cv::imread(filename)" and then transferring its data to QImage -> QPixmap -> QLabel. NO problem with that.

    Now, I need to load some images into Qt resource files. I created the proper .qrc via Qt Creator, and copied and registered image files in it. Well, If I try to load images from resources, it doesn't work:

    QImage qi = QImage(":images/red.jpg");
    if (qi.isNull())
    {
    QMessageBox::warning(this,"hey","hey");
    }


    Of course, at beginning I was struggling with resource names for an entire day. Until I decided to start other project, and copypasted the resource file, and the code that loads that QImage. In the test project, It works OK. (same computer, same IDE & Environment, but no OpenCV linking).
    Seeing this, I decided to try this piece of code:

    QString fn = QFileDialog::getOpenFileName(this,"Load image");
    qi = QImage(fn);
    if (qi.isNull())
    {
    QMessageBox::warning(this,"hey","hey");
    }


    In original code, this doesn't work! fn is loaded with right filename, but "qi = QImage(fn);" fails. In the Test program, this works as expected.

    This is a big problem, because I want to set some icons in windows, and some images for several widgets and QSplashScreen. It's not very acceptable to copy image files into generated binaries folders and load them, assuming user will do nothing with them...

    I must point again, that this is NOT a issue with Qt resource filename.

    Is there some workaround or idea about this?

    PD: I tried QPixmap(":images/red.jpg"); but program fails execution.

    PD: Some project settings:

    ResFiles.qrc:
    <RCC>
    <qresource prefix="/">
    <file>images/red.png</file>
    </qresource>
    </RCC>


    QOP.proj file:
    #-------------------------------------------------
    #
    # Project created by QtCreator 2013-03-09T23:56:16
    #
    #-------------------------------------------------

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = QOP
    TEMPLATE = app

    SOURCES += main.cpp\
    mainwindow.cpp \
    [several files more...]

    HEADERS += mainwindow.h \
    [several files more...]

    FORMS += mainwindow.ui \
    camwindow.ui \
    dialogsetupcam.ui \
    dialogtestcam_sr4k.ui \
    dialogtestcam_pmdnano.ui \
    dialogcommand_pmdnano.ui \
    dialogcreatecam.ui

    CONFIG += link_pkgconfig
    PKGCONFIG += opencv

    CONFIG += link_pkgconfig
    PKGCONFIG +=

    #Do not use this configuration to get PCL, some sublibraries aren't properly accesible, in example Visualizer
    #CONFIG += link_pkgconfig
    #PKGCONFIG += pcl_io-1.6

    #PCL Headers
    INCLUDEPATH += /usr/include/pcl-1.6\
    /usr/include/flann/\
    /usr/include/eigen3/\
    /usr/include/openni/
    #PCL Libraries
    LIBS += -lpcl_common\
    -lpcl_features\
    -lpcl_filters\
    -lpcl_geometry\
    -lpcl_io\
    -lpcl_kdtree\
    -lpcl_keypoints\
    -lpcl_octree\
    -lpcl_registration\
    -lpcl_sample_consensus\
    -lpcl_search\
    -lpcl_segmentation\
    -lpcl_surface\
    -lpcl_tracking\
    -lpcl_visualization

    #VTK Headers
    INCLUDEPATH += /usr/include/vtk-5.8
    #VTK Libraries
    LIBS += -lQVTK\
    -lvtkalglib\
    -lvtkCharts\
    -lvtkCommon\
    -lvtkDICOMParser\
    -lvtkexoIIc\
    -lvtkFiltering\
    -lvtkftgl\
    -lvtkGenericFiltering\
    -lvtkGeovis\
    -lvtkGraphics\
    -lvtkHybrid\
    -lvtkImaging\
    -lvtkInfovis\
    -lvtkIO\
    -lvtkmetaio\
    -lvtkParallel\
    -lvtkproj4\
    -lvtkQtChart\
    -lvtkRendering\
    -lvtksys\
    -lvtkverdict\
    -lvtkViews\
    -lvtkVolumeRendering\
    -lvtkWidgets

    RESOURCES += \
    ResFiles.qrc

    OTHER_FILES += \
    images/red.png

Similar Threads

  1. Handle QContextMenuEvent conflict
    By cia.michele in forum Qt Programming
    Replies: 7
    Last Post: 2nd May 2011, 15:59
  2. Install opencv on ubuntu error, please help
    By cooper in forum General Programming
    Replies: 2
    Last Post: 16th July 2009, 13:46
  3. MinGW conflict?
    By Paolo_R in forum Newbie
    Replies: 3
    Last Post: 30th June 2009, 06:16
  4. Framebuffer conflict
    By Vidar Bøe in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 21st November 2008, 11:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.