package openCV;


import java.util.Arrays;


import org.bytedeco.javacpp.DoublePointer;

import org.bytedeco.javacpp.opencv_core.IplImage;

import org.opencv.core.Core;

import org.opencv.core.Core.MinMaxLocResult;


import com.googlecode.javacv.cpp.opencv_highgui.CvTrackbarCallback;

import com.googlecode.javacv.cpp.opencv_legacy.CvCallback;


//필수 4개 임포트

import static org.bytedeco.javacpp.opencv_imgproc.*;

import static org.bytedeco.javacpp.opencv_highgui.*;

import static org.bytedeco.javacpp.opencv_imgcodecs.*;

import static org.bytedeco.javacpp.opencv_core.*;


public class template {


public double imageAnalysis(String originPath, String tmpPath) {

// TODO Auto-generated method stub


IplImage src = cvLoadImage(originPath);

IplImage tmp = cvLoadImage(tmpPath);

int width = src.width();

int height = src.height();

IplImage result = cvCreateImage(cvSize(src.width() - tmp.width() + 1, src.height() - tmp.height() + 1),

IPL_DEPTH_32F, 1);

cvZero(result);


// Match Template Function from OpenCV

cvMatchTemplate(src, tmp, result, CV_TM_CCOEFF_NORMED);

DoublePointer min_val = new DoublePointer(1);

DoublePointer max_val = new DoublePointer(1);


CvPoint minLoc = new CvPoint();

CvPoint maxLoc = new CvPoint();


// Get the Max or Min Correlation Value

cvMinMaxLoc(result, min_val, max_val, minLoc, maxLoc, null);


CvPoint point = new CvPoint();

point.x(maxLoc.x() + tmp.width());

point.y(maxLoc.y() + tmp.height());


if (max_val.get() < 0.7) {

// System.out.println("정확히 일치하는 이미지가없습니다.");

// hk.keyPresss();0000000000

} else {

cvRectangle(src, maxLoc, point, CvScalar.RED, 4, 8, 0);// Draw


// hk.mouseMove((maxLoc.x() + tmp.width()/2), (maxLoc.y() + tmp.height()/2));

// a

// Rectanglea

// for

// Matched4

// Region4


}


// CvRect rect = new CvRect();

// rect.x(maxLoc.x());

// rect.y(maxLoc.y());

// rect.width(tmp.width());

// rect.height(tmp.height());

// cvSetImageROI(src, rect);

// IplImage imageNew = cvCreateImage(cvGetSize(src),

// src.depth(),

// src.nChannels());

// cvCopy(src, imageNew);

// cvSaveImage("C:\\Users\\kk\\Pictures\\3.png", imageNew);

cvShowImage("Lena Image", src);

cvWaitKey(0);


cvReleaseImage(src);

cvReleaseImage(tmp);

cvReleaseImage(result);

return max_val.get();

}

}



'JAVA > 자바CV' 카테고리의 다른 글

자바CV 다운주소  (0) 2016.03.13
자바CV 필수 임포트  (0) 2016.03.12
블로그 이미지

왕왕왕왕

,