Question

I'm trying to compare to images in my phone's SDcard, so I wrote this piece of code.

package com.example.test;

import java.io.File;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    File img1=new File("mnt/sdcard/xx/IMG-20130123-WA0004.jpg");
    File img2=new File("mnt/sdcard/xx/IMG-20130124-WA0000.jpg");
    double l2_norm = cvNorm( img1, img2 );
}
}

I have imported OpenCV as a project in my Eclipse Workspace and set it as a library. My test project uses this library.

Now, I get this error The method cvNorm(File, File) is undefined for the type MainActivity

I searched for over 3 hours for the proper code or method but none seem to work and Eclipse isn't suggesting the correct imports. Could someone tell me the correct code?

Was it helpful?

Solution

This is Java. You have to import classes and refer to them by package.

import android.os.Bundle;
import android.app.Activity;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Mat img1 = Highgui.imread("mnt/sdcard/xx/IMG-20130123-WA0004.jpg");
        Mat img2 = Highgui.imread("mnt/sdcard/xx/IMG-20130124-WA0000.jpg");
        double l2_norm = Core.norm(img1, img2);
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top