opencv 常用图片操作函数备忘

来源:互联网 发布:腾讯股票分红 知乎 编辑:程序博客网 时间:2024/06/05 13:26


图像翻转函数flip 

Flips a 2D array around vertical, horizontal, or both axes.

  • C++: void flip(InputArraysrc, OutputArraydst, int flipCode)
  • C:   void cvFlip(const CvArr*src, CvArr*dst=NULL, intflip_mode=0)

Parameters:

  • src - input array
  • dst - output array of the same size and type as src.
  • flipCode -  a flag to specify how to flip the array; 0 means flipping around the x-axis and positive value (for example, 1) means flipping around y-axis. Negative value (for example, -1) means flipping around both axes (see the discussion below for the formulas).

The function flip flips the array in one of three different ways (row and column indices are 0-based):


The example scenarios of using the function are the following:

  • Vertical flipping of the image (flipCode==0) to switch between top-left and bottom-left image origin. This is a typical operation in video processing on Microsoft Windows* OS.
  • Horizontal flipping of the image with the subsequent horizontal shift and absolute difference calculation to check for a vertical-axis symmetry (flipCode>0).
  • Simultaneous horizontal and vertical flipping of the image with the subsequent shift and absolute difference calculation to check for a central symmetry (flipCode<0).
  • Reversing the order of point arrays (flipCode>0 orflipCode==0).

灰度直方图均衡化

equalizeHist

Equalizes the histogram of a grayscale image.

C++: void equalizeHist(InputArray src, OutputArray dst)
Python: cv2.equalizeHist(src[, dst]) → dst
C: void cvEqualizeHist(const CvArr* src, CvArr* dst)
Parameters:
  • src – Source 8-bit single channel image.
  • dst – Destination image of the same size and type as src .

The function equalizes the histogram of the input image using the following algorithm:

  1. Calculate the histogram H for src .

  2. Normalize the histogram so that the sum of histogram bins is 255.

  3. Compute the integral of the histogram:

    H'_i =  \sum _{0  \le j < i} H(j)

  4. Transform the image using H' as a look-up table: \texttt{dst}(x,y) = H'(\texttt{src}(x,y))

The algorithm normalizes the brightness and increases the contrast of the image.


颜色空间变换cvtColor

Converts an image from one color space to another.

C++: void cvtColor(InputArray src, OutputArray dst, int code, int dstCn=0 )
Python: cv2.cvtColor(src, code[, dst[, dstCn]]) → dst
C: void cvCvtColor(const CvArr* src, CvArr* dst, int code)
Python: cv.CvtColor(src, dst, code) → None
Parameters:
  • src – Source image: 8-bit unsigned, 16-bit unsigned ( CV_16UC... ), or single-precision floating-point.
  • dst – Destination image of the same size and depth as src .
  • code – Color space conversion code. See the description below.
  • dstCn – Number of channels in the destination image. If the parameter is 0, the number of the channels is derived automatically from src and code .

原创粉丝点击