I am currently doing a project related to CHDK. One of my target is to do some analysis to the picture that user have taken(shape detection, etc.). However, the picture is saved in JPEG mode, which cannot directly analyze. Can anyone offer me some idea of how to approach this target?
Quote from: xsgs111 on 26 / February / 2015, 21:49:29I am currently doing a project related to CHDK. One of my target is to do some analysis to the picture that user have taken(shape detection, etc.). However, the picture is saved in JPEG mode, which cannot directly analyze. Can anyone offer me some idea of how to approach this target?If you want to do it when the picture is captured, you can analyze the raw buffer. Be warned that if you want to analyze the whole buffer it will be quite slow. In the development branch, I have added the ability to read raw pixels from Lua script, discussed starting at http://chdk.setepontos.com/index.php?topic=11081.msg119265#msg119265 but this is even slower than C code.Otherwise, if you want to analyze jpegs saved on the card, you would either need to implement a jpeg decoder or figure out how to re-use the one in the canon firmware.If you only need low resolution, you could look at the viewport buffer while the image is shown in review mode. This isn't available from script, but is already used for other purposes like PTP live view.Using your own jpeg decode would likely be difficult because the amount of ram available to CHDK is likely to be less than a decoded image. Additionally, CHDK doesn't have standard runtime libraries available, so third party libraries will probably be difficult to port.If analyzing the images off camera on a PC (or an SBC like raspberry pi or a smart phone) is an option, that would probably be much simpler, because you will have a lot more CPU and RAM, and will have a vast collection of imaging libraries available.
Thanks for your reply! I am quite OK with the delay since the analyze won't be too difficult.Do you have any idea on which function should I looked into if I want to do any "runtime" analysis on the raw picture? Also, what's the raw buffer's format, RGB or YUV?
Quote from: xsgs111 on 26 / February / 2015, 23:18:40Thanks for your reply! I am quite OK with the delay since the analyze won't be too difficult.Do you have any idea on which function should I looked into if I want to do any "runtime" analysis on the raw picture? Also, what's the raw buffer's format, RGB or YUV?The raw buffer is bayer RGB. See http://chdk.wikia.com/wiki/Frame_buffers for more information.In C code you can use get_raw_pixel from core/raw.c to read a single bayer element. To know which color a pixel is, you need to look at the camera_sensor.cfa_pattern and the coordinates. In the trunk code, modules/rawhookops.c contains the Lua interface. Even if you don't want to use Lua, this has examples of getting RGB from the bayer pattern.The raw buffer is only valid during the shooting process. To keep it from getting destroyed while you are working on it, the processing code should be in core/raw.c raw_process or use the raw hook from Lua.
I really appreciate your help! One more question is that is it safe(valid) to directly change the content in buffer, like flip all the colors or change all red into blue?
Quote from: xsgs111 on 27 / February / 2015, 01:08:26I really appreciate your help! One more question is that is it safe(valid) to directly change the content in buffer, like flip all the colors or change all red into blue?Yes, I've done this extensively in my Lua raw hook scripts. The debug displays on the videos in http://chdk.setepontos.com/index.php?topic=11081.40 are all done that way.If you call set_raw_pixel outside of the time the raw buffer is valid (in raw_process or the Lua raw hook) then the camera might be using the memory for something else. So don't do that
But it seems that by modifying the raw_process it won't directly change the JPEG file it save. If I turned on the saving raw I can see the change I make in the raw file, but there's no effect on the JPEG file. Do you have any idea on how to change the JPEG at the same time?
Quote from: reyalp on 27 / February / 2015, 01:49:51Quote from: xsgs111 on 27 / February / 2015, 01:08:26I really appreciate your help! One more question is that is it safe(valid) to directly change the content in buffer, like flip all the colors or change all red into blue?Yes, I've done this extensively in my Lua raw hook scripts. The debug displays on the videos in http://chdk.setepontos.com/index.php?topic=11081.40 are all done that way.If you call set_raw_pixel outside of the time the raw buffer is valid (in raw_process or the Lua raw hook) then the camera might be using the memory for something else. So don't do that I've try it out and everything seems working well . But it seems that by modifying the raw_process it won't directly change the JPEG file it save. If I turned on the saving raw I can see the change I make in the raw file, but there's no effect on the JPEG file. Do you have any idea on how to change the JPEG at the same time?Thanks!
Started by kdeal Feature Requests
Started by davecool RAW Shooting and Processing
Started by Gigi Treosei General Help and Assistance on using CHDK stable releases
Started by redfordl22 General Help and Assistance on using CHDK stable releases
Started by 74prof Feature Requests