ntayungao / Fortify

http://projects2.apc.edu.ph/wiki/index.php/Fortify
0 stars 0 forks source link

Source Code for Pattern Matching #1

Open ntayungao opened 6 years ago

ntayungao commented 6 years ago

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()

ntayungao commented 6 years ago

https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/py_matcher/py_matcher.html

ntayungao commented 6 years ago

Python code for Pattern Matching

ntayungao commented 6 years ago

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

} }

ntayungao commented 6 years ago

Java Pattern Match in regular expression http://www.java2s.com/Code/Java/Regular-Expressions/PatternMatch.htm

ntayungao commented 6 years ago

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);

} }

ntayungao commented 6 years ago

Java Simple Pattern Match http://www.java2s.com/Code/Java/Regular-Expressions/SimplePattern.htm

ntayungao commented 6 years ago

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]);
}

} }

ntayungao commented 6 years ago

Java Pattern Split http://www.java2s.com/Code/Java/Regular-Expressions/PatternSplit.htm

ntayungao commented 6 years ago

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]);
}

} }

ntayungao commented 6 years ago

Java Pattern Split http://www.java2s.com/Code/Java/Regular-Expressions/Anotherpatternsplit.htm

ntayungao commented 6 years ago

Java Pattern Matching https://docs.opencv.org/2.4/doc/tutorials/introduction/desktop_java/java_dev_intro.html

ntayungao commented 6 years ago

Java Pattern Matching https://stackoverflow.com/questions/11541154/checking-images-for-similarity-with-opencv