Exemplo n.º 1
0
static VALUE Drawable_initialize(int argc, VALUE *argv, VALUE vSelf) {
	// Get C++ object pointer from vSelf
	Drawable *pSelf;
	Data_Get_Struct(vSelf, Drawable, pSelf);
	if(argc == 0) {
		// Nothing to initialize
	} else if(argc >= 1 && argc <= 5 && (argc < 5 || IS(argv[4], g_cColor))) {
		if(argc >= 1)
			pSelf->SetLeft((float)NUM2DBL(argv[0]));
		if(argc >= 2)
			pSelf->SetTop((float)NUM2DBL(argv[1]));
		if(argc >= 3) {
			if(ISNUM(argv[2])) {
				float f = (float)NUM2DBL(argv[2]);
				pSelf->SetScale(f, f);
			} else if(IS(argv[2], rb_cArray)) {
				float x = (float)NUM2DBL(rb_ary_entry(argv[2], 0));
				float y = (float)NUM2DBL(rb_ary_entry(argv[2], 1));
				pSelf->SetScale(x, y);
			}
		}
		if(argc >= 4)
			pSelf->SetRotation((float)NUM2DBL(argv[3]));
		if(argc >= 5)
			pSelf->SetColor(*(Color *)DATA_PTR(argv[4]));
	} else
		rb_raise(rb_eTypeError, "wrong argument type(s)");
	return vSelf;
}
Exemplo n.º 2
0
static VALUE Drawable_set_scale(VALUE vSelf, VALUE vScale) {
	// Get C++ object pointer from vSelf
	Drawable *pSelf;
	Data_Get_Struct(vSelf, Drawable, pSelf);
	if(ISNUM(vScale)) {
		float f = (float)NUM2DBL(vScale);
		pSelf->SetScale(f, f);
	} else if(IS(vScale, rb_cArray)) {
		float x = (float)NUM2DBL(rb_ary_entry(vScale, 0));
		float y = (float)NUM2DBL(rb_ary_entry(vScale, 1));
		pSelf->SetScale(x, y);
	} else
		rb_raise(rb_eTypeError, "wrong argument type(s)");
	return Qnil;
}
void videocallback(IplImage *image)
{
    bool flip_image = (image->origin?true:false);
    if (flip_image) {
        cvFlip(image);
        image->origin = !image->origin;
    }

    if (init) {
        init = false;
        cout << "Loading calibration: " << calibrationFilename.str();
        if (fernEstimator.setCalibration(calibrationFilename.str(), image->width, image->height)) {
            cout << " [Ok]" << endl;
        } else {
            fernEstimator.setResolution(image->width, image->height);
            cout << " [Fail]" << endl;
        }
        double p[16];
        fernEstimator.camera().GetOpenglProjectionMatrix(p, image->width, image->height);
        GlutViewer::SetGlProjectionMatrix(p);
        d.SetScale(10);
        gray = cv::Mat(image);
    }

    if (image->nChannels == 3) {
        cv::Mat img = cvarrToMat(image);
        cv::cvtColor(img, gray, CV_RGB2GRAY);
    }
    else {
        gray = image;
    }

    vector<CvPoint2D64f> ipts;
    vector<CvPoint3D64f> mpts;

    fernDetector.findFeatures(gray, true);
    fernDetector.imagePoints(ipts);
    fernDetector.modelPoints(mpts, true);
    double test = fernDetector.inlierRatio();
    if (test > 0.15 && mpts.size() > 4) {
        fernEstimator.calculateFromPointCorrespondences(mpts, ipts);
    }

    GlutViewer::DrawableClear();
    Pose pose = fernEstimator.pose();
    pose.GetMatrixGL(d.gl_mat);
    GlutViewer::DrawableAdd(&d);

    if (flip_image) {
        cvFlip(image);
        image->origin = !image->origin;
    }
}