Fixin a few bugs

This commit is contained in:
Josh Yelon 2007-11-12 06:20:10 +00:00
parent 08fd26dbd0
commit 2f42e29cf7
3 changed files with 29 additions and 20 deletions

View File

@ -16,4 +16,16 @@
//
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
// Function: ARToolKit::set_threshold
// Access: private
// Description: As part of its analysis, the ARToolKit occasionally
// converts images to black and white by thresholding
// them. The threshold is set to 0.5 by default, but
// you can tweak it here.
////////////////////////////////////////////////////////////////////
INLINE void ARToolKit::
set_threshold(double thresh) {
_threshold = thresh;
}

View File

@ -163,6 +163,7 @@ make(NodePath camera, const Filename &paramfile, double marker_size) {
ARToolKit *result = new ARToolKit();
result->_camera = camera;
result->_camera_param = new ARParam;
result->_threshold = 0.5;
result->_marker_size = marker_size;
memcpy(result->_camera_param, &wparam, sizeof(wparam));
return result;
@ -256,9 +257,10 @@ detach_patterns() {
// Function: ARToolKit::analyze
// Access: Public
// Description: Analyzes the non-pad region of the specified texture.
// This causes all attached nodepaths to move.
////////////////////////////////////////////////////////////////////
void ARToolKit::
analyze(Texture *tex, double thresh) {
analyze(Texture *tex) {
nassertv(tex->has_ram_image());
nassertv(tex->get_ram_image_compression() == Texture::CM_off);
nassertv(tex->get_component_type() == Texture::T_unsigned_byte);
@ -301,8 +303,7 @@ analyze(Texture *tex, double thresh) {
ARMarkerInfo *marker_info;
int marker_num;
cerr << "Analyze video " << xsize << " x " << ysize << "\n";
if (arDetectMarker(data, thresh, &marker_info, &marker_num) < 0) {
if (arDetectMarker(data, _threshold * 256, &marker_info, &marker_num) < 0) {
grutil_cat.error() << "ARToolKit detection error.\n";
return;
}
@ -338,22 +339,17 @@ analyze(Texture *tex, double thresh) {
mat(3,3) = 1.0;
LVecBase3f scale, shear, hpr, pos;
decompose_matrix(mat, scale, shear, hpr, pos);
np.set_pos(pos);
np.set_hpr(hpr);
NodePath parent = np.get_parent();
if (parent.is_empty()) {
grutil_cat.error() << "NodePath must have a parent.\n";
} else {
np.reparent_to(_camera);
np.set_pos_hpr(pos,hpr);
np.wrt_reparent_to(parent);
}
np.show();
// cerr << "Markert:\n"
// << " Id: " << inf->id << "\n"
// << " Area: " << inf->area << "\n"
// << " Dir: " << inf->dir << "\n"
// << " Cf: " << inf->cf << "\n"
// << " Pos: " << inf->pos[0] << "," << inf->pos[1] << "\n"
// << " Vtx0: " << inf->vertex[0][0] << "," << inf->vertex[0][1] << "\n"
// << " Vtx1: " << inf->vertex[1][0] << "," << inf->vertex[1][1] << "\n"
// << " Vtx2: " << inf->vertex[2][0] << "," << inf->vertex[2][1] << "\n"
// << " Vtx3: " << inf->vertex[3][0] << "," << inf->vertex[3][1] << "\n"
// << " Row0: " << patt_trans[0][0] << " " << patt_trans[0][1] << " " << patt_trans[0][2] << " " << patt_trans[0][3] << "\n"
// << " Row1: " << patt_trans[1][0] << " " << patt_trans[1][1] << " " << patt_trans[1][2] << " " << patt_trans[1][3] << "\n"
// << " Row2: " << patt_trans[2][0] << " " << patt_trans[2][1] << " " << patt_trans[2][2] << " " << patt_trans[2][3] << "\n";
} else {
np.hide();
}

View File

@ -50,9 +50,10 @@ PUBLISHED:
static ARToolKit *make(NodePath camera, const Filename &paramfile, double markersize);
~ARToolKit();
INLINE void set_threshold(double n);
void attach_pattern(const Filename &pattern, NodePath path);
void detach_patterns();
void analyze(Texture *tex, double thresh);
void analyze(Texture *tex);
private:
static int get_pattern(const Filename &pattern);
@ -67,7 +68,7 @@ private:
NodePath _camera;
void *_camera_param;
double _threshold;
double _marker_size;
};