title: PNG encoding with Go is slow
body: <p>I'm acquiring frames from my built in webcam with go-opencv. The time it takes to acquire an image from the camera  is ~50ms. The time to encode the PNG is ~300ms.  Encoding a JPEG is 3x faster, but still horribly slow.</p>
  
  <p>Why is this running so slowly?</p>
  
  <p><em>Note</em>:
  I've written similar code against NodeJS, executed on the same machine, and have absolutely no problem hitting 30fps w/ additional image processing.  For me, this removes hardware issues from the equation.</p>
  
  <p>My code looks like this:</p>
  
  <pre><code>import (
      "fmt"
      "image/png"
  
      "github.com/lazywei/go-opencv/opencv"
  )
  
  camera := opencv.NewCameraCapture(0)
  if camera == nil {
      panic("Unable to open camera.")
  }
  defer camera.Release()
  
  for {
      if camera.GrabFrame() {
          img := camera.RetrieveFrame(1)
          if img != nil {
              frame := img.ToImage()
              buffer := new(bytes.Buffer)
              png.Encode(buffer, frame)
          } else {
              fmt.Println("Unable to capture frame")
          }
      }
  
  }
  </code></pre>