问题描述
我要检查,如果两个图像使用OpenCV的相似或没有在Java中,我使用OpenCV进行的,并使用ORB
I have to check if two images are similar or not in java using OpenCV, I am using OpenCV for that and using ORB
下面是我的主类
System.out.println("Welcome to OpenCV " + Core.VERSION);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);());
System.out.println(System.getProperty("user.dir"));
File f1 = new File(System.getProperty("user.dir") + "\\test.jpg");
File f2 = new File(System.getProperty("user.dir") + "\\test2.jpg");
MatchingDemo2 m = new MatchingDemo2();
m.mth(f1.getAbsolutePath(), f2.getAbsolutePath());
和这里是我的 MatchingDemo2.java 文件
public class MatchingDemo2 {
public void mth(String inFile, String templateFile){
FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
//Create descriptors
//first image
// generate descriptors
//second image
// generate descriptors
System.out.println("size " + matches.size());
//HOW DO I KNOW IF IMAGES MATCHED OR NOT ????
//THIS CODE IS FOR CONNECTIONS BUT I AM NOT ABLE TO DO IT
//feature and connection colors
Scalar RED = new Scalar(255,0,0);
Scalar GREEN = new Scalar(0,255,0);
//output image
Mat outputImg = new Mat();
MatOfByte drawnMatches = new MatOfByte();
//this will draw all matches, works fine
Features2d.drawMatches(img1, keypoints1, img2, keypoints2, matches,
outputImg, GREEN, RED, drawnMatches, Features2d.NOT_DRAW_SINGLE_POINTS);
int DIST_LIMIT = 80;
List<DMatch> matchList = matches.toList();
List<DMatch> matches_final = new ArrayList<DMatch>();
for(int i=0; i<matchList.size(); i++){
if(matchList.get(i).distance <= DIST_LIMIT){
matches_final.add(matches.toList().get(i));
}
}
MatOfDMatch matches_final_mat = new MatOfDMatch();
matches_final_mat.fromList(matches_final);
for(int i=0; i< matches_final.size(); i++){
System.out.println("Good Matchs "+ matches_final.get(i));
}
}
}
但是,当我检查了良好的配衬我得到这个
But when i check the Good Matchs i get this
size 1x328
Good Matchs DMatch [queryIdx=0, trainIdx=93, imgIdx=0, distance=52.0]
Good Matchs DMatch [queryIdx=1, trainIdx=173, imgIdx=0, distance=57.0]
Good Matchs DMatch [queryIdx=2, trainIdx=92, imgIdx=0, distance=53.0]
Good Matchs DMatch [queryIdx=3, trainIdx=80, imgIdx=0, distance=26.0]
Good Matchs DMatch [queryIdx=5, trainIdx=164, imgIdx=0, distance=40.0]
Good Matchs DMatch [queryIdx=6, trainIdx=228, imgIdx=0, distance=53.0]
Good Matchs DMatch [queryIdx=7, trainIdx=179, imgIdx=0, distance=14.0]
Good Matchs DMatch [queryIdx=8, trainIdx=78, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=9, trainIdx=166, imgIdx=0, distance=69.0]
Good Matchs DMatch [queryIdx=10, trainIdx=74, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=11, trainIdx=245, imgIdx=0, distance=38.0]
Good Matchs DMatch [queryIdx=12, trainIdx=120, imgIdx=0, distance=66.0]
Good Matchs DMatch [queryIdx=13, trainIdx=244, imgIdx=0, distance=41.0]
Good Matchs DMatch [queryIdx=14, trainIdx=67, imgIdx=0, distance=50.0]
Good Matchs DMatch [queryIdx=15, trainIdx=185, imgIdx=0, distance=55.0]
Good Matchs DMatch [queryIdx=16, trainIdx=97, imgIdx=0, distance=21.0]
Good Matchs DMatch [queryIdx=17, trainIdx=172, imgIdx=0, distance=67.0]
Good Matchs DMatch [queryIdx=18, trainIdx=354, imgIdx=0, distance=67.0]
Good Matchs DMatch [queryIdx=19, trainIdx=302, imgIdx=0, distance=53.0]
Good Matchs DMatch [queryIdx=20, trainIdx=176, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=21, trainIdx=60, imgIdx=0, distance=66.0]
Good Matchs DMatch [queryIdx=22, trainIdx=72, imgIdx=0, distance=62.0]
Good Matchs DMatch [queryIdx=23, trainIdx=63, imgIdx=0, distance=54.0]
Good Matchs DMatch [queryIdx=24, trainIdx=176, imgIdx=0, distance=63.0]
Good Matchs DMatch [queryIdx=25, trainIdx=49, imgIdx=0, distance=58.0]
Good Matchs DMatch [queryIdx=26, trainIdx=77, imgIdx=0, distance=52.0]
Good Matchs DMatch [queryIdx=27, trainIdx=302, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=28, trainIdx=265, imgIdx=0, distance=71.0]
Good Matchs DMatch [queryIdx=29, trainIdx=67, imgIdx=0, distance=49.0]
Good Matchs DMatch [queryIdx=30, trainIdx=302, imgIdx=0, distance=64.0]
Good Matchs DMatch [queryIdx=31, trainIdx=265, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=32, trainIdx=73, imgIdx=0, distance=73.0]
Good Matchs DMatch [queryIdx=33, trainIdx=67, imgIdx=0, distance=55.0]
Good Matchs DMatch [queryIdx=34, trainIdx=283, imgIdx=0, distance=63.0]
Good Matchs DMatch [queryIdx=35, trainIdx=145, imgIdx=0, distance=60.0]
Good Matchs DMatch [queryIdx=36, trainIdx=71, imgIdx=0, distance=54.0]
Good Matchs DMatch [queryIdx=37, trainIdx=167, imgIdx=0, distance=67.0]
Good Matchs DMatch [queryIdx=38, trainIdx=94, imgIdx=0, distance=60.0]
Good Matchs DMatch [queryIdx=39, trainIdx=88, imgIdx=0, distance=68.0]
Good Matchs DMatch [queryIdx=40, trainIdx=88, imgIdx=0, distance=69.0]
Good Matchs DMatch [queryIdx=41, trainIdx=179, imgIdx=0, distance=28.0]
Good Matchs DMatch [queryIdx=42, trainIdx=64, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=43, trainIdx=223, imgIdx=0, distance=71.0]
Good Matchs DMatch [queryIdx=44, trainIdx=80, imgIdx=0, distance=30.0]
Good Matchs DMatch [queryIdx=45, trainIdx=196, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=46, trainIdx=52, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=47, trainIdx=93, imgIdx=0, distance=60.0]
Good Matchs DMatch [queryIdx=48, trainIdx=187, imgIdx=0, distance=49.0]
Good Matchs DMatch [queryIdx=49, trainIdx=179, imgIdx=0, distance=50.0]
Good Matchs DMatch [queryIdx=50, trainIdx=283, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=51, trainIdx=171, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=52, trainIdx=302, imgIdx=0, distance=60.0]
Good Matchs DMatch [queryIdx=53, trainIdx=67, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=54, trainIdx=15, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=55, trainIdx=173, imgIdx=0, distance=66.0]
Good Matchs DMatch [queryIdx=56, trainIdx=302, imgIdx=0, distance=56.0]
Good Matchs DMatch [queryIdx=57, trainIdx=47, imgIdx=0, distance=56.0]
Good Matchs DMatch [queryIdx=58, trainIdx=187, imgIdx=0, distance=58.0]
Good Matchs DMatch [queryIdx=59, trainIdx=344, imgIdx=0, distance=64.0]
Good Matchs DMatch [queryIdx=60, trainIdx=164, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=61, trainIdx=125, imgIdx=0, distance=50.0]
Good Matchs DMatch [queryIdx=62, trainIdx=77, imgIdx=0, distance=72.0]
Good Matchs DMatch [queryIdx=63, trainIdx=22, imgIdx=0, distance=79.0]
Good Matchs DMatch [queryIdx=64, trainIdx=82, imgIdx=0, distance=69.0]
Good Matchs DMatch [queryIdx=65, trainIdx=93, imgIdx=0, distance=63.0]
Good Matchs DMatch [queryIdx=66, trainIdx=241, imgIdx=0, distance=35.0]
Good Matchs DMatch [queryIdx=67, trainIdx=80, imgIdx=0, distance=18.0]
Good Matchs DMatch [queryIdx=68, trainIdx=179, imgIdx=0, distance=20.0]
Good Matchs DMatch [queryIdx=69, trainIdx=242, imgIdx=0, distance=50.0]
Good Matchs DMatch [queryIdx=70, trainIdx=80, imgIdx=0, distance=22.0]
Good Matchs DMatch [queryIdx=71, trainIdx=179, imgIdx=0, distance=19.0]
Good Matchs DMatch [queryIdx=72, trainIdx=92, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=73, trainIdx=94, imgIdx=0, distance=56.0]
Good Matchs DMatch [queryIdx=74, trainIdx=173, imgIdx=0, distance=49.0]
Good Matchs DMatch [queryIdx=75, trainIdx=94, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=76, trainIdx=94, imgIdx=0, distance=48.0]
Good Matchs DMatch [queryIdx=77, trainIdx=92, imgIdx=0, distance=52.0]
Good Matchs DMatch [queryIdx=78, trainIdx=80, imgIdx=0, distance=20.0]
Good Matchs DMatch [queryIdx=80, trainIdx=119, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=81, trainIdx=228, imgIdx=0, distance=47.0]
Good Matchs DMatch [queryIdx=82, trainIdx=179, imgIdx=0, distance=14.0]
Good Matchs DMatch [queryIdx=83, trainIdx=227, imgIdx=0, distance=52.0]
Good Matchs DMatch [queryIdx=84, trainIdx=84, imgIdx=0, distance=57.0]
Good Matchs DMatch [queryIdx=85, trainIdx=245, imgIdx=0, distance=40.0]
Good Matchs DMatch [queryIdx=86, trainIdx=58, imgIdx=0, distance=64.0]
Good Matchs DMatch [queryIdx=87, trainIdx=14, imgIdx=0, distance=62.0]
Good Matchs DMatch [queryIdx=88, trainIdx=187, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=89, trainIdx=185, imgIdx=0, distance=57.0]
Good Matchs DMatch [queryIdx=90, trainIdx=178, imgIdx=0, distance=25.0]
Good Matchs DMatch [queryIdx=91, trainIdx=220, imgIdx=0, distance=56.0]
Good Matchs DMatch [queryIdx=92, trainIdx=205, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=93, trainIdx=60, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=94, trainIdx=44, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=95, trainIdx=16, imgIdx=0, distance=72.0]
Good Matchs DMatch [queryIdx=96, trainIdx=157, imgIdx=0, distance=63.0]
Good Matchs DMatch [queryIdx=97, trainIdx=135, imgIdx=0, distance=52.0]
Good Matchs DMatch [queryIdx=98, trainIdx=60, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=99, trainIdx=344, imgIdx=0, distance=60.0]
Good Matchs DMatch [queryIdx=100, trainIdx=77, imgIdx=0, distance=67.0]
Good Matchs DMatch [queryIdx=101, trainIdx=95, imgIdx=0, distance=76.0]
Good Matchs DMatch [queryIdx=102, trainIdx=72, imgIdx=0, distance=45.0]
Good Matchs DMatch [queryIdx=103, trainIdx=134, imgIdx=0, distance=70.0]
Good Matchs DMatch [queryIdx=104, trainIdx=154, imgIdx=0, distance=54.0]
Good Matchs DMatch [queryIdx=105, trainIdx=208, imgIdx=0, distance=77.0]
Good Matchs DMatch [queryIdx=106, trainIdx=73, imgIdx=0, distance=79.0]
Good Matchs DMatch [queryIdx=107, trainIdx=72, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=108, trainIdx=64, imgIdx=0, distance=73.0]
Good Matchs DMatch [queryIdx=109, trainIdx=72, imgIdx=0, distance=63.0]
Good Matchs DMatch [queryIdx=110, trainIdx=365, imgIdx=0, distance=66.0]
Good Matchs DMatch [queryIdx=111, trainIdx=148, imgIdx=0, distance=64.0]
Good Matchs DMatch [queryIdx=112, trainIdx=81, imgIdx=0, distance=42.0]
Good Matchs DMatch [queryIdx=113, trainIdx=56, imgIdx=0, distance=62.0]
Good Matchs DMatch [queryIdx=114, trainIdx=162, imgIdx=0, distance=48.0]
Good Matchs DMatch [queryIdx=115, trainIdx=56, imgIdx=0, distance=56.0]
Good Matchs DMatch [queryIdx=116, trainIdx=120, imgIdx=0, distance=58.0]
Good Matchs DMatch [queryIdx=117, trainIdx=72, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=118, trainIdx=92, imgIdx=0, distance=63.0]
Good Matchs DMatch [queryIdx=119, trainIdx=131, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=120, trainIdx=72, imgIdx=0, distance=46.0]
Good Matchs DMatch [queryIdx=121, trainIdx=74, imgIdx=0, distance=78.0]
Good Matchs DMatch [queryIdx=122, trainIdx=94, imgIdx=0, distance=56.0]
Good Matchs DMatch [queryIdx=123, trainIdx=72, imgIdx=0, distance=52.0]
Good Matchs DMatch [queryIdx=124, trainIdx=134, imgIdx=0, distance=71.0]
Good Matchs DMatch [queryIdx=125, trainIdx=72, imgIdx=0, distance=46.0]
Good Matchs DMatch [queryIdx=126, trainIdx=15, imgIdx=0, distance=73.0]
Good Matchs DMatch [queryIdx=127, trainIdx=72, imgIdx=0, distance=50.0]
Good Matchs DMatch [queryIdx=128, trainIdx=93, imgIdx=0, distance=56.0]
Good Matchs DMatch [queryIdx=129, trainIdx=68, imgIdx=0, distance=46.0]
Good Matchs DMatch [queryIdx=130, trainIdx=205, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=131, trainIdx=187, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=132, trainIdx=72, imgIdx=0, distance=47.0]
Good Matchs DMatch [queryIdx=133, trainIdx=220, imgIdx=0, distance=57.0]
Good Matchs DMatch [queryIdx=134, trainIdx=289, imgIdx=0, distance=60.0]
Good Matchs DMatch [queryIdx=135, trainIdx=82, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=136, trainIdx=93, imgIdx=0, distance=53.0]
Good Matchs DMatch [queryIdx=137, trainIdx=244, imgIdx=0, distance=18.0]
Good Matchs DMatch [queryIdx=138, trainIdx=244, imgIdx=0, distance=25.0]
Good Matchs DMatch [queryIdx=139, trainIdx=92, imgIdx=0, distance=66.0]
Good Matchs DMatch [queryIdx=140, trainIdx=244, imgIdx=0, distance=20.0]
Good Matchs DMatch [queryIdx=141, trainIdx=93, imgIdx=0, distance=45.0]
Good Matchs DMatch [queryIdx=142, trainIdx=93, imgIdx=0, distance=51.0]
Good Matchs DMatch [queryIdx=143, trainIdx=94, imgIdx=0, distance=51.0]
Good Matchs DMatch [queryIdx=144, trainIdx=94, imgIdx=0, distance=40.0]
Good Matchs DMatch [queryIdx=145, trainIdx=93, imgIdx=0, distance=47.0]
Good Matchs DMatch [queryIdx=146, trainIdx=244, imgIdx=0, distance=28.0]
Good Matchs DMatch [queryIdx=147, trainIdx=172, imgIdx=0, distance=77.0]
Good Matchs DMatch [queryIdx=148, trainIdx=170, imgIdx=0, distance=72.0]
Good Matchs DMatch [queryIdx=149, trainIdx=261, imgIdx=0, distance=72.0]
Good Matchs DMatch [queryIdx=150, trainIdx=228, imgIdx=0, distance=55.0]
Good Matchs DMatch [queryIdx=151, trainIdx=179, imgIdx=0, distance=19.0]
Good Matchs DMatch [queryIdx=152, trainIdx=227, imgIdx=0, distance=60.0]
Good Matchs DMatch [queryIdx=153, trainIdx=107, imgIdx=0, distance=56.0]
Good Matchs DMatch [queryIdx=154, trainIdx=174, imgIdx=0, distance=41.0]
Good Matchs DMatch [queryIdx=155, trainIdx=283, imgIdx=0, distance=76.0]
Good Matchs DMatch [queryIdx=156, trainIdx=254, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=157, trainIdx=185, imgIdx=0, distance=51.0]
Good Matchs DMatch [queryIdx=158, trainIdx=178, imgIdx=0, distance=30.0]
Good Matchs DMatch [queryIdx=159, trainIdx=278, imgIdx=0, distance=53.0]
Good Matchs DMatch [queryIdx=160, trainIdx=91, imgIdx=0, distance=62.0]
Good Matchs DMatch [queryIdx=161, trainIdx=148, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=162, trainIdx=157, imgIdx=0, distance=63.0]
Good Matchs DMatch [queryIdx=163, trainIdx=373, imgIdx=0, distance=73.0]
Good Matchs DMatch [queryIdx=164, trainIdx=226, imgIdx=0, distance=48.0]
Good Matchs DMatch [queryIdx=165, trainIdx=278, imgIdx=0, distance=64.0]
Good Matchs DMatch [queryIdx=166, trainIdx=283, imgIdx=0, distance=62.0]
Good Matchs DMatch [queryIdx=167, trainIdx=196, imgIdx=0, distance=64.0]
Good Matchs DMatch [queryIdx=168, trainIdx=344, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=169, trainIdx=157, imgIdx=0, distance=53.0]
Good Matchs DMatch [queryIdx=170, trainIdx=144, imgIdx=0, distance=79.0]
Good Matchs DMatch [queryIdx=171, trainIdx=154, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=172, trainIdx=211, imgIdx=0, distance=75.0]
Good Matchs DMatch [queryIdx=173, trainIdx=279, imgIdx=0, distance=64.0]
Good Matchs DMatch [queryIdx=174, trainIdx=211, imgIdx=0, distance=79.0]
Good Matchs DMatch [queryIdx=175, trainIdx=220, imgIdx=0, distance=68.0]
Good Matchs DMatch [queryIdx=176, trainIdx=218, imgIdx=0, distance=45.0]
Good Matchs DMatch [queryIdx=177, trainIdx=289, imgIdx=0, distance=75.0]
Good Matchs DMatch [queryIdx=178, trainIdx=223, imgIdx=0, distance=63.0]
Good Matchs DMatch [queryIdx=179, trainIdx=57, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=180, trainIdx=36, imgIdx=0, distance=73.0]
Good Matchs DMatch [queryIdx=181, trainIdx=111, imgIdx=0, distance=72.0]
Good Matchs DMatch [queryIdx=182, trainIdx=93, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=183, trainIdx=137, imgIdx=0, distance=63.0]
Good Matchs DMatch [queryIdx=184, trainIdx=157, imgIdx=0, distance=60.0]
Good Matchs DMatch [queryIdx=185, trainIdx=72, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=186, trainIdx=172, imgIdx=0, distance=47.0]
Good Matchs DMatch [queryIdx=187, trainIdx=279, imgIdx=0, distance=69.0]
Good Matchs DMatch [queryIdx=188, trainIdx=72, imgIdx=0, distance=55.0]
Good Matchs DMatch [queryIdx=189, trainIdx=96, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=190, trainIdx=220, imgIdx=0, distance=68.0]
Good Matchs DMatch [queryIdx=191, trainIdx=93, imgIdx=0, distance=48.0]
Good Matchs DMatch [queryIdx=192, trainIdx=279, imgIdx=0, distance=54.0]
Good Matchs DMatch [queryIdx=193, trainIdx=157, imgIdx=0, distance=54.0]
Good Matchs DMatch [queryIdx=194, trainIdx=91, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=195, trainIdx=278, imgIdx=0, distance=66.0]
Good Matchs DMatch [queryIdx=196, trainIdx=220, imgIdx=0, distance=57.0]
Good Matchs DMatch [queryIdx=197, trainIdx=74, imgIdx=0, distance=63.0]
Good Matchs DMatch [queryIdx=198, trainIdx=93, imgIdx=0, distance=34.0]
Good Matchs DMatch [queryIdx=199, trainIdx=81, imgIdx=0, distance=53.0]
Good Matchs DMatch [queryIdx=200, trainIdx=93, imgIdx=0, distance=45.0]
Good Matchs DMatch [queryIdx=201, trainIdx=90, imgIdx=0, distance=52.0]
Good Matchs DMatch [queryIdx=202, trainIdx=93, imgIdx=0, distance=52.0]
Good Matchs DMatch [queryIdx=203, trainIdx=94, imgIdx=0, distance=42.0]
Good Matchs DMatch [queryIdx=204, trainIdx=93, imgIdx=0, distance=35.0]
Good Matchs DMatch [queryIdx=205, trainIdx=94, imgIdx=0, distance=44.0]
Good Matchs DMatch [queryIdx=206, trainIdx=90, imgIdx=0, distance=72.0]
Good Matchs DMatch [queryIdx=207, trainIdx=179, imgIdx=0, distance=54.0]
Good Matchs DMatch [queryIdx=208, trainIdx=92, imgIdx=0, distance=48.0]
Good Matchs DMatch [queryIdx=209, trainIdx=91, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=210, trainIdx=119, imgIdx=0, distance=77.0]
Good Matchs DMatch [queryIdx=211, trainIdx=227, imgIdx=0, distance=66.0]
Good Matchs DMatch [queryIdx=212, trainIdx=186, imgIdx=0, distance=56.0]
Good Matchs DMatch [queryIdx=213, trainIdx=96, imgIdx=0, distance=69.0]
Good Matchs DMatch [queryIdx=214, trainIdx=77, imgIdx=0, distance=52.0]
Good Matchs DMatch [queryIdx=215, trainIdx=372, imgIdx=0, distance=67.0]
Good Matchs DMatch [queryIdx=216, trainIdx=334, imgIdx=0, distance=69.0]
Good Matchs DMatch [queryIdx=217, trainIdx=278, imgIdx=0, distance=67.0]
Good Matchs DMatch [queryIdx=218, trainIdx=325, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=219, trainIdx=188, imgIdx=0, distance=60.0]
Good Matchs DMatch [queryIdx=220, trainIdx=340, imgIdx=0, distance=56.0]
Good Matchs DMatch [queryIdx=221, trainIdx=72, imgIdx=0, distance=64.0]
Good Matchs DMatch [queryIdx=222, trainIdx=278, imgIdx=0, distance=69.0]
Good Matchs DMatch [queryIdx=223, trainIdx=221, imgIdx=0, distance=72.0]
Good Matchs DMatch [queryIdx=224, trainIdx=339, imgIdx=0, distance=74.0]
Good Matchs DMatch [queryIdx=225, trainIdx=155, imgIdx=0, distance=66.0]
Good Matchs DMatch [queryIdx=226, trainIdx=278, imgIdx=0, distance=56.0]
Good Matchs DMatch [queryIdx=227, trainIdx=165, imgIdx=0, distance=78.0]
Good Matchs DMatch [queryIdx=228, trainIdx=279, imgIdx=0, distance=71.0]
Good Matchs DMatch [queryIdx=229, trainIdx=355, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=231, trainIdx=69, imgIdx=0, distance=80.0]
Good Matchs DMatch [queryIdx=232, trainIdx=278, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=233, trainIdx=65, imgIdx=0, distance=71.0]
Good Matchs DMatch [queryIdx=234, trainIdx=93, imgIdx=0, distance=79.0]
Good Matchs DMatch [queryIdx=235, trainIdx=203, imgIdx=0, distance=78.0]
Good Matchs DMatch [queryIdx=236, trainIdx=159, imgIdx=0, distance=70.0]
Good Matchs DMatch [queryIdx=237, trainIdx=93, imgIdx=0, distance=45.0]
Good Matchs DMatch [queryIdx=238, trainIdx=172, imgIdx=0, distance=58.0]
Good Matchs DMatch [queryIdx=239, trainIdx=374, imgIdx=0, distance=67.0]
Good Matchs DMatch [queryIdx=240, trainIdx=278, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=241, trainIdx=223, imgIdx=0, distance=55.0]
Good Matchs DMatch [queryIdx=242, trainIdx=365, imgIdx=0, distance=58.0]
Good Matchs DMatch [queryIdx=243, trainIdx=91, imgIdx=0, distance=62.0]
Good Matchs DMatch [queryIdx=244, trainIdx=238, imgIdx=0, distance=57.0]
Good Matchs DMatch [queryIdx=245, trainIdx=299, imgIdx=0, distance=62.0]
Good Matchs DMatch [queryIdx=246, trainIdx=289, imgIdx=0, distance=63.0]
Good Matchs DMatch [queryIdx=247, trainIdx=93, imgIdx=0, distance=41.0]
Good Matchs DMatch [queryIdx=249, trainIdx=5, imgIdx=0, distance=56.0]
Good Matchs DMatch [queryIdx=250, trainIdx=93, imgIdx=0, distance=53.0]
Good Matchs DMatch [queryIdx=251, trainIdx=93, imgIdx=0, distance=34.0]
Good Matchs DMatch [queryIdx=252, trainIdx=97, imgIdx=0, distance=34.0]
Good Matchs DMatch [queryIdx=253, trainIdx=93, imgIdx=0, distance=37.0]
Good Matchs DMatch [queryIdx=254, trainIdx=174, imgIdx=0, distance=55.0]
Good Matchs DMatch [queryIdx=255, trainIdx=91, imgIdx=0, distance=72.0]
Good Matchs DMatch [queryIdx=256, trainIdx=81, imgIdx=0, distance=59.0]
Good Matchs DMatch [queryIdx=257, trainIdx=92, imgIdx=0, distance=57.0]
Good Matchs DMatch [queryIdx=258, trainIdx=212, imgIdx=0, distance=76.0]
Good Matchs DMatch [queryIdx=259, trainIdx=119, imgIdx=0, distance=67.0]
Good Matchs DMatch [queryIdx=260, trainIdx=228, imgIdx=0, distance=73.0]
Good Matchs DMatch [queryIdx=261, trainIdx=119, imgIdx=0, distance=68.0]
Good Matchs DMatch [queryIdx=263, trainIdx=266, imgIdx=0, distance=74.0]
Good Matchs DMatch [queryIdx=264, trainIdx=319, imgIdx=0, distance=72.0]
Good Matchs DMatch [queryIdx=265, trainIdx=157, imgIdx=0, distance=76.0]
Good Matchs DMatch [queryIdx=266, trainIdx=365, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=267, trainIdx=341, imgIdx=0, distance=76.0]
Good Matchs DMatch [queryIdx=268, trainIdx=303, imgIdx=0, distance=63.0]
Good Matchs DMatch [queryIdx=269, trainIdx=313, imgIdx=0, distance=69.0]
Good Matchs DMatch [queryIdx=271, trainIdx=350, imgIdx=0, distance=62.0]
Good Matchs DMatch [queryIdx=272, trainIdx=313, imgIdx=0, distance=68.0]
Good Matchs DMatch [queryIdx=278, trainIdx=267, imgIdx=0, distance=69.0]
Good Matchs DMatch [queryIdx=280, trainIdx=223, imgIdx=0, distance=71.0]
Good Matchs DMatch [queryIdx=281, trainIdx=267, imgIdx=0, distance=71.0]
Good Matchs DMatch [queryIdx=283, trainIdx=334, imgIdx=0, distance=72.0]
Good Matchs DMatch [queryIdx=284, trainIdx=313, imgIdx=0, distance=63.0]
Good Matchs DMatch [queryIdx=285, trainIdx=78, imgIdx=0, distance=76.0]
Good Matchs DMatch [queryIdx=286, trainIdx=312, imgIdx=0, distance=73.0]
Good Matchs DMatch [queryIdx=287, trainIdx=271, imgIdx=0, distance=68.0]
Good Matchs DMatch [queryIdx=288, trainIdx=170, imgIdx=0, distance=64.0]
Good Matchs DMatch [queryIdx=289, trainIdx=278, imgIdx=0, distance=64.0]
Good Matchs DMatch [queryIdx=290, trainIdx=282, imgIdx=0, distance=70.0]
Good Matchs DMatch [queryIdx=291, trainIdx=91, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=292, trainIdx=334, imgIdx=0, distance=67.0]
Good Matchs DMatch [queryIdx=293, trainIdx=80, imgIdx=0, distance=72.0]
Good Matchs DMatch [queryIdx=294, trainIdx=92, imgIdx=0, distance=47.0]
Good Matchs DMatch [queryIdx=295, trainIdx=301, imgIdx=0, distance=44.0]
Good Matchs DMatch [queryIdx=297, trainIdx=220, imgIdx=0, distance=78.0]
Good Matchs DMatch [queryIdx=298, trainIdx=374, imgIdx=0, distance=76.0]
Good Matchs DMatch [queryIdx=300, trainIdx=329, imgIdx=0, distance=74.0]
Good Matchs DMatch [queryIdx=302, trainIdx=285, imgIdx=0, distance=77.0]
Good Matchs DMatch [queryIdx=305, trainIdx=271, imgIdx=0, distance=80.0]
Good Matchs DMatch [queryIdx=307, trainIdx=350, imgIdx=0, distance=76.0]
Good Matchs DMatch [queryIdx=308, trainIdx=320, imgIdx=0, distance=71.0]
Good Matchs DMatch [queryIdx=309, trainIdx=163, imgIdx=0, distance=76.0]
Good Matchs DMatch [queryIdx=310, trainIdx=170, imgIdx=0, distance=73.0]
Good Matchs DMatch [queryIdx=311, trainIdx=357, imgIdx=0, distance=65.0]
Good Matchs DMatch [queryIdx=312, trainIdx=320, imgIdx=0, distance=62.0]
Good Matchs DMatch [queryIdx=314, trainIdx=342, imgIdx=0, distance=75.0]
Good Matchs DMatch [queryIdx=315, trainIdx=162, imgIdx=0, distance=72.0]
Good Matchs DMatch [queryIdx=316, trainIdx=239, imgIdx=0, distance=74.0]
Good Matchs DMatch [queryIdx=317, trainIdx=171, imgIdx=0, distance=56.0]
Good Matchs DMatch [queryIdx=318, trainIdx=244, imgIdx=0, distance=61.0]
Good Matchs DMatch [queryIdx=319, trainIdx=369, imgIdx=0, distance=77.0]
Good Matchs DMatch [queryIdx=320, trainIdx=346, imgIdx=0, distance=67.0]
Good Matchs DMatch [queryIdx=322, trainIdx=158, imgIdx=0, distance=78.0]
Good Matchs DMatch [queryIdx=325, trainIdx=92, imgIdx=0, distance=73.0]
Good Matchs DMatch [queryIdx=326, trainIdx=236, imgIdx=0, distance=76.0]
Good Matchs DMatch [queryIdx=327, trainIdx=162, imgIdx=0, distance=70.0]
这是我得到匹配的数量是相同的相同的图像,以及针对不同的图像我真的很困惑?你能解释这个现象如何比较两个图像,并告诉他们是否相似或不使用的OpenCV
The number of matches that i get is same for the same image as well as for different imagesI am really confused ? Can you one explain how to compare two images and tell if they are similar or not using OpenCV
这里有所,我想实现
推荐答案
由于使用暴力破解匹配器,你总是会得到从您的查询(模板)中的所有关键点的描述最好的匹配在您的火车(图像包含查询) 。即:猜解匹配总会找到100%的匹配(相当于最关键点在火车描述所有查询关键点描述符)
Since you are using BRUTEFORCE matcher you will always get best possible matches for all the keypoint descriptors from your query(template) in your train(image that contains query).i.e: BRUTEFORCE matcher will always find 100% matches(best equivalent keypoints for all query keypoint descriptors in train descriptors).
这意味着你需要过滤的匹配,而正确的匹配(围层)和不正确的匹配(异常值)相匹配。
This means you need to filter the matches as correct matches(inliers) and incorrect matches(outliers) matches.
您可以通过两种方式做到这一点
You can do it in two ways
1.Distance计算
使用距离所提到的安德烈Smorodov。您可以使用此方法(但这并不总能提供正确的结果)
Using distance as mentioned by Andrey Smorodov. You can use this method(But this does not always provide correct results)
List<DMatch> matchesList = matches.toList();
Double max_dist = 0.0;
Double min_dist = 100.0;
for (int i = 0; i < matchesList.size(); i++) {
Double dist = (double) matchesList.get(i).distance;
if (dist < min_dist)
min_dist = dist;
if (dist > max_dist)
max_dist = dist;
}
LinkedList<DMatch> good_matches = new LinkedList<DMatch>();
for (int i = 0; i < matchesList.size(); i++) {
if (matchesList.get(i).distance <= (3 * min_dist)) // change the limit as you desire
good_matches.addLast(matchesList.get(i));
}
2.Determine面膜
您可以使用findHomography来获得,它可以让你找到的围层和异常清楚(因为它认为考虑到相机的姿势角度来看,这几乎是正确的),掩模
You can use the findHomography to get the mask which lets you find the inliers and outliers clearly(Since it considers into account camera pose perspective it is almost correct)
LinkedList<Point> objList = new LinkedList<Point>();
LinkedList<Point> sceneList = new LinkedList<Point>();
List<KeyPoint> keypoints_RefList = keypointsRef.toList();
List<KeyPoint> keypoints_List = keypoints.toList();
for (int i = 0; i < good_matches.size(); i++) {
objList.addLast(keypoints_RefList.get(good_matches.get(i).queryIdx).pt);
sceneList.addLast(keypoints_List.get(good_matches.get(i).trainIdx).pt);
}
MatOfPoint2f obj = new MatOfPoint2f();
MatOfPoint2f scene = new MatOfPoint2f();
obj.fromList(objList);
scene.fromList(sceneList);
Mat mask = new Mat();
Mat hg = Calib3d.findHomography(obj, scene, 8, 10, mask);
现在的面具是一个可选的输出findHomography这是每个对每场比赛的1或0值的数组。对于相应的匹配掩码值 1,如果它是一个英利尔山区和 0,如果它是一个异常值
Now the mask is an optional output in findHomography which is a array of either 1 or 0 value each for every match.The mask value for corresponding match is 1 if it is an inlier and 0 if it is an outlier.
您可以使用它作为一个标准来确定是否有面具的近90%为1,那么你可以有输出是真实的。
You may use this as a criteria to decide if you have almost 90% of mask to be 1 then you can have the output to be true.
我在识别特定对象从Android的Java的摄像头边框使用它,并得到了这些日志结果
I use it in recognizing specific objects from android java camera frame and got these log results
08-22 01:08:38.929: I/OCVSample::Activity(25799): Keypoints Size: 1x477 KeypointsRef Size : 1x165
08-22 01:08:39.049: I/OCVSample::Activity(25799): descriptor Size: 32x477 descriptorRef Size : 32x165
08-22 01:08:39.129: I/OCVSample::Activity(25799): Matches Size: 1x165
08-22 01:08:39.129: I/OCVSample::Activity(25799): matchesList Size: 165
08-22 01:08:39.139: I/OCVSample::Activity(25799): Max dist : 460.44110107421875 Min dist : 100.0
08-22 01:08:39.139: I/OCVSample::Activity(25799): good matches size: 19
08-22 01:08:39.139: I/OCVSample::Activity(25799): obj size : 1x165
08-22 01:08:39.139: I/OCVSample::Activity(25799): scene size : 1x165
08-22 01:08:40.239: I/OCVSample::Activity(25799): Homography mask size : 1x165
08-22 01:08:40.239: I/OCVSample::Activity(25799): Homography mask : [1; 1; 1; 1; 1; 1; 1; 0; 1; 0; 1; 1; 1; 1; 0; 1; 1; 1; 0; 1; 1; 1; 1; 0; 1; 0; 1; 1; 1; 1; 1; 1; 0; 0; 1; 1; 1; 1; 0; 1; 0; 1; 1; 1; 1; 1; 0; 1; 1; 1; 1; 1; 1; 1; 0; 1; 1; 0; 1; 0; 1; 0; 0; 1; 0; 1; 1; 1; 1; 1; 1; 1; 0; 1; 1; 1; 1; 1; 0; 1; 1; 1; 1; 0; 0; 1; 1; 0; 1; 1; 1; 1; 0; 1; 0; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 1; 0; 1; 1; 1; 1; 0; 0; 0; 1; 0; 1; 1; 1; 1; 0; 0; 1; 1; 1; 1; 1; 0; 1; 0; 1; 1; 0; 1; 0; 1; 1; 1; 1; 1; 1; 0; 1; 1; 0; 1; 1; 1; 1; 0; 1; 1; 1; 1; 1; 1; 1; 0; 1; 1; 0; 0; 1; 1]
3 还有一种简单的方法是比较这两个图像的直方图这一点,你可以使用 compHist(); 如图所示的OpenCV功能的同时也参考OpenCV的文件。
3. Yet another simpler approach would be comparing the histogram of those two images for this you can use compHist(); function of openCV as shown hereand also refer openCV documents.
各种方法使输出范围从0到1或更高的值,这个输出取决于直方图之间的相似性。小心一些方法1在其他一些方法,100%的匹配和0。对于卡方法低分重新presents一个比一个高的分数更好的匹配。一场完美的比赛为0,总失配是无界(取决于直方图的大小)。
Various methods in compare histogram gives output range from 0 to 1 or higher value, this output depends on similarity between histograms. Careful in some methods 1 is 100% positive match and 0 in some other method."For chi-square method a low score represents a better match than a high score. A perfect match is 0 and a total mismatch is unbounded (depending on the size of the histogram)."
余: - 两个完全不同的图像可以有完全相同的直方图值
Remainder:- Two completely different images can have exactly the same histogram value.
提示:
1.Now关于knnMatch只需使用matcher.knnMatch();及相应的数据类型为输出
1.Now regarding knnMatch just use matcher.knnMatch(); and the appropriate datatypes for output.
2.Also在
matcher.match(query, train, matches);
查询=>关键点描述符的模板,例如。一个球和
the query => keypoint descriptors for template-eg. a ball and
火车=>关键点描述符的图像包含相同的球吧。无查询描述符的小于没有列车描述符确保你得到这个权利。
the train => keypoint descriptor for image that contains the same ball in it.The no of query descriptor is less than no of train descriptor make sure you get this right.
现在的好运气。
这篇关于如何检查是否两个图像相似或不使用OpenCV的在Java中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!