0

I have a scenario, where I have to display number of images in a for loop. Please look at the code.

I want to analyse all the hough-detected lines separately. So I am trying to extract each detected line in the image. So I would get as many images as the number of detected lines.

for ( int i = 0;i<lines.size();i++)
{
Vec4i draw = lines[i];
line(vMat[i],Point(draw[0],draw[1]),Point(draw[2],draw[3]),Scalar(0,0,255),1,CV_AA);
imshow("Lines",vMat[i]);
}

I get only the last detected line image because of the comme name "Lines".

Is there any possibility to add the iterator information in imshow?

I tried using a string array. But concatenating the integer (index of the vector) with the string is for me seems to be difficult (adding 'boost' libraries and so on).

Is there any simple alternative for my problem ?

Thanks, Karthik

Community
  • 1
  • 1
Karthik_elan
  • 323
  • 1
  • 6
  • 13
  • I couldn't understand your problem. So you want to display a text in an image? – ChronoTrigger Mar 02 '14 at 19:30
  • So your loop assigns to "Lines" multiple times, and only contains one? What does imshow() do exactly? – JonPall Mar 02 '14 at 19:31
  • Maybe you want to add `cv::waitKey();` after `imshow` so you have time to actually check what `imshow` is showing. – ChronoTrigger Mar 02 '14 at 19:33
  • @ChronoTrigger: I want to display more images by appending the index number to the image window so that I can note down the index number of typical (desired) lines. That would be handy for me to work only on the particular lines. Otherwise, I have to put like "draw = Lines[0]", imshow("Lines[0]") and put manually all the number of lines. To be more precise "imshow("Lines"+i,vMat[i])". But it wouldn't work. I hope I made it clear. If not, please ask me, I am ready to clarify it better. – Karthik_elan Mar 02 '14 at 19:46
  • @JonPall, I want my loop to append the iterator to the string "Lines". So I get various images like "Lines[0]", "Lines[1]", "Lines[2]" and so on. My question can be put in other words too. "How can we show multiple images from a image vector ?" I hope I made it clear now. Or not ? – Karthik_elan Mar 02 '14 at 19:50
  • @ChronoTrigger: Yes, this is what I was thinking of. The waitkey allowed me to note the index numbers. **Thank you very much. I was just curious to know how do we show images from an image vector, similar to opening images.** – Karthik_elan Mar 02 '14 at 20:00

1 Answers1

1

Is there any possibility to add the iterator information in imshow?

imshow("Lines",vMat[i]);

You might consider adding 2 lines:

{ 
  std::stringstream ss; 
  ss << "Lines[" << i << "] "; 
  imshow(ss.str().c_str(), vMat[i]); 
}

I typically add the braces to free up the 'ss' label, and clean up the stringstream.

2785528
  • 5,438
  • 2
  • 18
  • 20
  • Wow. That worked. Explanation of the code would be highly helpful for me to understand. – Karthik_elan Mar 02 '14 at 20:14
  • 1
    The std::stringstream works just like any other stream. It allows you to use formatted output (in this case) into ss. The result is buffered internally, and that buffering can be accessed (as a std::string) using ss.str(). This in turn can be accessed (as a c-string, i.e. a null-terminated string) using c_str(). std::stringstream also supports formatted extraction. And they are also available in both std::istringstream and std::ostringstream forms. – 2785528 Mar 02 '14 at 20:23