Repository: opencv
Issue: Possibly a bug fix of OpenCV 4.1.0 with Python3 support?
Labels: priority: low,category: build/install,incomplete

I **ALWAYS** met the following **ERROR** messages while compiling OpenCV 4.1.0 with Python3:

```bash
In file included from ....../opencv/modules/python/src2/cv2.cpp:1722:0:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h: In function ‘PyObject* pyopencv_cv_dnn_dnn_Net_getFLOPS(PyObject*, PyObject*, PyObject*)’:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39763:5: error: ‘vector_MatShape’ was not declared in this scope
     vector_MatShape netInputShapes;
     ^~~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39763:5: note: suggested alternative: ‘vector_Match’
     vector_MatShape netInputShapes;
     ^~~~~~~~~~~~~~~
     vector_Match
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39768:43: error: ‘netInputShapes’ was not declared in this scope
         pyopencv_to(pyobj_netInputShapes, netInputShapes, ArgInfo("netInputShapes", 0)) )
                                           ^~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39768:43: note: suggested alternative: ‘pyobj_netInputShapes’
         pyopencv_to(pyobj_netInputShapes, netInputShapes, ArgInfo("netInputShapes", 0)) )
                                           ^~~~~~~~~~~~~~
                                           pyobj_netInputShapes
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39794:5: error: ‘vector_MatShape’ was not declared in this scope
     vector_MatShape netInputShapes;
     ^~~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39794:5: note: suggested alternative: ‘vector_Match’
     vector_MatShape netInputShapes;
     ^~~~~~~~~~~~~~~
     vector_Match
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39799:43: error: ‘netInputShapes’ was not declared in this scope
         pyopencv_to(pyobj_netInputShapes, netInputShapes, ArgInfo("netInputShapes", 0)) )
                                           ^~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39799:43: note: suggested alternative: ‘pyobj_netInputShapes’
         pyopencv_to(pyobj_netInputShapes, netInputShapes, ArgInfo("netInputShapes", 0)) )
                                           ^~~~~~~~~~~~~~
                                           pyobj_netInputShapes
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h: In function ‘PyObject* pyopencv_cv_dnn_dnn_Net_getLayer(PyObject*, PyObject*, PyObject*)’:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39835:5: error: ‘LayerId’ was not declared in this scope
     LayerId layerId;
     ^~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39840:36: error: ‘layerId’ was not declared in this scope
         pyopencv_to(pyobj_layerId, layerId, ArgInfo("layerId", 0)) )
                                    ^~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h: In function ‘PyObject* pyopencv_cv_dnn_dnn_Net_getLayersShapes(PyObject*, PyObject*, PyObject*)’:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39948:5: error: ‘vector_MatShape’ was not declared in this scope
     vector_MatShape netInputShapes;
     ^~~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39948:5: note: suggested alternative: ‘vector_Match’
     vector_MatShape netInputShapes;
     ^~~~~~~~~~~~~~~
     vector_Match
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39950:5: error: ‘vector_vector_MatShape’ was not declared in this scope
     vector_vector_MatShape inLayersShapes;
     ^~~~~~~~~~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39950:5: note: suggested alternative: ‘vector_vector_DMatch’
     vector_vector_MatShape inLayersShapes;
     ^~~~~~~~~~~~~~~~~~~~~~
     vector_vector_DMatch
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39951:28: error: expected ‘;’ before ‘outLayersShapes’
     vector_vector_MatShape outLayersShapes;
                            ^~~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39955:43: error: ‘netInputShapes’ was not declared in this scope
         pyopencv_to(pyobj_netInputShapes, netInputShapes, ArgInfo("netInputShapes", 0)) )
                                           ^~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39955:43: note: suggested alternative: ‘pyobj_netInputShapes’
         pyopencv_to(pyobj_netInputShapes, netInputShapes, ArgInfo("netInputShapes", 0)) )
                                           ^~~~~~~~~~~~~~
                                           pyobj_netInputShapes
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39957:69: error: ‘inLayersShapes’ was not declared in this scope
         ERRWRAP2(_self_->getLayersShapes(netInputShapes, layersIds, inLayersShapes, outLayersShapes));
                                                                     ^
....../opencv/modules/python/src2/cv2.cpp:175:5: note: in definition of macro ‘ERRWRAP2’
     expr; \
     ^~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39957:85: error: ‘outLayersShapes’ was not declared in this scope
         ERRWRAP2(_self_->getLayersShapes(netInputShapes, layersIds, inLayersShapes, outLayersShapes));
                                                                                     ^
....../opencv/modules/python/src2/cv2.cpp:175:5: note: in definition of macro ‘ERRWRAP2’
     expr; \
     ^~~~
In file included from ....../opencv/modules/python/src2/cv2.cpp:1722:0:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39958:79: error: ‘inLayersShapes’ was not declared in this scope
         return Py_BuildValue("(NNN)", pyopencv_from(layersIds), pyopencv_from(inLayersShapes), pyopencv_from(outLayersShapes));
                                                                               ^~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39958:110: error: ‘outLayersShapes’ was not declared in this scope
         return Py_BuildValue("(NNN)", pyopencv_from(layersIds), pyopencv_from(inLayersShapes), pyopencv_from(outLayersShapes));
                                                                                                              ^~~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39967:5: error: ‘vector_vector_MatShape’ was not declared in this scope
     vector_vector_MatShape inLayersShapes;
     ^~~~~~~~~~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39967:5: note: suggested alternative: ‘vector_vector_DMatch’
     vector_vector_MatShape inLayersShapes;
     ^~~~~~~~~~~~~~~~~~~~~~
     vector_vector_DMatch
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39968:28: error: expected ‘;’ before ‘outLayersShapes’
     vector_vector_MatShape outLayersShapes;
                            ^~~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39974:68: error: ‘inLayersShapes’ was not declared in this scope
         ERRWRAP2(_self_->getLayersShapes(netInputShape, layersIds, inLayersShapes, outLayersShapes));
                                                                    ^
....../opencv/modules/python/src2/cv2.cpp:175:5: note: in definition of macro ‘ERRWRAP2’
     expr; \
     ^~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39974:84: error: ‘outLayersShapes’ was not declared in this scope
         ERRWRAP2(_self_->getLayersShapes(netInputShape, layersIds, inLayersShapes, outLayersShapes));
                                                                                    ^
....../opencv/modules/python/src2/cv2.cpp:175:5: note: in definition of macro ‘ERRWRAP2’
     expr; \
     ^~~~
In file included from ....../opencv/modules/python/src2/cv2.cpp:1722:0:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39975:79: error: ‘inLayersShapes’ was not declared in this scope
         return Py_BuildValue("(NNN)", pyopencv_from(layersIds), pyopencv_from(inLayersShapes), pyopencv_from(outLayersShapes));
                                                                               ^~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39975:110: error: ‘outLayersShapes’ was not declared in this scope
         return Py_BuildValue("(NNN)", pyopencv_from(layersIds), pyopencv_from(inLayersShapes), pyopencv_from(outLayersShapes));
                                                                                                              ^~~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h: In function ‘PyObject* pyopencv_cv_dnn_dnn_Net_getMemoryConsumption(PyObject*, PyObject*, PyObject*)’:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40010:5: error: ‘vector_MatShape’ was not declared in this scope
     vector_MatShape netInputShapes;
     ^~~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40010:5: note: suggested alternative: ‘vector_Match’
     vector_MatShape netInputShapes;
     ^~~~~~~~~~~~~~~
     vector_Match
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40016:43: error: ‘netInputShapes’ was not declared in this scope
         pyopencv_to(pyobj_netInputShapes, netInputShapes, ArgInfo("netInputShapes", 0)) )
                                           ^~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40016:43: note: suggested alternative: ‘pyobj_netInputShapes’
         pyopencv_to(pyobj_netInputShapes, netInputShapes, ArgInfo("netInputShapes", 0)) )
                                           ^~~~~~~~~~~~~~
                                           pyobj_netInputShapes
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h: In function ‘PyObject* pyopencv_cv_dnn_dnn_Net_getParam(PyObject*, PyObject*, PyObject*)’:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40053:5: error: ‘LayerId’ was not declared in this scope
     LayerId layer;
     ^~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40059:34: error: ‘layer’ was not declared in this scope
         pyopencv_to(pyobj_layer, layer, ArgInfo("layer", 0)) )
                                  ^~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h: In function ‘PyObject* pyopencv_cv_dnn_dnn_Net_setParam(PyObject*, PyObject*, PyObject*)’:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40261:5: error: ‘LayerId’ was not declared in this scope
     LayerId layer;
     ^~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40268:34: error: ‘layer’ was not declared in this scope
         pyopencv_to(pyobj_layer, layer, ArgInfo("layer", 0)) &&
                                  ^~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40279:5: error: ‘LayerId’ was not declared in this scope
     LayerId layer;
     ^~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40286:34: error: ‘layer’ was not declared in this scope
         pyopencv_to(pyobj_layer, layer, ArgInfo("layer", 0)) &&
                                  ^~~~~
In file included from ....../opencv/modules/python/src2/cv2.cpp:1722:0:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h: In function ‘PyObject* pyopencv_cv_dnn_dnn_AsyncMat_wait_for(PyObject*, PyObject*, PyObject*)’:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40447:5: error: ‘chrono_milliseconds’ was not declared in this scope
     chrono_milliseconds timeout;
     ^~~~~~~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40447:5: note: suggested alternative: ‘_PyTime_AsMilliseconds’
     chrono_milliseconds timeout;
     ^~~~~~~~~~~~~~~~~~~
     _PyTime_AsMilliseconds
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40448:5: error: ‘AsyncMatStatus’ was not declared in this scope
     AsyncMatStatus retval;
     ^~~~~~~~~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40452:36: error: ‘timeout’ was not declared in this scope
         pyopencv_to(pyobj_timeout, timeout, ArgInfo("timeout", 0)) )
                                    ^~~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40452:36: note: suggested alternative: ‘timer_t’
         pyopencv_to(pyobj_timeout, timeout, ArgInfo("timeout", 0)) )
                                    ^~~~~~~
                                    timer_t
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40454:18: error: ‘retval’ was not declared in this scope
         ERRWRAP2(retval = _self_->wait_for(timeout));
                  ^
....../opencv/modules/python/src2/cv2.cpp:175:5: note: in definition of macro ‘ERRWRAP2’
     expr; \
     ^~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40454:18: note: suggested alternative: ‘read’
         ERRWRAP2(retval = _self_->wait_for(timeout));
                  ^
....../opencv/modules/python/src2/cv2.cpp:175:5: note: in definition of macro ‘ERRWRAP2’
     expr; \
     ^~~~
In file included from ....../opencv/modules/python/src2/cv2.cpp:1722:0:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40455:30: error: ‘retval’ was not declared in this scope
         return pyopencv_from(retval);
                              ^~~~~~
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40455:30: note: suggested alternative: ‘read’
         return pyopencv_from(retval);
                              ^~~~~~
                              read
....../opencv/modules/python/src2/cv2.cpp: In instantiation of ‘bool pyopencv_to(PyObject*, T&, const char*) [with T = std::vector<cv::Mat>; PyObject = _object]’:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39294:44:   required from here
....../opencv/modules/python/src2/cv2.cpp:24:105: error: ‘to’ is not a member of ‘PyOpenCV_Converter<std::vector<cv::Mat>, void>’
 bool pyopencv_to(PyObject* obj, T& p, const char* name = "<unknown>") { return PyOpenCV_Converter<T>::to(obj, p, name); }
                                                                                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
....../opencv/modules/python/src2/cv2.cpp: In instantiation of ‘PyObject* pyopencv_from(const T&) [with T = std::future<cv::Mat>; PyObject = _object]’:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39746:36:   required from here
....../opencv/modules/python/src2/cv2.cpp:27:75: error: ‘from’ is not a member of ‘PyOpenCV_Converter<std::future<cv::Mat>, void>’
 PyObject* pyopencv_from(const T& src) { return PyOpenCV_Converter<T>::from(src); }
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
modules/python3/CMakeFiles/opencv_python3.dir/build.make:65: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o' failed
make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
make[2]: Leaving directory '....../opencv/build'
CMakeFiles/Makefile2:10518: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/all' failed
make[1]: *** [modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
make[1]: Leaving directory '....../opencv/build'
Makefile:165: recipe for target 'all' failed
make: *** [all] Error 2
```


Therefore, I directly copied the following several lines from file 
**opencv/modules/dnn/misc/python/pyopencv_dnn.hpp**

```bash
typedef dnn::DictValue LayerId;
typedef std::vector<dnn::MatShape> vector_MatShape;
typedef std::vector<std::vector<dnn::MatShape> > vector_vector_MatShape;
#ifdef CV_CXX11
typedef std::chrono::milliseconds chrono_milliseconds;
typedef std::future_status AsyncMatStatus;
#else
typedef size_t chrono_milliseconds;
typedef size_t AsyncMatStatus;
#endif
```

and put on top of file
**pyopencv_generated_types.h**

Now, I still have the following **ERROR** messages:

```bash
....../opencv/modules/python/src2/cv2.cpp: In instantiation of ‘bool pyopencv_to(PyObject*, T&, const char*) [w
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39304:44:   required from here
....../opencv/modules/python/src2/cv2.cpp:24:105: error: ‘to’ is not a member of ‘PyOpenCV_Converter<std::vecto
 bool pyopencv_to(PyObject* obj, T& p, const char* name = "<unknown>") { return PyOpenCV_Converter<T>::to(obj, p, name); }
                                                                                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
....../opencv/modules/python/src2/cv2.cpp: In instantiation of ‘PyObject* pyopencv_from(const T&) [with T = std
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39756:36:   required from here
....../opencv/modules/python/src2/cv2.cpp:27:75: error: ‘from’ is not a member of ‘PyOpenCV_Converter<std::futu
 PyObject* pyopencv_from(const T& src) { return PyOpenCV_Converter<T>::from(src); }
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
....../opencv/modules/python/src2/cv2.cpp: In instantiation of ‘bool pyopencv_to(PyObject*, T&, const char*) [w = _object]’:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:39850:66:   required from here
....../opencv/modules/python/src2/cv2.cpp:24:105: error: ‘to’ is not a member of ‘PyOpenCV_Converter<cv::dnn::d
 bool pyopencv_to(PyObject* obj, T& p, const char* name = "<unknown>") { return PyOpenCV_Converter<T>::to(obj, p, name); }
                                                                                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
....../opencv/modules/python/src2/cv2.cpp: In instantiation of ‘bool pyopencv_to(PyObject*, T&, const char*) [w, 1000> >; PyObject = _object]’:
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40462:66:   required from here
....../opencv/modules/python/src2/cv2.cpp:24:105: error: ‘to’ is not a member of ‘PyOpenCV_Converter<std::chron
....../opencv/modules/python/src2/cv2.cpp: In instantiation of ‘PyObject* pyopencv_from(const T&) [with T = std
....../opencv/build/modules/python_bindings_generator/pyopencv_generated_types.h:40465:36:   required from here
....../opencv/modules/python/src2/cv2.cpp:27:75: error: ‘from’ is not a member of ‘PyOpenCV_Converter<std::futu
 PyObject* pyopencv_from(const T& src) { return PyOpenCV_Converter<T>::from(src); }
                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
modules/python3/CMakeFiles/opencv_python3.dir/build.make:65: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o' failed
make[2]: *** [modules/python3/CMakeFiles/opencv_python3.dir/__/src2/cv2.cpp.o] Error 1
make[2]: Leaving directory '....../opencv/build'
CMakeFiles/Makefile2:10518: recipe for target 'modules/python3/CMakeFiles/opencv_python3.dir/all' failed
make[1]: *** [modules/python3/CMakeFiles/opencv_python3.dir/all] Error 2
make[1]: Leaving directory '....../opencv/build'
Makefile:165: recipe for target 'all' failed
make: *** [all] Error 2
```

Any suggestions?