Under normal circumstances, the python interface of OpenCV is basically the same as the C language interface. however, some functions and struct may be different when python interfaces are difficult to implement. the following is a detailed description of this content. I hope it will help you.
Function interfaces should also be consistent with the C language. the biggest difference is when the function returns values through parameters. because some basic parameters in python cannot be changed, the alternative method is to return multiple values at a time. similarly, most of the structures are similar to those in C, but the syntax may be somewhat different.
- How to configure the Python socket Service
- Python logs require constant learning.
- Understand how to create a program with multiple threads in Python
- Exploring the Python Object System
- Use the Python standard library to modify the search engine to obtain results
The following describes important differences. For details, refer to the python interface code.
No IplImage
The biggest difference is that there is no IplImage In the python interface! This is mainly to avoid the deficiency of implicit sharing in IplImage processing by SWIG. The following is an alternative method:
The original IplImage function is returned. Now, the original CvMat read IplImage is returned to the CvMat function, and the IplImage attribute not available in CvMat is added to support IplImage, such as height, width, depth, and imageDataSize. ROI and COI functions are forbidden. however, you can use cvGetSubRect/cvSplit/cvMerge to implement similar functions.
Iterative access
CvMat extends two basic methods in python: _ iter _ and _ getitem _ to Support Simple Element access.
Iteration through rows
- <python>x = cvCreateMat(m, n, type) for row in x:
-
- # row is same as that returned by cvGetRow python>
-
Column-based iteration
- <python>for col in x.colrange():
- # col is same as that returned by cvGetCol python>
Slicing Method
Get a row
- <python>row = x[i] python>
-
Retrieve a column
- <python>col = x[:, i] python>
Obtain a region
- <python>slice = x[0:10, 0:10] python>
-
Get an element
- <python>elem = x[i, j]
-
- or
- elem = x[i][j]
-
- or if x is a vector
- elem = x[i] python>
-
The same method can be used to modify elements.
- <python># x and y are CvMat's x[0:10, 0:5] = y[10:20, 1:6] x[i, j]
- = 1; x[:, :] = 1; x[:, :] = cvScalar(1); x[0:10, i]
- = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] python>
-