Author Topic: camera image as low light sensor  (Read 1111 times)

Offline vio

  • Sr. Newbie
  • *
  • Posts: 47
  • Karma: +0/-0
camera image as low light sensor
« on: August 17, 2012, 01:41:58 am »
Because I do not have a light sensor, I wrote a script to detect if the snapshot taken from the camera is too small, meaning the image is almost black. If this is true, different scenes can run (like turn infrared on camera on, turn on a virtual switch, ....). Of course the values need to be changed according with the camera snapshot path and the size of the picture during dust, day and night. Hope it helps.

Code: [Select]
--get snapshot
os.execute("curl -o /tmp/log/cmh/snap.jpg http://user:pass@ip/tmpfs/snap.jpg")
local snapfile = '/var/log/cmh/snap.jpg'
local minfilesize = 10000
local DEVICE_ID = xyz

-- small file means black image
local outf = , 'a')
local filesize = outf:seek("end")
 luup.log("snap.jpg file size: ".. filesize)
if (filesize < minfilesize) then
local status = luup.variable_get("urn:upnp-org:serviceId:VSwitch1", "Status",  DEVICE_ID)
        luup.log("low light: ".. status)
-- luup.log("will set low light virtual switch on")
                return true
                -- luup.log("low light virtual switch already off")
                return false
  return false
« Last Edit: September 12, 2012, 11:04:14 am by oTi@ »

Offline dschedgick

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: camera image as low light sensor
« Reply #1 on: December 29, 2017, 09:09:36 pm »
Hi Vio,
I would also like to use my camera as a sensor, but not through filesize.  I would like to use the image to determine if a light has been turned on within the field of view by cropping the image and examining the intensity within that cropped area.  I can do this in Matlab very easily and the algorithm works (from acquiring the image on my camera, pulling the color info from the jpeg, converting the colors to intensity, then making a determination of whether the light is on.  Since I am new to Lua and the Veraplus controller, I am not sure how to do all the steps. 

I think I can collect the image from my Axis camera:

local opstatus, image, httpstatus = luup.inet.wget("http://local_cam_ip/axis-cgi/jpg/image.cgi?login=XX&password=XX",10) 

or another way:

image_url = 'http://local_cam_ip/axis-cgi/jpg/image.cgi?login=XX&password=XX'
local body, code, headers, status = http.request(image_url)

This is where I get stuck.  How do I get from "image" or "body" to a matrix or table that I can act on to determine the RGB values?  Any thoughts?
Thank you,
« Last Edit: December 29, 2017, 09:14:57 pm by dschedgick »