Live View with Canon EDSDK 2.5.2 VB.NET
Asked Answered
P

3

4

I am trying to do 1 of two things, preference number 1:

Turn on the Live View using VB.NET and the Canon EDSDK 2.5.2 and render the live output in a Windows Forms application. Currently I am trying to put it to a picture box; however, I am open to suggestions for sure.

The second option would be to at least turn on the Live View and have it stream via the Video output on the camera to a monitor.

I really want to accomplish the first though! Below is my current codebase, help!

Private Sub btnStartLiveView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartLiveView.Click

    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 outMemoryRef As IntPtr
    Dim evfImage As IntPtr

    err = EdsCreateMemoryStream(0, stream)

    If err = EDS_ERR_OK Then

        err = EdsCreateImageRef(stream, outMemoryRef) '(stream, evfImage)'

    Else

        Dim str As String = Hex(err)

        MessageBox.Show(str)

    End If

    If err = EDS_ERR_OK Then
        err = EdsDownloadEvfImage(model.getCameraObject(), evfImage)
    Else

        Dim str As String = Hex(err)

        MessageBox.Show("&H" & str & "L") ' Shows &H2CL which = ERR_FILE_FORMAT_NOT_RECOGNIZED'
    End If

    ' Get the Incidental Data of the Image'

    If err = EDS_ERR_OK Then

        Dim zoom As UInt32
        Dim point As IntPtr


        EdsGetPropertyData(outMemoryRef, kEdsPropID_Evf_ZoomPosition, 0, Marshal.SizeOf(zoom), zoom)

        EdsGetPropertyData(outMemoryRef, kEdsPropID_Evf_ZoomPosition, 0, Marshal.SizeOf(point), point)

    Else

        'MessageBox.Show(err.ToString())'

    End If


    Dim buffer(Marshal.SizeOf(stream)) As Byte

    Dim mStream As System.IO.Stream = New System.IO.MemoryStream(Marshal.SizeOf(stream))


    Dim gcTime As GCHandle = GCHandle.Alloc(0, GCHandleType.Pinned)
    Dim pTime As IntPtr = gcTime.AddrOfPinnedObject()
    Marshal.Copy(stream, buffer, 0, Marshal.SizeOf(stream))

    mStream.Write(buffer, 0, Marshal.SizeOf(stream))

    Me.PictureBox1.Image = Image.FromStream(mStream)

    EdsRelease(stream)
End Sub
Phosphine answered 21/5, 2009 at 21:28 Comment(2)
Can you describe more in detail what it is that is not working, how it is not working (detailed error messages, on which line it fails and such)?Boastful
It fails on this line: err = EdsCreateImageRef(stream, outMemoryRef) with ERR_FILE_FORMAT_NOT_RECOGNIZED Any help is greatly appreciated...Phosphine
T
2

Here's a .vb file in which I define class Camera which lets you do top level things like

Dim camera as New Camera
camera.EstablishSession()
camera.TakePicture("C:\path\to\save.jpg")
camera.StartLiveView(me.LiveViewPictureBox)
camera.StopLiveView()
camera.FlushTransferQueue()

I think you may find it useful:

<snip>

Over the years I've received multiple emails for updates to this block of code, which is on GitHub as open source:

http://github.com/superjoe30/Camlift-Controller

The Camera class is in slnCamliftController / src / Camera.vb

Some of this code is embarrassingly terrible. For example, in order to get it to work for the 5D and 7D camera, I have to create a program that initializes the SDK and then crashes on purpose. Terrible! I know! This is found in Klugesaurus. It's like when you try to connect to the 5D or 7D, nothing works. There is a pit of spikes there. So we shove a peasant (The Klugesaurus) onto the spikes, killing him (it fails silently), so we can walk across the peasant's dead body to safety.

It's ugly and terrible, but: It works every time. If you don't do it, it doesn't work. I have asked Canon multiple times if they would release source code for EOS Utility, which connects to the 5D and 7D perfectly. They have solidly refused each time. My coworker jokes that they don't want to reveal that they, too, are using a Klugesaurus. Anyways, I just wanted to give you a heads up to that nasty detail.

I also have created a Python module to interface with the camera: http://github.com/superjoe30/pyedsdk

Toscana answered 5/8, 2009 at 5:50 Comment(2)
I've since made big edits to this class. If you want an updated and useful camera API, contact me. I'd have to make sure I have rights to distribute it and stuff. Otherwise just use the clipping as an example of working code.Toscana
I have trouble too on trying the live view. Would you mind posted it somewhere @superjoe30?Cerebrovascular
P
2

I was the one who originally posted this question. I see that there are others here who are still seeking the answer. I have posted the solution that we finally came up with over on my blog at http://www.overridepro.com/2009/06/28/canon-sdk-live-view/ .

Pulsate answered 15/10, 2010 at 14:28 Comment(0)
I
0

There are code samples here and discussions on different ways of acomplishing it.

Inhibitory answered 25/5, 2009 at 16:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.