Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Using a webcam as an ambient light sensor


  • Please log in to reply
13 replies to this topic
Tiler
  • Guests
  • Last active:
  • Joined: --
Hey everyone, I'm planning on modifying a webcam script I found somewhere on the forum for capturing webcam images in order to make the webcam act as a light sensor in order to set backlight/backlit keyboard options on a laptop appropriately.

Before I go further I would just like to say that I am looking for ideas at this point, not handouts.

I found a basic formula browsing the web for calculating the "brightness" of a pixel, and just figured basically I would process every pixel in the image and average the results from the formula, then set benchmarks for different levels of average "brightness".

Here is the formula:
brightness = 0.299 * R + 0.587 * G + 0.114 * B

Seems to be simple and of intelligent design, as the green pixel counts for much more then the red and blue pixels (green is the first color our eyes see I believe)..

Anyways to sum up, the question is this:

What way do you guys think would be the best way to process every pixel of an image using AutoHotkey?

I had the idea of displaying the intended image for inspection on a gui shown off the screen, then using pixelgetcolour to read every one, but I figured it would be slow, obsolete, etc. compared to ideas I will get here.

Any help is greatly appreciated.

Tiler
  • Guests
  • Last active:
  • Joined: --
Just an update, unfortunately it turns out pixelgetcolour just reports every pixel is white once it's off screen; so my idea for reading the colors of the pixels won't work.

Really hoping on some other ideas, thanks guys. :)

Tiler
  • Guests
  • Last active:
  • Joined: --
Found this script here: http://www.autohotke...topic59051.html

Which seems to allow the reading of external images' pixels! :)

However I can't seem to get it to work, using this code:

fname = blue.bmp
BMPLoad(fname, ByRef bmpdata)
msgbox % BMPGetPixel(ByRef bmpdata, "5", "5") 
; should retrieve the pixel at 5x5?

Maybe I'm interpreting the script's use wrong, or my code is written wrong. Not sure and I'm very tired but could use a point in the right direction if I'm going about this the wrong way.

Thanks

TheAllmighty
  • Guests
  • Last active:
  • Joined: --

Maybe I'm interpreting the script's use wrong, or my code is written wrong.

both actually.
you will be better of using [func]RegionGetColor - Average color a window - v3.8 +MCode!

Wicked
  • Members
  • 504 posts
  • Last active: Jun 14 2014 06:04 PM
  • Joined: 07 Jun 2008
If you decided to do the off screen window, I would personally use PrintWindow and GDI+. ;).

Carcophan
  • Members
  • 1578 posts
  • Last active: Nov 27 2013 06:46 PM
  • Joined: 24 Dec 2008

calculating the "brightness"



I really like your idea, I honestly wish I could contribute some code or assistance, but wanted to make one small point, with the best of intentions, please don't take this the wrong way.


HP had some facial recognition software built into its webcams, that had some 'issues', lets say. I don't know if a software resolution was reached, but here is a little more info, <!-- m -->http://www.cnn.com/2... ... index.html<!-- m -->


My point is, how will you determine the camera's viewable area, and be able to separate a white wall, a black face, a TV, a lamp, cat, CapsLock LED, sunglasses or cake apart? My 'room' could be bright as the day, but if the background/wall is brown or black or curtains or anything, it should skew results I imagine.

Tiler
  • Guests
  • Last active:
  • Joined: --
I've considered the problem of images like a bright face (from the light of the monitor) or a dark wall (from the background) being a problem, but I thought about it and I don't see it being a huge issue, although it could cause some rare false-reads, its not a life or death situation or a security risk, its just to set backlighting of a keyboard/brightness of a screen ;)

And I will look into RegionGetColor, specifically the AvgBitmap function, might come of some use.

Any more suggestions still appreciated :)

  • Guests
  • Last active:
  • Joined: --

Maybe I'm interpreting the script's use wrong, or my code is written wrong.

both actually.
you will be better of using [func]RegionGetColor - Average color a window - v3.8 +MCode!


So the script I was trying to use can not read a bmp file's pixel colours?

TheAllmighty
  • Guests
  • Last active:
  • Joined: --

So the script I was trying to use can not read a bmp file's pixel colours?

No, it can, but that´s not the point.
Like the title says: ImageSearch without external images
it´s a script that does an ImageSearch with an reference-image that is coded into the script.

Tiller
  • Guests
  • Last active:
  • Joined: --
Got it working using infoG's script, unable to test the webcam capture but the brightness calculation works =)

vphreeze
  • Members
  • 1 posts
  • Last active: Jun 28 2013 06:17 PM
  • Joined: 06 Oct 2010
not sure if your still working on this, but have you seen this guys work?

http://sven.killig.de/BLUntrl/

randallf
  • Members
  • 711 posts
  • Last active: Jan 07 2014 11:45 PM
  • Joined: 06 Jul 2009
SmarterGuard has an image capture feature based on brightness (rather, a tolerance setting for brightness). It is free, doesn't have to show the camera and will create timestamped image files that you could detect the presence of and read from.

mailsummit2000
  • Members
  • 34 posts
  • Last active: Jun 03 2010 01:50 AM
  • Joined: 26 Jul 2008
I would love to see the development of this script.
I am trying to do a similar thing. I want to set up a program to monitor the brightness in the room. That way, when I turn the lights off as I leave my room, it will lower the music volume, and when I turn it on, it will raise the music volume, and start playing visualizations.

bobbysoon
  • Members
  • 81 posts
  • Last active: May 03 2014 09:50 PM
  • Joined: 15 Mar 2011

I too would love to see this happen. Maybe a bump would stir up some new developments :)

I think sampling issues wouldn't be so bad if it was triggered with a hotkey rather than periodically ran. The user could reposition oneself or the laptop and resample if results are undesirable.