Content-Length: 337944 | pFad | http://github.com/opencv/opencv/commit/2a6286dd91ef26247cb8b05e0c103b6831e4cd8a

91 feat: add matrix type stubs generation · opencv/opencv@2a6286d · GitHub
Skip to content

Commit 2a6286d

Browse files
committed
feat: add matrix type stubs generation
Adds missing typing stubs: - Matrix depths: `CV_8U`, `CV_8S` and etc. - Matrix type constants: `CV_8UC1`, `CV_32FC3` and etc. - Matrix type factory functions: `CV_*(channels) -> int` and `CV_MAKETYPE`
1 parent fdc0c12 commit 2a6286d

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

modules/python/src2/typing_stubs_generation/api_refinement.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
from typing import Sequence, Callable
66

7-
from .nodes import NamespaceNode, FunctionNode, OptionalTypeNode, ClassProperty, PrimitiveTypeNode
7+
from .nodes import (NamespaceNode, FunctionNode, OptionalTypeNode,
8+
ClassProperty, PrimitiveTypeNode)
89
from .ast_utils import find_function_node, SymbolName
910

1011

1112
def apply_manual_api_refinement(root: NamespaceNode) -> None:
13+
export_matrix_type_constants(root)
1214
# Export OpenCV exception class
1315
builtin_exception = root.add_class("Exception")
1416
builtin_exception.is_exported = False
@@ -17,6 +19,33 @@ def apply_manual_api_refinement(root: NamespaceNode) -> None:
1719
refine_symbol(root, symbol_name)
1820

1921

22+
def export_matrix_type_constants(root: NamespaceNode) -> None:
23+
MAX_PREDEFINED_CHANNELS = 4
24+
25+
depth_names = ("CV_8U", "CV_8S", "CV_16U", "CV_16S", "CV_32S",
26+
"CV_32F", "CV_64F", "CV_16F")
27+
for depth_value, depth_name in enumerate(depth_names):
28+
# Export depth constants
29+
root.add_constant(depth_name, str(depth_value))
30+
# Export predefined types
31+
for c in range(MAX_PREDEFINED_CHANNELS):
32+
root.add_constant(f"{depth_name}C{c + 1}",
33+
f"{depth_value + 8 * c}")
34+
# Export type creation function
35+
root.add_function(
36+
f"{depth_name}C",
37+
(FunctionNode.Arg("channels", PrimitiveTypeNode.int_()), ),
38+
FunctionNode.RetType(PrimitiveTypeNode.int_())
39+
)
40+
# Export CV_MAKETYPE
41+
root.add_function(
42+
"CV_MAKETYPE",
43+
(FunctionNode.Arg("depth", PrimitiveTypeNode.int_()),
44+
FunctionNode.Arg("channels", PrimitiveTypeNode.int_())),
45+
FunctionNode.RetType(PrimitiveTypeNode.int_())
46+
)
47+
48+
2049
def make_optional_arg(arg_name: str) -> Callable[[NamespaceNode, SymbolName], None]:
2150
def _make_optional_arg(root_node: NamespaceNode,
2251
function_symbol_name: SymbolName) -> None:

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/opencv/opencv/commit/2a6286dd91ef26247cb8b05e0c103b6831e4cd8a

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy