
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to flip an image using Java OpenCV library?
The flip() method of the Core class of OpenCV flips an image along the x/y axis. This method accepts −
A source matrix congaing the data of the original image.
An empty destination matrix to hold the data of the resultant image.
A flip code to specify the direction of the image (0 –x axis, +ve – y axis, – ve both the axes).
To flip an image −
Load the OpenCV core native library, using the loadLibrary() method.
Read the contents of the image file to a matrix using the imread() method.
Create an empty matric to hold the result.
Invoke the flip() method by passing the above-created matrices.
Create an image using the imwrite() method, bypassing the destination matrix as a parameter.
Example
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.imgcodecs.Imgcodecs; public class ChangingOrientation { public static void main(String args[]) { //Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); //Reading the Image from the file and storing it in to a Matrix object String file ="D:\Images\cat.jpg"; Mat src = Imgcodecs.imread(file); //Creating an empty matrix to store the result Mat dst = new Mat(); //Changing the orientation of an image Core.flip(src, dst, -1); //Writing the image Imgcodecs.imwrite("D:\Images\flipping.jpg", dst); System.out.println("Image Processed"); } }
Input
Output
- Related Articles
- How to write an image using Java OpenCV library?
- How to add noise to an image using Java OpenCV library?
- How to add text to an image using Java OpenCV library?
- How to add borders to an image using Java OpenCV library?
- How to detect faces in an image using Java OpenCV library?
- How to draw markers on an image using Java OpenCV library?
- How to find Image Contours using Java OpenCV library?
- How to draw Image Contours using Java OpenCV library?
- How to create a watermark on an image using Java OpenCV library?
- How to alter the contrast of an image using Java OpenCV library?
- How to alter the brightness of an image using Java OpenCV library?
- How to alter the sharpness of an image using Java OpenCV library?
- How to flip an image in OpenCV Python?
- How to create a mirror image using Java OpenCV library?
- How to change the color spaces of an image using Java OpenCV library?

Advertisements