Created
December 2, 2015 15:03
-
-
Save retrozoid/db132381d0e1befd532e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws Exception { | |
opencv_core.IplImage src = cvLoadImage("src.jpg", 0); | |
opencv_core.IplImage tmp = cvLoadImage("tmp.png", 0); | |
opencv_core.IplImage result = cvCreateImage(cvSize(src.width() - tmp.width() + 1, src.height() - tmp.height() + 1), IPL_DEPTH_32F, src.nChannels()); | |
cvZero(result); | |
// Match Template Function from OpenCV | |
cvMatchTemplate(src, tmp, result, opencv_imgproc.CV_TM_CCORR_NORMED); | |
// DoublePointer min_val_o = new DoublePointer(); | |
// DoublePointer max_val_o = new DoublePointer(); | |
double[] min_val = new double[2]; | |
double[] max_val = new double[2]; | |
opencv_core.CvPoint minLoc = new opencv_core.CvPoint(); | |
opencv_core.CvPoint maxLoc = new opencv_core.CvPoint(); | |
cvMinMaxLoc(result, null, null, minLoc, maxLoc, null); | |
cvMinMaxLoc(result, min_val, max_val); | |
Log.w(result.toString()); | |
Log.w("MIN=" + min_val[0]); | |
Log.w("MAX=" + max_val[0]); | |
// | |
// Get the Max or Min Correlation Value | |
// System.out.println(Arrays.toString(min_val)); | |
// System.out.println(Arrays.toString(max_val)); | |
opencv_core.CvPoint point = new opencv_core.CvPoint(); | |
point.x(maxLoc.x() + tmp.width()); | |
point.y(maxLoc.y() + tmp.height()); | |
// cvMinMaxLoc(src, min_val, max_val,0,0,result); | |
cvRectangle(src, maxLoc, point, opencv_core.CvScalar.RED, 2, 8, 0); // Draw a | |
// // Rectangle for | |
// // Matched | |
// // Region | |
// opencv_core.CvRect rect = new opencv_core.CvRect(); | |
// rect.x(maxLoc.x()); | |
// rect.y(maxLoc.y()); | |
// rect.width(tmp.width() + width); | |
// rect.height(tmp.width() + height); | |
// cvSetImageROI(src, rect); | |
IplImage imageNew = cvCreateImage(cvGetSize(src), src.depth(), src.nChannels()); | |
cvCopy(src, imageNew); | |
cvSaveImage("res.png", imageNew); | |
cvReleaseImage(src); | |
cvReleaseImage(tmp); | |
cvReleaseImage(result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment