Skip to content

Instantly share code, notes, and snippets.

@ser1zw
Created March 23, 2014 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ser1zw/9720199 to your computer and use it in GitHub Desktop.
Save ser1zw/9720199 to your computer and use it in GitHub Desktop.
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