Opencv-image reversal and flip

Source: Internet
Author: User
Tags bmp image image flip

/*
Name: imagereverseandrolover. cpp
Function: Read the BMP image file, reverse and flip the image, and display it on the screen.
*/
/* ===================================================== ==================================================== ===
See http://hi.baidu.com/cateyefish/item/60167fcddfe8a52ce80f2e2ato modify
Cvflip Function
Vertical, horizontal, vertical, and horizontal flip of two-dimensional arrays

Void cvflip (const cvarr * SRC, cvarr * DST = NULL, int flip_mode = 0 );

SRC: original array; DST: Destination array. Internal replacement is implemented when DST = NULL.

Flip_mode specifies the array flip Mode

Flip_mode = 0: Flip along the X axis
Flip_mode> 0: Flip along the Y axis
Flip_mode <0: flipped along the X and Y axes
 
The cvflip function is used to flip an array in one of the following three ways (rows and column subscripts are based on 0 ):
DST (I, j) = SRC (rows (SRC)-i-1, j) If flip_mode = 0
DST (I, j) = SRC (I, cols (src1)-J-1) If flip_mode> 0
DST (I, j) = SRC (rows (SRC)-i-1, cols (SRC)-J-1) If flip_mode <0

Functions are mainly used in:

Vertical flip image (flip_mode> 0) is used to convert the top-left and bottom-left image structures. It is mainly used for video operation in Win32 system.
Horizontal image conversion (flip_mode = 0), using continuous Horizontal conversion and absolute difference check Vertical Axial Symmetry
Horizontal and vertical simultaneous conversion (flip_mode <0) for continuous Horizontal conversion and absolute truth value difference check center Symmetry
Flip the order of the 1-dimensional pointer array (flip_mode> 0)
*/

# Include <iostream> # include <opencv2/CORE/core. HPP> # include <opencv2/imgproc. HPP> # include <opencv2/highgui. HPP> using namespace STD; using namespace CV; int main () {iplimage * psrcimg = NULL; iplimage * cursor = NULL; iplimage * proverselnimg = NULL; psrcimg = cvloadimage ("D: \ lena.bmp ", 0); // cvloadimage (filename,-1); default number of original channels for image reading // cvloadimage (filename, 0 ); forcibly convert the read image to a grayscale image // cvloadimage (filename, 1); read the color image if (psrcimg = NULL) {cout <"fail to load image" <Endl; return-1;} proloverlnimg = cvcloneimage (psrcimg); proverselnimg = cvcloneimage (psrcimg); If (proloverlnimg = NULL) & (proverselnimg = NULL )) {cout <"fail to clone the image" <Endl; Return-1 ;}// image flip processing ----------------------------------- cvflip (proloverlnimg, null, 0 ); // load the image to flip up or down the X axis // ------------------------------------ image reverse processing ---------------------------- int length, width, step, channel; uchar * data; int I, J, K; length = proverselnimg-> height; width = proverselnimg-> width; step = proverselnimg-> widthstep; Channel = proverselnimg-> nchannels; Data = (uchar *) proverselnimg-> imagedata; for (I = 0; I <length; I ++) {for (j = 0; j <width; j ++) {for (k = 0; k <channel; k ++) {data [I * Step + J * channel + k] = 255-data [I * Step + J * channel + k] ;}} //************************************** **************************************** * ********* // cvnamedwindow ("src ", 0); // 0 indicates that the image is displayed with a fixed window size. If no value is input, cvnamedwindow ("src") is the same as the original image size by default. cvnamedwindow ("xturnover "); cvnamedwindow ("picreverse"); cvshowimage ("src", psrcimg); cvshowimage ("xturnover", signature); cvshowimage ("picreverse", proverselnimg); cvwaitkey (0 ); cvreleaseimage (& psrcimg); cvreleaseimage (& images); cvdestroywindow ("src"); cvdestroywindow ("xturnover"); cvdestroywindow ("picreverse "); return 0 ;}

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.