Opencv image in qt3d



  • Hello, i am successfully able to integrate QT with opencv using this tutorial:

    http://stackoverflow.com/questions/15881913/how-to-link-opencv-in-qtcreator-and-use-qt-library

    However, i am trying to write the code not in the main.cpp file but in a different cubevie.cpp file that comes as a tutorial with qt3d.

    @/*
    ****************************************************************************/
    #include <QApplication>
    #include "cubeview.h"
    #include "qglbuilder.h"
    #include "qglcube.h"
    #include "haptics.h"
    #include <iostream>
    #include <QThread>
    #include <QTimer>
    #include <QDebug>
    #include "qglpainter.h"
    #include "qgraphicstranslation3d.h"
    #include "opencv2/core/core.hpp"
    #include "opencv2/highgui/highgui.hpp"
    //#include "opencv/cv.h"

    //! [1] constructor, initialize the cube, cursor and camera
    CubeView::CubeView(QWidget *parent)
    {
    //opencv code
    cv::Mat image;
    image= cv::imread(":/blackcircle.jpg");
    cv::namedWindow("hello");
    cv::imshow("hello", image)

    //! [1]
    QGLBuilder builder1;
    builder1 << QGL::Faceted;
    builder1 << QGLCube(2);
    cube = builder1.finalizedSceneNode();
    
    //camera setup
    camera()->setFieldOfView(35);
    camera()->setNearPlane(1);
    camera()->setFarPlane(15);
    

    //! [2] set texture for cube and cursor
    logo.setImage(QImage(QLatin1String(":/blackcircle.jpg")));

    }

    CubeView::~CubeView()
    {
    logo.cleanupResources();
    delete cube;
    }
    //! [3]
    void CubeView::paintGL(QGLPainter *painter)
    {
    painter->setStandardEffect(QGL::LitDecalTexture2D);
    logo.bind();
    cube->draw(painter);

    }

    @

    *But this gives me the following error.
    QWidget: Cannot create a QWidget without QApplication
    Invalid parameter passed to C runtime function.

    Is it because, already a window is open and I cannot open another window to see my image?*


Log in to reply
 

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