Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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

                                            }
  imshow("line", cdst);

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

I have: http://www.pictureshack.ru/images/74010_2.jpg

I need: http://www.pictureshack.ru/images/43835_1.jpg

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

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

                                             }
  imshow("line", cdst);

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

I have: http://www.pictureshack.ru/images/74010_2.jpg

I need: http://www.pictureshack.ru/images/43835_1.jpg

click to hide/show revision 3
No.3 Revision

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

I have a Code: Code:

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

                                        CV_CHAIN_APPROX_NONE);

    for ( size_t (size_t i = 0; i < contours.size(); i++)

                                            {   

                                            {
        Rect minRect = boundingRect(contours[i]);

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

                                            xx=minRect.x+minRect.width/2;
                                            xy=minRect.y+minRect.height/2;
                                    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/74010_2.jpg

I need: http://www.pictureshack.ru/images/43835_1.jpg