Пример #1
0
QMatrix4x4 ChilitagsDetection::projectionMatrix() const {
    cv::Mat mat = m_surface.getChilitags().getCameraMatrix();
    QMatrix4x4 projectionMatrix;

    projectionMatrix.fill(0);
    for (int i = 0; i<3; ++i)
        for (int j = 0; j<3; ++j)
            projectionMatrix(i,j) = mat.at<double>(i,j);
    projectionMatrix(3,2) = 1;

    return projectionMatrix;
 }
Пример #2
0
static QMatrix4x4 channelMap(const VideoFormat& fmt)
{
    if (fmt.isPlanar()) //currently only for planar
        return QMatrix4x4();
    switch (fmt.pixelFormat()) {
    case VideoFormat::Format_UYVY:
        return QMatrix4x4(0.0f, 0.5f, 0.0f, 0.5f,
                                 1.0f, 0.0f, 0.0f, 0.0f,
                                 0.0f, 0.0f, 1.0f, 0.0f,
                                 0.0f, 0.0f, 0.0f, 1.0f);
    case VideoFormat::Format_YUYV:
        return QMatrix4x4(0.5f, 0.0f, 0.5f, 0.0f,
                                 0.0f, 1.0f, 0.0f, 0.0f,
                                 0.0f, 0.0f, 0.0f, 1.0f,
                                 0.0f, 0.0f, 0.0f, 1.0f);
    case VideoFormat::Format_VYUY:
        return QMatrix4x4(0.0f, 0.5f, 0.0f, 0.5f,
                                 0.0f, 0.0f, 1.0f, 0.0f,
                                 1.0f, 0.0f, 0.0f, 0.0f,
                                 0.0f, 0.0f, 0.0f, 1.0f);
    case VideoFormat::Format_YVYU:
        return QMatrix4x4(0.5f, 0.0f, 0.5f, 0.0f,
                                 0.0f, 0.0f, 0.0f, 1.0f,
                                 0.0f, 1.0f, 0.0f, 0.0f,
                                 0.0f, 0.0f, 0.0f, 1.0f);
    case VideoFormat::Format_VYU:
        return QMatrix4x4(0.0f, 1.0f, 0.0f, 0.0f,
                                 0.0f, 0.0f, 1.0f, 0.0f,
                                 1.0f, 0.0f, 0.0f, 0.0f,
                                 0.0f, 0.0f, 0.0f, 1.0f);
    default:
        break;
    }

    const quint8 *channels = NULL;//{ 0, 1, 2, 3};
    for (int i = 0; gl_channel_maps[i].pixfmt != VideoFormat::Format_Invalid; ++i) {
        if (gl_channel_maps[i].pixfmt == fmt.pixelFormat()) {
            channels = gl_channel_maps[i].channels;
            break;
        }
    }
    QMatrix4x4 m;
    if (!channels)
        return m;
    m.fill(0);
    for (int i = 0; i < 4; ++i) {
        m(i, channels[i]) = 1;
    }
    qDebug() << m;
    return m;
}
Пример #3
0
void ARCameraCalibrator::drawCalibrationGrid()
{
    using namespace QScrollEngine;
    QMutexLocker ml(&m_mutex);

    if (scene() == nullptr)
        return;

    if (m_lastCalibrationFrame->isCreated()) {
        QScrollEngineContext* context = scene()->parentContext();
        AR::Point2i frameSize = m_lastCalibrationFrame->imageSize();

        context->glDepthMask(GL_FALSE);
        context->glDisable(GL_DEPTH_TEST);
        context->glDisable(GL_BLEND);

        if (m_flagUpdateFrameTexture) {
            if (m_tempFrameTexture->isCreated()) {
                if ((m_tempFrameTexture->width() != m_lastImage.width()) ||
                        (m_tempFrameTexture->height() != m_lastImage.height())) {
                    m_tempFrameTexture->bind();
                    m_tempFrameTexture->destroy();
                    m_tempFrameTexture->setFormat(QOpenGLTexture::RGBA8_UNorm);
                    m_tempFrameTexture->setSize(m_lastImage.width(), m_lastImage.height(), 4);
                    m_tempFrameTexture->allocateStorage();
                } else {
                    m_tempFrameTexture->bind();
                }
            } else {
                m_tempFrameTexture->create();
                m_tempFrameTexture->bind();
                m_tempFrameTexture->setFormat(QOpenGLTexture::RGBA8_UNorm);
                m_tempFrameTexture->setSize(m_lastImage.width(), m_lastImage.height(), 4);
                m_tempFrameTexture->allocateStorage();
            }
            if (m_lastPixelFormat == QVideoFrame::Format_BGR32) {
                m_tempFrameTexture->setData(QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, m_lastImage.data());
            } else {
                m_tempFrameTexture->setData(QOpenGLTexture::BGRA, QOpenGLTexture::UInt8, m_lastImage.data());
            }
            m_tempFrameTexture->generateMipMaps();
        }

        m_textureRenderer->draw(m_tempFrameTexture->textureId(), m_textureMatrix);

        QMatrix4x4 textureMatrix;
        textureMatrix.fill(0.0f);
        for (int i=0; i<2; ++i) {
            textureMatrix(i, 0) = m_textureMatrix(i, 0);
            textureMatrix(i, 1) = m_textureMatrix(i, 1);
            textureMatrix(i, 3) = m_textureMatrix(i, 2);
        }
        textureMatrix(3, 0) = m_textureMatrix(2, 0);
        textureMatrix(3, 1) = m_textureMatrix(2, 1);
        textureMatrix(3, 3) = m_textureMatrix(2, 2);

        QMatrix4x4 t;
        t.setToIdentity();
        t(0, 0) = 0.5f;
        t(1, 1) = -0.5f;
        t(0, 3) = 0.5f;
        t(1, 3) = 0.5f;

        QMatrix4x4 transformMatrix;
        transformMatrix.ortho(0.0f, (float)(frameSize.x),
                              0.0f, (float)(frameSize.y), 0.0f, 1.0f);
        transformMatrix = t.inverted() * textureMatrix * t * transformMatrix;

        int countLineVertices;
        QVector2D* lineVertices;

        context->glLineWidth(4.0f);

        countLineVertices = (int)(m_linesOfImageGrid.size() * 2);
        lineVertices = new QVector2D[countLineVertices];
        for (int i=0; i<(int)m_linesOfImageGrid.size(); ++i) {
            std::pair<AR::Point2f, AR::Point2f>& line = m_linesOfImageGrid[i];
            lineVertices[i * 2].setX(line.first.x);
            lineVertices[i * 2].setY(line.first.y);
            lineVertices[i * 2 + 1].setX(line.second.x);
            lineVertices[i * 2 + 1].setY(line.second.y);
        }
        context->drawLines(lineVertices, countLineVertices, QColor(0, 155, 255), transformMatrix);
        delete[] lineVertices;

        context->glEnable(GL_BLEND);

        /*countLineVertices = (int)(m_linesOf3DGrid.size() * 2);
        lineVertices = new QVector2D[countLineVertices];
        for (int i=0; i<(int)m_linesOf3DGrid.size(); ++i) {
            std::pair<AR::Point2f, AR::Point2f>& line = m_linesOf3DGrid[i];
            lineVertices[i * 2].setX(line.first.x);
            lineVertices[i * 2].setY(line.first.y);
            lineVertices[i * 2 + 1].setX(line.second.x);
            lineVertices[i * 2 + 1].setY(line.second.y);
        }
        context->drawLines(lineVertices, countLineVertices, QColor(155, 0, 255, 100), transformMatrix);
        delete[] lineVertices;*/

        context->glLineWidth(4.0f);

        countLineVertices = (int)(m_errors.size() * 2);
        lineVertices = new QVector2D[countLineVertices];
        for (int i=0; i<(int)m_errors.size(); ++i) {
            std::pair<AR::Point2f, AR::Point2f>& line = m_errors[i];
            lineVertices[i * 2].setX(line.first.x);
            lineVertices[i * 2].setY(line.first.y);
            lineVertices[i * 2 + 1].setX(line.second.x);
            lineVertices[i * 2 + 1].setY(line.second.y);
        }
        context->drawLines(lineVertices, countLineVertices, QColor(255, 255, 0, 200), transformMatrix);
        delete[] lineVertices;

        context->glDisable(GL_BLEND);
    }
}