I want to check two images are similar or different with opencv.
if they are same printf(\"same\");
if they are not same printf(\"not same\");
is there any method or
It is not so easy task, and it is impossible to do with one if. What I recommend is to match image's interest points. Basically you can use opencv library to identify interest points on images and perform the match of them. If the percentage of the match is high enough, you can conclude that images are the same. This percentage in most cases depends of kind of images which you want to match. It means that you need to adjust the value of the acceptance percentage.
To perform fingerprint matching you can use ORB,FREAK,BRISK,SURF algorithms. But I recommend you to use ORB. You can read more about this here.
Here is some tips how you can do it with OpenCV for Java:
//Load images to compare
Mat img1 = Highgui.imread(filename1, Highgui.CV_LOAD_IMAGE_GRAYSCALE);
Mat img2 = Highgui.imread(filename1, Highgui.CV_LOAD_IMAGE_GRAYSCALE);
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
MatOfKeyPoint keypoints2 = new MatOfKeyPoint();
Mat descriptors1 = new Mat();
Mat descriptors2 = new Mat();
//Definition of ORB keypoint detector and descriptor extractors
FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.ORB);
//Detect keypoints
detector.detect(img1, keypoints1);
detector.detect(img2, keypoints2);
//Extract descriptors
extractor.compute(img1, keypoints1, descriptors1);
extractor.compute(img2, keypoints2, descriptors2);
//Definition of descriptor matcher
DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
//Match points of two images
MatOfDMatch matches = new MatOfDMatch();
matcher.match(descriptors1,descriptors2 ,matches);
Note that it is a quite basic image matcher. How to make it better you should investigate it according to images that you want to match. Also take a look to Good Matches method, which you can find here.