chili-epfl / chilitags

Robust Fiducial Markers for Augmented Reality And Robotics
http://chili.epfl.ch/software
123 stars 57 forks source link

Tag size adjustment and resolution #51

Closed patrickliu90 closed 10 years ago

patrickliu90 commented 10 years ago

Hi everyone, I'm new to chilitags. I made some tags of my own, and the size of the my tags is different from the initialized tag size, so when I'm reading from the transformation matrix, the translation vector is a little odd. Could somebody how to fix this? Or where I can reset the tag size (maybe the length of the black and white boxes) in the code?

And I also have some difficulty adjusting my camera's resolution, my Logitech webcam have pretty good resolution, in the estimate3d-gui the resolution is set to 640*480, anyone know where I can change that?

Should be some basic questions, thanks a lot, Chi

qbonnard commented 10 years ago

Hello !

Regarding the tag of the size, would Chilitag3D::setDefaultSize() help ?

estimate3d-gui does not take command line parameters for the resolution like detect-live does, but something like: int xRes = 1600; int yRes = 1200;

ifdef OPENCV3

capture.set(cv::CAP_PROP_FRAME_WIDTH, xRes);
capture.set(cv::CAP_PROP_FRAME_HEIGHT, yRes);

else

capture.set(CV_CAP_PROP_FRAME_WIDTH, xRes);
capture.set(CV_CAP_PROP_FRAME_HEIGHT, yRes);

endif

after you initialised the videocapture shoud do the trick.

On Thu, Jul 17, 2014 at 10:38 PM, patrickliu90 notifications@github.com wrote:

Hi everyone, I'm new to chilitags. I made some tags of my own, and the size of the my tags is different from the initialized tag size, so when I'm reading from the transformation matrix, the translation vector is a little odd. Could somebody how to fix this? Or where I can reset the tag size (maybe the length of the black and white boxes) in the code?

And I also have some difficulty adjusting my camera's resolution, my Logitech webcam have pretty good resolution, in the estimate3d-gui the resolution is set to 640*480, anyone know where I can change that?

Should be some basic questions, thanks a lot, Chi

— Reply to this email directly or view it on GitHub https://github.com/chili-epfl/chilitags/issues/51.

patrickliu90 commented 10 years ago

Thanks, I think capture.set() can only handle one input, I tried your method and there is a compile error.

About the tag size, where can I find the description of Chilitag3D::setDefaultSize() ? I'm also wondering the default size is the size of the whole tag (the size of the big black squire) or the size of the black and white boxes, and is it in millimeter or centimeter.

Thanks, a lot. Chi

severin-lemaignan commented 10 years ago

Hello Patrick,

You'll find answers to your questions in the API documentation:

Hope it answers your questions! (if it does, please close the issue. Otherwise, ask ;-) )

patrickliu90 commented 10 years ago

Actually I already tried the default resolution setting in chilitags.hpp, I changed it to 1024*576, like this

Chilitags3D(cv::Size cameraResolution = cv::Size(1024, 576));

which I'm sure my webcam has this resolution, but it does not work, after compilation the binary still gives a window with 640*480 resolution, and can't be amplified. I'm using a Logitech c920 webcam btw don't know if it helps.

About the tag size adjustment, I'm kind of nube, could you give me something like maybe a piece of code and where it should be, my tag size is 90mm. The .yml file really confuses me.

Thanks a lot

severin-lemaignan commented 10 years ago

Copy-pasted from estimatio3d-gui.

/*******************************************************************************
* Copyright 2013-2014 EPFL *
* Copyright 2013-2014 Quentin Bonnard *
* *
* This file is part of chilitags. *
* *
* Chilitags is free software: you can redistribute it and/or modify *
* it under the terms of the Lesser GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* Chilitags is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with Chilitags. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************/

#include <iostream>

#include <chilitags.hpp>

#include <opencv2/core/core.hpp> // for cv::Mat
#include <opencv2/core/core_c.h> // CV_AA
#include <opencv2/highgui/highgui.hpp> // for camera capture
#include <opencv2/imgproc/imgproc.hpp> // for camera capture

using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{

    /*****************************/
    /* Init camera capture */
    /*****************************/
    int cameraIndex = 0;
    cv::VideoCapture capture(cameraIndex);
    if (!capture.isOpened())
    {
        cerr << "Unable to initialise video capture.\n";
        return 1;
    }

    /******************************/
    /* Setting up pose estimation */
    /******************************/
    double inputWidth = 1024;
    double inputHeight = 576;
    capture.set(CV_CAP_PROP_FRAME_WIDTH, inputWidth);
    capture.set(CV_CAP_PROP_FRAME_HEIGHT, inputHeight);

    chilitags::Chilitags3D chilitags3D(Size(inputWidth, inputHeight));
    chilitags3D.setDefaultTagSize(90);

    cv::Mat projectionMat = cv::Mat::zeros(4,4,CV_64F);
    chilitags3D.getCameraMatrix().copyTo(projectionMat(cv::Rect(0,0,3,3)));
    cv::Matx44d projection = projectionMat;
    projection(3,2) = 1;

    /*****************************/
    /* Go! */
    /*****************************/
    cv::namedWindow("Pose Estimation");

    for (; 'q' != (char) cv::waitKey(10); ) {
        cv::Mat inputImage;
        capture.read(inputImage);
        cv::Mat outputImage = inputImage.clone();

        for (auto& kv : chilitags3D.estimate(inputImage)) {

            static const float DEFAULT_SIZE = 20.f;
            static const cv::Vec4d UNITS[4] {
                {0.f, 0.f, 0.f, 1.f},
                {DEFAULT_SIZE, 0.f, 0.f, 1.f},
                {0.f, DEFAULT_SIZE, 0.f, 1.f},
                {0.f, 0.f, DEFAULT_SIZE, 1.f},
            };

            cv::Matx44d transformation = kv.second;
            cv::Vec4f referential[4] = {
                projection*transformation*UNITS[0],
                projection*transformation*UNITS[1],
                projection*transformation*UNITS[2],
                projection*transformation*UNITS[3],
            };

            std::vector<cv::Point2f> t2DPoints;
            for (auto homogenousPoint : referential)
                t2DPoints.push_back(cv::Point2f(
                    homogenousPoint[0]/homogenousPoint[3],
                    homogenousPoint[1]/homogenousPoint[3]));

            static const int SHIFT = 16;
            static const float PRECISION = 1<<SHIFT;
            static const std::string AXIS_NAMES[3] = { "x", "y", "z" };
            static const cv::Scalar AXIS_COLORS[3] = {
                {0,0,255},{0,255,0},{255,0,0},
            };
            for (int i : {1,2,3}) {
                cv::line(
                    outputImage,
                    PRECISION*t2DPoints[0],
                    PRECISION*t2DPoints[i],
                    AXIS_COLORS[i-1],
                    1, CV_AA, SHIFT);
                cv::putText(outputImage, AXIS_NAMES[i-1], t2DPoints[i],
                            cv::FONT_HERSHEY_SIMPLEX, 0.5, AXIS_COLORS[i-1]);
            }

            cv::putText(outputImage, kv.first, t2DPoints[0],
                        cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(255,255,255));
        }

        cv::imshow("Pose Estimation", outputImage);
    }

    cv::destroyWindow("Pose Estimation");
    capture.release();

    return 0;
}

This should work. If it doesn't use the right resolution, you may want to refer to OpenCV documentation (it's not an issue with chilitags).

patrickliu90 commented 10 years ago

Great it's working!!

Thank you so much.

qbonnard commented 10 years ago

Good to hear that ! I assume that I can close the issue, please reopen if I was wrong.