Created
May 27, 2017 02:55
-
-
Save zhanghang1989/8549919ddf38d08b72720c1653c001f1 to your computer and use it in GitHub Desktop.
Torch Lua Camera Demo
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 'torch' | |
require 'image' | |
require 'camera' | |
require 'qt' | |
local function main() | |
local camera_opt = { | |
idx = 0, | |
fps = 30, | |
height = 480, | |
width = 640, | |
} | |
local cam = image.Camera(camera_opt) | |
local win = nil | |
local idx = 1 | |
while true do | |
-- Grab a frame from the webcam | |
local img = cam:forward():clamp(0,255) | |
idx = idx + 1 | |
if not win then | |
-- On the first call use image.display to construct a window | |
win = image.display(img) | |
else | |
-- Reuse the same window | |
win.image = img | |
local size = win.window.size:totable() | |
local qt_img = qt.QImage.fromTensor(img) | |
win.painter:image(0, 0, size.width, size.height, qt_img) | |
end | |
end | |
end | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment