Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you use a webcam with ruby-opencv in realtime?

Tags:

c++

ruby

opencv

I'm thinking of building a quick and dirty script to help a friend out. It will need to take webcam input and perform very simple computation on it (think delta brightness of the pixels over time, relatively computationally simple).

I am currently leaning towards c++ like so along with opencv but I was wondering, since it's such a computationally inexpensive task, (relatively speaking of course) if there was a way to simply use ruby-opencv or some other techniques to keep it in a scripting language.

I haven't been able to find any way to import realtime webcamera images into a ruby script since I've been looking but I'd be more than happy to have my search skills proven inadequate by the wonderful SO community!

Places I've looked so far:

hornetseye

c++ script (what I'm leaning towards)

using an ffi

In summary; Is there a way to import realtime webcamera images into a ruby script to perform simple computation on them? (I was thinking with opencv but am not tied to any particular idea.

like image 387
Mike H-R Avatar asked Jan 11 '23 15:01

Mike H-R


1 Answers

Using ruby-opencv you can capture and display camera images as follows

#!/usr/bin/env ruby
require 'opencv'
include OpenCV
FPS = 30
input = CvCapture.open
win = GUI::Window.new 'video'
loop do
  img = input.query
  win.show img
  key = GUI.wait_key 1000 / FPS
  break if key and key.chr == "\e"
end
like image 75
wedesoft Avatar answered Jan 19 '23 20:01

wedesoft