Howto retrieve the corresponding cpp-file of given header-file

Hey everybody,
I am rather new to C++ and i just registered for this forum because i need help with an issue that at first sight seems to be very specific, but is rather a general thing, I guess:

I am using the OpenCV library (2.3.1-7) and Qt-Creator (2.4.1) and I have this simplified piece of code that reads in an image as cv::Mat and then applies the OpenCV function pyrDown to the cv::Mat.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/gpu/gpu.hpp"

using namespace std;
using namespace cv;

int main()
{
    Mat image1=imread("../image1.jpeg");
    imshow("image1",image1);



    cv::Mat pyrimag;
    pyrDown(image1,pyrimag);
    imshow("pyrimag",pyrimag);

    while(true) {
        char c = cvWaitKey(33);
        if( c == 'c' ) break;
     }
    return 0;
}


This piece of code runs just fine and puts out the two different images as exected.
What I need to do now is to retrieve the source code of the "pyrDown"-function and then modify it according to the needs of the project that I am working on.


If I comment out the following line
//#include "opencv2/gpu/gpu.hpp"
then this results in the following error message:
'pyrDown' was not declared in this scope.
Apparently, pyrDown only works if #include "opencv2/gpu/gpu.hpp" is included in my code. Therefore the header of pyrDown should be included in this file, correct??

I am using Qt-Creator and the tooltip text for "pyrDown" is as follows:
"void pyrDown(InputArray src, OutputArray dst, const Size &dstsize=Size())"

Therefore, when i checked the file "/usr/include/opencv2/gpu/gpu.hpp" (which is the complete path to the file), looking for the headers of "pyrDown" I expected to find a matching header.
But instead, I only found this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
        //! smoothes the source image and downsamples it
        CV_EXPORTS void pyrDown(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
        
        struct CV_EXPORTS PyrDownBuf;
        
        CV_EXPORTS void pyrDown(const GpuMat& src, GpuMat& dst, PyrDownBuf& buf, Stream& stream = Stream::Null());
        
        struct CV_EXPORTS PyrDownBuf
        {
            PyrDownBuf() : image_type(-1) {}
            PyrDownBuf(Size image_size, int image_type_) : image_type(-1) { create(image_size, image_type_); }
            void create(Size image_size, int image_type_);

        private:
            friend void pyrDown(const GpuMat&, GpuMat&, PyrDownBuf&, Stream& stream);

            static Mat ker;
            GpuMat buf;
            Ptr<FilterEngine_GPU> filter;
            int image_type;
        };



Those are all the lines of code where the character string "pyrDown" is included.
To me, being rather a newbie, it is kind of strange that there is no header that matches the call of the function as it was included in my simplified code example at the very top of this post.

What I would like to understand is the following:

1) Is the file gpu.hpp really the one that stores the header that is used for the call in my code example? If so, I would like to understand why this is the case, since the data types of the parameters seem not to match (eg "GpuMat&" vs. "InputArray"). In gpu.hpp there are other files included, using the "#include"-command, but a text search in those files did not find any strings like "pyrDown" in any of them.

2) If gpu.hpp is not the header file that I am looking for, which one is the correct one and where can I find it?

3) The most important part for me is: Where can I retrieve the corresponding .cpp file for pyrDown, since this is crucial to the progress in my project. I have googled a lot and I found lots of .cpp files that were named "pyrDown.cpp" (example: https://github.com/cdemel/OpenCV/blob/master/modules/ocl/src/pyrdown.cpp), but none of them seems to be the one that I am looking for since either the data types in the header are not in accordance with what I expect or there are #include commands for files that I do not have available on my machine. And I assume that any .cpp-file that tries to use files that are not on my computer can not be the one that is used for the call in the code example at the top of this post.

I guess that it is sth. rather simple, but after many hours of searching the internet and trying to work with the gpu.hpp-files that I found, I am pretty much stuck and have no clue how to approach the whole problem.
If anybody could give me a hint? I would really appreciate it! Thanks in advance!
Regards, Ron
1
2
3
4
5
6
7
// imgproc/imgproc.hpp
CV_EXPORTS_W void pyrDown(
   InputArray src, 
   OutputArray dst,
   const Size& dstsize=Size(), 
   int borderType=BORDER_DEFAULT
);
an `InputArray' can be constructed from a `Mat'


> What I need to do now is to retrieve the source code of the "pyrDown"-function
> and then modify it according to the needs of the project that I am working on.
Try not to break anything. It may be easier to do another function.
In version 2.4.3 `modules/imgproc/src/pyramids.cpp'

> there are #include commands for files that I do not have available on my machine.
Download the full source code.


In order for your snips to work, you are linking against `$(pkg-config --libs opencv)'
i.e. against *.so files.
Thanks for the quick response!

Up to now I downloaded the complete source code available here:
http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.3/

`modules/imgproc/src/pyramids.cpp' was included, exactly as you said.

How should I proceed now? Should I also update the OpenCV-packages that are currently installed?
Or is it OK to leave that as it is? Will there be no problems due to different versions: 2.4.3 vs. 2.3.1-7.
If I dpkg -l *opencv* in my terminal then this returns

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                   Version                Description
+++-======================-======================-============================================================
ii  libopencv-calib3d-dev  2.3.1-7                development files for libopencv-calib3d
ii  libopencv-calib3d2.3   2.3.1-7                computer vision Camera Calibration library
ii  libopencv-contrib-dev  2.3.1-7                development files for libopencv-contrib
ii  libopencv-contrib2.3   2.3.1-7                computer vision contrib library
ii  libopencv-core-dev     2.3.1-7                development files for libopencv-core
ii  libopencv-core2.3      2.3.1-7                computer vision core library
ii  libopencv-dev          2.3.1-7                development files for opencv
ii  libopencv-features2d-d 2.3.1-7                development files for libopencv-features2d
ii  libopencv-features2d2. 2.3.1-7                computer vision Feature Detection and Descriptor Extraction 
ii  libopencv-flann-dev    2.3.1-7                development files for libopencv-flann
ii  libopencv-flann2.3     2.3.1-7                computer vision Clustering and Search in Multi-Dimensional s
ii  libopencv-gpu-dev      2.3.1-7                development files for libopencv-gpu
ii  libopencv-gpu2.3       2.3.1-7                computer vision GPU Processing library
ii  libopencv-highgui-dev  2.3.1-7                development files for libopencv-highgui
ii  libopencv-highgui2.3   2.3.1-7                computer vision High-level GUI and Media I/O library
ii  libopencv-imgproc-dev  2.3.1-7                development files for libopencv-imgproc
ii  libopencv-imgproc2.3   2.3.1-7                computer vision Image Processing library
ii  libopencv-legacy-dev   2.3.1-7                development files for libopencv-legacy
ii  libopencv-legacy2.3    2.3.1-7                computer vision legacy library
ii  libopencv-ml-dev       2.3.1-7                development files for libopencv-ml
ii  libopencv-ml2.3        2.3.1-7                computer vision Machine Learning library
ii  libopencv-objdetect-de 2.3.1-7                development files for libopencv-objdetect
ii  libopencv-objdetect2.3 2.3.1-7                computer vision Object Detection library
ii  libopencv-video-dev    2.3.1-7                development files for libopencv-video
ii  libopencv-video2.3     2.3.1-7                computer vision Video analysis library


Thanks, Ron
As you intend to break it, make a local installation.
http://opencv.willowgarage.com/wiki/InstallGuide
-D CMAKE_INSTALL_PREFIX

$ make
$ make install

Make sure that it is working
In order to use those libraries instead of the ones in /usr/lib
Installing and using a shared library (3.5) http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html


Now you can modify what you please, updating the libraries with `make install'

Good luck.
Topic archived. No new replies allowed.