# how can I draw a vertical line down the middle of a rectangular?

I have a Code:

int main(int argc, char** argv)
{
const char* filename = argc >= 2 ? argv[1] : "1.jpg";
if (src.empty())
{
cout << "can not open " << filename << endl;
return -1;
}
Mat dst, cdst;
Canny(src, dst, 50, 200, 3);
cvtColor(dst, cdst, CV_GRAY2BGR);
vector<vector<Point> > contours;
vector<Point> contour;
findContours(dst, contours, CV_RETR_TREE, CV_CHAIN_APPROX_NONE);

for (size_t i = 0; i < contours.size(); i++)
{
Rect minRect = boundingRect(contours[i]);

if (minRect.width > 1 & minRect.height > 1)
{
rectangle(cdst, minRect, Scalar(0, 0, 255));
putText(cdst,
format("width = %d , height = %d", minRect.width, minRect.height),
Point(minRect.x, minRect.y),FONT_HERSHEY_PLAIN, 1, Scalar(0, 255, 0));
}
drawContours(cdst, contours, i, color);

xx = minRect.x + minRect.width / 2;
xy = minRect.y + minRect.height / 2;
cout << "Rect center: x = " << xx << " y = " << xy << endl;
}
imshow("line", cdst);
}


how can I draw a vertical line down the middle of a rectangular?

edit retag close merge delete

Sort by ยป oldest newest most voted

Why not this ?

cv::Point  middleTop(xx,0)
cv::Point  middleBottom(xx,cdst.rows);
cv::line(cdst,middleTop,middleBottom,Scalar(0,255,0));

more

Thank you very much !!!!

( 2015-11-20 03:28:45 -0500 )edit

Official site

GitHub

Wiki

Documentation