Skip to content
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

opencv-python stubs #8879

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"stubs/protobuf",
"stubs/google-cloud-ndb",
"stubs/influxdb-client",
"stubs/opencv-python/cv2/cv2.pyi",
"stubs/passlib",
"stubs/peewee",
"stubs/pika",
Expand Down
18 changes: 18 additions & 0 deletions stubs/opencv-python/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Partial files inserted in code when generating config.
cv2.config-?.*

# Python 2
cv2.load_config_py2

# Specific args and kwargs definition
cv2.GMat.__init__
cv2.cv2.GMat.__init__
cv2.mat_wrapper.Mat.__init__
cv2.mat_wrapper.Mat.__new__

# In actual execution, these wouldn't be None during error handling
(cv2\.)?cv2.error\..*

# cv2.Mat is not a Union
# We cheat the Mat type because of variance issues
cv2.Mat
5 changes: 5 additions & 0 deletions stubs/opencv-python/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Can't bump to 4.6 until https://github.com/opencv/opencv-python/issues/676 is fixed.
version = "4.5.*"

[tool.stubtest]
ignore_missing_stub = false
110 changes: 110 additions & 0 deletions stubs/opencv-python/cv2/Error.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
BAD_ALIGN: int
BAD_ALPHA_CHANNEL: int
BAD_CALL_BACK: int
BAD_COI: int
BAD_DATA_PTR: int
BAD_DEPTH: int
BAD_IMAGE_SIZE: int
BAD_MODEL_OR_CH_SEQ: int
BAD_NUM_CHANNEL1U: int
BAD_NUM_CHANNELS: int
BAD_OFFSET: int
BAD_ORDER: int
BAD_ORIGIN: int
BAD_ROISIZE: int
BAD_STEP: int
BAD_TILE_SIZE: int
BadAlign: int
BadAlphaChannel: int
BadCOI: int
BadCallBack: int
BadDataPtr: int
BadDepth: int
BadImageSize: int
BadModelOrChSeq: int
BadNumChannel1U: int
BadNumChannels: int
BadOffset: int
BadOrder: int
BadOrigin: int
BadROISize: int
BadStep: int
BadTileSize: int
GPU_API_CALL_ERROR: int
GPU_NOT_SUPPORTED: int
GpuApiCallError: int
GpuNotSupported: int
HEADER_IS_NULL: int
HeaderIsNull: int
MASK_IS_TILED: int
MaskIsTiled: int
OPEN_CLAPI_CALL_ERROR: int
OPEN_CLDOUBLE_NOT_SUPPORTED: int
OPEN_CLINIT_ERROR: int
OPEN_CLNO_AMDBLAS_FFT: int
OPEN_GL_API_CALL_ERROR: int
OPEN_GL_NOT_SUPPORTED: int
OpenCLApiCallError: int
OpenCLDoubleNotSupported: int
OpenCLInitError: int
OpenCLNoAMDBlasFft: int
OpenGlApiCallError: int
OpenGlNotSupported: int
STS_ASSERT: int
STS_AUTO_TRACE: int
STS_BACK_TRACE: int
STS_BAD_ARG: int
STS_BAD_FLAG: int
STS_BAD_FUNC: int
STS_BAD_MASK: int
STS_BAD_MEM_BLOCK: int
STS_BAD_POINT: int
STS_BAD_SIZE: int
STS_DIV_BY_ZERO: int
STS_ERROR: int
STS_FILTER_OFFSET_ERR: int
STS_FILTER_STRUCT_CONTENT_ERR: int
STS_INPLACE_NOT_SUPPORTED: int
STS_INTERNAL: int
STS_KERNEL_STRUCT_CONTENT_ERR: int
STS_NOT_IMPLEMENTED: int
STS_NO_CONV: int
STS_NO_MEM: int
STS_NULL_PTR: int
STS_OBJECT_NOT_FOUND: int
STS_OK: int
STS_OUT_OF_RANGE: int
STS_PARSE_ERROR: int
STS_UNMATCHED_FORMATS: int
STS_UNMATCHED_SIZES: int
STS_UNSUPPORTED_FORMAT: int
STS_VEC_LENGTH_ERR: int
StsAssert: int
StsAutoTrace: int
StsBackTrace: int
StsBadArg: int
StsBadFlag: int
StsBadFunc: int
StsBadMask: int
StsBadMemBlock: int
StsBadPoint: int
StsBadSize: int
StsDivByZero: int
StsError: int
StsFilterOffsetErr: int
StsFilterStructContentErr: int
StsInplaceNotSupported: int
StsInternal: int
StsKernelStructContentErr: int
StsNoConv: int
StsNoMem: int
StsNotImplemented: int
StsNullPtr: int
StsObjectNotFound: int
StsOk: int
StsOutOfRange: int
StsParseError: int
StsUnmatchedFormats: int
StsUnmatchedSizes: int
StsUnsupportedFormat: int
StsVecLengthErr: int
21 changes: 21 additions & 0 deletions stubs/opencv-python/cv2/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typing_extensions import TypeAlias

from cv2 import (
Error as Error,
data as data,
gapi as gapi,
mat_wrapper as mat_wrapper,
misc as misc,
utils as utils,
version as version,
)
from cv2.cv2 import *
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 | _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 Event_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: ...