OpenCV--笔记
package com.bobonew.util;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import javax.imageio.ImageIO;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfFloat;
import org.opencv.core.MatOfInt;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.Imgproc;
import org.opencv.objdetect.CascadeClassifier;
/**
* opencv图像识别
*
* @author czz
* @data 2017年3月22日 下午3:35:36
*/
public class OpencvUtil {
public static void main(String[] args) {
String img1 = "C:/Users/weixj/Desktop/compare1_1.jpg";
String img2 = "C:/Users/weixj/Desktop/compare1_2.jpg";
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
Date d = new Date();
String str = sdf.format(d);
String outFilepath = "D:/" + str + ".jpg";
// grayscaleImage(img1, outFilepath, "jpg");
// thresholdImage(img1, outFilepath);
// watermarkImage(img1, outFilepath);
// detectFace(img1, outFilepath);
comPareHist(img1, img2);
comPareHist_1(img1, img2);
}
/**
* 图像相似比对
*
* @param srcimg
* @param desimg
*/
public static void comPareHist(String srcimg, String desimg) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat srcMat = Highgui.imread(srcimg);
Mat desMat = Highgui.imread(desimg);
Mat hist0 = new Mat();
Mat hist1 = new Mat();
int hist_bins = 30; // number of histogram bins
int hist_range[] = { 0