QImage unable to open jpg files



  • Hi,

    I am developing some software with Qt and OpenCV.
    I made a simple widget to open images files. If I open with OpenCV (imread) and than shows with Qt I don't have any problem.
    If I open the files with Qt (QImage::load) I cannot open all the jpg files.
    I tried with the example that I found in Qt installation and I see the same problem.

    Regards.


  • Lifetime Qt Champion

    Hi,

    How did you install Qt ?

    What does qDebug() << QImageReader::supportedImageFormats() return ?



  • Hi,

    I have built Qt from sources on Jetson TK1 where I have Ubuntu 14.04 LTS.
    As I wrote the problem is not for all the jpg files.
    In particular i have jpg files that I saved from 2 different webcams (Logitech C270 and C920-C) both using a Qt program and from Gnome Cheese.
    I have problem to open the two files saved with Qt.

    This is what qDebug returns:
    ("bmp", "cur", "dds", "gif", "icns", "ico", "jp2", "jpeg", "jpg", "mng", "pbm", "pgm", "png", "ppm", "svg", "svgz", "tga", "tif", "tiff", "wbmp", "webp", "xbm", "xpm")

    Regards.


  • Lifetime Qt Champion

    So, do you mean that saving a jpeg with Qt will no open with Qt again ?



  • Yes, it looks so.



  • Do you view the images from the webcams in your Qt application before saving it with Qt (QImage::save())?



  • I think to have found the reason.
    At the beginning I included only QImage together with Opencv and I can open the jpeg files, saved by Qt, using cv::imread.
    Later I added QCamera library in the same project and I got some messages like:

    JPEG parameter struct mismatch: library thinks size is 432, caller expect 488.

    But if use QImage alone I can work without problems.
    Then I tried to save the picture in PNG format and I can open without problem with Qt.
    So, my idea is that there is some kind of conflict about JPEG format.

    Regards.


  • Lifetime Qt Champion

    You might be using two different versions of the jpeg library. The one used by OpenCV and the one for the jpeg plugin in Qt.



  • @mchinand Yes, I can see the images from webcam. I use to shows in a widget with the class QViewfinder.
    To save file I use the functions provide by QCameraImageCapture.
    Moreover I show the captured frame in a QLabel widget by QPixmap and from this I saved with QFile.
    But the same problem.
    If I save in PNG or TIFF no problem.

    @SGaist I think you are right, but I don't know how to say to Qt to use the same of OpenCV.
    I could use OpenCV to capture the image from webcam, the problem is that OpenCV let me to do with a fix resolution. So, to try to overcome a problem I face another one.

    Regards


  • Lifetime Qt Champion

    Did you build either for them ?



  • @SGaist
    OpenCV was already built in the software pack supplied with Jetson Tk1.
    The version is made in order to get the best performance from the Jetson board.
    Later I built Qt and Qt Creator.
    I follow the instructions I found in Qt wiki and I added the suggested library (Building from git).
    But I have not so deep knowledge to understand if there was something connected with jpeg library.

    Regards.


  • Lifetime Qt Champion

    Check with ldd where the libjpeg used by OpenCV is located. If it's the system lib then you can add -system-libjpeg to your configure options.


  • Lifetime Qt Champion

    You might also want to check with Qt 5.5.1 there was a bug in 5.5.0 see this bug report



  • @SGaist Thank you for your advices.
    I am workig on them. I will inform you as soon as I have some results.



  • @SGaist
    I am back again.
    Before to build with the new 5.5.1 I reset the Jetson TK1 with the new release of Jetson Pack (Before I had 1.1 now 1.2).
    I download from Qt git the version 5.5.1 and I compiled without problem.
    Then I download from git the version 3.6 of QtCreator and compiled wtihout problem (to compile correctly I had to modify something in 3rd party Botan as I found in nVidia forum).
    When I run Qt Creator I have a problem in the configuration of Buil & Run.
    I can configure the GCC Compiler but in the Kit the Compiler doesn't show any option.

    MZ



  • @SGaist

    About QtCreator: I can use the version that I get form Ubutnu repository (3.0.1) and I can configure the Kit without problem.

    About jpeg: I still have problem. Now I cannot read the image from webcam.

    MZ


  • Lifetime Qt Champion

    Are you sure you are building using the system libjpeg ?



  • With the version 5.5.0 the option didin't work. There was an error.
    Now I try again with 5.5.1 and I have an error again.
    Here the steps i did:

    • download source from git;
    • init-repository ( I use the option --no-webkit but it looks it doesn't work because I get also webkit);
    • checkout 5.5.1;
    • removed manually webkits/webengine (deleted forlders);
    • ./configure -qtxcb -system-libjpeg -nomake examples -nomake tests;
    • make: with -system-libjpeg I have an error
      ../../../gui/image/qjpeghandler.cpp:64:21: fatal error: jpeglib.h: No such file or directory

    MZ


  • Lifetime Qt Champion

    Did you install the system libjpeg dev package ?



  • You are right, I forgot to install it.
    I did and rebuild.
    But still the same error:
    JPEG parameter struct mismatch: library thinks size is 432, caller expect 488.

    In the past I looked for examples of use of Qt + OpenCV and if possible developed on Jetson TK1.
    I found some example of Qt + OpenCV and one project developed on Jetson TK1 with only OpenCV.
    All don't use Qt (QCamera) to grab pictures (while they use all the other features of Qt, even QThread) but directly OpenCV.
    The one developed with Jetson TK1 has developed a tool based directly on V4L2, to have more flexibility in the control of the camera.
    These examples work.

    MZ


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.