Python interface and C language have different functions (1)

Source: Internet
Author: User

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

 
 
  1. <python>x = cvCreateMat(m, n, type) for row in x:   
  2.  
  3.  # row is same as that returned by cvGetRow python> 
  4.  

Column-based iteration

 
 
  1. <python>for col in x.colrange():   
  2.  # col is same as that returned by cvGetCol python> 

Slicing Method

 Get a row

 
 
  1. <python>row = x[i] python>   
  2.  

Retrieve a column

 
 
  1. <python>col = x[:, i] python>  

Obtain a region

 
 
  1. <python>slice = x[0:10, 0:10] python>   
  2.  

Get an element

 
 
  1. <python>elem = x[i, j]   
  2.  
  3. or   
  4. elem = x[i][j]   
  5.  
  6. or if x is a vector   
  7. elem = x[i] python>   
  8.  

The same method can be used to modify elements.

 
 
  1. <python># x and y are CvMat's x[0:10, 0:5] = y[10:20, 1:6] x[i, j]
  2.  = 1; x[:, :] = 1; x[:, :] = cvScalar(1); x[0:10, i]
  3.  = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] python>   
  4.  


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.