2013年3月30日土曜日

Sony Vaio Duo 11 Review: AR developers' perspective

This review is only interested in whether the Sony Vaio Duo 11, a Window 8 tablet PC, can be used as an augmented reality (AR) terminal. The most important advantages of Windows 8 tablet as far as this review are that windows developers are not forced to change their programming environment, and that Windows 8 devices only offer the option of using Intel CPUs. Therefore, this review does not mention the usability of either normal Windows 8 GUI or pre-installed software.

Configuration related to AR

  • OS: Windows 8 Pro 64
  • CPU: Intel Core i7-3687U (max 3.30GHz, 2 cores, 4 threads)
  • GPU: Intel HD Graphics 4000
  • RAM: 8GB
  • rear camera: Full HD web camera
  • front camera: Full HD web camera
  • pose sensor:accelerometer,gyro,magnetic field sensor
  • weight: 1.665 kg
  • size: 319.9mm×199mm×17.85mm

Limitation on Camera Capture

If you use Vaio Duo 11 as an AR device, the camera, together with the display, becomes an indispensable part. The Vaio duo 11 has front and rear cameras which are placed in opposite directions to each other. The rear camera can be used to obtain a real scene to be displayed with virtual (CG) objects. The front camera can also be used to detect user's action for interaction in augmented reality space. In this sense, it is interesting whether or not both cameras can work simultaneously, which has not yet been seen. The following list shows the possible combination of video resolutions.

  • front: 320x240 (7.5fps), rear: 1280x1024 (7.5fps) (frame droping)
  • front: 640x480 (30fps), rear: 640x480 (30fps) (frame droping)
  • front: 640x480 (30fps), rear: 320x240 (30fps)
  • front: 320x240 (30fps), rear: 640x480 (30fps)
  • front: 320x240 (30fps), rear: 320x240 (30fps)

Possible choice in practical use for AR is 640x480 pixels for one camera and 320x240 for the other. What is surprising is that each camera cannot capture full HD resolution video (1920 x 1080) at 30 fps. "Full HD web camera" means full HD sill camera. This is a really misleading expression. The above list were obtained by testing the following OpenCV code. DirectShow GraphEdit did not work well.

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
 
int main(int, char**)
{
    VideoCapture cap1(0);
    cap1.set(CV_CAP_PROP_FRAME_WIDTH, 320.0);
    cap1.set(CV_CAP_PROP_FRAME_HEIGHT,240.0);
 
    VideoCapture cap2(1);
    cap2.set(CV_CAP_PROP_FRAME_WIDTH,640);
    cap2.set(CV_CAP_PROP_FRAME_HEIGHT,480);
 
    std::cout &lt;&lt; cap1.get(CV_CAP_PROP_FPS);
    std::cout &lt;&lt; cap2.get(CV_CAP_PROP_FPS);
 
    cap1.set(CV_CAP_PROP_FPS,30);
    cap2.set(CV_CAP_PROP_FPS,30);
 
    double sum_t = 0;
    for(int i=0;;i++)
    {
        double t = (double)getTickCount();
        Mat frame1;
        cap1 &gt;&gt; frame1;
        imshow(&quot;cap1&quot;, frame1);
 
        Mat frame2;
        cap2 &gt;&gt; frame2;
        imshow(&quot;cap2&quot;, frame2);
 
        sum_t += getTickFrequency()/((double)getTickCount() - t);
        if(i % 10 ==0)
        {
            std::cout &lt;&lt; sum_t/10 &lt;&lt; &quot;\r&quot;;
            sum_t =0;
        }
        if(waitKey(1) &gt;= 0) break;
    }
    return 0;
}

2013年3月7日木曜日

PTAM/PTAMMの変数アクセス法

Trackerクラスからのアクセス

現在のキーフレームで観測される特徴点の三次元位置を列挙したい

PTAM/PTAMMの特徴はキーフレームという代表フレーム上の特徴点のみが三次元復元される。 現在のフレームに最も違いカメラ位置であるキーフレームで観測される特徴点のみを列挙したい場合には、 Trackerクラスのメンバ変数mCurrentKFから特徴点を参照すれば良い。

KeyFrame & nearestKF = mMapMaker.ClosestKeyFrame(mCurrentKF); //もともとprivateだがpublicに変更した
std::map::iterator p;
std::map::iterator s = nearestKF.mMeasurements.begin();
std::map::iterator e = nearestKF.mMeasurements.end();
for(p = s; p != e; ++p)
{
 MapPoint& mp = *(p->first);
 if(mp.bBad) continue; //三次元位置が推定されていない点も登録されている
 std::cout 
  << mp.veWorldPos[0] << "," 
  << mp.veWorldPos[1] << "," 
  << mp.veWorldPos[2] << std::endl;
}

現フレームでトラックされた特徴点の三次元位置を列挙したい

現フレームで新たに検出された特徴点のうち、 既に三次元位置が登録されている特徴点とのマッチングを終え、 マップ点の三次元位置と関連付けられている特徴点のみを列挙したい場合は、 特徴点を参照するタイミングに注意せねばならない。 単純には、以下のmy_process()ようにトラッキングを終えた直後に、参照すればよい。

void Tracker::TrackFrame(Image<CVD::byte> &imFrame, bool bDraw)
{
    :
    :
 
    // Decide what to do - if there is a map, try to track the map ...
    if(mpMap->IsGood())
    {
        if(mnLostFrames < NUM_LOST_FRAMES)  // .. but only if we're not lost!
        {
            if(mbUseSBIInit)
                CalcSBIRotation();
            ApplyMotionModel();       // 
            TrackMap();               //  These three lines do the main tracking work.
            UpdateMotionModel();      // 
 
            //このタイミングでトラッキングされたばかりの特徴点データを取得する。
            my_process();

この箇所では、TrackerDataからとランキングされている特徴点の三次元位置を以下のように取得する。

void Tracker::my_process()
{
    vector<TrackerData*>::iterator it = vIterationSet.begin();
    for(; it!= vIterationSet.end(); ++it)
    {
        if(! (*it)->bFound) continue;
 
        //2d
        Vector<2> & pos2d = (*it)->v2Found;
        cout << boost::fromat("2d point: %f, %f\n") % pos2d[0] % pos2d[1];
 
        //3d
        Vector<3> & pos3d = (*it)->Point.v3WorldPos;
        cout << boost::fromat("3d point: %f, %f, %f\n") % pos3d[0] % pos2d[1] % pos2d[2];
    }
}