Ask Your Question

seifullaah73's profile - activity

2013-07-26 09:09:16 -0500 received badge  Supporter (source)
2013-07-25 16:02:42 -0500 asked a question opencv projectPoints error

Hi guys

I'm trying to find a way to project a 3D point onto a 2D silhouette image.

I am using projectPoints and the parameters obtained from the calibratecamera functions.

I get the following error when it tries to execute the projectpoints function

OpenCV Error: Assertion failed (0 <= i && i < (int)v.size()) in unknown function file ...... \matrix.cpp, line 981.

below is my code



using namespace cv;
using namespace std;

int main()
    Mat image, grayscale;
    int numcorners, horcorner,vercorner;
    Mat icovar;
    Scalar meanmat;
    int k=1;
    //covariance for dark combined
    double covar[3][3]={{180.1437, 180.8316, 179.0236},{188.8316,355.5152,238.8029},{179.0236,238.8029,267.9239}};

    Mat covmat(3,3,CV_64F,covar);

    Mat mask = Mat::zeros(480, 640, CV_8UC1);   //create matrix same size as image which is 480 by 640 based on the webcam capture
    //intitialize capture
    Vec3b pixel;
    double distance = 200;
    double mdist=0;
    float x,y,z;

    icovar=inversemat(covmat);      //determinant of covariance matrix is zero. SOLVED

    Mat corners;
    printf("Enter number of corners horizontally: ");
    scanf("%d", &horcorner);
    printf("Enter number of corners vertically: ");
    scanf("%d", &vercorner);

    vector<vector<Point3f>> object_points;
    vector<vector<Point2f>> image_points;

    vector<Point3f> obj;
    vector<Point2f> img;

    vector<Point3f> threedpoint;
    vector<Point2f> projectedpoints;

    Mat intrinsic = Mat(3, 3, CV_32FC1);
    Mat distCoeffs;
    vector<Mat> rvecs;
    vector<Mat> tvecs;
    intrinsic.ptr<float>(0)[0] = 1;
    intrinsic.ptr<float>(1)[1] = 1;

    printf("Enter the distance between the two marked corners in the x direction (mm): ");
    printf("Enter the distance between the two marked corners in the y direction (mm): ");
    printf("Enter the height of the object (mm): ");

    int sz[] = {x,y,z};

    Mat threedimension(3,sz,CV_32F,Scalar::all(1));  //create 3dim matrix, type 32 filled with 1s.

    VideoCapture webcam;;    
        //copy webcam stream to image
            cout<<"\nThe Camera is being used by another application, make sure all applications using the camera are closed and try running this program again."<<endl;
        for(int i = 0; i < image.rows;i++)
            for(int j=0; j<image.cols;j++)  //in case it fails changed it from i=1 to i=0
                pixel=<Vec3b>(i,j);    //prints wierd characters
        //goodfeatures(grayimage, output to store corners, quality factor, distance factor)
        goodFeaturesToTrack(grayscale,corners,numcorners,0.1,100);   //good so far 0.1 and 100 also 0.01 and 100 a little ok i chose this
        // Mark these corners on the original image
        cornerSubPix(grayscale, corners, Size(11, 11), Size(-1, -1), TermCriteria(CV_TERMCRIT_EPS | CV_TERMCRIT_ITER, 30, 0.1 ...
2013-02-11 18:44:02 -0500 asked a question camera calibration problem

Any e experts on here, please help

here is my code i have used

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);

vector<vector<Point3d>> object_points;
vector<vector<Point2d>> image_points;

vector<Point2d> corners;
int successes=0;

Mat image;
Mat gray_image;
capture >> image;

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

    cvtColor(image, gray_image, CV_BGR2GRAY);

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

        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("win1", image);
    imshow("win2", gray_image);

    capture >> image;

    int key = waitKey(1);

        return 0;

    if(key==' ' && found!=0)
        printf("Snap stored!\n");



Mat intrinsic = Mat(3, 3, CV_32FC1);
Mat distCoeffs;
vector<Mat> rvecs;
vector<Mat> tvecs;

intrinsic.ptr<float>(0)[0] = 1;
intrinsic.ptr<float>(1)[1] = 1;

calibrateCamera(object_points, image_points, image.size(), intrinsic, distCoeffs, rvecs, tvecs);

Mat imageUndistorted;
    capture >> image;
    undistort(image, imageUndistorted, intrinsic, distCoeffs);

    imshow("win1", image);
    imshow("win2", imageUndistorted);



return 0;


any help thanks

2013-01-28 17:55:00 -0500 received badge  Editor (source)
2013-01-28 17:52:36 -0500 asked a question OpenCV 2.4 install problem

Hey Guys

I have a problem, i had opencv 2.2 which was easy to install and when i try to run a program for camera capture, but a problem occurred that only a grey output window was displayed. So i thought i would upgrade it to 2.4. So i downloaded 2.4, which told me to extract to a place, i extracted it to C:\OpenCV2.4\

I went to link this to Visual studio 2010 but when i try to link libraries, i couldn't find lib folder in the opencv2.4 folder. I forgot to mention since inside opencv2.4 was a folder called opencv i moved everything in there outside and delete the opencv folder.

Help would be appreciated either on fixing the camera or help with installing opencv2.4 as the lib folder is missing