org.opencv.features2d.DMatch Java Examples

The following examples show how to use org.opencv.features2d.DMatch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Converters.java    From marvel with MIT License 5 votes vote down vote up
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
    if (matches == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_64FC4 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_64FC4 != m.type() ||  m.cols()!=1\n" + m);

    matches.clear();
    double[] buff = new double[4 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3]));
    }
}
 
Example #2
Source File: Converters.java    From ResistorScanner with MIT License 5 votes vote down vote up
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
    if (matches == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_64FC4 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_64FC4 != m.type() ||  m.cols()!=1\n" + m);

    matches.clear();
    double[] buff = new double[4 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3]));
    }
}
 
Example #3
Source File: MatOfDMatch.java    From ResistorScanner with MIT License 5 votes vote down vote up
public void fromArray(DMatch...a) {
    if(a==null || a.length==0)
        return;
    int num = a.length;
    alloc(num);
    float buff[] = new float[num * _channels];
    for(int i=0; i<num; i++) {
        DMatch m = a[i];
        buff[_channels*i+0] = m.queryIdx;
        buff[_channels*i+1] = m.trainIdx;
        buff[_channels*i+2] = m.imgIdx;
        buff[_channels*i+3] = m.distance;
    }
    put(0, 0, buff); //TODO: check ret val!
}
 
Example #4
Source File: MatOfDMatch.java    From Android-Car-duino with GNU General Public License v2.0 5 votes vote down vote up
public DMatch[] toArray() {
    int num = (int) total();
    DMatch[] a = new DMatch[num];
    if(num == 0)
        return a;
    float buff[] = new float[num * _channels];
    get(0, 0, buff); //TODO: check ret val!
    for(int i=0; i<num; i++)
        a[i] = new DMatch((int) buff[_channels*i+0], (int) buff[_channels*i+1], (int) buff[_channels*i+2], buff[_channels*i+3]);
    return a;
}
 
Example #5
Source File: MatOfDMatch.java    From Android-Car-duino with GNU General Public License v2.0 5 votes vote down vote up
public void fromArray(DMatch...a) {
    if(a==null || a.length==0)
        return;
    int num = a.length;
    alloc(num);
    float buff[] = new float[num * _channels];
    for(int i=0; i<num; i++) {
        DMatch m = a[i];
        buff[_channels*i+0] = m.queryIdx;
        buff[_channels*i+1] = m.trainIdx;
        buff[_channels*i+2] = m.imgIdx;
        buff[_channels*i+3] = m.distance;
    }
    put(0, 0, buff); //TODO: check ret val!
}
 
Example #6
Source File: MatOfDMatch.java    From ResistorScanner with MIT License 5 votes vote down vote up
public DMatch[] toArray() {
    int num = (int) total();
    DMatch[] a = new DMatch[num];
    if(num == 0)
        return a;
    float buff[] = new float[num * _channels];
    get(0, 0, buff); //TODO: check ret val!
    for(int i=0; i<num; i++)
        a[i] = new DMatch((int) buff[_channels*i+0], (int) buff[_channels*i+1], (int) buff[_channels*i+2], buff[_channels*i+3]);
    return a;
}
 
Example #7
Source File: Converters.java    From Android-Car-duino with GNU General Public License v2.0 5 votes vote down vote up
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
    if (matches == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_64FC4 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_64FC4 != m.type() ||  m.cols()!=1\n" + m);

    matches.clear();
    double[] buff = new double[4 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3]));
    }
}
 
Example #8
Source File: MatOfDMatch.java    From marvel with MIT License 5 votes vote down vote up
public DMatch[] toArray() {
    int num = (int) total();
    DMatch[] a = new DMatch[num];
    if(num == 0)
        return a;
    float buff[] = new float[num * _channels];
    get(0, 0, buff); //TODO: check ret val!
    for(int i=0; i<num; i++)
        a[i] = new DMatch((int) buff[_channels*i+0], (int) buff[_channels*i+1], (int) buff[_channels*i+2], buff[_channels*i+3]);
    return a;
}
 
Example #9
Source File: MatOfDMatch.java    From marvel with MIT License 5 votes vote down vote up
public void fromArray(DMatch...a) {
    if(a==null || a.length==0)
        return;
    int num = a.length;
    alloc(num);
    float buff[] = new float[num * _channels];
    for(int i=0; i<num; i++) {
        DMatch m = a[i];
        buff[_channels*i+0] = m.queryIdx;
        buff[_channels*i+1] = m.trainIdx;
        buff[_channels*i+2] = m.imgIdx;
        buff[_channels*i+3] = m.distance;
    }
    put(0, 0, buff); //TODO: check ret val!
}
 
Example #10
Source File: PartialMatcher.java    From StormCV with Apache License 2.0 5 votes vote down vote up
@Override
public List<Frame> execute(CVParticle particle) throws Exception {
	List<Frame> result = new ArrayList<Frame>();
	Frame frame = null;
	Mat frameDescriptor = null;
	if(particle instanceof Frame) {
		frame = (Frame)particle;
		if(frame.getImageType().equals(Frame.NO_IMAGE)) return result;
		frameDescriptor = this.calculateDescriptors(frame.getImageBytes());
	}else if(particle instanceof Feature){
		Feature feature = (Feature)particle;
		frameDescriptor = this.feature2Mat(feature);
		frame = new Frame(feature.getStreamId(), feature.getSequenceNr(), Frame.NO_IMAGE, new byte[]{}, 0, new Rectangle(0,0,0,0));
	}else return result;
	
	result.add(frame);
	
	
	List<MatOfDMatch> mm = new ArrayList<MatOfDMatch>();
	matcher.knnMatch( frameDescriptor, mm, 2 );
	HashMap<Integer, MutableInt> idCount = new HashMap<Integer, MutableInt>();
	for ( int i = 0; i < mm.size(); i++ ){
		DMatch dmatches[] = mm.get(i).toArray();
		if ( dmatches[0].distance < minStrongMatchDist * dmatches[1].distance ){
			MutableInt mi = idCount.get(dmatches[0].imgIdx);
			if(mi == null) idCount.put(dmatches[0].imgIdx, new MutableInt());
			else mi.incr();
		}
	}

	String matchStr = new String();
	for(int id : idCount.keySet()){
		if(idCount.get(id).get() >= minStrongMatches){
			matchStr += "\""+prototypes.get(id)+"\":"+idCount.get(id).get()+";";
		}
	}
	frame.getMetadata().put("strong_matches", matchStr);
	
	return result;
}
 
Example #11
Source File: FeatureMatcherOp.java    From StormCV with Apache License 2.0 5 votes vote down vote up
@Override
public List<Frame> execute(CVParticle particle) throws Exception {
	List<Frame> result = new ArrayList<Frame>();
	if(!(particle instanceof Frame)) return result;
	
	Frame frame = (Frame)particle;
	if(frame.getImageType().equals(Frame.NO_IMAGE)) return result;
	
	Mat frameDescriptor = this.calculateDescriptors(frame.getImageBytes());
	for(Mat proto : prototypes.keySet()){
		
		int strongMatches = 0;
		List<MatOfDMatch> matches = new ArrayList<MatOfDMatch>();
		matcher.knnMatch( frameDescriptor, proto, matches, 2 );
		for ( int i = 0; i < matches.size(); i++ ){
			DMatch dmatches[] = matches.get(i).toArray();
			if ( dmatches[0].distance < minStrongMatchDist * dmatches[1].distance ){
				strongMatches++;
			}
		}
		
		if(strongMatches >= minStrongMatches){
			if(!frame.getMetadata().containsKey("strong_matches")){
				frame.getMetadata().put("strong_matches", new String());
			}
			String value = (String)frame.getMetadata().get("strong_matches");
			value +=  prototypes.get(proto)+"("+strongMatches+"), ";
			frame.getMetadata().put("strong_matches", value);
			if(result.size() == 0) result.add(frame);
		}
	}
	return result;
}
 
Example #12
Source File: Converters.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
    if (matches == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_64FC4 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_64FC4 != m.type() ||  m.cols()!=1\n" + m);

    matches.clear();
    double[] buff = new double[4 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3]));
    }
}
 
Example #13
Source File: MatOfDMatch.java    From android-object-distance with Apache License 2.0 5 votes vote down vote up
public DMatch[] toArray() {
    int num = (int) total();
    DMatch[] a = new DMatch[num];
    if(num == 0)
        return a;
    float buff[] = new float[num * _channels];
    get(0, 0, buff); //TODO: check ret val!
    for(int i=0; i<num; i++)
        a[i] = new DMatch((int) buff[_channels*i+0], (int) buff[_channels*i+1], (int) buff[_channels*i+2], buff[_channels*i+3]);
    return a;
}
 
Example #14
Source File: MatOfDMatch.java    From android-object-distance with Apache License 2.0 5 votes vote down vote up
public void fromArray(DMatch...a) {
    if(a==null || a.length==0)
        return;
    int num = a.length;
    alloc(num);
    float buff[] = new float[num * _channels];
    for(int i=0; i<num; i++) {
        DMatch m = a[i];
        buff[_channels*i+0] = m.queryIdx;
        buff[_channels*i+1] = m.trainIdx;
        buff[_channels*i+2] = m.imgIdx;
        buff[_channels*i+3] = m.distance;
    }
    put(0, 0, buff); //TODO: check ret val!
}
 
Example #15
Source File: Converters.java    From android-object-distance with Apache License 2.0 5 votes vote down vote up
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
    if (matches == null)
        throw new IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_64FC4 != m.type() || m.cols() != 1)
        throw new IllegalArgumentException(
                "CvType.CV_64FC4 != m.type() ||  m.cols()!=1\n" + m);

    matches.clear();
    double[] buff = new double[4 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3]));
    }
}
 
Example #16
Source File: MatOfDMatch.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
public void fromArray(DMatch...a) {
    if(a==null || a.length==0)
        return;
    int num = a.length;
    alloc(num);
    float buff[] = new float[num * _channels];
    for(int i=0; i<num; i++) {
        DMatch m = a[i];
        buff[_channels*i+0] = m.queryIdx;
        buff[_channels*i+1] = m.trainIdx;
        buff[_channels*i+2] = m.imgIdx;
        buff[_channels*i+3] = m.distance;
    }
    put(0, 0, buff); //TODO: check ret val!
}
 
Example #17
Source File: MatOfDMatch.java    From effective_android_sample with Apache License 2.0 5 votes vote down vote up
public DMatch[] toArray() {
    int num = (int) total();
    DMatch[] a = new DMatch[num];
    if(num == 0)
        return a;
    float buff[] = new float[num * _channels];
    get(0, 0, buff); //TODO: check ret val!
    for(int i=0; i<num; i++)
        a[i] = new DMatch((int) buff[_channels*i+0], (int) buff[_channels*i+1], (int) buff[_channels*i+2], buff[_channels*i+3]);
    return a;
}
 
Example #18
Source File: MatOfDMatch.java    From SoftwarePilot with MIT License 5 votes vote down vote up
public DMatch[] toArray() {
    int num = (int) total();
    DMatch[] a = new DMatch[num];
    if(num == 0)
        return a;
    float buff[] = new float[num * _channels];
    get(0, 0, buff); //TODO: check ret val!
    for(int i=0; i<num; i++)
        a[i] = new DMatch((int) buff[_channels*i+0], (int) buff[_channels*i+1], (int) buff[_channels*i+2], buff[_channels*i+3]);
    return a;
}
 
Example #19
Source File: MatOfDMatch.java    From SoftwarePilot with MIT License 5 votes vote down vote up
public void fromArray(DMatch...a) {
    if(a==null || a.length==0)
        return;
    int num = a.length;
    alloc(num);
    float buff[] = new float[num * _channels];
    for(int i=0; i<num; i++) {
        DMatch m = a[i];
        buff[_channels*i+0] = m.queryIdx;
        buff[_channels*i+1] = m.trainIdx;
        buff[_channels*i+2] = m.imgIdx;
        buff[_channels*i+3] = m.distance;
    }
    put(0, 0, buff); //TODO: check ret val!
}
 
Example #20
Source File: Converters.java    From SoftwarePilot with MIT License 5 votes vote down vote up
public static void Mat_to_vector_DMatch(Mat m, List<DMatch> matches) {
    if (matches == null)
        throw new java.lang.IllegalArgumentException("Output List can't be null");
    int count = m.rows();
    if (CvType.CV_64FC4 != m.type() || m.cols() != 1)
        throw new java.lang.IllegalArgumentException(
                "CvType.CV_64FC4 != m.type() ||  m.cols()!=1\n" + m);

    matches.clear();
    double[] buff = new double[4 * count];
    m.get(0, 0, buff);
    for (int i = 0; i < count; i++) {
        matches.add(new DMatch((int) buff[4 * i], (int) buff[4 * i + 1], (int) buff[4 * i + 2], (float) buff[4 * i + 3]));
    }
}
 
Example #21
Source File: MatOfDMatch.java    From effective_android_sample with Apache License 2.0 4 votes vote down vote up
public List<DMatch> toList() {
    DMatch[] adm = toArray();
    return Arrays.asList(adm);
}
 
Example #22
Source File: MatOfDMatch.java    From effective_android_sample with Apache License 2.0 4 votes vote down vote up
public MatOfDMatch(DMatch...ap) {
    super();
    fromArray(ap);
}
 
Example #23
Source File: MatOfDMatch.java    From ResistorScanner with MIT License 4 votes vote down vote up
public List<DMatch> toList() {
    DMatch[] adm = toArray();
    return Arrays.asList(adm);
}
 
Example #24
Source File: MatOfDMatch.java    From ResistorScanner with MIT License 4 votes vote down vote up
public void fromList(List<DMatch> ldm) {
    DMatch adm[] = ldm.toArray(new DMatch[0]);
    fromArray(adm);
}
 
Example #25
Source File: MatOfDMatch.java    From effective_android_sample with Apache License 2.0 4 votes vote down vote up
public void fromList(List<DMatch> ldm) {
    DMatch adm[] = ldm.toArray(new DMatch[0]);
    fromArray(adm);
}
 
Example #26
Source File: MatOfDMatch.java    From ResistorScanner with MIT License 4 votes vote down vote up
public MatOfDMatch(DMatch...ap) {
    super();
    fromArray(ap);
}
 
Example #27
Source File: MatOfDMatch.java    From Android-Car-duino with GNU General Public License v2.0 4 votes vote down vote up
public List<DMatch> toList() {
    DMatch[] adm = toArray();
    return Arrays.asList(adm);
}
 
Example #28
Source File: MatOfDMatch.java    From Android-Car-duino with GNU General Public License v2.0 4 votes vote down vote up
public void fromList(List<DMatch> ldm) {
    DMatch adm[] = ldm.toArray(new DMatch[0]);
    fromArray(adm);
}
 
Example #29
Source File: MatOfDMatch.java    From Android-Car-duino with GNU General Public License v2.0 4 votes vote down vote up
public MatOfDMatch(DMatch...ap) {
    super();
    fromArray(ap);
}
 
Example #30
Source File: MatOfDMatch.java    From marvel with MIT License 4 votes vote down vote up
public List<DMatch> toList() {
    DMatch[] adm = toArray();
    return Arrays.asList(adm);
}