title: Hough Lines P - How to know if there is no line detected?
body: <p>I used <code>HoughLinesP</code> to identify lines. However, my problem is how do I know when there are no lines detected. I have tried comparing the vector lines to null but nothing happens. To be precise, here is my code:</p>
  
  <pre><code>for(size_t k=0; k&lt;lines.size(); k++){
      Vec4i l = lines[k];
      line(gray, Point(l[0], l[1]), Point(l[2], l[3]),Scalar(0,0,255), 3, CV_AA);
      double x = l[2]-l[0];
      double y = l[3]-l[1];
      double slope = (x/y);
      double rad = atan(slope);
      double pi = 3.1416;
      double deg = (rad*180)/pi;
      double fin = deg+90;
  
      int part = 0;
      if (lines.empty()){printf("NO LINE IN THIS PORTION OF THE IMAGE!");part = 0;}
      else{
          if (fin&gt;=0 &amp;&amp; fin&lt;=45){part = 1;}
          else if (fin&gt;45 &amp;&amp; fin&lt;=90){part = 2;}
          else if (fin&gt;90 &amp;&amp; fin&lt;=135){part = 3;}
          else if (fin&gt;135 &amp;&amp; fin&lt;=180){part = 4;}
      }
      printf("portion number = %d angle = %f PART = %d\n",j, fin, part);
  }
  </code></pre>
  
  <p>I am identifying a particular sector with the <code>part</code> variable. If there are no lines detected, I would like for <code>part == 0</code> to be true. But, I can't find the correct way to know if there are no lines detected. It is only printing angles if there is already a line in the image. Thanks!</p>