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

[portability] Use existing cv::putText #11

Closed
ebachard opened this issue Oct 30, 2016 · 5 comments
Closed

[portability] Use existing cv::putText #11

ebachard opened this issue Oct 30, 2016 · 5 comments

Comments

@ebachard
Copy link

ebachard commented Oct 30, 2016

Hello,

I recently discovered cvui, and I'm extremely interested. The idea is great, and I'm all for avoiding Qt to write a software.

For portability reasons, I think you should replace cvui::printf, with something from cv, even when writing the 2 + 3.2 = 5.2 example (in main-app.cpp), associated to two helpers, named intToString and floatToString (see below).

I'm not used to github, but I'll try to attach several patches. Waiting, you'll find a wild copy-paste. Apologies in advance.

@@ -43,11 +49,20 @@ int main(int argc, const char *argv[])
        // You can also specify the size of the text and its color
        // using hex 0xRRGGBB CSS-like style.
        cvui::text(frame, 200, 30, "Use hex 0xRRGGBB colors easily", 0.4, 0xff0000);
-       
-       // Sometimes you want to show text that is not that simple, e.g. strings + numbers.
-       // You can use cvui::printf for that. It accepts a variable number of parameter, pretty
-       // much like printf does.
-       cvui::printf(frame, 200, 50, 0.4, 0x00ff00, "Use printf formatting: %d + %.2f = %f", 2, 3.2, 5.2);
+
+                // cv::putText() signature, from opencv2/imgproc.hpp:
+                // putText(img, text, textOrg, fontFace, fontScale, Scalar::all(255),
+                //              thickness, LINE_TYPE /* default value = 8 */);
+
+                cv::Scalar aColor = CV_RGB(0, 255, 0);
+       cv::putText(frame,
+                            "Using cv::putText() : "+intToString(2)+" + "+floatToString(3.2)+" = "+floatToString(5.2),
+                            cv::Point(200,56),
+                            fontFace,
+                            0.4,
+                            aColor,
+                            1.5,
+                            8);

        // Buttons will return true if they were clicked, which makes
        // handling clicks a breeze.
@@ -88,7 +103,17 @@ int main(int argc, const char *argv[])
        cvui::checkbox(frame, 200, 190, "A checked checkbox", &checked2);

        // Display the lib version at the bottom of the screen
-       cvui::printf(frame, frame.cols - 80, frame.rows - 20, 0.4, 0xCECECE, "cvui v.%s", cvui::VERSION);
+//     cvui::printf(frame, frame.cols - 80, frame.rows - 20, 0.4, 0xCECECE, "cvui v.%s", cvui::VERSION);
+
+                aColor = CV_RGB(206, 206, 206);  /* 0xCE = 206 */
+                cv::putText(frame,
+                            "cvui v"+intToString(VERSION_MAJOR)+"."+intToString(VERSION_MINOR)+"."+intToString(VERSION_MICRO),
+                            cv::Point(frame.cols - 80,frame.rows - 10 /*FIXME : use font height instead of a magic */),
+                            fontFace,
+                            0.4,
+                            aColor,
+                            1.5,
+                            8);

        // This function must be called *AFTER* all UI components. It does
        // all the behind the scenes magic to handle mouse clicks, etc.

For intToString and floatToString, I propose to add the declarations in cvui.h like follow:

(in cvui.h)


+std::string intToString(int);
+std::string floatToString(double);

 namespace cvui
 {
in cvui.cpp:

+/* helpers */
+
+std::string intToString(int number)
+{
+   std::ostringstream ss;
+   ss << number;
+   return ss.str();
+}
+
+std::string floatToString(double aFloat)
+{
+   std::ostringstream ss;
+   ss << aFloat;
+   return ss.str();
+}
+
+
@ebachard
Copy link
Author

ooops, looks like something was wrong with the code instertion ... apologies :-/

@ebachard
Copy link
Author

Apologies, I'll read how to send patch, because I'm more used to speak patch language than html things.

@Dovyski
Copy link
Owner

Dovyski commented Oct 31, 2016

Hello! Don't worry about formatting nor any Github idiosyncrasy, your contribution is the valuable part.

I would like you to elaborate a bit more regarding cvui::printf portability. Is it not portable because of a misbehavior or compilation warning/error on Linux/Mac?

I see the benefit of using cv::putText, but the general idea of cvui is to abstract opencv drawing primities to provide a simpler and more powerful API. I think the methods you suggested (intToString() and floatToString()) could be replaced by the already existing std::to_string():

// ... 
cv::putText(frame,
 "cvuiv" + std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR) + "." + std::to_string(VERSION_MICRO),
  cv::Point(frame.cols - 80,frame.rows - 10 /*FIXME : use font height instead of a magic */),
  fontFace,
  0.4,
  aColor,
  1.5,
  8);

//...   

@ebachard
Copy link
Author

ebachard commented Nov 8, 2016

Le 31/10/2016 20:16, Fernando Bevilacqua a écrit :

Hello! Don't worry about formatting nor any Github idiosyncrasy, your contribution is the valuable part.

Hello Fernando,

Apologies for the loooong delay : several things made me away from
keyboard, and I hope I'll have more time this week.

(of course, I'll answer the other mails you sent me asap)

I would like you to elaborate a bit more regarding cvui::printf portability. Is it not portable because of a misbehavior or compilation warning/error on Linux/Mac?

The problem is most of the time Microsoft, deciding something, without
verify the portability is respected on other OS's, and what I read here
and there told me it's simply not possible to use this directly. As I
wrote, I was busy last week, but I'll try to propose another solution
-means something simly working on Unix'es- once I'll have the time to
work on that. e.g., currently, some strings displaying is broken, due to
the uggly workaround I used (first thing was to make it compile, per see
:-)

I see the benefit of using cv::putText, but the general idea of cvui is to abstract opencv drawing primities to provide a simpler and more powerful API. I think the methods you suggested (intToString() and floatToString()) could be replaced by the already existing std::to_string():

OOOops, my bad :-)

I was simply unaware such solution was existing. Of course it is more
simple to use that, under to condition to build adding "-std=c++11 " in
the command line.

// ...
cv::putText(frame,
  "cvuiv" + std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR) + "." + std::to_string(VERSION_MICRO),
   cv::Point(frame.cols - 80,frame.rows - 10 /*FIXME : use font height instead of a magic */),
   fontFace,
   0.4,
   aColor,
   1.5,
   8);

Tested one minute ago => works as expected on Linux (not tested on Mac OS X)

Regards,
Eric Bachard

//...


@Dovyski
Copy link
Owner

Dovyski commented Apr 15, 2017

I think all the issues reported here were fixed by 80f382f. If you face any problems, please open a new issue.

@Dovyski Dovyski closed this as completed Apr 15, 2017
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

No branches or pull requests

2 participants