Ask Your Question
0

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

asked 2015-11-20 02:21:56 -0500

MValeriy gravatar image

updated 2015-11-20 02:44:50 -0500

pklab gravatar image

I have a Code:

int main(int argc, char** argv)
{
    const char* filename = argc >= 2 ? argv[1] : "1.jpg";
    Mat src = imread(filename, 0);
    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?

I have: http://www.pictureshack.ru/images/740...

I need: http://www.pictureshack.ru/images/438...

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-11-20 02:35:48 -0500

pklab gravatar image

Why not this ?

cv::Point  middleTop(xx,0)
cv::Point  middleBottom(xx,cdst.rows);
cv::line(cdst,middleTop,middleBottom,Scalar(0,255,0));
edit flag offensive delete link more

Comments

Thank you very much !!!!

MValeriy gravatar imageMValeriy ( 2015-11-20 03:28:45 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-11-20 02:21:56 -0500

Seen: 584 times

Last updated: Nov 20 '15