0

I'd like to get a value from a variable that's located deeply in the source code of the OpenCV library. Specifically, I'm trying to print out the value of stage_sum from the file haar.cpp. My starting point, facedetect.cpp, calls the method detectMultiScale, which then calls the function cvHaarDetectObjects, which calls cvHaarDetectObjectsForROC etc., until it finally reaches the function cvRunHaarClassifierCascadeSum, where stage_sum is calculated.

Is there a way I could get the value out to facedetect.cpp easily, without changing the declarations of all the preceding functions/methods, headers etc.? Simply trying to cout or printf the value directly in the source code hasn't given any results.

Thanks everyone for your help!

mkolarek
  • 527
  • 1
  • 7
  • 16

2 Answers2

2

One option is simply to use a debugger.

However, if you want to do this programatically (i.e. access the variable as part of your application code), then unless the variable is exposed in the library's public interface, there are two options available:

  • Modify the library's source code, and recompile it.
  • Resort to undefined-behaviour (fiddling around with the raw bytes that make up an object, etc.).
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
  • I 'make' the library after every change (I'm under Ubuntu), I suppose that this falls under recompiling? And I don't understand what exactly undefined-behaviour means, are you reffering to accesing the value via some kind of pointer? – mkolarek Apr 09 '12 at 16:46
0

Just to point the obvious, adding a std::cout() or printf() call inside haar.cpp won't do the trick. You need to recompile OpenCV for this changes to take effect and then reinstall the libraries on your system.

karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • in case of android platform, it possibly will not help as by default `stdout` and `stderr` are redirected to `dev/null`, that's why I asked about the platform in comment to the question. – Alex Apr 09 '12 at 15:33
  • The platform in question is Ubuntu, and I 'make' the whole library after every change (I suppose that I don't have to reinstall it as well?). – mkolarek Apr 09 '12 at 16:36
  • @Alex Then write the output to a file instead of stdin/stderr. :P – karlphillip Apr 09 '12 at 16:37
  • @kolarek you have to reinstall it when you rebuild it! `make install` – karlphillip Apr 09 '12 at 16:37
  • 2
    God, I'm such an idiot! I'll try this right away. Thank you very much! – mkolarek Apr 09 '12 at 16:49
  • @karlphillip yes, but what is the shortest way to do it from the OpenCV source point of view? – Alex Apr 10 '12 at 06:51
  • @Alex I'm not sure I understand your question. Which possible *ways* do you want to compare? – karlphillip Apr 10 '12 at 14:41
  • @karlphillip I mean how can I inside OpenCV redirect stdout to file? Something tells me that it must be done at application level, not a library level. – Alex Apr 10 '12 at 15:10
  • @Alex One can always use the [LD_PRELOAD trick](http://stackoverflow.com/questions/426230/what-is-the-ld-preload-trick). Assuming Linux, of course (which is the scope of the question). – karlphillip Apr 10 '12 at 16:16
  • @karlphillip Actually, I mean android platform (see the first comment for the answer), but it is not actually topic of this question. Anyway, thanks. – Alex Apr 11 '12 at 07:06