From 32f92880342e3f651653336c2f3e7511e9cc9c9b Mon Sep 17 00:00:00 2001 From: Maidul Hasan Masum <79536779+mh-masum6875@users.noreply.github.com> Date: Sun, 25 Oct 2026 02:16:36 +0800 Subject: [PATCH 1/2] python: add documentation signatures for manually wrapped highgui functions --- modules/python/src2/gen2.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/python/src2/gen2.py b/modules/python/src2/gen2.py index 4649b0ebe8..3ef4cfde38 100755 --- a/modules/python/src2/gen2.py +++ b/modules/python/src2/gen2.py @@ -1505,6 +1505,16 @@ class PythonWrapperGenerator(object): for name, constinfo in constlist: self.gen_const_reg(constinfo) + # step 6: add documentation signatures for the functions wrapped by hand in cv2.cpp, + # because they are not parsed from the headers + manual_signatures = [ + ("cv::createTrackbar", "cv.createTrackbar", "trackbarName, windowName, value, count, onChange", "None"), + ("cv::createButton", "cv.createButton", "buttonName, onChange[, userData[, buttonType[, initialButtonState]]]", "None"), + ("cv::setMouseCallback", "cv.setMouseCallback", "window_name, on_mouse[, param]", "None"), + ] + for cname, py_name, arg, ret in manual_signatures: + self.py_signatures.setdefault(cname, []).append(dict(name=py_name, arg=arg, ret=ret)) + # All symbols are collected and AST is reconstructed, generating # typing stubs... self.typing_stubs_generator.generate(output_path) From 77d9a8e69c588800a3a1b57c3f5e0a2838c39008 Mon Sep 17 00:00:00 2001 From: Maidul Hasan Masum Date: Wed, 28 Oct 2026 14:13:46 +0000 Subject: [PATCH 2/2] python: align setMouseCallback argument names with its keywords Same change as the 5.x port, to keep the two branches in sync. The wrapper parses window_name, on_mouse and param, but the cv2.cpp help text and the typing stub in api_refinement.py both say windowName and onMouse, so the stub promises keywords the runtime rejects: >>> cv2.setMouseCallback(windowName="w", onMouse=cb) TypeError: function missing required argument 'window_name' (pos 1) createTrackbar is left alone: it is registered METH_VARARGS, so its arguments cannot be passed by keyword at all. --- modules/python/src2/cv2.cpp | 2 +- .../python/src2/typing_stubs_generation/api_refinement.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index 2a19611344..8ef4bc4a2c 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -115,7 +115,7 @@ static PyMethodDef special_methods[] = { #ifdef HAVE_OPENCV_HIGHGUI {"createTrackbar", (PyCFunction)pycvCreateTrackbar, METH_VARARGS, "createTrackbar(trackbarName, windowName, value, count, onChange) -> None"}, {"createButton", CV_PY_FN_WITH_KW(pycvCreateButton), "createButton(buttonName, onChange [, userData, buttonType, initialButtonState]) -> None"}, - {"setMouseCallback", CV_PY_FN_WITH_KW(pycvSetMouseCallback), "setMouseCallback(windowName, onMouse [, param]) -> None"}, + {"setMouseCallback", CV_PY_FN_WITH_KW(pycvSetMouseCallback), "setMouseCallback(window_name, on_mouse [, param]) -> None"}, #endif #ifdef HAVE_OPENCV_DNN {"dnn_registerLayer", CV_PY_FN_WITH_KW(pyopencv_cv_dnn_registerLayer), "registerLayer(type, class) -> None"}, diff --git a/modules/python/src2/typing_stubs_generation/api_refinement.py b/modules/python/src2/typing_stubs_generation/api_refinement.py index f1f31fbae5..5ba7ea0205 100644 --- a/modules/python/src2/typing_stubs_generation/api_refinement.py +++ b/modules/python/src2/typing_stubs_generation/api_refinement.py @@ -254,17 +254,17 @@ def refine_highgui_module(root: NamespaceNode) -> None: ) """ def setMouseCallback( - windowName: str, - onMouse: Callback[[int, int, int, int, Any | None], None], + window_name: str, + on_mouse: Callback[[int, int, int, int, Any | None], None], param: Any | None = ... ) -> None: ... """ root.add_function( "setMouseCallback", [ - FunctionNode.Arg("windowName", PrimitiveTypeNode.str_()), + FunctionNode.Arg("window_name", PrimitiveTypeNode.str_()), FunctionNode.Arg( - "onMouse", + "on_mouse", CallableTypeNode("MouseCallback", [ PrimitiveTypeNode.int_(), PrimitiveTypeNode.int_(),