8000 opencv-python stubs by Avasam · Pull Request #8879 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

opencv-python stubs #8879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
53cbde4
Bump PyInstaller-stubs to 5.5
Avasam Oct 10, 2022
7f6a836
Merge branch 'master' of https://github.com/python/typeshed
Avasam Oct 10, 2022
517bd33
Initial generated cv2 stubs
Avasam Oct 10, 2022
63d7170
Added microsoft/python-type-stubs/cv2
Avasam Oct 11, 2022
1a00677
Set signatures from existing docstrings
Avasam Oct 11, 2022
aef1b26
Added https://github.com/microsoft/python-type-stubs/pull/219
Avasam Oct 11, 2022
b9224e3
Added https://github.com/microsoft/python-type-stubs/pull/227
Avasam Oct 11, 2022
85f6091
Added https://github.com/microsoft/python-type-stubs/pull/232
Avasam Oct 11, 2022
9fdc94e
Empty docstrings
Avasam Oct 11, 2022
1e3488c
Use the more flexible _Mat (NDArray) for typing
Avasam Oct 11, 2022
b72ac55
Fix dts to dst
Avasam Oct 11, 2022
41dba77
Added missing packages + strict types in cv2.gapi
Avasam Oct 12, 2022
edfd948
Updated list to Sequence in method args
Avasam Oct 12, 2022
8b35a5a
stricter pyright
Avasam Oct 12, 2022
e2c4a41
Fix Flake8
Avasam Oct 12, 2022
7e8b5dd
complete some Incomplete
Avasam Oct 12, 2022
6e5ab28
Removed docstrings
Avasam Oct 12, 2022
9cf3c44
fix pyright test
Avasam Oct 12, 2022
6a03195
Fixed Mat variances
Avasam Oct 12, 2022
f75c2f9
fixed cv2.error and cv2.Error
Avasam Oct 12, 2022
7fb76ea
Flake8 and stubtest
Avasam Oct 12, 2022
c9431d2
don't return Any with # incomplete method
Avasam Oct 14, 2022
0a688b7
don't return Any with # incomplete method
Avasam Oct 14, 2022
900e731
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 14, 2022
37bb1d1
Class def updates
Avasam Oct 15, 2022
ebe36a1
Merge branch 'opencv2' of https://github.com/Avasam/typeshed into ope…
Avasam Oct 15, 2022
06f73ba
Additional comments
Avasam Oct 15, 2022
c66b19c
Move _RotatedRect
Avasam Oct 15, 2022
203de26
mypy type: ignore[misc] explanation comment
Avasam Oct 15, 2022
28dc455
Completed generated modules
Avasam Oct 19, 2022
ffcfcee
Merge branch 'master' of https://github.com/python/typeshed into opencv2
Avasam Oct 20, 2022
bb50269
Fix flake8 warnings
Avasam Oct 20, 2022
22f29a7
Merge branch 'python:main' into opencv2
Avasam Nov 12, 2022
6b35384
Merge branch 'main' of https://github.com/python/typeshed into opencv2
Avasam Dec 5, 2022
6919768
noqa: Y042" has no matching violations
Avasam Dec 5, 2022
6d21d55
Merge branch 'main' into opencv2
AlexWaygood Jan 11, 2023
3b4f9b3
Merge branch 'main' of https://github.com/python/typeshed into opencv2
Avasam Jun 5, 2023
bfd370d
Merge branch 'opencv2' of https://github.com/Avasam/typeshed into ope…
Avasam Jun 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Completed generated modules
  • Loading branch information
Avasam committed Oct 20, 2022
commit 28dc455c4a9dda7906c6ff3b1e7f9a62fd0cd4cb
4 changes: 2 additions & 2 deletions stubs/opencv-python/cv2/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ from cv2 import (
version as version,
)
from cv2.cv2 import *
from cv2.mat_wrapper import Mat as _WrappedMat, _NDArray
from cv2.mat_wrapper import Mat as _WrappedMat, _NDArray, _NDArrayF

__all__: list[str] = []

def bootstrap() -> None: ...

Mat: TypeAlias = _WrappedMat | _NDArray
# TODO: Make Mat generic with int or float
_MatF: TypeAlias = _WrappedMat | _NDArray # noqa: Y047
_MatF: TypeAlias = _WrappedMat | _NDArrayF # noqa: Y047
78 changes: 78 additions & 0 deletions stubs/opencv-python/cv2/cuda.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from typing import TypeVar, overload

from cv2 import Mat
from cv2.cv2 import _Boolean, _NumericScalar, _UMat, cuda_Event, cuda_GpuMat, cuda_GpuMat_Allocator, cuda_Stream

_TGpuMat = TypeVar("_TGpuMat", bound=cuda_GpuMat | _UMat)

DEVICE_INFO_COMPUTE_MODE_DEFAULT: int
DEVICE_INFO_COMPUTE_MODE_EXCLUSIVE: int
DEVICE_INFO_COMPUTE_MODE_EXCLUSIVE_PROCESS: int
DEVICE_INFO_COMPUTE_MODE_PROHIBITED: int
DYNAMIC_PARALLELISM: int
DeviceInfo_ComputeModeDefault: int
DeviceInfo_ComputeModeExclusive: int
DeviceInfo_ComputeModeExclusiveProcess: int
DeviceInfo_ComputeModeProhibited: int
EVENT_BLOCKING_SYNC: int
EVENT_DEFAULT: int
EVENT_DISABLE_TIMING: int
EVENT_INTERPROCESS: int
Event_BLOCKING_SYNC: int
Event_DEFAULT: int
Event_DISABLE_TIMING: int
Event_INTERPROCESS: int
FEATURE_SET_COMPUTE_10: int
FEATURE_SET_COMPUTE_11: int
FEATURE_SET_COMPUTE_12: int
FEATURE_SET_COMPUTE_13: int
FEATURE_SET_COMPUTE_20: int
FEATURE_SET_COMPUTE_21: int
FEATURE_SET_COMPUTE_30: int
FEATURE_SET_COMPUTE_32: int
FEATURE_SET_COMPUTE_35: int
FEATURE_SET_COMPUTE_50: int
GLOBAL_ATOMICS: int
HOST_MEM_PAGE_LOCKED: int
HOST_MEM_SHARED: int
HOST_MEM_WRITE_COMBINED: int
HostMem_PAGE_LOCKED: int
HostMem_SHARED: int
HostMem_WRITE_COMBINED: int
NATIVE_DOUBLE: int
SHARED_ATOMICS: int
WARP_SHUFFLE_FUNCTIONS: int

def Even 10000 t_elapsedTime(start: cuda_Event, end: cuda_Event) -> float: ...
def GpuMat_defaultAllocator() -> cuda_GpuMat_Allocator: ...
def GpuMat_setDefaultAllocator(allocator: cuda_GpuMat_Allocator) -> None: ...
def Stream_Null() -> cuda_Stream: ...
def TargetArchs_has(major: int | None, minor: int | None) -> bool: ...
def TargetArchs_hasBin(major: int | None, minor: int | None) -> bool: ...
def TargetArchs_hasEqualOrGreater(major: int | None, minor: int | None) -> bool: ...
def TargetArchs_hasEqualOrGreaterBin(major: int | None, minor: int | None) -> bool: ...
def TargetArchs_hasEqualOrGreaterPtx(major: int | None, minor: int | None) -> bool: ...
def TargetArchs_hasEqualOrLessPtx(major: int | None, minor: int | None) -> bool: ...
def TargetArchs_hasPtx(major: int | None, minor: int | None) -> bool: ...
@overload
def createContinuous(rows: int, cols: int, type: int, arr: _NumericScalar) -> Mat: ... # type: ignore[misc] # https://github.com/python/mypy/issues/8881
@overload
def createContinuous(rows: int, cols: int, type: int, arr: _TGpuMat) -> _TGpuMat: ... # type: ignore[misc] # https://github.com/python/mypy/issues/8881
@overload
def createContinuous(rows: int | None, cols: int | None, type: int | None, arr: cuda_GpuMat | _UMat = ...) -> None: ...
@overload
def ensureSizeIsEnough(rows: int, cols: int, type: int, arr: _NumericScalar) -> Mat: ... # type: ignore[misc] # https://github.com/python/mypy/issues/8881
@overload
def ensureSizeIsEnough(rows: int, cols: int, type: int, arr: _TGpuMat) -> _TGpuMat: ... # type: ignore[misc] # https://github.com/python/mypy/issues/8881
@overload
def ensureSizeIsEnough(rows: int | None, cols: int | None, type: int | None, arr: cuda_GpuMat | _UMat = ...) -> None: ...
def getCudaEnabledDeviceCount() -> int: ...
def getDevice() -> int: ...
def printCudaDeviceInfo(device: int | None) -> None: ...
def printShortCudaDeviceInfo(device: int | None) -> None: ...
def registerPageLocked(m: Mat | _NumericScalar) -> None: ...
def resetDevice() -> None: ...
def setBufferPoolConfig(deviceId: int | None, stackSize: int | None, stackCount: int | None) -> None: ...
def setBufferPoolUsage(on: _Boolean) -> None: ...
def setDevice(device: int | None) -> None: ...
def unregisterPageLocked(m: Mat | _NumericScalar) -> None: ...
168 changes: 101 additions & 67 deletions stubs/opencv-python/cv2/cv2.pyi

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions stubs/opencv-python/cv2/detail.pyi
10000
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ from cv2.cv2 import (
_Point,
_Rect,
_Size,
_TUMat,
_TUMatF,
_UMat,
_UMatF,
detail_BestOf2NearestMatcher,
detail_Blender,
detail_ExposureCompensator,
Expand Down Expand Up @@ -151,13 +148,19 @@ def computeImageFeatures(
def computeImageFeatures2(featuresFinder: Feature2D, image: _UMat, mask: _UMat = ...) -> detail_ImageFeatures: ...
def createLaplacePyr(img: _UMat, num_levels: int, pyr: Sequence[_UMat]) -> tuple[UMat, ...]: ...
def createLaplacePyrGpu(img: _UMat, num_levels: int, pyr: Sequence[_UMat]) -> tuple[UMat, ...]: ...
def createWeightMap(mask: _TUMat, sharpness: float, weight: _TUMat) -> _TUMat: ...
@overload
def createWeightMap(mask: Mat, sharpness: float, weight: Mat) -> Mat: ...
@overload
def createWeightMap(mask: _UMat, sharpness: float, weight: _UMat) -> UMat: ...
def focalsFromHomography(H: Mat, f0: float, f1: float, f0_ok: bool, f1_ok: bool) -> None: ...
def leaveBiggestComponent(
features: Sequence[detail_ImageFeatures], pairwise_matches: Sequence[detail_MatchesInfo], conf_threshold: float
) -> tuple[int, ...]: ...
def matchesGraphAsString(pathes: Sequence[str], pairwise_matches: Sequence[detail_MatchesInfo], conf_threshold: float) -> str: ...
def normalizeUsingWeightMap(weight: _UMatF, src: _TUMatF) -> _TUMatF: ...
@overload
def normalizeUsingWeightMap(weight: Mat, src: Mat) -> Mat: ...
@overload
def normalizeUsingWeightMap(weight: _UMat, src: _UMat) -> UMat: ...
def overlapRoi(tl1: _Point, tl2: _Point, sz1: _Size, sz2: _Size, roi: _Rect) -> bool: ...
def restoreImageFromLaplacePyr(pyr: Sequence[_UMat]) -> tuple[UMat, ...]: ...
def restoreImageFromLaplacePyrGpu(pyr: Sequence[_UMat]) -> tuple[UMat, ...]: ...
Expand Down
110 changes: 110 additions & 0 deletions stubs/opencv-python/cv2/dnn.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
from collections.abc import Sequence
from typing import overload
from typing_extensions import TypeAlias

from cv2 import Mat, _MatF
from cv2.cv2 import _Boolean, _NumericScalar, _RectFloat, _RotatedRect, _Scalar, _Size, _UMat, dnn_Net
from cv2.mat_wrapper import _NDArray, _NDArrayF

_Buffer: TypeAlias = Sequence[_NumericScalar] | bytes | None

DNN_BACKEND_CUDA: int
DNN_BACKEND_DEFAULT: int
DNN_BACKEND_HALIDE: int
DNN_BACKEND_INFERENCE_ENGINE: int
DNN_BACKEND_OPENCV: int
DNN_BACKEND_VKCOM: int
DNN_BACKEND_WEBNN: int
DNN_TARGET_CPU: int
DNN_TARGET_CUDA: int
DNN_TARGET_CUDA_FP16: int
DNN_TARGET_FPGA: int
DNN_TARGET_HDDL: int
DNN_TARGET_MYRIAD: int
DNN_TARGET_OPENCL: int
DNN_TARGET_OPENCL_FP16: int
DNN_TARGET_VULKAN: int
SOFT_NMSMETHOD_SOFTNMS_GAUSSIAN: int
SOFT_NMSMETHOD_SOFTNMS_LINEAR: int
SoftNMSMethod_SOFTNMS_GAUSSIAN: int
SoftNMSMethod_SOFTNMS_LINEAR: int

def NMSBoxes(
bboxes: Sequence[_RectFloat | None] | None,
scores: Sequence[float | None] | None,
score_threshold: float | None,
nms_threshold: float | None,
eta: float | None = ...,
top_k: int | None = ...,
) -> _NDArray: ...
def NMSBoxesRotated(
bboxes: Sequence[_RotatedRect | None] | None,
scores: Sequence[float | None] | None,
score_threshold: float | None,
nms_threshold: float | None,
eta: float | None = ...,
top_k: int | None = ...,
) -> _NDArray: ...
@overload
def Net_readFromModelOptimizer(xml: str, bin: str) -> dnn_Net: ...
@overload
def Net_readFromModelOptimizer(bufferModelConfig: _Buffer, bufferWeights: _Buffer) -> dnn_Net: ...
def blobFromImage(
image: _UMat | None,
scalefactor: float | None = ...,
size: _Size | None = ...,
mean: _Scalar = ...,
swapRB: _Boolean = ...,
crop: _Boolean = ...,
ddepth: int | None = ...,
) -> Mat: ...
def blobFromImages(
images: Sequence[_UMat | None],
scalefactor: float | None = ...,
size: _Size | None = ...,
mean: _Scalar = ...,
swapRB: _Boolean = ...,
crop: _Boolean = ...,
ddepth: int | None = ...,
) -> Mat: ...
def getAvailableTargets(be: int | None) -> _NDArray: ...
def imagesFromBlob(blob_: _MatF, images_: Sequence[_MatF | Mat] = ...) -> tuple[_MatF, ...]: ...
@overload
def readNet(model: str, config: str = ..., framework: str = ...) -> dnn_Net: ...
@overload
def readNet(framework: str, bufferModel: _Buffer, bufferConfig: _Buffer = ...) -> dnn_Net: ...
@overload
def readNetFromCaffe(prototxt: str, caffeModel: str = ...) -> dnn_Net: ...
@overload
def readNetFromCaffe(bufferProto: _Buffer, bufferModel: _Buffer = ...) -> dnn_Net: ...
@overload
def readNetFromDarknet(cfgFile: str, darknetModel: str = ...) -> dnn_Net: ...
@overload
def readNetFromDarknet(bufferCfg: _Buffer, bufferModel: _Buffer = ...) -> dnn_Net: ...
@overload
def readNetFromModelOptimizer(xml: str, bin: str) -> dnn_Net: ...
@overload
def readNetFromModelOptimizer(bufferModelConfig: _Buffer, bufferWeights: _Buffer) -> dnn_Net: ...
@overload
def readNetFromONNX(onnxFile: str) -> dnn_Net: ...
@overload
def readNetFromONNX(buffer: _Buffer) -> dnn_Net: ...
@overload
def readNetFromTensorflow(model: str, config: str = ...) -> dnn_Net: ...
@overload
def readNetFromTensorflow(bufferModel: _Buffer, bufferConfig: _Buffer = ...) -> dnn_Net: ...
def readNetFromTorch(model: str, isBinary: _Boolean = ..., evaluate: _Boolean = ...) -> dnn_Net: ...
def readTensorFromONNX(path: str) -> Mat: ...
def readTorchBlob(filename: str, isBinary: _Boolean = ...) -> Mat: ...
def shrinkCaffeModel(src: str, dst: str, layersTypes: Sequence[str] = ...) -> None: ...
def softNMSBoxes(
bboxes: Sequence[_RectFloat | None] | None,
scores: Sequence[float | None] | None,
score_threshold: float | None,
nms_threshold: float | None,
eta: float | None = ...,
top_k: int | None = ...,
sigma: float | None = ...,
method: int | None = ...,
) -> tuple[_NDArrayF, _NDArray]: ...
def writeTextGraph(model: str, output: str) -> None: ...
Loading
0