You are using a version without Ads of this website. Please, consider donating:

projectPoints opencv

Hi

does any one know how to use it a function for 3d reconstruction. I followed the manual on the website but it seems to give me error.
 assertion failed (0 <= i && I < (int)v.size(j) in unknown function file matrix.cpp.

i suck at understanding errors.

my code is quite long

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144`` ``````#include #include #include #include #include #include #include #include"reconstruction.h" 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}}; meanmat[0]=13.8340; meanmat[1]=68.3459; meanmat[2]=22.7451; 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; 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); numcorners=horcorner*vercorner; namedWindow("original",1); vector> object_points; vector> image_points; vector obj; vector img; vector projectedpoints; VideoCapture webcam; webcam.open(-1); while(1) { //copy webcam stream to image webcam>>image; if(!webcam.isOpened()) { cout<<"\nThe Camera is being used by another application, make sure all applications using the camera are closed and try running this program again."<(i,j); //prints wierd characters mdist=mahadistance(icovar,meanmat,pixel); if(mdist(i,j)=255; else mask.at(i,j)=0; } } cvtColor(image,grayscale,CV_BGR2GRAY); //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)); if(corners.rows==numcorners) { for(int i=0;i(i),3,CV_RGB(255,0,0),1,8,0); obj.push_back(Point3f(float(i/vercorner), float(i%vercorner), 0.0f)); //setting up the units of calibration img.push_back(corners.at(i)); } image_points.push_back(img); object_points.push_back(obj); Mat intrinsic = Mat(3, 3, CV_32FC1); Mat distCoeffs; vector rvecs; vector tvecs; intrinsic.ptr(0)[0] = 1; intrinsic.ptr(1)[1] = 1; calibrateCamera(object_points, image_points, image.size(), intrinsic, distCoeffs, rvecs, tvecs); //unhandled exception error at this point not because of too much points if(k==1) { k=k+1; float xmax=0,xmin=1000,ymax=0,ymin=1000,z; for(int l=0;l(l,0)(l,0); } if(corners.at(l,1)(l,1); } if(corners.at(l,0)>xmax) { xmax=corners.at(l,0); } if(corners.at(l,1)>ymax) { ymax=corners.at(l,1); } } printf("Enter the height of the object (mm)"); scanf("%f",&z); int sz[] = {(xmax-xmin),(ymax-ymin),z}; Mat threedimension(3,sz,CV_32F,Scalar::all(1)); //create 3dim matrix, type 32 filled with 1s. //access each element like threedimension.at(x,y,z) } projectPoints(obj,rvecs,tvecs,intrinsic,distCoeffs,projectedpoints); cout<

in the meanwhile i will keep checking see if i discover anything.

thanks
Last edited on
backtrace shows that the error is triggered in
`projectPoints(obj,rvecs,tvecs,intrinsic,distCoeffs,projectedpoints);`
exactly, it crashes at that point when i step through it.
the main reason i have heard for this is empty vectors but i don't have empty vectors.

that's why this confuses me.

thanks
Topic archived. No new replies allowed.

You are using a version without Ads of this website. Please, consider donating: