mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
add Mat::circle
This commit is contained in:
parent
bc71727a34
commit
8636eca0c4
4 changed files with 124 additions and 0 deletions
|
@ -1238,6 +1238,9 @@ namespace rubyopencv {
|
||||||
rb_define_method(rb_klass, "line", RUBY_METHOD_FUNC(rb_line), -1); // in ext/opencv/mat_drawing.cpp
|
rb_define_method(rb_klass, "line", RUBY_METHOD_FUNC(rb_line), -1); // in ext/opencv/mat_drawing.cpp
|
||||||
rb_define_method(rb_klass, "line!", RUBY_METHOD_FUNC(rb_line_bang), -1); // in ext/opencv/mat_drawing.cpp
|
rb_define_method(rb_klass, "line!", RUBY_METHOD_FUNC(rb_line_bang), -1); // in ext/opencv/mat_drawing.cpp
|
||||||
|
|
||||||
|
rb_define_method(rb_klass, "circle", RUBY_METHOD_FUNC(rb_circle), -1); // in ext/opencv/mat_drawing.cpp
|
||||||
|
rb_define_method(rb_klass, "circle!", RUBY_METHOD_FUNC(rb_circle_bang), -1); // in ext/opencv/mat_drawing.cpp
|
||||||
|
|
||||||
rb_define_method(rb_klass, "rectangle", RUBY_METHOD_FUNC(rb_rectangle), -1); // in ext/opencv/mat_drawing.cpp
|
rb_define_method(rb_klass, "rectangle", RUBY_METHOD_FUNC(rb_rectangle), -1); // in ext/opencv/mat_drawing.cpp
|
||||||
rb_define_method(rb_klass, "rectangle!", RUBY_METHOD_FUNC(rb_rectangle_bang), -1); // in ext/opencv/mat_drawing.cpp
|
rb_define_method(rb_klass, "rectangle!", RUBY_METHOD_FUNC(rb_rectangle_bang), -1); // in ext/opencv/mat_drawing.cpp
|
||||||
|
|
||||||
|
|
|
@ -154,5 +154,64 @@ namespace rubyopencv {
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Draws a circle
|
||||||
|
*
|
||||||
|
* @overload circle(center, radius, options = nil)
|
||||||
|
* @param center [Point] Center of the circle.
|
||||||
|
* @param radius [Integer] Radius of the circle.
|
||||||
|
* @param color [Scalar] Circle color.
|
||||||
|
* @param options [Hash] Drawing options
|
||||||
|
* @option options [Integer] :thickness Line thickness.
|
||||||
|
* @option options [Integer] :line_type Type of the line.
|
||||||
|
* * 8 - 8-connected line.
|
||||||
|
* * 4 - 4-connected line.
|
||||||
|
* * <tt>CV_AA</tt> - Antialiased line.
|
||||||
|
* @option options [Integer] :shift Number of fractional bits in the coordinates of
|
||||||
|
* the center and in the radius value.
|
||||||
|
* @return [Mat] Output array
|
||||||
|
* @opencv_func cv::circle
|
||||||
|
*/
|
||||||
|
VALUE rb_circle(int argc, VALUE *argv, VALUE self) {
|
||||||
|
VALUE dst = rb_clone(self);
|
||||||
|
return rb_circle_bang(argc, argv, dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Draws a circle
|
||||||
|
*
|
||||||
|
* @overload circle!(center, radius, options = nil)
|
||||||
|
* @param center [Point] Center of the circle.
|
||||||
|
* @param radius [Integer] Radius of the circle.
|
||||||
|
* @param color [Scalar] Circle color.
|
||||||
|
* @param options [Hash] Drawing options
|
||||||
|
* @option options [Integer] :thickness Line thickness.
|
||||||
|
* @option options [Integer] :line_type Type of the line.
|
||||||
|
* * 8 - 8-connected line.
|
||||||
|
* * 4 - 4-connected line.
|
||||||
|
* * <tt>CV_AA</tt> - Antialiased line.
|
||||||
|
* @option options [Integer] :shift Number of fractional bits in the coordinates of
|
||||||
|
* the center and in the radius value.
|
||||||
|
* @return [Mat] Output array
|
||||||
|
* @opencv_func cv::circle
|
||||||
|
*/
|
||||||
|
VALUE rb_circle_bang(int argc, VALUE *argv, VALUE self) {
|
||||||
|
VALUE center, radius, color, option;
|
||||||
|
rb_scan_args(argc, argv, "31", ¢er, &radius, &color, &option);
|
||||||
|
|
||||||
|
cv::Mat* selfptr = obj2mat(self);
|
||||||
|
drawing_option_t opt = drawing_option(option);
|
||||||
|
try {
|
||||||
|
cv::Point center_value = Point::conpatible_obj2point(center);
|
||||||
|
cv::Scalar color_value = *(Scalar::obj2scalar(color));
|
||||||
|
cv::circle(*selfptr, center_value, NUM2INT(radius), color_value, opt.thickness, opt.line_type, opt.shift);
|
||||||
|
}
|
||||||
|
catch (cv::Exception& e) {
|
||||||
|
Error::raise(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,5 +7,8 @@ namespace rubyopencv {
|
||||||
|
|
||||||
VALUE rb_rectangle(int argc, VALUE *argv, VALUE self);
|
VALUE rb_rectangle(int argc, VALUE *argv, VALUE self);
|
||||||
VALUE rb_rectangle_bang(int argc, VALUE *argv, VALUE self);
|
VALUE rb_rectangle_bang(int argc, VALUE *argv, VALUE self);
|
||||||
|
|
||||||
|
VALUE rb_circle(int argc, VALUE *argv, VALUE self);
|
||||||
|
VALUE rb_circle_bang(int argc, VALUE *argv, VALUE self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
59
test/test_mat_drawing.rb
Executable file
59
test/test_mat_drawing.rb
Executable file
|
@ -0,0 +1,59 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
# -*- mode: ruby; coding: utf-8 -*-
|
||||||
|
require 'opencv'
|
||||||
|
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
||||||
|
|
||||||
|
include Cv
|
||||||
|
|
||||||
|
class TestMat < OpenCVTestCase
|
||||||
|
def test_circle
|
||||||
|
m0 = Cv::Mat.zeros(128, 128, Cv::CV_8UC3) + Cv::Scalar.new(255, 255, 255)
|
||||||
|
center = Cv::Point.new(m0.cols * 0.5, m0.rows * 0.5)
|
||||||
|
radius = 32
|
||||||
|
color = Cv::Scalar.new(255, 0, 0)
|
||||||
|
option = { thickness: 2, line_type: Cv::CV_AA, shift: 0 }
|
||||||
|
|
||||||
|
m1 = m0.circle(center, radius, color, option)
|
||||||
|
assert_equal(m0.class, m1.class)
|
||||||
|
assert_equal(m0.rows, m1.rows)
|
||||||
|
assert_equal(m0.cols, m1.cols)
|
||||||
|
|
||||||
|
m2 = m0.clone
|
||||||
|
m2.circle!(center, radius, color, option)
|
||||||
|
assert_equal(m0.class, m2.class)
|
||||||
|
assert_equal(m0.rows, m2.rows)
|
||||||
|
assert_equal(m0.cols, m2.cols)
|
||||||
|
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.circle(DUMMY_OBJ, radius, color, option)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.circle(center, DUMMY_OBJ, color, option)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.circle(center, radius, DUMMY_OBJ, option)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.circle(center, radius, color, DUMMY_OBJ)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.circle!(DUMMY_OBJ, radius, color, option)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.circle!(center, DUMMY_OBJ, color, option)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.circle!(center, radius, DUMMY_OBJ, option)
|
||||||
|
}
|
||||||
|
assert_raise(TypeError) {
|
||||||
|
m0.circle!(center, radius, color, DUMMY_OBJ)
|
||||||
|
}
|
||||||
|
|
||||||
|
# w1 = Window.new('Circle 1')
|
||||||
|
# w1.show m1
|
||||||
|
# w2 = Window.new('Circle 2')
|
||||||
|
# w2.show m2
|
||||||
|
# Cv::wait_key
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue