title: how to draw line in opencv
body: <p>hello every ace i have some problem
  Here   is my code who can teach me how to   draw a straight line in the video at center?
  And how to reduce my green line in the video  ,because i want to find the Vanishing Point.</p>
  
  <pre><code>#include &lt;opencv2/imgproc/imgproc.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  #include &lt;iostream&gt;e
  using namespace cv;
  using namespace std;
  Point2f center(0,0);
  Point2f computeIntersect(Vec4i a, Vec4i b)
  
  {
      int x1 = a[0], y1 = a[1], x2 = a[2], y2 = a[3], x3 = b[0], y3 = b[1], x4 = b[2], y4 = b[3];
      float denom;
  
      if (float d = ((float)(x1 - x2) * (y3 - y4)) - ((y1 - y2) * (x3 - x4)))
      {
              Point2f pt;
              pt.x = ((x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
              pt.y = ((x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;
              return pt;
      }
      else
              return Point2f(-1, -1);
  
  
  }
  void sortCorners(std::vector&lt;Point2f&gt;&amp; corners, Point2f center)
  
  {
      std::vector&lt;Point2f&gt; top, bot;
  
  
  
  
  
      for (int i = 0; i &lt; corners.size(); i++)
      {
              if (corners[i].y &lt; center.y)
                      top.push_back(corners[i]);
              else
                      bot.push_back(corners[i]);
      }
  
      Point2f tl = top[0].x &gt; top[1].x ? top[1] : top[0];
      Point2f tr = top[0].x &gt; top[1].x ? top[0] : top[1];
      Point2f bl = bot[0].x &gt; bot[1].x ? bot[1] : bot[0];
      Point2f br = bot[0].x &gt; bot[1].x ? bot[0] : bot[1];
  
      corners.clear();
      corners.push_back(tl);
      corners.push_back(tr);
      corners.push_back(br);
      corners.push_back(bl);
  }
  Mat src;
  int main()
  
  {
  
  
  
  
  
  
  
  VideoCapture cap("C://pic/way.mp4");
  while ( cap.isOpened() )
  {
  cap &gt;&gt; src;
  
  
  
  
  
      //Mat src = imread("D:\\11.jpg");
      if (src.empty())
              return -1;
  
      Mat bw;
      cvtColor(src, bw, CV_BGR2GRAY);
      blur(bw, bw, Size(3, 3));
      Canny(bw, bw, 150, 100, 3);
  
      std::vector&lt;Vec4i&gt; lines;
      HoughLinesP(bw, lines, 1, CV_PI/180, 70, 30, 10);
  
      // Expand the lines
      for (int i = 0; i &lt; lines.size(); i++)
      {
              Vec4i v = lines[i];
              lines[i][0] = 0;
              lines[i][1] = ((float)v[1] - v[3]) / (v[0] - v[2]) * -v[0] + v[1]; 
              lines[i][2] = src.cols; 
              lines[i][3] = ((float)v[1] - v[3]) / (v[0] - v[2]) * (src.cols - v[2]) + v[3];
      }
  
      std::vector&lt;Point2f&gt; corners;
      for (int i = 0; i &lt; lines.size(); i++)
      {
              for (int j = i+1; j &lt; lines.size(); j++)
              {
                      Point2f pt = computeIntersect(lines[i], lines[j]);
                      if (pt.x &gt;= 0 &amp;&amp; pt.y &gt;= 0)
                              corners.push_back(pt);
              }
      }
  
      std::vector&lt;Point2f&gt; approx;
      approxPolyDP(Mat(corners), approx, arcLength(Mat(corners), true) * 0.02, true);
  
  
      // Get mass center
      for (int i = 0; i &lt; corners.size(); i++)
              center += corners[i];
      center *= (1. / corners.size());
  
      sortCorners(corners, center);
  
      Mat dst = src.clone();
  
      // Draw lines
      for (int i = 0; i &lt; lines.size(); i++)
      {
              Vec4i v = lines[i];
              line(dst, Point(v[0], v[1]), Point(v[2], v[3]), CV_RGB(0,255,0));
      }
  
      // Draw corner points
  
      circle(dst, corners[3], 3, CV_RGB(255,255,255), 2);
          cout &lt;&lt; "Detected " &lt;&lt; corners[3] &lt;&lt; "\n";
  
      // Draw mass center
      circle(dst, center, 3, CV_RGB(255,255,0), 2);
  
      Mat quad = Mat::zeros(300, 220, CV_8UC3);
  
      std::vector&lt;Point2f&gt; quad_pts;
      quad_pts.push_back(Point2f(0, 0));
      quad_pts.push_back(Point2f(quad.cols, 0));
      quad_pts.push_back(Point2f(quad.cols, quad.rows));
      quad_pts.push_back(Point2f(0, quad.rows));
  
      Mat transmtx = getPerspectiveTransform(corners, quad_pts);
      warpPerspective(src, quad, transmtx, quad.size());
  
      imshow("image", bw);
      imshow("images", dst);
  
      if(waitKey(27) &gt;= 0)  break; }
  
  
  
  
   return 0;}
  </code></pre>