Class: Wildfire::Converter::Transformer
- Extended by:
- OpenCV
- Defined in:
- lib/wildfire/converter/transformer.rb
Constant Summary
Constants inherited from Core
Class Method Summary collapse
- .approximate(mat) ⇒ Object
- .binary(mat) ⇒ Object
- .blur(mat) ⇒ Object
- .canny(mat) ⇒ Object
- .cv_point_array(array) ⇒ Object
- .dilate(mat) ⇒ Object
- .erode(mat) ⇒ Object
- .flip(mat) ⇒ Object
- .four_point_transform(mat, points) ⇒ Object
- .grey(mat) ⇒ Object
- .median_blur(mat) ⇒ Object
- .one_rotation(mat) ⇒ Object
- .quick_save(mat) ⇒ Object
- .rotate(mat, repetitions) ⇒ Object
- .substract(mat1, mat2) ⇒ Object
-
.temp_mat ⇒ Object
just duping.
- .transpose(mat) ⇒ Object
- .warp(mat, perspective, new_size) ⇒ Object
Methods inherited from Core
#generate_path, #quick_save, #save, #temp_mat
Class Method Details
.approximate(mat) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/wildfire/converter/transformer.rb', line 16 def approximate(mat) accuracy = 0.02 * Cv.arc_length(mat, false) approxed_curve = temp_mat Cv.approx_polydp(mat, approxed_curve, accuracy, true) approxed_curve end |
.binary(mat) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/wildfire/converter/transformer.rb', line 68 def binary(mat) binaried = temp_mat Cv.threshold(mat, binaried, 1, 1, Cv::THRESH_OTSU) # Cv.threshold(mat, binaried, Cv::THRESH_BINARY) binaried end |
.blur(mat) ⇒ Object
30 31 32 33 34 |
# File 'lib/wildfire/converter/transformer.rb', line 30 def blur(mat) blur_mat = temp_mat Cv.gaussian_blur(mat, blur_mat, Cv::Size.new(5, 5), 0) blur_mat end |
.canny(mat) ⇒ Object
56 57 58 59 60 |
# File 'lib/wildfire/converter/transformer.rb', line 56 def canny(mat) cannied = temp_mat Cv.canny(mat, cannied, 100, 50) cannied end |
.cv_point_array(array) ⇒ Object
94 95 96 97 98 |
# File 'lib/wildfire/converter/transformer.rb', line 94 def cv_point_array(array) mat = Cv::Mat.new(array) mat.convert_to(mat, Cv::CV_32FC2) mat end |
.dilate(mat) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/wildfire/converter/transformer.rb', line 49 def dilate(mat) dilated_mat = temp_mat kernel = temp_mat Cv.dilate(mat, dilated_mat, kernel) dilated_mat end |
.erode(mat) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/wildfire/converter/transformer.rb', line 42 def erode(mat) eroded_mat = temp_mat kernel = temp_mat Cv.erode(mat, eroded_mat, kernel) eroded_mat end |
.flip(mat) ⇒ Object
114 115 116 117 118 |
# File 'lib/wildfire/converter/transformer.rb', line 114 def flip(mat) flipped = temp_mat Cv.flip(mat, flipped, 0) flipped end |
.four_point_transform(mat, points) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/wildfire/converter/transformer.rb', line 75 def four_point_transform(mat, points) calculator = Converter::SizeCalculator.new(points) destination = [ [0, 0], [calculator.max_width - 1, 0], [calculator.max_width - 1, calculator.max_height - 1], [0, calculator.max_height - 1], ] input = cv_point_array(destination) output = cv_point_array(calculator.points.map { |p| [p[0], p[1]] }) perspective = Cv.get_perspective_transform(input, output) new_size = Cv::Size.new(calculator.max_width, calculator.max_height) warped = warp(mat, perspective, new_size) rotate(transpose(warped), 3) end |
.grey(mat) ⇒ Object
24 25 26 27 28 |
# File 'lib/wildfire/converter/transformer.rb', line 24 def grey(mat) grey_mat = temp_mat Cv.cvt_color(mat, grey_mat, CV_BGR2GRAY) grey_mat end |
.median_blur(mat) ⇒ Object
36 37 38 39 40 |
# File 'lib/wildfire/converter/transformer.rb', line 36 def median_blur(mat) blur_mat = temp_mat Cv.median_blur(mat, blur_mat, 3) blur_mat end |
.one_rotation(mat) ⇒ Object
130 131 132 |
# File 'lib/wildfire/converter/transformer.rb', line 130 def one_rotation(mat) flip(transpose(mat)) end |
.quick_save(mat) ⇒ Object
12 13 14 |
# File 'lib/wildfire/converter/transformer.rb', line 12 def quick_save(mat) Cv.imwrite('/home/domas/quick_photo.jpg', mat) end |
.rotate(mat, repetitions) ⇒ Object
120 121 122 123 124 125 126 127 128 |
# File 'lib/wildfire/converter/transformer.rb', line 120 def rotate(mat, repetitions) result = mat repetitions.times do result = one_rotation(result) end result end |
.substract(mat1, mat2) ⇒ Object
62 63 64 65 66 |
# File 'lib/wildfire/converter/transformer.rb', line 62 def substract(mat1, mat2) result = temp_mat Cv.subtract(mat1, mat2, result) result end |
.temp_mat ⇒ Object
just duping
8 9 10 |
# File 'lib/wildfire/converter/transformer.rb', line 8 def temp_mat Cv.imread('/tmp/paper_god.jpg') end |
.transpose(mat) ⇒ Object
108 109 110 111 112 |
# File 'lib/wildfire/converter/transformer.rb', line 108 def transpose(mat) transposed = temp_mat Cv.transpose(mat, transposed) transposed end |
.warp(mat, perspective, new_size) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/wildfire/converter/transformer.rb', line 100 def warp(mat, perspective, new_size) warped = temp_mat Cv.warp_perspective(mat, warped, perspective, new_size, Cv::INTER_LINEAR | Cv::WARP_INVERSE_MAP) quick_save(warped) warped end |