Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

i'd propose a similar, but maybe easier approach: instead of generating a new, seperate python module (.so), embed your code into the existing cv2.so

1. put your code into the opencv src tree:

make a new folder inside opencv/modules, containing your code:

opencv/modules/testcv
|   CMakeLists.txt
|
+---include
|   \---opencv2
|           testcv.hpp    // hpp, not h, please !
|
\---src
        testcv.cpp

2. edit CmakeLists.txt:

your code depends on opencv_core, opencv_imgcodecs, and opencv_highgui, so put the dependancies there:

set(the_description "my fancy cvtest")

ocv_define_module(cvtest opencv_imgproc opencv_core opencv_highgui WRAP python)

3. build the opencv libs & python wrappers as usual:

cmake <lots of args> <opencv_src>

make && make install

i'd propose a similar, but maybe easier approach: instead of generating a new, seperate python module (.so), embed your code into the existing cv2.so

1. put your code into the opencv src tree:

make a new folder inside opencv/modules, containing your code:

opencv/modules/testcv
|   CMakeLists.txt
|
+---include
|   \---opencv2
|           testcv.hpp    // hpp, not h, please !
|
\---src
        testcv.cpp

2. edit CmakeLists.txt:

your code depends on opencv_core, opencv_imgcodecs, and opencv_highgui, so put the dependancies there:

set(the_description "my fancy cvtest")

ocv_define_module(cvtest opencv_imgproc opencv_core opencv_highgui WRAP python)

3. build the opencv libs & python wrappers as usual:

https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html

cmake <lots of args> <opencv_src>

make && make install

i'd propose a similar, but maybe easier approach: instead of generating a new, seperate python module (.so), embed your code into the existing cv2.so

1. put your code into the opencv src tree:

make a new folder inside opencv/modules, containing your code:

opencv/modules/testcv
|   CMakeLists.txt
|
+---include
|   \---opencv2
|           testcv.hpp    // hpp, not h, please !
|
\---src
        testcv.cpp

2. edit CmakeLists.txt:

your code depends on opencv_core, opencv_imgcodecs, and opencv_highgui, so put the dependancies there:

set(the_description "my fancy cvtest")

ocv_define_module(cvtest opencv_imgproc opencv_core opencv_highgui WRAP python)

3. build the opencv libs & python wrappers as usual:

https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html

cmake <lots of args> <opencv_src>

make && make install

4. use your code:

import cv2

t = cv2.testCV() # it's inside cv2 now!
t.TakeALook()

i'd propose a similar, but maybe easier approach: instead of generating a new, seperate python module (.so), embed your code into the existing cv2.so

1. put your code into the opencv src tree:

make a new folder inside opencv/modules, containing your code:

opencv/modules/testcv
|   CMakeLists.txt
|
+---include
|   \---opencv2
|           testcv.hpp    // hpp, not h, please !
|
\---src
        testcv.cpp

2. edit CmakeLists.txt:CmakeLists.txt (and your code):

your code depends on opencv_core, opencv_imgcodecs, and opencv_highgui, so put the dependancies there:

set(the_description "my fancy cvtest")

ocv_define_module(cvtest opencv_imgproc opencv_core opencv_highgui WRAP python)

.

//testcv.hpp:

#include <opencv2/opencv.hpp>
namespace cv { // put it into cv2 namespace

CV_EXPORTS_W class TestCV
{
public:
    CV_WRAP TestCV();
    CV_WRAP void TakeALook();
};
}

.

//testcv.cpp

#include "testcv.hpp"
using namespace std;
using namespace cv;

TestCV::TestCV()
{

}
void TestCV::TakeALook()
{
    Mat src=imread("a.jpg");
    imshow("see!",src);
    waitKey(0);
}

3. build the opencv libs & python wrappers as usual:

(along with your own code, now !)

https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html

cmake <lots of args> <opencv_src>

make && make install

4. use your code:

import cv2

t = cv2.testCV() # it's inside cv2 now!
t.TakeALook()

i'd propose a similar, but maybe easier approach: instead of generating a new, seperate python module (.so), embed your code into the existing cv2.so

1. put your code into the opencv src tree:

make a new folder inside opencv/modules, containing your code:

opencv/modules/testcv
|   CMakeLists.txt
|
+---include
|   \---opencv2
|           testcv.hpp    // hpp, not h, please !
|
\---src
        testcv.cpp

2. edit CmakeLists.txt (and your code):

your code depends on opencv_core, opencv_imgcodecs, and opencv_highgui, so put the dependancies there:

set(the_description "my fancy cvtest")

ocv_define_module(cvtest opencv_imgproc opencv_core opencv_highgui WRAP python)

.

//testcv.hpp:

#include <opencv2/opencv.hpp>
namespace cv { // put it into cv2 namespace
// if you add your own namespace (inside cv2) here, it will be: cv2.myspace.TestCV() later

CV_EXPORTS_W class TestCV
{
public:
    CV_WRAP TestCV();
    CV_WRAP void TakeALook();
};
}

.

//testcv.cpp

#include "testcv.hpp"
using namespace std;
using namespace cv;

TestCV::TestCV()
{

}
void TestCV::TakeALook()
{
    Mat src=imread("a.jpg");
    imshow("see!",src);
    waitKey(0);
}

3. build the opencv libs & python wrappers as usual:

(along with your own code, now !)

https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html

cmake <lots of args> <opencv_src>

make && make install

4. use your code:

import cv2

t = cv2.testCV() # it's inside cv2 now!
t.TakeALook()

i'd propose a similar, but maybe easier approach: instead of generating a new, seperate python module (.so), embed your code into the existing cv2.so

1. put your code into the opencv src tree:

make a new folder inside opencv/modules, containing your code:

opencv/modules/testcv
|   CMakeLists.txt
|
+---include
|   \---opencv2
|           testcv.hpp    // hpp, not h, please !
|
\---src
        testcv.cpp

2. edit CmakeLists.txt (and your code):

your code depends on opencv_core, opencv_imgcodecs, and opencv_highgui, so put the dependancies there:

set(the_description "my fancy cvtest")

ocv_define_module(cvtest opencv_imgproc opencv_core opencv_highgui WRAP python)

.

//testcv.hpp:

#include <opencv2/opencv.hpp>
namespace cv { // put it into cv2 namespace
// if you add your own namespace (inside cv2) here, it will be: cv2.myspace.TestCV() later

CV_EXPORTS_W class TestCV
{
public:
    CV_WRAP TestCV();
    CV_WRAP void TakeALook();
};
}

.

//testcv.cpp

#include "testcv.hpp"
using namespace std;
using namespace cv;

TestCV::TestCV()
{

}
void TestCV::TakeALook()
{
    Mat src=imread("a.jpg");
    imshow("see!",src);
    waitKey(0);
}

3. build the opencv libs & python wrappers as usual:

(along with your own code, now !)

https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html

cmake <lots of args> <opencv_src>

make && make install

4. use your code:

import cv2

t = cv2.testCV() # it's inside cv2 now!
t.TakeALook()