Can CHDK do this? - Hello, I'm a NEWBIE - HELP!! (Newbies assistance, User Guides and thank you notes) - CHDK Forum
supplierdeeply

Can CHDK do this?

  • 5 Replies
  • 1387 Views
Can CHDK do this?
« on: 02 / December / 2013, 01:18:02 »
Advertisements
Hello everyone,

I run into CHDK while researching for a project and I have to say it looks like a really promising tool. However, before I dig through all the deepest details of CHDK I would like to understand if it can really do what I need it to do. Can someone please help me answer these questions:

1. I need to automatically shoot a 10ms shot with manual settings as soon as motion is detected. As far as I understood this is easily done with the standard motion detection script.

2. I need to do image processing directly on the camera (e.g. detect the size and position of a yellow circle in the image). As far as I understood this can also be done with a simple script.

3. I need to send the calculated values (e.g. circle center position) to an external PLC running a third party OS. I have read the section PTP Extension, but it is not clear to me if I can just send data (as simple bytes) over the USB instead of entire files. In case PTP would not work, are there alternatives to it (e.g. UDP over the USB line)?

4. Points 2 and 3 need to complete within 100ms, which is why I cannot wait until the camera saves the image to the CF card, then transfers it to a PC, then do image processing there and finally send the data over to the PLC. That approach would take much too long. I need to do data analysis directly on the raw image before it is saved as a file. I actually do not even need to save it at all if that matters. I am not sure if that is possible.

I hope my intentions are clear. I don't need a solution to the details, I just need to understand if CHDK is the right tool for me.

Thank you!

*

Offline reyalp

  • ******
  • 12004
Re: Can CHDK do this?
« Reply #1 on: 02 / December / 2013, 02:33:19 »
1. I need to automatically shoot a 10ms shot with manual settings as soon as motion is detected. As far as I understood this is easily done with the standard motion detection script.
This should be possible.
Quote
2. I need to do image processing directly on the camera (e.g. detect the size and position of a yellow circle in the image). As far as I understood this can also be done with a simple script.
This is not currently possible with script. It should be fairly straightforward with C code, you should be able to just throw your code in core/raw.c raw_process around where the shot histogram stuff is done. But see below...
Quote
3. I need to send the calculated values (e.g. circle center position) to an external PLC running a third party OS. I have read the section PTP Extension, but it is not clear to me if I can just send data (as simple bytes) over the USB instead of entire files. In case PTP would not work, are there alternatives to it (e.g. UDP over the USB line)?
You cannot just send data over the PTP connection, you need a USB host on the other end with a software stack that understands PTP and the CHDK extension. If you have this, you can send whatever data you like using the script message interface http://chdk.wikia.com/wiki/Lua/PTP_Scripting#read_usb_msg

You cannot just send arbitrary bytes over USB, the camera firmware expects a PTP host on the other end, and we have not reverse engineered the lower levels of the camera USB stack.

If you don't mind opening up the camera and soldering, you could probably use the UART: http://chdk.wikia.com/wiki/UART

If your data is very limited you could use one of the camera LEDs for output. You can also use http://chdk.wikia.com/wiki/USB_Shutter_Remote for limited, low speed input.
Quote
4. Points 2 and 3 need to complete within 100ms, which is why I cannot wait until the camera saves the image to the CF card,
If your image analysis requires examining a large part of the raw image buffer, this will be difficult or impossible. The camera CPU is not particularly fast, just reading every pixel would take quite a bit more than 100ms.

Note that if you do not need high resolution, you don't need to shoot at all, you could just analyze the live view data used on the LCD. This is typically 240 or 480 lines depending on the camera. This is the same buffer we use for motion detection.
Don't forget what the H stands for.

*

Offline Davo

  • ***
  • 153
Re: Can CHDK do this?
« Reply #2 on: 02 / December / 2013, 07:00:55 »
Note that if you do not need high resolution, you don't need to shoot at all, you could just analyze the live view data used on the LCD. This is typically 240 or 480 lines depending on the camera. This is the same buffer we use for motion detection.

My AstroKam software uses the LiveView data and I get around 10fps on the LiveView screen. It then uses the AForge.NET framework to invert or monochrome the video stream. I use AForge in some other applications where I use its pattern recognition routines to track sunspots. Finding the position of a yellow circle would be a doddle for AForge and its code is open source so you can tweak it.

Re: Can CHDK do this?
« Reply #3 on: 02 / December / 2013, 20:29:43 »
Thank you guys for the helpful answers.

I had imagined the data communication over the USB was not going to be easy. The PLC certainly does not understand PTP and CHDK, it can only handle raw bytes.

Using the LiveView is apparently the only way to go. I can accept the low resolution, but: can I guarantee that the LiveView frame is exactly 10ms long and starts exactly when triggered by the motion detection script?

I have to do motion detection on the camera. Doing it on the PC would be too slow and I would very likely miss the action (unless I would somehow get a 100fps stream from the LiveView).

Once I know I can get the right frame on the PC then I could accept a 10fps stream and could do object recognition there (with either OpenCV or AForge).

Thank you!


Re: Can CHDK do this?
« Reply #4 on: 02 / December / 2013, 20:51:09 »
Using the LiveView is apparently the only way to go. I can accept the low resolution, but: can I guarantee that the LiveView frame is exactly 10ms long and starts exactly when triggered by the motion detection script?
Are you aware that most cameras running CHDK motion detection will normally not respond in much under 100 mSec to a motion event?

Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 12004
Re: Can CHDK do this?
« Reply #5 on: 02 / December / 2013, 21:16:00 »
I had imagined the data communication over the USB was not going to be easy. The PLC certainly does not understand PTP and CHDK, it can only handle raw bytes.
Is the PLC a USB host? Do you have the ability to run your own code on it?

Anyway, practically speaking without a PTP stack on the host side, you will not be able to use USB to talk to CHDK.

An alternative might be to use a PC or a linux capable SBC like the raspberry pi between your camera and PLC.
Quote
Using the LiveView is apparently the only way to go. I can accept the low resolution, but: can I guarantee that the LiveView frame is exactly 10ms long and starts exactly when triggered by the motion detection script?
No. The shutter speed in live view would normally be chosen automatically by the camera. You might be able to control it using something like http://chdk.setepontos.com/index.php?topic=5295.100

Note that the reaction time of MD is substantially longer than 10ms, it varies depending on the camera but will likely be over 100ms. See http://chdk.setepontos.com/index.php?topic=9366.50
Quote
I have to do motion detection on the camera. Doing it on the PC would be too slow and I would very likely miss the action (unless I would somehow get a 100fps stream from the LiveView).
MD only operates at the frame rate of the live view (at best, on some cameras it might only see every third frame) which is probably something like 30 fps.
Don't forget what the H stands for.

 

Related Topics