OpenCV_FindTransformECC.java
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.TermCriteria;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.video.Video;
public class OpenCV_FindTransformECC {
static{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); }
public static void main(String[] args) {
Mat templste = Imgcodecs.imread("D:\\projects\\Java\\OpenCV_Samples\\resource\\imgs\\DSC_0675.jpg ",Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
Mat needToBeAdjusted = Imgcodecs.imread("D:\\projects\\Java\\OpenCV_Samples\\resource\\imgs\\DSC_0663.jpg ",Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
//Définition de la matrice de déformation du modèle de mouvement
Mat warp_matrix2=Mat.eye(2, 3, CvType.CV_32F);
int maxIterations=5000;
Mat mask=new Mat();
//Arithmétique ECC appliquée. Résultat Matrice de chaîne résiduelle
Video.findTransformECC(templste, needToBeAdjusted, warp_matrix2,Video.MOTION_EUCLIDEAN,new TermCriteria(TermCriteria.COUNT | TermCriteria.EPS, maxIterations, 1E-10),mask);
Mat aligned=new Mat();
//for Euclidean and Affine
Imgproc.warpAffine(needToBeAdjusted, aligned, warp_matrix2, templste.size(),Imgproc.INTER_LINEAR+Imgproc.WARP_INVERSE_MAP);
Imgcodecs.imwrite("D:\\projects\\Java\\OpenCV_Samples\\resource\\imgs\\findTransformECC2.jpg ",aligned);
}
}
Recommended Posts