-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopencv-flann.rb
33 lines (26 loc) · 1.02 KB
/
opencv-flann.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'ropencv'
include OpenCV
img1 = cv::imread ARGV.shift, cv::IMREAD_GRAYSCALE
img2 = cv::imread ARGV.shift, cv::IMREAD_GRAYSCALE
#detector, norm = cv::SIFT.new, cv::NORM_L2
detector, norm = cv::ORB.create, cv::NORM_HAMMING
kp1 = Vector.new cv::KeyPoint
kp2 = Vector.new cv::KeyPoint
des1 = cv::Mat.new(3, 4, cv::CV_64FC1)
des2 = cv::Mat.new(3, 4, cv::CV_64FC1)
detector.detect_and_compute img1, cv::Mat.new, kp1, des1
detector.detect_and_compute img2, cv::Mat.new, kp2, des2
# XXX: this fails with NameError: missing flann
matcher = cv::FlannBasedMatcher::new
matches = Vector.new Vector.new cv::DMatch
matcher.knn_match des1, des2, matches, 2
#good = Vector.new cv::DMatch
#matches.each do |match|
#m, n = match[0], match[1]
#good << m if m.distance < 0.7 * n.distance
#end
#puts "matched #{good.count}"
#img_matches = cv::Mat.new 3, 4, cv::CV_64FC1
#cv::draw_matches img1, kp1, img2, kp2, good, img_matches, cv::Scalar::all(-1), cv::Scalar::all(-1), Vector::Char.new(), 2
#cv::imshow 'matches', img_matches
#cv::wait_key 0