diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9023fa1965..59a3e316d1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1611,7 +1611,7 @@ status("")
status(" Interfaces:")
status(" Python:" BUILD_NEW_PYTHON_SUPPORT THEN YES ELSE NO)
status(" Python interpreter:" PYTHON_EXECUTABLE THEN "${PYTHON_EXECUTABLE} (ver ${PYTHON_VERSION_MAJOR_MINOR})" ELSE NO)
-status(" Python numpy:" PYTHON_USE_NUMPY THEN YES ELSE "NO (Python interface will not cover OpenCV 2.x API)")
+status(" Python numpy:" PYTHON_USE_NUMPY THEN YES ELSE "NO (Python wrappers will not be generated)")
if(ANDROID AND ANDROID_API_LEVEL LESS 8)
status(" Java:" "NO (Java API requires Android API level 8 or higher)")
else()
diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt
index deef05133d..17d71f1fcb 100644
--- a/modules/CMakeLists.txt
+++ b/modules/CMakeLists.txt
@@ -24,7 +24,7 @@ add_subdirectory(contrib)
add_subdirectory(ml)
add_subdirectory(objdetect)
-if(PYTHONLIBS_FOUND AND BUILD_NEW_PYTHON_SUPPORT)
+if(PYTHONLIBS_FOUND AND BUILD_NEW_PYTHON_SUPPORT AND PYTHON_USE_NUMPY)
add_subdirectory(python)
endif()
diff --git a/modules/core/doc/old_basic_structures.rst b/modules/core/doc/old_basic_structures.rst
index 4e0c189752..b7483a8e0e 100644
--- a/modules/core/doc/old_basic_structures.rst
+++ b/modules/core/doc/old_basic_structures.rst
@@ -1729,7 +1729,7 @@ For example, `NumPy `_ arrays support the array interfa
.. code-block::python
- >>> import cv, numpy
+ >>> import cv2.cv as cv, numpy
>>> a = numpy.ones((480, 640))
>>> mat = cv.fromarray(a)
>>> print cv.GetDims(mat), cv.CV_MAT_CN(cv.GetElemType(mat))
diff --git a/modules/python/CMakeLists.txt b/modules/python/CMakeLists.txt
index ce21d22840..0b64b1c266 100644
--- a/modules/python/CMakeLists.txt
+++ b/modules/python/CMakeLists.txt
@@ -5,7 +5,6 @@ project(opencv_python)
include_directories(${PYTHON_INCLUDE_PATH})
include_directories(
- "${CMAKE_CURRENT_SOURCE_DIR}/src1"
"${CMAKE_CURRENT_SOURCE_DIR}/src2"
"${OpenCV_SOURCE_DIR}/modules/core/include"
"${OpenCV_SOURCE_DIR}/modules/imgproc/include"
@@ -37,37 +36,6 @@ if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
endif()
-add_custom_command(
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated0.i
- COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src1/gen.py" "${CMAKE_CURRENT_SOURCE_DIR}/src1"
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src1/api
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src1/defs
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src1/gen.py
- )
-
-
-set(cv_target "opencv_python")
-add_library(${cv_target} SHARED src1/cv.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated0.i)
-target_link_libraries(${cv_target} ${PYTHON_LIBRARIES} opencv_core opencv_imgproc opencv_video opencv_ml opencv_features2d opencv_highgui opencv_calib3d opencv_objdetect opencv_legacy opencv_contrib)
-
-set_target_properties(${cv_target} PROPERTIES PREFIX "")
-set_target_properties(${cv_target} PROPERTIES OUTPUT_NAME "cv")
-
-execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig; print distutils.sysconfig.get_config_var('SO')"
- RESULT_VARIABLE PYTHON_CVPY_PROCESS
- OUTPUT_VARIABLE CVPY_SUFFIX
- OUTPUT_STRIP_TRAILING_WHITESPACE)
-
-set_target_properties(${cv_target} PROPERTIES SUFFIX ${CVPY_SUFFIX})
-
-if (MSVC AND NOT BUILD_SHARED_LIBS)
- set_target_properties(${cv_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
-endif()
-
-set(cvpymodules ${cv_target})
-
-if(PYTHON_USE_NUMPY)
-
set(cv2_generated_hdrs
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_funcs.h"
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_func_tab.h"
@@ -75,28 +43,41 @@ set(cv2_generated_hdrs
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_type_reg.h"
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_const_reg.h")
+
add_custom_command(
- OUTPUT ${cv2_generated_hdrs}
- COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src2/gen2.py" ${CMAKE_CURRENT_BINARY_DIR} ${opencv_hdrs}
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/gen2.py
- DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/hdr_parser.py
- DEPENDS ${opencv_hdrs})
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/generated0.i
+ COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src2/gen.py" "${CMAKE_CURRENT_SOURCE_DIR}/src2"
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/api
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/defs
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/gen.py
+ )
-set(cv2_target "opencv2_python")
-add_library(${cv2_target} SHARED src2/cv2.cpp src2/opencv_extra_api.hpp ${cv2_generated_hdrs})
+add_custom_command(
+ OUTPUT ${cv2_generated_hdrs}
+ COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src2/gen2.py" ${CMAKE_CURRENT_BINARY_DIR} ${opencv_hdrs}
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/gen2.py
+ DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/hdr_parser.py
+ DEPENDS ${opencv_hdrs})
+
+set(cv2_target "opencv_python")
+add_library(${cv2_target} SHARED src2/cv2.cpp ${CMAKE_CURRENT_BINARY_DIR}/generated0.i src2/opencv_extra_api.hpp ${cv2_generated_hdrs} src2/cv2.cv.hpp)
target_link_libraries(${cv2_target} ${PYTHON_LIBRARIES} opencv_core opencv_imgproc opencv_video opencv_ml opencv_features2d opencv_highgui opencv_calib3d opencv_objdetect opencv_legacy opencv_contrib)
-
+
set_target_properties(${cv2_target} PROPERTIES PREFIX "")
set_target_properties(${cv2_target} PROPERTIES OUTPUT_NAME "cv2")
+
+execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "import distutils.sysconfig; print distutils.sysconfig.get_config_var('SO')"
+ RESULT_VARIABLE PYTHON_CVPY_PROCESS
+ OUTPUT_VARIABLE CVPY_SUFFIX
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+
set_target_properties(${cv2_target} PROPERTIES SUFFIX ${CVPY_SUFFIX})
if (MSVC AND NOT BUILD_SHARED_LIBS)
set_target_properties(${cv2_target} PROPERTIES LINK_FLAGS "/NODEFAULTLIB:atlthunk.lib /NODEFAULTLIB:atlsd.lib /DEBUG")
endif()
-set(cvpymodules ${cvpymodules} ${cv2_target})
-
-endif()
+set(cvpymodules ${cv2_target})
if(WIN32)
install(TARGETS ${cvpymodules}
@@ -105,7 +86,6 @@ if(WIN32)
ARCHIVE DESTINATION "Python${PYTHON_VERSION_MAJOR_MINOR}/Lib/site-packages" COMPONENT main
)
else()
- #install(FILES ${LIBRARY_OUTPUT_PATH}/cv${CVPY_SUFFIX} DESTINATION ${PYTHON_PACKAGES_PATH})
install(TARGETS ${cvpymodules}
RUNTIME DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main
LIBRARY DESTINATION ${PYTHON_PACKAGES_PATH} COMPONENT main
diff --git a/modules/python/src1/api b/modules/python/src2/api
similarity index 100%
rename from modules/python/src1/api
rename to modules/python/src2/api
diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp
index 39469ff0db..b0b263604f 100644
--- a/modules/python/src2/cv2.cpp
+++ b/modules/python/src2/cv2.cpp
@@ -833,6 +833,8 @@ static int to_ok(PyTypeObject *to)
return (PyType_Ready(to) == 0);
}
+#include "cv2.cv.hpp"
+
extern "C"
#if defined WIN32 || defined _WIN32
__declspec(dllexport)
@@ -848,16 +850,17 @@ void initcv2()
#include "pyopencv_generated_type_reg.h"
#endif
- PyObject* m = Py_InitModule(MODULESTR"", methods);
+ PyObject* m = Py_InitModule(MODULESTR, methods);
PyObject* d = PyModule_GetDict(m);
PyDict_SetItemString(d, "__version__", PyString_FromString("$Rev: 4557 $"));
opencv_error = PyErr_NewException((char*)MODULESTR".error", NULL, NULL);
PyDict_SetItemString(d, "error", opencv_error);
+
+ PyObject* cv_m = init_cv();
- // AFAIK the only floating-point constant
- PyDict_SetItemString(d, "CV_PI", PyFloat_FromDouble(CV_PI));
+ PyDict_SetItemString(d, "cv", cv_m);
#define PUBLISH(I) PyDict_SetItemString(d, #I, PyInt_FromLong(I))
#define PUBLISHU(I) PyDict_SetItemString(d, #I, PyLong_FromUnsignedLong(I))
@@ -942,7 +945,6 @@ void initcv2()
PUBLISH(CV_AA);
-
#include "pyopencv_generated_const_reg.h"
}
diff --git a/modules/python/src1/cv.cpp b/modules/python/src2/cv2.cv.hpp
similarity index 95%
rename from modules/python/src1/cv.cpp
rename to modules/python/src2/cv2.cv.hpp
index e8287733a8..fd3f91eab9 100644
--- a/modules/python/src1/cv.cpp
+++ b/modules/python/src2/cv2.cv.hpp
@@ -1,16 +1,7 @@
-#include
+#include "opencv2/legacy/legacy.hpp"
+#include "opencv2/legacy/compat.hpp"
-#include
-
-#include "opencv/cxcore.h"
-#include "opencv/cv.h"
-#include "opencv/cvaux.h"
-#include "opencv/cvwimage.h"
-#include "opencv/highgui.h"
-
-#define MODULESTR "cv"
-
-static PyObject *opencv_error;
+#define OLD_MODULESTR "cv2.cv"
struct memtrack_t {
PyObject_HEAD
@@ -168,21 +159,6 @@ static void translate_error_to_exception(void)
/************************************************************************/
-static int failmsg(const char *fmt, ...)
-{
- char str[1000];
-
- va_list ap;
- va_start(ap, fmt);
- vsnprintf(str, sizeof(str), fmt, ap);
- va_end(ap);
-
- PyErr_SetString(PyExc_TypeError, str);
- return 0;
-}
-
-/************************************************************************/
-
/* These get/setters are polymorphic, used in both iplimage and cvmat */
static PyObject *PyObject_FromCvScalar(CvScalar s, int type)
@@ -355,7 +331,7 @@ static PyMappingMethods iplimage_as_map = {
static PyTypeObject iplimage_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".iplimage", /*name*/
+ OLD_MODULESTR".iplimage", /*name*/
sizeof(iplimage_t), /*basicsize*/
};
@@ -665,7 +641,7 @@ static PyMappingMethods cvmat_as_map = {
static PyTypeObject cvmat_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".cvmat", /*name*/
+ OLD_MODULESTR".cvmat", /*name*/
sizeof(cvmat_t), /*basicsize*/
};
@@ -830,7 +806,7 @@ static PyMappingMethods cvmatnd_as_map = {
static PyTypeObject cvmatnd_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".cvmatnd", /*name*/
+ OLD_MODULESTR".cvmatnd", /*name*/
sizeof(cvmatnd_t), /*basicsize*/
};
@@ -862,7 +838,7 @@ static void cvhistogram_dealloc(PyObject *self)
static PyTypeObject cvhistogram_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".cvhistogram", /*name*/
+ OLD_MODULESTR".cvhistogram", /*name*/
sizeof(cvhistogram_t), /*basicsize*/
};
@@ -915,7 +891,7 @@ static PyObject *cvlineiterator_next(PyObject *o)
static PyTypeObject cvlineiterator_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".cvlineiterator", /*name*/
+ OLD_MODULESTR".cvlineiterator", /*name*/
sizeof(cvlineiterator_t), /*basicsize*/
};
@@ -958,7 +934,7 @@ static void memtrack_dealloc(PyObject *self)
static PyTypeObject memtrack_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".memtrack", /*name*/
+ OLD_MODULESTR".memtrack", /*name*/
sizeof(memtrack_t), /*basicsize*/
};
@@ -1005,7 +981,7 @@ static void cvmemstorage_dealloc(PyObject *self)
static PyTypeObject cvmemstorage_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".cvmemstorage", /*name*/
+ OLD_MODULESTR".cvmemstorage", /*name*/
sizeof(cvmemstorage_t), /*basicsize*/
};
@@ -1021,7 +997,7 @@ static void cvmemstorage_specials(void)
static PyTypeObject cvfont_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".cvfont", /*name*/
+ OLD_MODULESTR".cvfont", /*name*/
sizeof(cvfont_t), /*basicsize*/
};
@@ -1034,7 +1010,7 @@ static void cvfont_specials(void) { }
static PyTypeObject cvrng_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".cvrng", /*name*/
+ OLD_MODULESTR".cvrng", /*name*/
sizeof(cvrng_t), /*basicsize*/
};
@@ -1049,7 +1025,7 @@ static void cvrng_specials(void)
static PyTypeObject cvcontourtree_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".cvcontourtree", /*name*/
+ OLD_MODULESTR".cvcontourtree", /*name*/
sizeof(cvcontourtree_t), /*basicsize*/
};
@@ -1063,7 +1039,7 @@ static void cvcontourtree_specials(void) { }
static PyTypeObject cvsubdiv2dedge_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".cvsubdiv2dedge", /*name*/
+ OLD_MODULESTR".cvsubdiv2dedge", /*name*/
sizeof(cvsubdiv2dedge_t), /*basicsize*/
};
@@ -1246,7 +1222,7 @@ static PyMappingMethods cvseq_mapping = {
static PyTypeObject cvseq_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".cvseq", /*name*/
+ OLD_MODULESTR".cvseq", /*name*/
sizeof(cvseq_t), /*basicsize*/
};
@@ -1294,7 +1270,7 @@ static void cvset_dealloc(PyObject *self)
static PyTypeObject cvset_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".cvset", /*name*/
+ OLD_MODULESTR".cvset", /*name*/
sizeof(cvset_t), /*basicsize*/
};
@@ -1334,7 +1310,7 @@ static void cvset_specials(void)
static PyTypeObject cvsubdiv2d_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".cvsubdiv2d", /*name*/
+ OLD_MODULESTR".cvsubdiv2d", /*name*/
sizeof(cvsubdiv2d_t), /*basicsize*/
};
@@ -1365,7 +1341,7 @@ static void cvsubdiv2d_specials(void)
static PyTypeObject cvsubdiv2dpoint_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
- MODULESTR".cvsubdiv2dpoint", /*name*/
+ OLD_MODULESTR".cvsubdiv2dpoint", /*name*/
sizeof(cvsubdiv2dpoint_t), /*basicsize*/
};
@@ -3367,75 +3343,6 @@ static PyObject *pycvReshapeMatND(PyObject *self, PyObject *args)
return shareDataND(o, cva, pn);
}
-static void OnMouse(int event, int x, int y, int flags, void* param)
-{
- PyGILState_STATE gstate;
- gstate = PyGILState_Ensure();
-
- PyObject *o = (PyObject*)param;
- PyObject *args = Py_BuildValue("iiiiO", event, x, y, flags, PyTuple_GetItem(o, 1));
-
- PyObject *r = PyObject_Call(PyTuple_GetItem(o, 0), args, NULL);
- if (r == NULL)
- PyErr_Print();
- else
- Py_DECREF(r);
- Py_DECREF(args);
- PyGILState_Release(gstate);
-}
-
-static PyObject *pycvSetMouseCallback(PyObject *self, PyObject *args, PyObject *kw)
-{
- const char *keywords[] = { "window_name", "on_mouse", "param", NULL };
- char* name;
- PyObject *on_mouse;
- PyObject *param = NULL;
-
- if (!PyArg_ParseTupleAndKeywords(args, kw, "sO|O", (char**)keywords, &name, &on_mouse, ¶m))
- return NULL;
- if (!PyCallable_Check(on_mouse)) {
- PyErr_SetString(PyExc_TypeError, "on_mouse must be callable");
- return NULL;
- }
- if (param == NULL) {
- param = Py_None;
- }
- ERRWRAP(cvSetMouseCallback(name, OnMouse, Py_BuildValue("OO", on_mouse, param)));
- Py_RETURN_NONE;
-}
-
-void OnChange(int pos, void *param)
-{
- PyGILState_STATE gstate;
- gstate = PyGILState_Ensure();
-
- PyObject *o = (PyObject*)param;
- PyObject *args = Py_BuildValue("(i)", pos);
- PyObject *r = PyObject_Call(PyTuple_GetItem(o, 0), args, NULL);
- if (r == NULL)
- PyErr_Print();
- Py_DECREF(args);
- PyGILState_Release(gstate);
-}
-
-static PyObject *pycvCreateTrackbar(PyObject *self, PyObject *args)
-{
- PyObject *on_change;
- char* trackbar_name;
- char* window_name;
- int *value = new int;
- int count;
-
- if (!PyArg_ParseTuple(args, "ssiiO", &trackbar_name, &window_name, value, &count, &on_change))
- return NULL;
- if (!PyCallable_Check(on_change)) {
- PyErr_SetString(PyExc_TypeError, "on_change must be callable");
- return NULL;
- }
- ERRWRAP(cvCreateTrackbar2(trackbar_name, window_name, value, count, OnChange, Py_BuildValue("OO", on_change, Py_None)));
- Py_RETURN_NONE;
-}
-
static PyObject *pycvFindContours(PyObject *self, PyObject *args, PyObject *kw)
{
CvArr* image;
@@ -3964,17 +3871,12 @@ static double cppKMeans(const CvArr* _samples, int cluster_count, CvArr* _labels
#include "generated0.i"
-static PyMethodDef methods[] = {
+static PyMethodDef old_methods[] = {
#if PYTHON_USE_NUMPY
{"fromarray", (PyCFunction)pycvfromarray, METH_KEYWORDS, "fromarray(array) -> cvmatnd"},
#endif
- //{"CalcOpticalFlowFarneback", (PyCFunction)pycvCalcOpticalFlowFarneback, METH_KEYWORDS, "CalcOpticalFlowFarneback(prev, next, flow, pyr_scale=0.5, levels=3, win_size=15, iterations=3, poly_n=7, poly_sigma=1.5, flags=0) -> None"},
- //{"_HOGComputeDescriptors", (PyCFunction)pycvHOGComputeDescriptors, METH_KEYWORDS, "_HOGComputeDescriptors(image, win_stride=block_stride, locations=None, padding=(0,0), win_size=(64,128), block_size=(16,16), block_stride=(8,8), cell_size=(8,8), nbins=9, gammaCorrection=true) -> list_of_descriptors"},
- //{"_HOGDetect", (PyCFunction)pycvHOGDetect, METH_KEYWORDS, "_HOGDetect(image, svm_classifier, win_stride=block_stride, locations=None, padding=(0,0), win_size=(64,128), block_size=(16,16), block_stride=(8,8), cell_size=(8,8), nbins=9, gammaCorrection=true) -> list_of_points"},
- //{"_HOGDetectMultiScale", (PyCFunction)pycvHOGDetectMultiScale, METH_KEYWORDS, "_HOGDetectMultiScale(image, svm_classifier, win_stride=block_stride, scale=1.05, group_threshold=2, padding=(0,0), win_size=(64,128), block_size=(16,16), block_stride=(8,8), cell_size=(8,8), nbins=9, gammaCorrection=true) -> list_of_points"},
-
{"FindDataMatrix", pyfinddatamatrix, METH_VARARGS},
{"temp_test", temp_test, METH_VARARGS},
@@ -3986,33 +3888,13 @@ static PyMethodDef methods[] = {
/************************************************************************/
/* Module init */
-static int to_ok(PyTypeObject *to)
+PyObject* init_cv()
{
- to->tp_alloc = PyType_GenericAlloc;
- to->tp_new = PyType_GenericNew;
- to->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
- return (PyType_Ready(to) == 0);
-}
-
-#define MKTYPE(NAME) NAME##_specials(); if (!to_ok(&NAME##_Type)) return
-
-using namespace cv;
-
-extern "C"
-#if defined WIN32 || defined _WIN32
-__declspec(dllexport)
-#endif
-
-void initcv()
-{
-#if PYTHON_USE_NUMPY
- import_array();
-#endif
-
PyObject *m, *d;
-
cvSetErrMode(CV_ErrModeParent);
+ #define MKTYPE(NAME) NAME##_specials(); to_ok(&NAME##_Type)
+
MKTYPE(cvcontourtree);
MKTYPE(cvfont);
MKTYPE(cvhistogram);
@@ -4031,12 +3913,12 @@ void initcv()
#include "generated4.i"
- m = Py_InitModule(MODULESTR"", methods);
+ #undef MKTYPE
+
+ m = Py_InitModule(OLD_MODULESTR, old_methods);
d = PyModule_GetDict(m);
PyDict_SetItemString(d, "__version__", PyString_FromString("$Rev: 4557 $"));
-
- opencv_error = PyErr_NewException((char*)MODULESTR".error", NULL, NULL);
PyDict_SetItemString(d, "error", opencv_error);
// Couple of warnings about strict aliasing here. Not clear how to fix.
@@ -4127,7 +4009,13 @@ void initcv()
PUBLISH(GC_INIT_WITH_RECT);
PUBLISH(GC_INIT_WITH_MASK);
PUBLISH(GC_EVAL);
-
+
#include "generated2.i"
+
+#undef PUBLISH
+#undef PUBLISHU
+#undef PUBLISH2
+
+ return m;
}
diff --git a/modules/python/src1/defs b/modules/python/src2/defs
similarity index 100%
rename from modules/python/src1/defs
rename to modules/python/src2/defs
diff --git a/modules/python/src1/gen.py b/modules/python/src2/gen.py
similarity index 100%
rename from modules/python/src1/gen.py
rename to modules/python/src2/gen.py
diff --git a/modules/python/test/calchist.py b/modules/python/test/calchist.py
index f379dfec1a..0434f52d2f 100644
--- a/modules/python/test/calchist.py
+++ b/modules/python/test/calchist.py
@@ -1,7 +1,7 @@
# Calculating and displaying 2D Hue-Saturation histogram of a color image
import sys
-import cv
+import cv2.cv as cv
def hs_histogram(src):
# Convert to HSV
diff --git a/modules/python/test/camera_calibration.py b/modules/python/test/camera_calibration.py
index 8952e3cc23..989207c8a8 100644
--- a/modules/python/test/camera_calibration.py
+++ b/modules/python/test/camera_calibration.py
@@ -5,7 +5,7 @@ import random
import numpy
import transformations
-import cv
+import cv2.cv as cv
def clamp(a, x, b):
return numpy.maximum(a, numpy.minimum(x, b))
diff --git a/modules/python/test/findstereocorrespondence.py b/modules/python/test/findstereocorrespondence.py
index fd3e57f5fc..9cc19412c2 100644
--- a/modules/python/test/findstereocorrespondence.py
+++ b/modules/python/test/findstereocorrespondence.py
@@ -1,5 +1,5 @@
import sys
-import cv
+import cv2.cv as cv
def findstereocorrespondence(image_left, image_right):
# image_left and image_right are the input 8-bit single-channel images
diff --git a/modules/python/test/goodfeatures.py b/modules/python/test/goodfeatures.py
index d68bd1f9f9..37f64ac4d3 100644
--- a/modules/python/test/goodfeatures.py
+++ b/modules/python/test/goodfeatures.py
@@ -1,4 +1,4 @@
-import cv
+import cv2.cv as cv
import unittest
class TestGoodFeaturesToTrack(unittest.TestCase):
diff --git a/modules/python/test/leak1.py b/modules/python/test/leak1.py
index c451c0e06c..49326dab50 100644
--- a/modules/python/test/leak1.py
+++ b/modules/python/test/leak1.py
@@ -1,4 +1,4 @@
-import cv
+import cv2.cv as cv
import numpy as np
cv.NamedWindow('Leak')
while 1:
diff --git a/modules/python/test/leak2.py b/modules/python/test/leak2.py
index a67352f197..ca511a40ec 100644
--- a/modules/python/test/leak2.py
+++ b/modules/python/test/leak2.py
@@ -1,4 +1,4 @@
-import cv
+import cv2.cv as cv
import numpy as np
import time
diff --git a/modules/python/test/leak3.py b/modules/python/test/leak3.py
index c12364e8e6..901d7be20f 100644
--- a/modules/python/test/leak3.py
+++ b/modules/python/test/leak3.py
@@ -1,4 +1,4 @@
-import cv
+import cv2.cv as cv
import math
import time
diff --git a/modules/python/test/leak4.py b/modules/python/test/leak4.py
index 3268200522..8d8ba8883a 100644
--- a/modules/python/test/leak4.py
+++ b/modules/python/test/leak4.py
@@ -1,4 +1,4 @@
-import cv
+import cv2.cv as cv
import math
import time
diff --git a/modules/python/test/precornerdetect.py b/modules/python/test/precornerdetect.py
index 4f4da06b17..2d739c3b73 100644
--- a/modules/python/test/precornerdetect.py
+++ b/modules/python/test/precornerdetect.py
@@ -1,4 +1,4 @@
-import cv
+import cv2.cv as cv
def precornerdetect(image):
# assume that the image is floating-point
diff --git a/modules/python/test/test.py b/modules/python/test/test.py
index 9271aa33a4..9b5ddafff7 100644
--- a/modules/python/test/test.py
+++ b/modules/python/test/test.py
@@ -12,7 +12,7 @@ import getopt
import operator
import functools
-import cv
+import cv2.cv as cv
class OpenCVTests(unittest.TestCase):
diff --git a/modules/python/test/ticket_6.py b/modules/python/test/ticket_6.py
index 5f3d015d88..71534317c9 100644
--- a/modules/python/test/ticket_6.py
+++ b/modules/python/test/ticket_6.py
@@ -1,5 +1,5 @@
import urllib
-import cv
+import cv2.cv as cv
import Image
import unittest
diff --git a/modules/python/test/tickets.py b/modules/python/test/tickets.py
index a6f33396c8..aa6818059a 100644
--- a/modules/python/test/tickets.py
+++ b/modules/python/test/tickets.py
@@ -6,7 +6,7 @@ import sys
import array
import os
-import cv
+import cv2.cv as cv
def find_sample(s):
for d in ["../samples/c/", "../doc/pics/"]:
diff --git a/modules/video/test/test_main.cpp b/modules/video/test/test_main.cpp
index 6b24993447..410814c1d2 100644
--- a/modules/video/test/test_main.cpp
+++ b/modules/video/test/test_main.cpp
@@ -1,3 +1,63 @@
#include "test_precomp.hpp"
-CV_TEST_MAIN("cv")
+//CV_TEST_MAIN("cv")
+
+#if 1
+using namespace cv;
+
+int main(int, char**)
+{
+ Mat prevImg = imread("/Users/vp/work/ocv/opencv_extra/testdata/cv/optflow/rock_1.bmp", 0);
+ Mat nextImg = imread("/Users/vp/work/ocv/opencv_extra/testdata/cv/optflow/rock_2.bmp", 0);
+ FileStorage fs("/Users/vp/work/ocv/opencv_extra/testdata/cv/optflow/lk_prev.dat", FileStorage::READ);
+ vector u, v;
+ Mat _u;
+ fs["points"] >> _u;
+ _u.reshape(2, 0).copyTo(u);
+ vector status;
+ vector err;
+ double tmin = 0;
+
+ for( int k = 0; k < 3; k++ )
+ {
+ double t = (double)getTickCount();
+#if 1
+ calcOpticalFlowPyrLK(prevImg, nextImg, u, v, status, err, Size(11,11),
+ 5, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0.01), 100);
+#else
+ {
+ CvMat _prevImg = prevImg;
+ CvMat _nextImg = nextImg;
+ v.resize(u.size());
+ status.resize(u.size());
+ err.resize(u.size());
+ cvCalcOpticalFlowPyrLK(&_prevImg, &_nextImg, 0, 0, (CvPoint2D32f*)&u[0], (CvPoint2D32f*)&v[0], (int)u.size(),
+ cvSize(21, 21), 4, (char*)&status[0],
+ &err[0], cvTermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.01), 0);
+ }
+#endif
+ t = (double)getTickCount() - t;
+ tmin = k == 0 ? t : std::min(tmin, t);
+ }
+ printf("time = %gms\n", tmin*1000./getTickFrequency());
+
+ Mat color;
+ cvtColor(prevImg, color, CV_GRAY2BGR);
+ for( size_t i = 0; i < u.size(); i++ )
+ {
+ Point2f ui = u[i], vi = v[i];
+ if( cvIsNaN(v[i].x) || cvIsNaN(v[i].y) || !status[i] )
+ {
+ const float r = 2.f;
+ line(color, Point2f(u[i].x-r,u[i].y-r), Point2f(u[i].x+r,u[i].y+r), Scalar(0, 0, 255), 1);
+ line(color, Point2f(u[i].x-r,u[i].y+r), Point2f(u[i].x+r,u[i].y-r), Scalar(0, 0, 255), 1);
+ continue;
+ }
+ line(color, ui, vi, Scalar(0, 255, 0), 1);
+ }
+ imshow("flow", color);
+ waitKey();
+ return 0;
+}
+#endif
+
diff --git a/samples/python/camera.py b/samples/python/camera.py
index 7459534a0b..9a57ac5215 100644
--- a/samples/python/camera.py
+++ b/samples/python/camera.py
@@ -1,4 +1,4 @@
-import cv
+import cv2.cv as cv
import time
cv.NamedWindow("camera", 1)
diff --git a/samples/python/camshift.py b/samples/python/camshift.py
index a1e848b43c..2f28977267 100644
--- a/samples/python/camshift.py
+++ b/samples/python/camshift.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
-import cv
+import cv2.cv as cv
def is_rect_nonzero(r):
(_,_,w,h) = r
diff --git a/samples/python/chessboard.py b/samples/python/chessboard.py
index b05c70b1b0..31372b0dbd 100755
--- a/samples/python/chessboard.py
+++ b/samples/python/chessboard.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-import cv
+import cv2.cv as cv
import sys
import urllib2
diff --git a/samples/python/contours.py b/samples/python/contours.py
index 9a69c54afc..4388b8eced 100755
--- a/samples/python/contours.py
+++ b/samples/python/contours.py
@@ -3,7 +3,7 @@
print "OpenCV Python version of contours"
# import the necessary things for OpenCV
-import cv
+import cv2.cv as cv
# some default constants
_SIZE = 500
diff --git a/samples/python/convexhull.py b/samples/python/convexhull.py
index e9affd7640..8795d0bd92 100755
--- a/samples/python/convexhull.py
+++ b/samples/python/convexhull.py
@@ -3,7 +3,7 @@
print "OpenCV Python version of convexhull"
# import the necessary things for OpenCV
-import cv
+import cv2.cv as cv
# to generate random values
import random
diff --git a/samples/python/cv20squares.py b/samples/python/cv20squares.py
index a7c560fa38..7bb0c7a9ee 100644
--- a/samples/python/cv20squares.py
+++ b/samples/python/cv20squares.py
@@ -5,7 +5,7 @@ Find Squares in image by finding countours and filtering
#otherwise ok
import math
-import cv
+import cv2.cv as cv
def angle(pt1, pt2, pt0):
"calculate angle contained by 3 points(x, y)"
diff --git a/samples/python/cvutils.py b/samples/python/cvutils.py
index 21e9a7d0ce..47785d1e72 100644
--- a/samples/python/cvutils.py
+++ b/samples/python/cvutils.py
@@ -1,4 +1,4 @@
-import cv
+import cv2.cv as cv
import urllib2
from sys import argv
diff --git a/samples/python/delaunay.py b/samples/python/delaunay.py
index 10af4fb393..d9a4700d90 100755
--- a/samples/python/delaunay.py
+++ b/samples/python/delaunay.py
@@ -6,7 +6,7 @@ delaunay triangulation and voronoi tesselation
Original Author (C version): ?
Converted to Python by: Roman Stanchak
"""
-import cv
+import cv2.cv as cv
import random
def draw_subdiv_point( img, fp, color ):
diff --git a/samples/python/demhist.py b/samples/python/demhist.py
index d1f720b054..a6b1019258 100755
--- a/samples/python/demhist.py
+++ b/samples/python/demhist.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-import cv
+import cv2.cv as cv
import sys
import urllib2
diff --git a/samples/python/dft.py b/samples/python/dft.py
index 147dc665af..f4408ca819 100755
--- a/samples/python/dft.py
+++ b/samples/python/dft.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-import cv
+import cv2.cv as cv
import sys
import urllib2
diff --git a/samples/python/distrans.py b/samples/python/distrans.py
index e5414e5a0f..aee9357169 100755
--- a/samples/python/distrans.py
+++ b/samples/python/distrans.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
import sys
-import cv
+import cv2.cv as cv
import urllib2
wndname = "Distance transform"
diff --git a/samples/python/dmtx.py b/samples/python/dmtx.py
index f749681aac..847f8507ec 100644
--- a/samples/python/dmtx.py
+++ b/samples/python/dmtx.py
@@ -1,4 +1,4 @@
-import cv
+import cv2.cv as cv
import time
from pydmtx import DataMatrix
import numpy
diff --git a/samples/python/drawing.py b/samples/python/drawing.py
index 6b007dad12..584e599605 100755
--- a/samples/python/drawing.py
+++ b/samples/python/drawing.py
@@ -4,7 +4,7 @@ import colorsys
print "OpenCV Python version of drawing"
-import cv
+import cv2.cv as cv
def random_color(random):
"""
diff --git a/samples/python/edge.py b/samples/python/edge.py
index 33bfdb6846..5730ecd6cb 100755
--- a/samples/python/edge.py
+++ b/samples/python/edge.py
@@ -4,7 +4,7 @@ print "OpenCV Python version of edge"
import sys
import urllib2
-import cv
+import cv2.cv as cv
# some definitions
win_name = "Edge"
diff --git a/samples/python/facedetect.py b/samples/python/facedetect.py
index 0c0c9bc24d..15f8302aa1 100755
--- a/samples/python/facedetect.py
+++ b/samples/python/facedetect.py
@@ -7,7 +7,7 @@ Original C implementation by: ?
Python implementation by: Roman Stanchak, James Bowman
"""
import sys
-import cv
+import cv2.cv as cv
from optparse import OptionParser
# Parameters for haar detection
diff --git a/samples/python/ffilldemo.py b/samples/python/ffilldemo.py
index 4eb4c44b06..1a2be0ebb2 100755
--- a/samples/python/ffilldemo.py
+++ b/samples/python/ffilldemo.py
@@ -2,7 +2,7 @@
import sys
import random
import urllib2
-import cv
+import cv2.cv as cv
im=None;
mask=None;
diff --git a/samples/python/fitellipse.py b/samples/python/fitellipse.py
index 398437d340..725838a4db 100755
--- a/samples/python/fitellipse.py
+++ b/samples/python/fitellipse.py
@@ -13,7 +13,7 @@ Python implementation by: Roman Stanchak, James Bowman
import sys
import urllib2
import random
-import cv
+import cv2.cv as cv
def contour_iterator(contour):
while contour:
diff --git a/samples/python/houghlines.py b/samples/python/houghlines.py
index 8bffdcc627..e86a70dd18 100755
--- a/samples/python/houghlines.py
+++ b/samples/python/houghlines.py
@@ -3,7 +3,7 @@
import sys
from math import sin, cos, sqrt, pi
-import cv
+import cv2.cv as cv
import urllib2
# toggle between CV_HOUGH_STANDARD and CV_HOUGH_PROBILISTIC
diff --git a/samples/python/inpaint.py b/samples/python/inpaint.py
index 1e06b93266..06444d995a 100755
--- a/samples/python/inpaint.py
+++ b/samples/python/inpaint.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
import urllib2
import sys
-import cv
+import cv2.cv as cv
class Sketcher:
def __init__(self, windowname, dests):
diff --git a/samples/python/kalman.py b/samples/python/kalman.py
index af64e8e012..36cd1ff91f 100755
--- a/samples/python/kalman.py
+++ b/samples/python/kalman.py
@@ -12,7 +12,7 @@
Pressing ESC will stop the program.
"""
import urllib2
-import cv
+import cv2.cv as cv
from math import cos, sin, sqrt
import sys
diff --git a/samples/python/kmeans.py b/samples/python/kmeans.py
index 36428bb171..ca5df6ebaf 100755
--- a/samples/python/kmeans.py
+++ b/samples/python/kmeans.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
import urllib2
-import cv
+import cv2.cv as cv
from random import randint
MAX_CLUSTERS = 5
diff --git a/samples/python/laplace.py b/samples/python/laplace.py
index c7d6f46c45..c1a3cfae70 100755
--- a/samples/python/laplace.py
+++ b/samples/python/laplace.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
import urllib2
-import cv
+import cv2.cv as cv
import sys
if __name__ == "__main__":
diff --git a/samples/python/lkdemo.py b/samples/python/lkdemo.py
index 2aa5843968..2071023cbe 100755
--- a/samples/python/lkdemo.py
+++ b/samples/python/lkdemo.py
@@ -5,7 +5,7 @@ print "OpenCV Python version of lkdemo"
import sys
# import the necessary things for OpenCV
-import cv
+import cv2.cv as cv
#############################################################################
# some "constants"
diff --git a/samples/python/logpolar.py b/samples/python/logpolar.py
index 6afebafed1..adbf7de081 100755
--- a/samples/python/logpolar.py
+++ b/samples/python/logpolar.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
import sys
import urllib2
-import cv
+import cv2.cv as cv
src=None
dst=None
diff --git a/samples/python/minarea.py b/samples/python/minarea.py
index 8310fbc84a..d38a7ceaf5 100755
--- a/samples/python/minarea.py
+++ b/samples/python/minarea.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
import urllib2
-import cv
+import cv2.cv as cv
from random import randint
def roundxy(pt):
diff --git a/samples/python/minidemo.py b/samples/python/minidemo.py
index dcc2922fe7..8c5924caa8 100755
--- a/samples/python/minidemo.py
+++ b/samples/python/minidemo.py
@@ -1,6 +1,6 @@
#! /usr/bin/env python
-import cv
+import cv2.cv as cv
cap = cv.CreateFileCapture("../c/tree.avi")
img = cv.QueryFrame(cap)
diff --git a/samples/python/morphology.py b/samples/python/morphology.py
index 2014675d19..efc525a69e 100755
--- a/samples/python/morphology.py
+++ b/samples/python/morphology.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
import sys
import urllib2
-import cv
+import cv2.cv as cv
src = 0
image = 0
diff --git a/samples/python/motempl.py b/samples/python/motempl.py
index 306c638fed..2b2426fb59 100755
--- a/samples/python/motempl.py
+++ b/samples/python/motempl.py
@@ -3,7 +3,7 @@ import urllib2
import sys
import time
from math import cos, sin
-import cv
+import cv2.cv as cv
CLOCKS_PER_SEC = 1.0
MHI_DURATION = 1
diff --git a/samples/python/numpy_array.py b/samples/python/numpy_array.py
index e0322f361f..deb9281d61 100644
--- a/samples/python/numpy_array.py
+++ b/samples/python/numpy_array.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
import urllib2
import sys
-import cv
+import cv2.cv as cv
import numpy
# SRGB-linear conversions using NumPy - see http://en.wikipedia.org/wiki/SRGB
diff --git a/samples/python/numpy_warhol.py b/samples/python/numpy_warhol.py
index 7309997971..97f32a9ae7 100644
--- a/samples/python/numpy_warhol.py
+++ b/samples/python/numpy_warhol.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
import urllib2
import sys
-import cv
+import cv2.cv as cv
import numpy
if __name__ == "__main__":
diff --git a/samples/python/pyramid_segmentation.py b/samples/python/pyramid_segmentation.py
index fa9dbd01cb..80293e2bd8 100755
--- a/samples/python/pyramid_segmentation.py
+++ b/samples/python/pyramid_segmentation.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-import cv
+import cv2.cv as cv
class PyrSegmentation:
def __init__(self, img0):
diff --git a/samples/python/squares.py b/samples/python/squares.py
index 6fe734deb8..ed8b8aeebe 100755
--- a/samples/python/squares.py
+++ b/samples/python/squares.py
@@ -7,7 +7,7 @@
import urllib2
from math import sqrt
-import cv
+import cv2.cv as cv
thresh = 50
img = None
diff --git a/samples/python/watershed.py b/samples/python/watershed.py
index 41075280e0..d2983e7125 100755
--- a/samples/python/watershed.py
+++ b/samples/python/watershed.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
import urllib2
import sys
-import cv
+import cv2.cv as cv
class Sketcher:
def __init__(self, windowname, dests):