Hi everyone. I am new to CHDK-scripting and this forum ;-)
I tried to to a script for hours now to manipulate an image which is captured before writing.
I tried to convert the image into greyscale picture.
Something like that:
width = rawop.get_raw_width()
height = rawop.get_raw_height()
for y = 0, height - 1 do
for x = 0, width - 1 do
r, g1, b, g2 = rawop.get_pixels_rgbg(x,y)
grayscale = (r + g1 + b) / 3
rawop.set_pixels_rgbg(x, y, grayscale, grayscale, grayscale)
end
end
I always got the error there is no current image.
How can I access the captured picture?
Is your code running in the
raw hook? If so, which camera and shooting mode?
If not, you should generally
1) set the raw hook with hook_raw.set( timeout in milliseconds)
2) shoot using key presses, like
press'shoot_half'
repeat sleep(10) until get_shooting()
click'shoot_full'
...
3) After shooting, use hook_raw.wait_ready (needs require'hookutil') before your loop
4) use hook_raw.continue() after the loop.
You can find examples of this approach in CHDK/SCRIPTS/TEST/rawdraw.lua, and additional hook examples in hooktest.lua and drtest.lua.
Note looping over the entire image pixel by pixel will be quite slow, and extremely slow if you don't use set_yield to reduce automatic script yielding. Without testing, I'd guess minutes. The timeout you set when you call hook_raw.set needs to be longer than the time your loop takes. If it times out sooner, you'll probably get the error mentioned.