# Why I can't create a polylines

t2 is a vector(Point2f). When I create a circle that's success. but can't create a polylines

     for (int sn=0; sn<2; sn++){
mat.copyTo(image);
for(int ar=0; ar<jnt[0]

.size(); ar++){
t1 = pointz.at(ar);
t0 = jnt[ax].at(ar); //ref
t1.x = c60 * (t0.x - t1.x) - s60 * (t0.y - t1.y) + t1.x;
t1.y =  s60 * (t0.x - t1.x) + c60 * (t0.y - t1.y) + t1.y;
t.push_back(t1);
}
t2=t;
t.clear();
etrans = evec.t();
Qnew = Mat (t2).reshape(0,5);
yminq = Qnew - q_bar;
b_bar = etrans.mul(yminq);
q_new = q_bar +( b_bar.mul(evec));
qbaru = q_new.reshape(0,1);
y_bar = qbaru;
pointz = t2;
q_bar = Mat(t2).reshape(0,5);
waitKey(1000);

}
for(int ao=0; ao<t2.size(); ao++){
Point pt = t2.at(ao);
circle(image,pt,1,Scalar(0,0,255),2);
}
cvtColor(image, image, COLOR_BGR2GRAY);
polylines(image,t2,false,Scalar(255,255,255),2,150,0);
imshow("Fitting",image);


this is the error

OpenCV Error: Assertion failed (p.checkVector(2, CV_32S) >= 0) in cv::polylines, file ........\opencv\modules\core\src\drawing.cpp, line 2067

thankyou :)

edit retag close merge delete

Sort by ยป oldest newest most voted

unfortunately, polylines expects a vector<Point>, not a vector<Point2f>.

while you can easily cast a single Point2f to Point, not so with a whole vector.

so, either draw single lines:

for(int ao=0; ao<t2.size()-1; ao++){
Point p0 = t2.at(ao);
Point p1 = t2.at(ao+1);
line(image,p0,p1,Scalar(0,0,255),2);
}


or copy to a vector<Point> :

vector<Point> pt;
for(int ao=0; ao<t2.size(); ao++){
pt.push_back( t2.at(ao) );
}
polylines(image,pt,false,Scalar(255,255,255),2,150,0);

more

thank you very much :))

( 2017-08-09 08:29:56 -0500 )edit

Official site

GitHub

Wiki

Documentation