Pages

Install OpenCV 2.4.4 in Windows for Java

As of OpenCV 2.4.4, OpenCV supports desktop Java development using nearly the same interface as for Android development

hello friends,
In this post i will tell you how to Install OpenCV 2.4.x  in Windows8(x64) for Java using Eclipse.

Pre-requisites(need to be downloaded)

Java : Download  Java Windows(x64) from jdk7u21

OpenCV : Download OpenCV 2.4.4 for Windows from  here.

Eclipse : Download Eclipse from here.

Installation

1.Uncompress opencv in C:\

2.Follow the video

3.In Eclipse      a) For external jars include location :"C:\opencv\build\java".
                        b) For native library location include:"C:\opencv\build\java\x64".for 64 bit machine
                                                                               :"C:\opencv\build\java\x86" for 32 bit machine

Watch Video







Load Image OpenCV Java

Description

The code given below is used to load image using OpenCV java.The first step is to read image.and then call LoadImage.java.

Main.java

import org.opencv.core.*;
import org.opencv.highgui.*;

public class Main {

public static void main(String[] args)
       {
System.loadLibrary("opencv_java244");
   Mat m=Highgui.imread("C:/Users/raj/Desktop/sa1.png",Highgui.CV_LOAD_IMAGE_COLOR);
new LoadImage("C:/Users/raj/Desktop/dst1.jpg",m);
       }
       }






LoadImage.java

 
import java.awt.*;
import javax.swing.*;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;

import org.opencv.highgui.Highgui;
public class LoadImage extends JFrame {
 
public LoadImage(String imgStr,Mat m)
{
Highgui.imwrite(imgStr,m);
JFrame frame = new JFrame("My GUI");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setResizable(true);
frame.setLocationRelativeTo(null);

// Inserts the image icon
ImageIcon image = new ImageIcon(imgStr);
frame.setSize(image.getIconWidth()+10,image.getIconHeight()+35);
// Draw the Image data into the BufferedImage
JLabel label1 = new JLabel(" ", image, JLabel.CENTER);
frame.getContentPane().add(label1);

frame.validate();
frame.setVisible(true);}

 

}


Morphological Image Processing


Under this Comes Erosion,Dilation,Opening,Closing,Convex Hull.