cv2 functions and data types (OpenCV python bindings)

Some OpenCV functions have restrictions on the input data type. When executing the cv2. Function () in python, an error may occur due to a mistake in specifying the ddepth of the input data type and output data depth. In the error message, values such as cv2.CV_8U are displayed as integers, so I'm confused as to what the input data type should be and how to specify the ddepth of the output data depth. I have something to do.

Similarly, building from the source code of the cv :: function () in C ++ may fail.

I will make a note so as not to repeat the same mistake.


dilate(...) dilate(src, kernel[, dst[, anchor[, iterations[, borderType[, borderValue]]]]]) -> dst

function CV_8U CV_8S CV_16U CV_16S CV_32S CV_32F CV_64F
value 0 1 2 3 4 5 6
np.dtype uint8 int8 uint16 int16 int32 float32 float64
cv2.dilate() o x o o x o o
cv2.erode() o x o o x o o
connectedComponentsWithStats() input o x x x x x x
connectedComponentsWithStats() labels x x o x o x x
connectedComponentsWithStats() stats x x x x o x x
connectedComponentsWithStats() centroids x x x x x x o
function CV_8U CV_8S CV_16U CV_16S CV_32S CV_32F CV_64F
np.dtype uint8 int8 uint16 int16 int32 float32 float64
cv2.Sobel() src o x o o x o o
cv2.Sobel() dst o x o o x o o
cv2.blur() src o x o o o o o
GaussianBlur() src o x o o x o o
filter2D() src o x o o x o o
cartToPolar() src x x x x x o o
polarToCart() src x x x x x o o
magnitude() src x x x x x o o
phase() src x x x x x o o
cv2.sqrt() src x x x x x o o
cvtColor() o x o x x o x

I haven't fully checked the combination yet.

Sobel(...) Sobel(src, ddepth, dx, dy[, dst[, ksize[, scale[, delta[, borderType]]]]]) -> dst

Sobel combination Input image src type: vertical axis Determines the type of output image ddepth: Horizontal axis

CV_8U CV_8S CV_16U CV_16S CV_32S CV_32F CV_64F
np.uint8 o x o o x o o
np.int8 x x x x x x x
np.uint16 o x o o x o o
np.int16 o x o o x o o
np.int32 x x x x x x x
np.float32 o x o o x o o
np.float64 o x o o x x o

Combination of cv2.filter2D (np.array (orgImg, dtype = npt), ddepth, kernel) Input image src type: vertical axis Determines the type of output image ddepth: Horizontal axis

CV_8U CV_8S CV_16U CV_16S CV_32S CV_32F CV_64F
np.uint8 o x o o x o o
np.int8 x x x x x x x
np.uint16 x x o x x o o
np.int16 x x x o x o o
np.int32 x x x x x x x
np.float32 x x x x x o x
np.float64 x x x x x x o
function CV_8U CV_8S CV_16U CV_16S CV_32S CV_32F CV_64F
np.dtype uint8 int8 uint16 int16 int32 float32 float64
cv2.threshold() src o o x x x o x
cv2.floodFill() src o o x x x o x
function CV_8U CV_8S CV_16U CV_16S CV_32S CV_32F CV_64F
np.dtype uint8 int8 uint16 int16 int32 float32 float64
cv2.Canny() src o o x x x x x
cv2.HoughLines()src Binary image o ? x x x x x
cv2.HoughCircles()src Binary image o ? x x x x x
# -*- coding: utf-8 -*-
u"""OpenCV cv::Check Mat type in Python
"""
import cv2
print cv2.CV_8U
print cv2.CV_8S
print cv2.CV_16U
print cv2.CV_16S
print cv2.CV_32S
print cv2.CV_32F
print cv2.CV_64F

Recommended Posts

cv2 functions and data types (OpenCV python bindings)
Python variables and data types learned in chemoinformatics
Python 3 sorted and comparison functions
Algebraic data types and FizzBuzz
Python higher-order functions and comprehensions
Python application: Data cleansing # 3: Use of OpenCV and preprocessing of image data
[Introduction to Data Scientists] Basics of Python ♬ Functions and classes
Environment construction of python and opencv
Notes on Python and dictionary types
Neural network with OpenCV 3 and Python 3
About python dict and sorted functions
Algebraic data types and pattern matching
Hashing data in R and Python
Algebraic data types and object-oriented programming
[Introduction to Data Scientists] Basics of Python ♬ Functions and anonymous functions, etc.
Data pipeline construction with Python and Luigi
Build Python3 and OpenCV environment on Ubuntu 18.04
Capturing images with Pupil, python and OpenCV
Python data structure and internal implementation ~ List ~
Python functions
Python data structure and operation (Python learning memo ③)
Easily graph data in shell and Python
Understanding data types and beginning linear regression
Compress python data and write to sqlite
Easy introduction of python3 series and OpenCV3
Use Python and MeCab with Azure Functions
Correspondence between Python built-in functions and Rust
Exchange encrypted data between Python and C #
Hello World and face detection with OpenCV 4.3 + Python
Head orientation estimation using Python and OpenCV + dlib
Julia Quick Note [22] Calling Python functions and Python modules
I tried object detection using Python and OpenCV
[Python] Swapping rows and columns in Numpy data
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
[Python] Conversion memo between time data and numerical data
Practice applying functions and global variables in Python
Data cleansing 3 Use of OpenCV and preprocessing of image data
Feature matching with OpenCV 3 and Python 3 (A-KAZE, KNN)
Try importing MLB data on Mac and Python
Python2.7 + CentOS7 + OpenCV3
Test python models and functions deployed online with Cloud Pack for Data with form-formatted input data
Data analysis python
#Python basics (functions)
OpenCV Samples (Python)
[Note] openCV + python
Python Easy-to-use functions
Python basics: functions
[python] Read data
Getting Started with python3 # 2 Learn about types and variables
[Python for Hikari-] Chapter 06-04 Functions (arguments and return value 3)
Full-width and half-width processing of CSV data in Python
List of Python libraries for data scientists and data engineers
[Ubuntu] [Python] Face detection comparison between dlib and OpenCV
Python Exercise for Beginners # 1 [Basic Data Types / If Statements]
[Python for Hikari-] Chapter 06-01 Functions (Intrinsic Functions and Function Definitions)
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Rotate and scale the image before cropping [python] [OpenCV]
Investigate Java and python data exchange with Apache Arrow
[Python for Hikari-] Chapter 06-03 Functions (arguments and return value 2)
[Python] Webcam frame size and FPS settings with OpenCV
[Python] Chapter 04-05 Various data structures (tuple creation and features)