Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detection problem with big resolution width #3

Open
Meach opened this issue Mar 5, 2013 · 6 comments
Open

detection problem with big resolution width #3

Meach opened this issue Mar 5, 2013 · 6 comments

Comments

@Meach
Copy link

Meach commented Mar 5, 2013

Hello,
I am having some trouble using your addons, until today when I tried to use it with a webcam, grabbing at more than 1024xsomething resolution.

I made a post on OF forum, with an image example: http://forum.openframeworks.cc/index.php/topic,12164.0.html

Cheers

@fishkingsin
Copy link
Owner

someone found this problem from launchpad
and seems have the solution

https://answers.launchpad.net/artoolkitplus/+question/160544

@Meach
Copy link
Author

Meach commented Mar 6, 2013

Nice, thanks for that.

I downloaded ARToolKitPlus source code and took a look at paramDistortion.cpp file.
I pasted what I think is the interesting part of this file because I don't have much clue on how to change it.

I see that in floatToFixed and fixedToFloat functions there are some short integer being used and some bitshift operations but I don't really know what to change in there.

Any idea @fishkingsin?

//
//  these functions store 2 values (x & y) in a single 32-bit unsigned integer
//  each value is stored as 11.5 fixed point
//

inline
void floatToFixed(ARFloat nX, ARFloat nY, unsigned int &nFixed) {
    short sx = (short) (nX * 32);
    short sy = (short) (nY * 32);

    unsigned short *ux = (unsigned short*) &sx;
    unsigned short *uy = (unsigned short*) &sy;

    nFixed = (*ux << 16) | *uy;
}

inline
void fixedToFloat(unsigned int nFixed, ARFloat& nX, ARFloat& nY) {
    unsigned short ux = (nFixed >> 16);
    unsigned short uy = (nFixed & 0xffff);

    short *sx = (short*) &ux;
    short *sy = (short*) &uy;

    nX = (*sx) / 32.0f;
    nY = (*sy) / 32.0f;
}

int Tracker::arCameraObserv2Ideal_LUT(Camera* pCam, ARFloat ox, ARFloat oy, ARFloat *ix, ARFloat *iy) {
    if (!undistO2ITable)
        buildUndistO2ITable(pCam);

    int x = (int) ox, y = (int) oy;

    fixedToFloat(undistO2ITable[x + y * arImXsize], *ix, *iy);
    return 0;
}

void Tracker::buildUndistO2ITable(Camera* pCam) {
    int x, y;
    ARFloat cx, cy, ox, oy;
    unsigned int fixed;
    char* cachename = NULL;
    bool loaded = false;

    if (loadCachedUndist) {
        assert(pCam->getFileName() != "");
        cachename = new char[strlen(pCam->getFileName().c_str()) + 5];
        strcpy(cachename, pCam->getFileName().c_str());
        strcat(cachename, ".LUT");
    }

    // we have to take care here when using a memory manager that can not free memory
    // (usually this lookup table should only be built once - unless we change camera resolution)
    //
    if (undistO2ITable)
        delete[] undistO2ITable;

    undistO2ITable = new unsigned int[arImXsize * arImYsize];

    if (loadCachedUndist) {
        if (FILE* fp = fopen(cachename, "rb")) {
            size_t numBytes = fread(undistO2ITable, 1, arImXsize * arImYsize * sizeof(unsigned int), fp);
            fclose(fp);

            if (numBytes == arImXsize * arImYsize * sizeof(unsigned int))
                loaded = true;
        }
    }

    if (!loaded) {
        for (x = 0; x < arImXsize; x++) {
            for (y = 0; y < arImYsize; y++) {
                arCameraObserv2Ideal_std(pCam, (ARFloat) x, (ARFloat) y, &cx, &cy);
                floatToFixed(cx, cy, fixed);
                fixedToFloat(fixed, ox, oy);
                undistO2ITable[x + y * arImXsize] = fixed;
            }
        }

        if (loadCachedUndist)
            if (FILE* fp = fopen(cachename, "wb")) {
                fwrite(undistO2ITable, 1, arImXsize * arImYsize * sizeof(unsigned int), fp);
                fclose(fp);
            }
    }

    delete[] cachename;
}

Thanks

@Meach Meach closed this as completed Mar 6, 2013
@Meach Meach reopened this Mar 6, 2013
@kalwalt
Copy link
Contributor

kalwalt commented Mar 6, 2013

I don't notice this bug before... but as i use HD screens with ofxARToolkitPlus addon i'm interested to solve this. But looking at Logitech_Notebook_Pro.cal you see:

ARToolKitPlus_CamCal_Rev02
640 480 330.27758683214108 228.10613100912309 891.32055276878066 888.496623076345940 -0.049480033893318 0.215863227944058 -0.001997733892605 -0.003151872552003 0.0 0.0 10

maybe changing aspect ratio here solve the issue?

@kalwalt
Copy link
Contributor

kalwalt commented Mar 6, 2013

and maybe it's needed another calibration file?

@Meach
Copy link
Author

Meach commented Mar 6, 2013

My plan is to make a new calibration file for the logitech c920, I currently use.
This evening if I have time, I will give it a try using this http://graphics.cs.msu.ru/en/node/909

@kalwalt
Copy link
Contributor

kalwalt commented Mar 6, 2013

good to know! i haven't a HD cam so i can't help you with this...sorry @Meach !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants