Ask Your Question

JavaD's profile - activity

2017-03-31 14:32:52 -0600 commented question Removing outliers from Similar Images

I used homography but it didn't match the two images

2017-03-31 14:26:57 -0600 asked a question How to Align two images

I am new to OpenCV and I need some help ..

Objective : I am trying to highlight the difference between two images

Problem : If the images differ in the position , the program highlights the whole image

How can I Align the images so that each feature in one image will be placed on the same feature in the second image , and eventually remove the outliers.

I used the following steps :

  1. import the 2 images
  2. convert them into grayScale
  3. get the features by Feature-detector
  4. use Find Homograpy
  5. Use Absdiff
  6. Highlight the difference

I been told to use WarpPrescriptive but I didn't know how to use it

If anyone can help me please

2017-03-27 14:55:33 -0600 asked a question Removing outliers from Similar Images

Hello..

I am implementing a java program that highlights the difference between two images.

I used the following steps :

  1. turning the images into gray scale
  2. apply feature detection to the images in order to check if they are similar
  3. applying absdiff to them
  4. highlighting the difference in the original picture

My problem is : when I upload two images that are similar but one of them have outliers, or the position is slightly different , the whole image become different

the code is : ` package image;

import org.opencv.calib3d.Calib3d;
import org.opencv.core.*;
import org.opencv.features2d.*;
import org.opencv.features2d.DMatch;
import org.opencv.features2d.KeyPoint;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.Imgproc;




import java.awt.image.BufferedImage;

import java.io.File;
import java.io.IOException; 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Vector;

import javax.imageio.ImageIO;
import javax.swing.JOptionPane;


public class SURFDetector22 {

 boolean answer;



 //copy matrix
 public static Mat imitate(Mat m){
        return new Mat(m.height(), m.width(), m.type());
    }

 //draw rect
  public static void drawRotatedRect(Mat image, RotatedRect rotatedRect, Scalar color, int thickness) {
      Point[] vertices = new Point[4];
      rotatedRect.points(vertices);
      MatOfPoint points = new MatOfPoint(vertices);
      Imgproc.drawContours(image, Arrays.asList(points), -1, color, thickness);
  }


  //diff btw matrices
 public static Mat diff(Mat mat1, Mat mat2){
        Mat dst = imitate(mat1);
        Core.absdiff(mat1, mat2, dst);
        return dst;}

public  void imageComparison(File file1, File file2) throws IOException {

    File lib = null;
    String os = System.getProperty("os.name");
    String bitness = System.getProperty("sun.arch.data.model");

    if (os.toUpperCase().contains("WINDOWS")) {
        if (bitness.endsWith("64")) {
            lib = new File("libs//x64//" + System.mapLibraryName("opencv_java2411"));
        } else {
            lib = new File("libs//x86//" + System.mapLibraryName("opencv_java2411"));
        }
    }

    System.loadLibrary( Core.NATIVE_LIBRARY_NAME );

    ///////step 1 : read images

    ///first image
    String bookObject = file1.getAbsolutePath();    
    Mat objectImage = Highgui.imread(bookObject, Highgui.CV_LOAD_IMAGE_COLOR);
     Mat mat1 = new Mat(objectImage.height(),objectImage.width(),CvType.CV_8UC1);
    Imgproc.cvtColor(objectImage, mat1, Imgproc.COLOR_RGB2GRAY);


    byte[] data1 = new byte[mat1.rows() * mat1.cols() * (int)(mat1.elemSize())];
    mat1.get(0, 0, data1);
    BufferedImage image1 = new BufferedImage(mat1.cols(),mat1.rows(), BufferedImage.TYPE_BYTE_GRAY);
    image1.getRaster().setDataElements(0, 0, mat1.cols(), mat1.rows(), data1);

    File ouptut = new File("gray//1.jpg");
    ImageIO.write(image1, "jpg", ouptut);

    //bade a3ml show la hyde el sora

    //2nd image
    String bookScene = file2.getAbsolutePath();
    Mat sceneImage = Highgui.imread(bookScene, Highgui.CV_LOAD_IMAGE_COLOR);
    Mat mat2 = new Mat(sceneImage.height(),sceneImage.width(),CvType.CV_8UC1);
  Imgproc.cvtColor(sceneImage, mat2, Imgproc.COLOR_RGB2GRAY );

  byte[] data2 = new byte[mat2.rows() * mat2.cols() * (int)(mat2.elemSize())];
  mat2.get(0, 0, data2);
  BufferedImage image2 = new BufferedImage(mat2.cols(),mat2.rows(), BufferedImage.TYPE_BYTE_GRAY);
  image2.getRaster().setDataElements(0, 0, mat2.cols(), mat2.rows(), data2);

  File ouptut2 = new File("gray//2.jpg");
  ImageIO.write(image2, "jpg", ouptut2);

  //////step 2 : Detect and extract features


  MatOfKeyPoint objectKeyPoints = new MatOfKeyPoint();
    FeatureDetector featureDetector = FeatureDetector.create(FeatureDetector.SURF);
    System.out.println("Detecting key points...");
    featureDetector.detect(mat1, objectKeyPoints);
    System.out.println("----- key pointss image 1----" + objectKeyPoints);
    //KeyPoint[] keypoints = objectKeyPoints.toArray();
    System.out.println(objectKeyPoints ...
(more)