Ask Your Question

sweptica's profile - activity

2015-05-18 10:49:50 -0600 commented answer Detecting an object inside a square table using findchessboardcorners

The reason i was using findchessboardCorners method is, in realtime it can still hold on to the inner corners irrespective or the perspective. But I tried implementing your code using webcam feed..a shift in perspective will affect the square detection :(

2015-05-18 10:20:00 -0600 received badge  Supporter (source)
2015-05-18 10:18:50 -0600 commented question Detecting an object inside a square table using findchessboardcorners

Im planning to use kinect to get the location of the user's foot (skeletal tracking), for now if I can just put an object anywhere on the square and detect whether the object is on the square and which square i'll be able to move forward maybe

2015-05-18 01:16:59 -0600 commented question Detecting an object inside a square table using findchessboardcorners

Hey, i tried you're exact code with my board, the image above but it only detects only 2 squares within the board. (The image of the board is given above) . . somehow with the image in the previous answer it works just as the output shown. Is there something i'm missing?

2015-05-17 15:43:05 -0600 asked a question Detecting an object inside a square table using findchessboardcorners

I'm trying to create an exercise game where the user's need to step on a square board depending on the instruction. I need to first detect the square board in the environment and then detect whether the user's foot is present in one of the squares within the board. (real time)

Here is the square table that I will be using

Square table

I need to find the boundary of the squares within the square board, for this purpose i'm trying the logic with a chessboard first. I am able to find the corners in the chessboard using findChessboardCorners function and drawing them successfully using cornerSubPix function. However when I place an object over the chessboard square pattern, the findChessboardCorners doesn't work anymore (returns 0). I realize that maybe the algorithm finds only connected squares using icvFindConnectedQuads. Is there a solution to this problem? (do i need to use chessboard to succesfully get my game working? Is there an alternative method to implement the game?)

#include <opencv2/core/core.hpp>;
#include <opencv/cv.h>;
#include <opencv2/highgui/highgui.hpp>;


using namespace cv;
using namespace std;

int main()
{
    int numBoards = 0;
    int numCornersHor;
    int numCornersVer;

    printf("Enter number of corners along width: ");
    scanf("%d",&numCornersHor);

    printf("Enter number of corners along height: ");
    scanf("%d",&numCornersVer);

    printf("Enter number of boards: ");
    scanf("%d",&numBoards);

    int numSquares = numCornersHor * numCornersVer;

    Size board_sz = Size(numCornersHor,numCornersVer);

    VideoCapture capture = VideoCapture(0);

    /*Physical location of the corners in real world (3D space)*/
    vector<vector<Point3f>> object_points;
    /*location of the corners on the image (2D image)*/
    vector<vector<Point2f>> image_points;

    /*Current image's (snapshots)  corners*/
    vector<Point2f>corners;
    int successes = 0;

    Mat image;
    Mat gray_image;
    capture >> image;

    vector<Point3f> obj;
    for(int j = 0; j < numSquares; j++)
    {
        obj.push_back(Point3f(j/numCornersHor,j%numCornersVer,0.0f));
    }

    while(successes < numBoards)
    {
        cvtColor(image,gray_image,CV_BGR2GRAY);

        bool found = findChessboardCorners(image,board_sz,corners, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FILTER_QUADS);

        if(found)
        {
            cornerSubPix(gray_image,corners,Size(11,11),Size(-1,-1),TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1));
            drawChessboardCorners(gray_image,board_sz,corners,found);
        }

        imshow("normal img",image);
        imshow("gray image", gray_image);

        capture >> image;
        int key = waitKey(1);

        if(key == '27')
            return 0;

        if(key == '0' && found!='0')
        {
            image_points.push_back(corners);
            object_points.push_back(obj);

            printf("Snap stored!");

            successes++;

            if(successes >= numBoards)
            {
                break;
            }
        }
    }

    return 0;
}