Open ntayungao opened 6 years ago
Python code for Pattern Matching
import java.util.regex.Pattern;
public class PatternMatchesTest { public static void main(String args[]) {
String regex = "ad*";
String input = "add";
boolean isMatch = Pattern.matches(regex, input);
System.out.println(isMatch);//return true
} }
Java Pattern Match in regular expression http://www.java2s.com/Code/Java/Regular-Expressions/PatternMatch.htm
import java.util.regex.Matcher; import java.util.regex.Pattern;
public class PatternMethodExample { public static void main(String args[]) { reusePatternMethodExample(); }
public static void reusePatternMethodExample() { Pattern p = Pattern.compile("\d"); Matcher matcher = p.matcher("5"); boolean isOk = matcher.matches(); System.out.println("original pattern matches " + isOk);
String tmp = p.pattern();
Pattern p2 = Pattern.compile(tmp);
matcher = p.matcher("5");
isOk = matcher.matches();
System.out.println("second pattern matches " + isOk);
} }
Java Simple Pattern Match http://www.java2s.com/Code/Java/Regular-Expressions/SimplePattern.htm
import java.util.regex.Pattern;
public class PatternSplitExample { public static void main(String args[]) { Pattern p = Pattern.compile(" "); String tmp = "this is the String I want to split up";
String[] tokens = p.split(tmp);
for (int i = 0; i < tokens.length; i++) {
System.out.println(tokens[i]);
}
} }
Java Pattern Split http://www.java2s.com/Code/Java/Regular-Expressions/PatternSplit.htm
import java.util.regex.Pattern;
public class PatternSplit { public static void main(String args[]) {
String statement = "I will not compromise. I will not "
+ "cooperate. There will be no concession, no conciliation, no "
+ "finding the middle ground, and no give and take.";
String tokens[] = null;
String splitPattern = "compromise|cooperate|concession|"
+ "conciliation|(finding the middle ground)|(give and take)";
Pattern p = Pattern.compile(splitPattern);
tokens = p.split(statement);
System.out.println("REGEX PATTERN:\n" + splitPattern + "\n");
System.out.println("STATEMENT:\n" + statement + "\n");
System.out.println("TOKENS:");
for (int i = 0; i < tokens.length; i++) {
System.out.println(tokens[i]);
}
} }
Java Pattern Split http://www.java2s.com/Code/Java/Regular-Expressions/Anotherpatternsplit.htm
Java Pattern Matching https://docs.opencv.org/2.4/doc/tutorials/introduction/desktop_java/java_dev_intro.html
Java Pattern Matching https://stackoverflow.com/questions/11541154/checking-images-for-similarity-with-opencv
import numpy as np import cv2 from matplotlib import pyplot as plt
img1 = cv2.imread('box.png',0) # queryImage img2 = cv2.imread('box_in_scene.png',0) # trainImage
Initiate SIFT detector
sift = cv2.SIFT()
find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1,None) kp2, des2 = sift.detectAndCompute(img2,None)
BFMatcher with default params
bf = cv2.BFMatcher() matches = bf.knnMatch(des1,des2, k=2)
Apply ratio test
good = [] for m,n in matches: if m.distance < 0.75*n.distance: good.append([m])
cv2.drawMatchesKnn expects list of lists as matches.
img3 = cv2.drawMatchesKnn(img1,kp1,img2,kp2,good,flags=2)
plt.imshow(img3),plt.show()