mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
Added example.
This commit is contained in:
parent
a524cda800
commit
b648bbfb74
4 changed files with 3182 additions and 1 deletions
27
README.md
27
README.md
|
@ -87,6 +87,32 @@ window.show(image)
|
|||
Cv::wait_key
|
||||
```
|
||||
|
||||
### Image Classification
|
||||
|
||||
A samples to classify objects in an image.
|
||||
|
||||
```ruby
|
||||
require 'opencv'
|
||||
|
||||
classes = []
|
||||
File.open("./examples/synset_words.txt", "r") do |f|
|
||||
f.each_line { |line|
|
||||
_, value = line.strip.split(" ", 2)
|
||||
classes << value.split(",", 2).first
|
||||
}
|
||||
f.close
|
||||
end
|
||||
|
||||
net = Cv::Dnn.read_net_from_caffe("./examples/bvlc_googlenet.prototxt", "./examples/bvlc_googlenet.caffemodel")
|
||||
net.set_input(Cv::Dnn.blob_from_image(Cv.imread("./examples/images/stuff.jpg", Cv::IMREAD_UNCHANGED), size: Cv::Size.new(224, 224), mean: Cv::Scalar.new(104, 117, 123)))
|
||||
predictions = net.forward
|
||||
|
||||
for i in 0..(predictions.cols - 1)
|
||||
confidence = predictions.at(0, i)[0]
|
||||
puts "#{classes[i]} #{confidence}" if confidence > 0.1
|
||||
end
|
||||
```
|
||||
|
||||
For more samples, see examples/*.rb
|
||||
|
||||
## LICENSE:
|
||||
|
@ -94,4 +120,3 @@ For more samples, see examples/*.rb
|
|||
The MIT Liscense
|
||||
|
||||
see LICENSE.txt
|
||||
|
||||
|
|
BIN
examples/bvlc_googlenet.caffemodel
Normal file
BIN
examples/bvlc_googlenet.caffemodel
Normal file
Binary file not shown.
2156
examples/bvlc_googlenet.prototxt
Normal file
2156
examples/bvlc_googlenet.prototxt
Normal file
File diff suppressed because it is too large
Load diff
1000
examples/synset_words.txt
Normal file
1000
examples/synset_words.txt
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue