clementfarabet / lua---camera

A very simple camera interface (frame grabber) for Torch7.
34 stars 18 forks source link

When use "cam=image.Camera()", I get some error. #32

Closed Laodax closed 7 years ago

Laodax commented 7 years ago

my step is below:

$ qula
> require 'camera' 
> camera.testme()
-------------------------------------------------
grabbing frames from your camera for about 10secs
Initializing device: /dev/video0
FPS wanted 1 
Using 1 buffers
camera[0] started : 1
stopping camera
done: create your own frame grabber with image.Camera()
--------------------------------------------------
> cam=image.Camera()
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ImageSource

> usage:
ImageSource{
    [idx = number]                      -- camera index  [default = 0]
    [width = number]                    -- width  [default = 640]
    [height = number]                   -- height  [default = 480]
    [buffers = number]                  -- number of buffers (v4l2 only)  [default = 1]
    [fps = number]                      -- optional frame rate (v4l2 only)  [default = 1]
}

ImageSource{width=number, idx=number}
ImageSource(number, ...)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
...ome/lab513/torch/install/share/lua/5.1/xlua/init.lua:321: error
stack traceback:
    [C]: in function 'error'
    ...ome/lab513/torch/install/share/lua/5.1/xlua/init.lua:321: in function 'error'
    ...ome/lab513/torch/install/share/lua/5.1/xlua/init.lua:544: in function 'unpack'
    ...home/lab513/torch/install/share/lua/5.1/v4l/init.lua:17: in function '__init'
    ...me/lab513/torch/install/share/lua/5.1/torch/init.lua:91: in function <...me/lab513/torch/install/share/lua/5.1/torch/init.lua:87>
    [C]: in function 'Camera'
    [string "cam=image.Camera()"]:1: in main chunk
    [C]: ?

I can grab frames from my camera for about 10secs. But when I use "cam=image.Camera()", I got some error. Did someone get the same error? Thanks.

@clementfarabet Would you please hlep me? Thank you very much.

Atcold commented 7 years ago

What about

cam = image.Camera{}
Laodax commented 7 years ago

@Atcold

~$ qlua
> require 'camera'
> cam=image.Camera{}
Initializing device: /dev/video0
FPS wanted 1 
Using 1 buffers
camera[0] started : 1
> 

It became this, but webcam didn't work. Is that reasonable?

Atcold commented 7 years ago

What about

require 'camera'
image.display(image.Camera{})
Laodax commented 7 years ago
> require 'camera'
> image.display(image.Camera{})
Initializing device: /dev/video0
FPS wanted 1 
Using 1 buffers
camera[0] started : 1
...me/lab513/torch/install/share/lua/5.1/image/init.lua:1438: attempt to index field '?' (a nil value)
stack traceback:
    ...me/lab513/torch/install/share/lua/5.1/image/init.lua:1438: in function 'toDisplayTensor'
    ...me/lab513/torch/install/share/lua/5.1/image/init.lua:1545: in function 'display'
    [string "image.display(image.Camera{})"]:1: in main chunk
    [C]: ?
> 

I want to know what ""cam = image.Camera() -- create the camera grabber"" means? And when I do this step by step(below), what will happen?

cam = image.Camera() -- create the camera grabber frame = cam:forward() -- return the next frame available cam:stop() -- release the camera image.display(frame) -- display frame

Thanks a lot!

Atcold commented 7 years ago

My bad.

require 'camera'
cam = image.Camera{}
image.display(cam:forward())
Laodax commented 7 years ago

That got worked! It can grab the first frame from the camera. Is that right?

Atcold commented 7 years ago

Yeah, just keep :forward()-ing for more frames. You can close the issue now.