Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ostream-like cv::putText helper function #313

Closed
wants to merge 2 commits into from
Closed

Added ostream-like cv::putText helper function #313

wants to merge 2 commits into from

Conversation

BloodAxe
Copy link
Contributor

This commit brings an ostream-like text rendering on the cv::Mat.
Unlike existing function, a new putText funtion allows to use operator << to print
text on cv::Mat and supports newline characters. You can see the
demonstration of the new cv::putText in drawing.cpp sample.

The proposed request allows to print text on the images in the following way:

putText(image2, cv::Point(100,100), CV_FONT_HERSHEY_COMPLEX, 1, Scalar(i, i, 255))
    << "cv::putText() Demo!" << std::endl 
    << "cv::putText(...) << \"Hello\\nWorld\";" << std::endl 
    << "You can use std::endl" << std::endl 
    << "or even\\n symbol\nto format text" << std::endl
    << "And we support formatters:\n"
    << "std::setprecision(5)" << std::setprecision(5) << CV_PI << std::endl
    << "std::scientific " << std::scientific << CV_PI << std::endl
    << "So you can use cv::putText like regular std::cout!";

The result of the rendering will be:
putTextOstream

This commit brings a ostream-like text rendering on the cv::Mat like the
cv::putText does.
Unlike existing function, this commit allows to use operator << to print
text on cv::Mat and supports newline characters. You can see the
demonstration of the new cv::putText in drawing.cpp sample.
@taka-no-me
Copy link

Hi Eugene, your contribution looks interesting but it compiles nowhere except Windows. You can find the results of pull request testing here: http://build.opencv.org/pullrequest.

Please fix all build problems including MSVC build warnings and update your pull request. After that someone will review and decide is it worth to include it into the library.

@ghost ghost assigned vpisarev Jan 21, 2013
@BloodAxe
Copy link
Contributor Author

Hi Andrey, thanks for fast response. I'm sorry that i've forgot to check for compilation errors under mac and linux platforms. This issue has been fixed in my recent commit. I've checked it on mac (XCode 4.5, Clang 1.0) and ubuntu (gcc 4.6.3).

@ghost ghost assigned vpisarev Jan 23, 2013
@mdim
Copy link
Contributor

mdim commented Jan 23, 2013

@vpisarev Vadim, can you please look at this interesting request?

@vpisarev
Copy link
Contributor

It looks nice; on the other hand, if we extend putText to properly handle "\n" symbols in the text strings (should not be very hard), i.e. without affecting external API, the same thing it's just a little syntax sugar over

stringstream s;
s << .... ;
s << .... ;
...
putText(..., s.str());

This feature adds one more external C++ class (a class, which needs to be documented, tested, supported for many years) without adding any essential functionality (and the functionality is only added to C++, not python or java), so I would not include it, sorry.

@mdim
Copy link
Contributor

mdim commented Jan 23, 2013

@BloodAxe sorry again, but we are closing your request by the reasons Vadim mentioned.

@mdim mdim closed this Jan 23, 2013
@BloodAxe
Copy link
Contributor Author

@vpisarev, Vadim, please don't tell me that support of a tiny class which uses STL-only functions, contains no pointer arithmetics or compicated internal logic is harder than support of four different types that represent image data (CvMat, CvArr, IplImage and cv::Mat)!

I perfectly understand that these old types are still in OpenCV for backward compatibility. If there would be a way to implement correct endline handling in putText function - it's already will be done. But there are a lot of code that relies on existing behaviour of putText. Changes in it can (and will) lead to wrong visualization in many apps.

During my researches i need to process video sequences and print debug information on top of it. You can imagine what a pain to print ten variables every frame:

  • Format a string using stringstream
  • Calcualte vertical offset
  • Render text using putText
  • Repeat ten times

You're right, the content of this pull request is syntax sugar. I beleive the helper functions (and text output is a helper function of the library) shoud be easy to use.

There is another argument that this PR is worth of merge. The proposed way uses std::cout idiom of printing text. But the existing putText function is more closely to printf() style. By the way i think it's also a good idea to allow putText to accept variable argument list like the printf does.

@vpisarev
Copy link
Contributor

first of all, you can always have this class in your project. Secondly, in 2.5 (or 2.6 at the latest) we are going to enable 3rd-party modules to be co-built and used together with the official OpenCV (something similar to Perl CPAN, R packages or 3rd-party Matlab toolboxes). Then you can just make a module with this and probably some other functionality and share it with other people without asking us. Even now it's possible - just make the folder with the same structure as imgproc, photo etc., put it inside opencv/modules and run CMake+make/VS/Xcode.

@zeroch
Copy link

zeroch commented Oct 29, 2015

Hi everyone above,
I see this PR has been long times ago. So I am wandering that OpenCV official release add this feature or intend to add this feature or not?

@BloodAxe
Copy link
Contributor Author

@zeroch It seems this PR will not be merged into OpenCV.

@eyildiz-ugoe
Copy link

Why is not integrated? It is kinda ridiculous that OpenCV does not support texts with line spaces.

savuor pushed a commit to nickyu-zhu/opencv that referenced this pull request Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants