AR in Linux C++

hi

i am trying to convert a sample of a AR into C++

i have created the window and a the card maker into c++ but i don know who to use the openCVtexture

can some one help me please

i put the ar sample in python and my version in c++

python example

from pandac.PandaModules import *
loadPrcFileData("", "auto-flip 1") #usualy the drawn texture lags a bit behind the calculted positions. this is a try to reduce the lag.

from direct.directbase import DirectStart
from direct.task import Task
from time import sleep



#------use OpenCVTexture under linux---------- use WebcamVideo under windows------------

tex = OpenCVTexture()
#---------------------

tex.setTexturesPower2(0)
#if you want to know what assert is doing.. ask pro-rsoft. all i know is, it prevents an assertion error :D

assert tex.fromCamera(0)



#create a card which shows the image captured by the webcam.

cm = CardMaker("background-card")

cm.setFrame(-1, 1, 1, -1)

card = render2d.attachNewNode(cm.generate())

card.setTexture(tex)

#set the rendering order manually to render the card-with the webcam-image behind the scene.

base.cam.node().getDisplayRegion(0).setSort(20)


#load a model to visualize the tracking
axis = loader.loadModel("sofa.egg")
axis.reparentTo(render)
axis.setScale(.2)


#initialize artoolkit, base.cam is our camera ,
#the camera_para.dat is the configuration file for your camera. this one comes with the artoolkit installation.
#last paremeter is the size of the pattern in panda-units.

ar = ARToolKit.make(base.cam, "./camera_para.dat", 1)

#attach the model to a pattern so it updates the model's position relative to the camera each time we call analyze()

ar.attachPattern("./patt.kanji", axis)

#updating the models positions each frame.

def updatePatterns(task):
	ar.analyze(tex, False)
  	return Task.cont
  
  
sleep(1) #some webcams are quite slow to start up so we add some safety

taskMgr.add(updatePatterns, "update-patterns",-100)



run()

c++ example

// Include all the stuff
#include "pandaFramework.h"
#include "pandaSystem.h"
#include "movieTexture.h"
#include "cardMaker.h"
#include "openCVTexture.h"
 
PandaFramework framework;

//Global variables
PT(MovieTexture) tex = new MovieTexture("name");
 
int main(int argc, char *argv[]) {

framework.open_framework(argc, argv);
framework.set_window_title("My Panda3D Window");
WindowFramework *window = framework.open_window();
TextureStage *stage;
LVecBase2f scale;  


tex->read("PandaSneezes.avi");   
//Setup a fullscreen card to set the video texture on.
CardMaker cm = CardMaker::CardMaker("My Fullscreen Card");
cm.set_frame_fullscreen_quad();
cm.set_uv_range(tex);   

NodePath *card = new NodePath(cm.generate());
card->reparent_to(window->get_render_2d());
card->set_texture(tex);
scale = tex->get_tex_scale();     
card->set_tex_scale(stage->get_default(), scale); 
 
//do the main loop, equal to run() in python
framework.main_loop();
//close the window framework
framework.close_framework();
return (0);
}

:unamused:

What exactly is not working?

I do know that OpenCVTexture is broken in Panda3D 1.7.x, sorry.

hi

the problem is how to use openCVtexture

in c++

i am using the 1.6.2 version o panda in ubuntu 9.10

where is the problem?
watch line 72 in the class references of your needed class. that how you declare your thingi. the panda sneeze vid dont have a known pattern inside, although he is black and white.

should not be hard to port this code into c++. :unamused: