Created
March 23, 2014 08:19
-
-
Save ser1zw/9720199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'opencv' | |
include OpenCV | |
w1 = GUI::Window.new("All") | |
w2 = GUI::Window.new("Removed") | |
# https://github.com/ruby-opencv/ruby-opencv/blob/master/examples/contours/rotated-boxes.jpg | |
out1 = CvMat.load("rotated-boxes.jpg", 1) | |
out2 = out1.clone | |
gray = out1.BGR2GRAY.threshold(200, 255, :binary) | |
contours = gray.find_contours | |
# (1) Draw all contours | |
contours.each { |c| | |
out1.circle!(c, 2, color: CvColor::Red, thichness: 2, line_type: :aa) | |
} | |
# (2) Draw some contours | |
contours.remove(9) # Remove the 10th element using OpenCV's cvSeqRemove | |
contours = contours.reject { |c| c.x % 2 == 0 } # Remove some points using Ruby's Enumerable#reject | |
contours.each { |c| | |
out2.circle!(c, 2, color: CvColor::Red, thichness: 2, line_type: :aa) | |
} | |
w1.show out1 | |
w2.show out2 | |
GUI::wait_key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment