Life: This article reposted from http://baike.baidu.com/view/3527644.htm
Note: The cvflip function of opencv can be used to flip an image. Of course, you can also flip an image by directly operating its BIT data, in the future, we hope to have the opportunity to study the steps for directly operating the image bit to flip.
The cvshowimage of the image captured by the image acquisition card is a reverse image, that is, the image captured by the image acquisition card is at the origin in the lower left corner, and the image origin displayed in the window is at the upper left corner, this is equivalent to turning over the X axis. You can use the cvflip () function to flip the image before displaying the image.
Flip vertical, horizontal or vertical and horizontal flip two-dimensional array void cvflip (const cvarr * SRC, cvarr * DST = NULL, int flip_mode = 0); # define cvmirror cvflipsrc original array. DST destination responsibility array. if DST = NULL is flipped, it is replaced internally. flip_mode specifies how to flip the array. Flip_mode = 0: Flip along X-axis, flip_mode> 0 (for example, 1) Flip along Y-axis, flip_mode <0 (for example,-1) Flip along X-axis and Y-axis. see the following formula for the function cvflip to flip an array in one of three ways (rows and column subscripts are based on 0): DST (I, j) = SRC (rows (SRC)-i-1, j) If flip_mode = 0dst (I, j) = SRC (I, cols (src1)-J-1) If flip_mode> 0dst (I, j) = SRC (rows (SRC) -i-1, cols (SRC)-J-1) If flip_mode <0 function mainly used in: vertical flip image (flip_mode> 0) for top-left and bottom-left image structure conversion, it is mainly used for video operation in Win32 system. horizontal image conversion, using continuous Horizontal conversion and absolute difference check Vertical Axial Symmetry (flip_mode> 0) horizontal and vertical simultaneous conversion, for continuous Horizontal conversion and absolute truth value difference check center symmetric S (flip_mode <0) Flip Order of 1-dimensional pointer array (flip_mode> 0) the following is an introduction to this function and a simple test applet. # Include "stdafx. H "# include" stdio. H "# include" CV. H "# include" highgui. H "int main () {iplimage * psrcimg = NULL; iplimage * pclnimg = NULL; psrcimg = cvloadimage (" flower.jpg ", 1); If (psrcimg = NULL) {printf ("fail to load images \ n"); Return-1;} pclnimg = cvcloneimage (psrcimg); If (pclnimg = NULL) {printf ("fail to clone the image \ n"); Return-1;} cvflip (pclnimg, null, 0); // The core here // not cvflip (SRC, P Clnimg, 0); // The pclinlmg must first load the image or copy the image! Cvnamedwindow ("src", 0); cvnamedwindow ("turnover", 0); cvshowimage ("src", psrcimg); cvshowimage ("turnover", pclnimg ); cvwaitkey (0); cvreleaseimage (& psrcimg); cvreleaseimage (& pclnimg); cvdestroywindow ("src"); cvdestroywindow ("turnover"); Return 0 ;} because some images extracted from Avi are in the same bottom-left format as windows bitmaps, that is, the image pixels start with the lower left corner. In this way, the image looks upside down and needs to be reversed vertically. The iplimage: origin parameter can be used to determine the flip. If the origin is 1, the flip graph is displayed. Use the cvflip function to flip. The following two sentences are added after "// display image": pfrimg-> origin = 1; pbkimg-> origin = 1;