Skip to content
Permalink
Browse files

Exposing 2D properties of the tags.

  • Loading branch information...
lorenzolightsgdwarf committed Jul 29, 2016
1 parent 1641c7d commit 5cc8431a6e714f0e10a64c6f6a3239dec5e6d36d
Showing with 119 additions and 15 deletions.
  1. +37 −7 artoolkit.cpp
  2. +13 −1 artoolkit.h
  3. +6 −1 artoolkit.qmltypes
  4. +0 −2 artoolkit_filter_runnable.h
  5. +16 −0 artoolkit_object.cpp
  6. +27 −2 artoolkit_object.h
  7. +16 −1 artoolkit_video_filter.cpp
  8. +4 −1 artoolkit_video_filter.h
@@ -112,7 +112,6 @@ void ARToolKit::run()
Q_FOREACH(int id,ar_objects.keys())
ar_objects[id]->visible=false;


if(marker_num>0){
marker_info=arGetMarker(ar_handle);
/*Pick best markers based on confidence*/
@@ -163,12 +162,13 @@ void ARToolKit::run()
}
/*.....*/
Q_FOREACH(int id,current_markers.keys()){
if(ar_objects.contains(id)){
if(ar_objects.contains(id)){
AR3DObject* o=ar_objects[id];
ARMarkerInfo current_marker=current_markers[id];
if(o->was_visible)
o->size<0 ? err=arGetTransMatSquareCont(ar_3d_handle, &(current_markers[id]), o->pose , default_marker_size, new_pose) : err=arGetTransMatSquareCont(ar_3d_handle, &(current_markers[id]), o->pose , o->size, new_pose);
o->size<0 ? err=arGetTransMatSquareCont(ar_3d_handle, &current_marker, o->pose , default_marker_size, new_pose) : err=arGetTransMatSquareCont(ar_3d_handle, &(current_markers[id]), o->pose , o->size, new_pose);
else
o->size<0 ? err=arGetTransMatSquare(ar_3d_handle, &(current_markers[id]), default_marker_size, new_pose): err=arGetTransMatSquare(ar_3d_handle, &(current_markers[id]), o->size, new_pose);
o->size<0 ? err=arGetTransMatSquare(ar_3d_handle, &current_marker, default_marker_size, new_pose): err=arGetTransMatSquare(ar_3d_handle, &(current_markers[id]), o->size, new_pose);
if(err<0)
continue;
/*Filter*/
@@ -195,10 +195,19 @@ void ARToolKit::run()
o->visible=true;

if(id>0)
posemap[QString("Mat_")+QString::number(--id)]=Pose(o->translation,o->rotation);
posemap[QString("Mat_")+QString::number(--id)]=Pose(o->translation,o->rotation,
QVector2D(current_marker.vertex[(4-current_marker.dirMatrix)%4][0],current_marker.vertex[(4-current_marker.dirMatrix)%4][1]),
QVector2D(current_marker.vertex[(5-current_marker.dirMatrix)%4][0],current_marker.vertex[(5-current_marker.dirMatrix)%4][1]),
QVector2D(current_marker.vertex[(6-current_marker.dirMatrix)%4][0],current_marker.vertex[(6-current_marker.dirMatrix)%4][1]),
QVector2D(current_marker.vertex[(7-current_marker.dirMatrix)%4][0],current_marker.vertex[(7-current_marker.dirMatrix)%4][1])
);
else if(id<0)
posemap[QString("Patt_")+QString::number(-id-1)]=Pose(o->translation,o->rotation);

posemap[QString("Patt_")+QString::number(-id-1)]=Pose(o->translation,o->rotation,
QVector2D(current_marker.vertex[(4-current_marker.dirMatrix)%4][0],current_marker.vertex[(4-current_marker.dirMatrix)%4][1]),
QVector2D(current_marker.vertex[(5-current_marker.dirMatrix)%4][0],current_marker.vertex[(5-current_marker.dirMatrix)%4][1]),
QVector2D(current_marker.vertex[(6-current_marker.dirMatrix)%4][0],current_marker.vertex[(6-current_marker.dirMatrix)%4][1]),
QVector2D(current_marker.vertex[(7-current_marker.dirMatrix)%4][0],current_marker.vertex[(7-current_marker.dirMatrix)%4][1])
);
}
else{
AR3DObject* new_object=new AR3DObject;
@@ -571,3 +580,24 @@ void ARToolKit::setupMarkerParameters()
arPattAttach(ar_handle, ar_patt_handle);
}
}


Pose::Pose()
{
translation=QVector3D();
rotation=QQuaternion();
TLCorner=QVector2D();
TRCorner=QVector2D();
BLCorner=QVector2D();
BRCorner=QVector2D();
}

Pose::Pose(const QVector3D &translation, const QQuaternion &rotation, const QVector2D &TLCorner, const QVector2D &TRCorner, const QVector2D &BRCorner, const QVector2D &BLCorner)
{
this->translation=translation;
this->rotation=rotation;
this->TLCorner=TLCorner;
this->TRCorner=TRCorner;
this->BRCorner=BRCorner;
this->BLCorner=BLCorner;
}
@@ -14,6 +14,7 @@ extern "C"{
#include <QSize>
#include <QMatrix4x4>
#include <QUrl>
#include <QVector2D>
/*
* A handle can load multiple patterns(up to ARPattHandle->patt_num_max).
* The pattern id depends on the order of loading of the file.
@@ -22,7 +23,18 @@ extern "C"{
*/


typedef QPair<QVector3D,QQuaternion> Pose;
struct Pose{
QVector3D translation;
QQuaternion rotation;
QVector2D TLCorner;
QVector2D TRCorner;
QVector2D BRCorner;
QVector2D BLCorner;
Pose();
Pose(const QVector3D& translation, const QQuaternion& rotation,
const QVector2D& TLCorner=QVector2D(-1,-1),const QVector2D& TRCorner=QVector2D(-1,-1),
const QVector2D& BRCorner=QVector2D(-1,-1),const QVector2D& BLCorner=QVector2D(-1,-1));
};
typedef QHash<QString,Pose> PoseMap;


@@ -4,7 +4,7 @@ import QtQuick.tooling 1.2
// It is used for QML tooling purposes only.
//
// This file was auto-generated by:
// 'qmlplugindump -v ARToolkit 1.0'
// 'qmlplugindump ARToolkit 1.0'

Module {
dependencies: ["QtQuick 2.0"]
@@ -16,6 +16,10 @@ Module {
exportMetaObjectRevisions: [0]
Property { name: "translation"; type: "QVector3D"; isReadonly: true }
Property { name: "rotationQuaternion"; type: "QQuaternion"; isReadonly: true }
Property { name: "TLCorner"; type: "QVector2D"; isReadonly: true }
Property { name: "TRCorner"; type: "QVector2D"; isReadonly: true }
Property { name: "BRCorner"; type: "QVector2D"; isReadonly: true }
Property { name: "BLCorner"; type: "QVector2D"; isReadonly: true }
Property { name: "objectIsVisible"; type: "bool"; isReadonly: true }
Property { name: "objectId"; type: "string" }
Signal { name: "poseChanged" }
@@ -58,6 +62,7 @@ Module {
Property { name: "pause"; type: "bool" }
Property { name: "defaultMarkerSize"; type: "double" }
Property { name: "matrixCode"; type: "MATRIX_CODE_TYPE" }
Property { name: "detectedMarkers"; type: "QVariantList"; isReadonly: true }
Method {
name: "unregisterObserver"
Parameter { name: "o"; type: "ARToolKitObject"; isPointer: true }
@@ -12,8 +12,6 @@
#include "artoolkit.h"
#include <QUrl>

typedef QPair<QVector3D,QQuaternion> Pose;
typedef QHash<QString,Pose> PoseMap;

class ARToolkitFilterRunnable: public QObject ,public QVideoFilterRunnable
{
@@ -7,6 +7,22 @@ ARToolKitObject::ARToolKitObject(QQuickItem *parent):
{
m_visible=false;
m_objectId=QString();
m_TLCorner=QVector2D(-1,-1);
m_TRCorner=QVector2D(-1,-1);
m_BRCorner=QVector2D(-1,-1);
m_BLCorner=QVector2D(-1,-1);
}

void ARToolKitObject::setCorners(const QVector2D &TL, const QVector2D &TR, const QVector2D &BR, const QVector2D &BL)
{
m_TLCorner=TL;
m_TRCorner=TR;
m_BLCorner=BL;
m_BRCorner=BR;
emit TLCornerChanged();
emit TRCornerChanged();
emit BRCornerChanged();
emit BLCornerChanged();
}

void ARToolKitObject::prependQuaternion(QQuaternion q)
@@ -6,12 +6,17 @@
#include <QQuickItem>
#include <QString>
#include <QQuaternion>

#include <QVector2D>
class ARToolKitObject : public QQuickItem
{
Q_OBJECT
Q_PROPERTY(QVector3D translation READ translation NOTIFY poseChanged)
Q_PROPERTY(QQuaternion rotationQuaternion READ rotationQuaternion NOTIFY poseChanged)
Q_PROPERTY(QVector2D TLCorner READ TLCorner NOTIFY TLCornerChanged)
Q_PROPERTY(QVector2D TRCorner READ TRCorner NOTIFY TRCornerChanged)
Q_PROPERTY(QVector2D BRCorner READ BRCorner NOTIFY BRCornerChanged)
Q_PROPERTY(QVector2D BLCorner READ BLCorner NOTIFY BLCornerChanged)

Q_PROPERTY(bool objectIsVisible READ objectIsVisible NOTIFY objectIsVisibleChanged)
Q_PROPERTY(QString objectId READ objectId WRITE setObjectId NOTIFY objectIdChanged)
public:
@@ -29,10 +34,20 @@ class ARToolKitObject : public QQuickItem
bool objectIsVisible(){
return m_visible;
}
QVector2D TLCorner(){return m_TLCorner;}
QVector2D TRCorner(){return m_TRCorner;}
QVector2D BRCorner(){return m_BRCorner;}
QVector2D BLCorner(){return m_BLCorner;}

void setVisible(bool val){
if(val!=m_visible){
m_visible=val;
if(!m_visible){
m_TLCorner=QVector2D(-1,-1);
m_TRCorner=QVector2D(-1,-1);
m_BRCorner=QVector2D(-1,-1);
m_BLCorner=QVector2D(-1,-1);
}
emit objectIsVisibleChanged();
}
}
@@ -45,19 +60,29 @@ class ARToolKitObject : public QQuickItem
emit objectIdChanged(tmp);
}
}

void setCorners(const QVector2D& TL,const QVector2D& TR,const QVector2D& BR,const QVector2D& BL);
Q_INVOKABLE void prependQuaternion(QQuaternion q);
Q_INVOKABLE void appendQuaternion(QQuaternion q);
signals:
void poseChanged();
void objectIsVisibleChanged();
void objectIdChanged(QString previousObjID);
void TLCornerChanged();
void TRCornerChanged();
void BRCornerChanged();
void BLCornerChanged();

private:
bool m_visible;
QString m_objectId;
QQuaternion m_rotation;
QVector3D m_translation;
QQuaternion m_pre,m_app;
QVector2D m_TLCorner;
QVector2D m_TRCorner;
QVector2D m_BRCorner;
QVector2D m_BLCorner;

};


@@ -198,11 +198,25 @@ void ARToolKitVideoFilter::updateObserver(QString prevObjId)
void ARToolKitVideoFilter::notifyObservers(const PoseMap &poses)
{
//Change to concurrent
m_detected_markers.clear();
QVariantMap marker_info;
Q_FOREACH(QString key, poses.keys()){
Pose p=poses[key];
marker_info["id"]=key;
marker_info["rotation"]=p.rotation;
marker_info["translation"]=p.translation;
marker_info["TLCorner"]=p.TLCorner;
marker_info["TRCorner"]=p.TRCorner;
marker_info["BRCorner"]=p.BRCorner;
marker_info["BLCorner"]=p.BLCorner;
m_detected_markers.append(marker_info);
}
Q_FOREACH(QString key, m_observers.keys()){
if(poses.contains(key)){
Q_FOREACH(ARToolKitObject* observer, m_observers.values(key)){
Pose p=poses[key];
observer->setPose(p.first,p.second);
observer->setPose(p.translation,p.rotation);
observer->setCorners(p.TLCorner,p.TRCorner,p.BRCorner,p.BLCorner);
observer->setVisible(true);
}
}
@@ -211,6 +225,7 @@ void ARToolKitVideoFilter::notifyObservers(const PoseMap &poses)
observer->setVisible(false);
}
}
emit detectedMarkersChanged();
}

void ARToolKitVideoFilter::cleanFilter()
@@ -20,6 +20,7 @@ class ARToolKitVideoFilter : public QAbstractVideoFilter
Q_PROPERTY(bool pause READ pause WRITE setPause NOTIFY pauseChanged)
Q_PROPERTY(qreal defaultMarkerSize READ defaultMarkerSize WRITE setDefaultMarkerSize NOTIFY defaultMarkerSizeChanged)
Q_PROPERTY(MATRIX_CODE_TYPE matrixCode READ matrixCode WRITE setMatrixCode NOTIFY matrixCodeChanged)
Q_PROPERTY(QVariantList detectedMarkers READ detectedMarkers NOTIFY detectedMarkersChanged)
public:
enum MATRIX_CODE_TYPE {
MATRIX_CODE_3x3= AR_MATRIX_CODE_3x3, // Matrix code in range 0-63.
@@ -55,14 +56,15 @@ class ARToolKitVideoFilter : public QAbstractVideoFilter
void setDefaultMarkerSize(qreal size);
MATRIX_CODE_TYPE matrixCode(){return m_matrix_code;}
void setMatrixCode(MATRIX_CODE_TYPE code);
QVariantList detectedMarkers(){return m_detected_markers;}
signals:
void projectionMatrixChanged();
void pauseChanged();
void cameraResolutionChanged();
void defaultMarkerSizeChanged();
void distortionParametersChanged();
void matrixCodeChanged();

void detectedMarkersChanged();
public slots:

Q_INVOKABLE void unregisterObserver(ARToolKitObject* o);
@@ -96,6 +98,7 @@ private slots:
QString m_multi_marker_config_name;

ARToolkitFilterRunnable* m_filter_runnable;
QVariantList m_detected_markers;
};

#endif // ARUCODETECTOR_H

0 comments on commit 5cc8431

Please sign in to comment.
You can’t perform that action at this time.