Canon SDK Live View

Okay, recently we needed to make a Canon EOS40D capture a Live Stream (keep in mind this is a Still Camera not a video camera) and pull the Live Stream back to a Windows Forms application and perform interactions with another system via Serial Commands.  The biggest struggle throughout the project was the Live Stream.  Taking pictures and the rest of the project was a snap (bad pun)….

There was absolutely NO documentation provided in a managed code such as .NET (which is what we were writing it in), Canon does not support the SDK, and documentation on the internet is nearly nothing.

Below is a sample of the LiveView loop and how to call it in a separate thread to make it run.

68 Comments for this entry

  • justin, July 6th, 2011 on 8:56 am

    @BT

    The issue Roberto had was referencing the DLL.

    You should be able to simply add the DLL to your BIN folder and then create a Reference to it. Simply Right Click on your project in Solution Explorer and click “Add Reference”.

    Browse for the DLL – now in your BIN folder and add it. This should make it available throughout the project.

  • justin, July 6th, 2011 on 8:58 am

    It seems there may be enough interest that I could post an anonymous read only access into our SVN repo to grab a snapshot of this code. It would be offered as is.

    I will gladly offer support but at this time I no longer have access to a camera as they were all sent to Disney when the Attraction went live.

  • justin, July 6th, 2011 on 9:05 am

    Also, got this comment in email but no way to reply as no email address was left. My response is listed below

    Hi, i’m a complete newb to VB and using Visual Basic 2010 Express to try to create our own imaging application which would take picture(s) in live view and store them in the current record of a database.

    I’ve gotten the sample program to compile and added your code from your post on the subject but can’t get a “live view” window to open.

    I added a Picture Box (PictureBox1) to my VB Sample form, but don’t know how to get it to “attach” to the live view from the camera.

    I’m not even sure i’m editing the correct file (CameraControlDlg.vb), should i be editing CameraController.vb?

    I can send my current code if you can help. Or just offer some pointers?

    Thanks!

    ———– ANSWER ———————–

    You need to name the Picture box the way it is named in the form and make sure it is on the same form as the main app. Then when the method runs it will run the Live View to the Picture Box.

  • justin, July 6th, 2011 on 9:06 am

    To see what this solution was actually used in at EPCOT take a look at this post. Should give you some ideas of how stable it ended up and what it is capable of. Keep up the work! I pulled out my hair for 4 months getting this to work so you guys get the leg up from that effort!

    http://www.overridepro.com/2010/08/14/kodak-imagination-show-video/

  • marc, August 15th, 2011 on 10:34 am

    Hello,

    I am working on my final career project and I am trying to use your code to make the liveview work, but I am having some problems.

    When executing this result = EDSDK.EdsDownloadEvfImage(pCamera, pImageEvf) it returns EDS_ERR_OBJECT_NOTREADY error. I decided to look on Internet and on documentation but they only recommend to do a loop and execute until error = EDS_ERR_OK.

    Did you had any problem with this error? Or do you know anyway to solve it?

    I am using a Canon 40D just like you, but wasn’t able to run this program properly.

    Thanks in advance.

  • justin, August 15th, 2011 on 1:32 pm

    Hi Marc–

    We originally set out with the 40D and ended up with the 50D because the 40D has gobs of problems with Live View, it will still work though it was just too spotty for us to use inside of Disney.

    Basically what it is telling you is that the camera is not ready. Are you sure you are executing the commands prior to that to get the camera ready?

    I know what they mean with doing the loop. Basically the camera can sometimes get ready immediately and sometimes take 2 or 3 seconds.

    See if you can get the camera to initialize and let me know.

  • marc, August 16th, 2011 on 1:05 pm

    Hi justin,

    Thanks for your help, you drove me in the right direction.

    I finally found a solution, the problem wasn’t caused by EdsDownloadEvfImage. I combined your code with another one and finally solved it.

    Here is a working code sample for LiveView using a Canon 40D and EDSDK v2.10 using VB.NET:

    There are some variables wich are Public Shared to comunicate with other classes, and avoid EdsDownloadEvfImage conflicts. Hope I solve someone else problems.

    #Region “Live View part”

    ‘// Creates an execute a thread with LiveView Function code
    Public Sub PreviewOn()

    System.Threading.Thread.Sleep(1000)

    LVThread = New Thread(AddressOf LiveView)

    LiveViewRunning = True

    LVThread.Start()

    End Sub

    Friend Sub LiveView()
    Dim first_time As Boolean = True

    While LiveViewRunning

    If LiveViewPaused Then ‘// pauses the LiveView to avoid conflicts while taking a picture
    System.Threading.Thread.Sleep(100)
    first_time = True
    Else

    Dim err As Integer = EDS_ERR_OK
    Dim prop As Integer = EdsEvfOutputDevice.kEdsEvfOutputDevice_PC
    Dim proptype As Integer = EDSDKTypes.kEdsPropID_Evf_OutputDevice

    ‘// Stock the property.’
    Dim wkIntPtr As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(prop))
    Marshal.StructureToPtr(prop, wkIntPtr, False)

    ‘send property/command to the camera’
    EdsSetPropertyData(model.getCameraObject(), proptype, 0, Marshal.SizeOf(prop), prop)

    Dim stream As IntPtr
    Dim evfImage As IntPtr
    Dim pCamera As IntPtr

    err = EdsCreateMemoryStream(0, stream)

    If err = EDS_ERR_OK Then
    err = EdsCreateEvfImageRef(stream, evfImage)
    Else
    Dim str As String = Hex(err)
    MessageBox.Show(str)
    End If

    If err = EDS_ERR_OK Then
    pCamera = model.getCameraObject()
    ‘// if it is the first time to execute the preview loop, waits 1,5 sec to avoid EDS_ERR_OBJECT_NOTREADY
    If first_time Then
    System.Threading.Thread.Sleep(1500)
    first_time = False
    End If
    err = EdsDownloadEvfImage(pCamera, evfImage)
    Else
    Dim str As String = Hex(err)
    MessageBox.Show(“&H” & str & “L”) ‘ Shows &H2CL which = ERR_FILE_FORMAT_NOT_RECOGNIZED’
    End If

    ”// PART WEB
    Dim n As Integer = 0
    While err = EDS_ERR_OBJECT_NOTREADY
    err = EdsDownloadEvfImage(pCamera, evfImage)
    Thread.Sleep(100)
    EdsRelease(stream)
    n = n + 1
    If n = 4 Then
    MsgBox(“EDS_ERR_OBJECT_NOTREADY”)
    End If
    End While

    If err EDS_ERR_OK Then
    ‘Program.log(LogCategory.[Error], “Unable to download Evf image:{0:X}”, result)

    MessageBox.Show(“Unable to download Evf image – ” & Hex(err))
    EdsRelease(stream)
    EdsRelease(evfImage)
    Exit Sub
    End If

    ‘Program.log(LogCategory.Debug, “Downloaded Evf image data.”)

    ‘ extract image data into

    Dim ipData As IntPtr
    err = EdsGetPointer(stream, ipData)
    If err EDS_ERR_OK Then
    ‘Program.log(LogCategory.[Error], “EdsGetPointer failed: {0:X}”, result)

    MessageBox.Show(“EdsGetPointer failed”)
    EdsRelease(stream)
    EdsRelease(evfImage)
    Exit Sub
    End If

    Dim len As UInteger
    err = EDSDK.EdsGetLength(stream, len)
    If err EDS_ERR_OK Then
    ‘Program.log(LogCategory.[Error], “EdsGetLength failed:{0:X}”, result)

    MessageBox.Show(“EdsGetLength failed”)
    EdsRelease(stream)
    EdsRelease(evfImage)
    EdsRelease(ipData)
    Exit Sub
    End If

    Dim buffer() As Byte = New Byte(CInt(len)) {}
    Marshal.Copy(ipData, buffer, 0, CInt(len))
    Dim memStream As New System.IO.MemoryStream(buffer)

    ‘ get the bitmap and draws the PictureBox
    Dim bitmap As Bitmap
    bitmap = bitmap.FromStream(memStream)
    LiveViewPictureBox.Image = bitmap
    LiveViewPictureBox.Refresh()

    ‘ cleanup
    memStream.Dispose()
    EDSDK.EdsRelease(stream)
    EDSDK.EdsRelease(evfImage)
    EDSDK.EdsRelease(ipData)

    End If
    End While
    Preview_Running = False
    End Sub

    #End Region

  • Chris, September 12th, 2011 on 4:08 am

    Have you guys been able to get a decent frame rate? Whenever I use live view the frame rate seems to be only a few frames per second.

  • justin, September 12th, 2011 on 10:34 am

    Hey Chris– Depends on the camera. With the 40D we started with it was very choppy. The 50D actually has video capabilities built in so it was a whole lot better. It ran live to Disney guests so it did turn out okay in the end. Is it super choppy or just not smooth enough for you? Also, what camera?

  • jhandrew, September 24th, 2011 on 11:50 am

    I have try using EOS 1000D, its work only for 4 loop while liveview and get error download Evf image

  • justin, September 24th, 2011 on 7:53 pm

    Are you saying when you run it through debug you see it work for 4 cycles and then it throws the error Cannot Download Evf Image?

  • John, October 4th, 2011 on 12:35 am

    hi justin,

    got an error Unable to download Evf image – A102
    EdsGetPointer failed… how to do i fixed this one…

  • Aleks, October 12th, 2011 on 5:25 am

    Greetings Justin! We’ve tested your piece of code with our Canon EOS 1000D. Our programme works fine. Presents Live View, takes pictures! We used Custom Canon provided SDK 2.10 vb wrapper and optimised it with the one you wrote. We succeeded! We also used Microsoft Visual Studio 2010, os Microsoft Windows XP Home Edition Version 2002 Service Pack 3.
    Thank you for your code and sharing. That’s well done! (by the way we encountered no error with “EdsDownloadEvfImage” or “error Unable to download Evf image – A102″ like it was mentioned above, thus you piece of code is fine)

  • Eric, October 17th, 2011 on 12:36 pm

    Another thank you for putting this code out there. I have gotten this to work on an EOS60D, VB .NET 2010, SDK 2.10 and running on Win7. End user wanted to see live video of the shot before taking the picture. This works quite nicely. I did have to put invoke commands around the picture box update and refresh commands though, otherwise my program would crash. (thread issue?) It appears you did not have this problem… ? Also, in my varied reading and research on using these cameras like this, it seems that some people indicate that leaving it on continuously in live view mode is not good due to heat build up, leading to some type of problem? Have you ever encountered any issues running for days at at time?

  • justin, October 17th, 2011 on 1:05 pm

    Your first issue is most likely a thread issue yes. We had several other methods that are not listed in this code snippet on how to handle threads.

    Yes, we did encounter the heat issue. Initially this was written for a EOS40D which did not even support Live VIdeo directly so we really stretched its limitations. The client was EPCOT (Disney) and the shows ran for 15 minutes at a time. What would happen was at the last queue the actor would not move the show into the wait mode which would turn live view off. When the camera hit a total of a couple hours of live view it would just shut off and would have to cool down for nearly an hour. This also led to burning out several cameras (3 I think). Once we moved the Canon 50D we no longer had these issues.

    To confirm testing I wrote a separate program that ran the live view continuously and snapped a photo every 20 minutes. Leaving it to run overnight and the next day (24 hours later) the program was still running fine with Live View. I believe the newer versions of the camera, 50D and now 60D have solved the heat issue. Let me know if you find out differently.

    Glad our code could help. Have a blessed day.

  • Eric, October 27th, 2011 on 9:23 am

    Hi Justin,

    We are seeing a strange error, wondering if you could offer an opinion? With our EOS60D, the liveveiw stuff works great, it also takes pictures great, but we are experiencing a couple of strange things. First, if we do nothing but start up live view, it invariably crashes. (Takes a while, like an hour or more). The place in the program where it hangs is ‘EDS_ERR_OBJECT_NOTREADY’, it appears that even repeatedly waiting, it just never ends being notready. But the bad thing is the camera at that point does not seem to be in a good mode, because even with a fresh program restart, liveview will not work. Simpley power cycling the camera fixes that. The other strange thing we see, when trying to share liveview and picture taking (toggling between threads essentially) we can seemingly get into the liveview thread where it just doesn’t seem to exit on its own. Curious if I might be able to ask you more about the threading parts of this process? We appear to have no heat issues with the liveview, unless this might be symptom of the camera heating? Thanks!

  • justin, October 27th, 2011 on 9:36 am

    Hi Eric,

    Wow, taking me back on this one. I spent several months each and every night at Disney working on these EXACT same issues – live view works, then stops, only way to fix is to power cycle the camera, I mean the exact same issues. While I am not familiar with the 60D the 50D that we settled on helped us to resolve all these issues so there is hope. I am sending an email to the email you listed with the subject CANON LIVE VIEW. You can respond with more detailed questions if you prefer. I will have to think back about how we solved each issue but we did solve them. Respond to my email and we will figure it out.

  • Soke, December 9th, 2011 on 3:18 am

    Hi Justin!
    Your code works fine for me, on Pentium IV, dual core etc. Thanks for that.
    Just one problem: live view is freezing when the code is running on Pentium I3 and camera is moving left/right, up/down…
    And one more thing: I can’t figure out how to start live view on camera, programmatically, without manually press that button,
    Obs. I’m using Canon EOS 600D.

    Any help will be appreciated!

Leave a Reply




*