Ask Your Question
0

How can I write numbers inside the detected circles on the image when using Hough Circle Transform?

asked 2014-12-31 02:06:14 -0600

iku317 gravatar image

I used the Hough Circle Transform to detected around 2000~4000 circular wood columns. I followed the link below. http://docs.opencv.org/doc/tutorials/... my questions are:

  1. How can I write a number inside the detected circles? i.e. to write a number 1,2,3, to each of detected circle inside the red circle.

  2. How can I save the image of question 1 to a file so that I can later check the result?

Thank you all very much for your advice. Sincerely,

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2014-12-31 03:03:46 -0600

updated 2014-12-31 09:23:35 -0600

cv::puttext to write the numbers and cv::imwrite to save the image. Although you could have easily find that on your own...

Google: "opencv print text" first hit: http://docs.opencv.org/modules/core/d...

Google: "opencv save image" first hit: http://docs.opencv.org/doc/tutorials/...

edit flag offensive delete link more

Comments

THank you very much . I followed your link and add the following code to the tutorial. However, the number can not be located around the center of a circle.

//For putting the numbers on the image; locate the center of the numbers to be putted on the image Point centerText(cvRound(circles[i][0])-radius/2, cvRound(circles[i][1])-radius/2);

  //Convert an integer to a string;
  ss << i+1;
  text = ss.str();     
  //Put the string on the image
  putText(src, text, centerText, fontFace, fontScale, Scalar::all(0),thicknessText,0); 
  //Clear the string;
  ss.str("");
iku317 gravatar imageiku317 ( 2015-01-05 21:53:44 -0600 )edit

Please do not add other answers if they don't have a solution, but use comments or edit button. I just switched it for you.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-01-06 06:19:56 -0600 )edit
2

answered 2015-01-06 06:23:12 -0600

updated 2015-01-06 06:23:34 -0600

In the tutorial go to this line of code

Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));

Now add the following line

stringstream ss;
ss << i+1;
putText(src, ss.str(), center, 1, 1, Scalar(255,0,0), 2,0);

This doest exactly what you want!

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2014-12-31 02:06:14 -0600

Seen: 2,469 times

Last updated: Jan 06 '15