[OpenCV] Chapter01-11 Obtaining frame stream properties

Obtaining frame stream properties

Source Code

package main

import (
 "fmt"
 "github.com/pkg/errors"
 "gocv.io/x/gocv"
 "log"
)

func main() {
 videoPath := "../../data/drop.avi"
 err := printCaptureProperties(videoPath)
 if err != nil {
  log.Panic("Could not print capture properties: " + videoPath)
 }

 cameraNo := 0
 err = printCaptureProperties(cameraNo)
 if err != nil {
  log.Panic("Could not print capture properties: " + string(cameraNo))
 }
}

func printCaptureProperties(param interface{}) error {
 var capture *gocv.VideoCapture
 var err error

 switch param.(type) {
 case int:
  capture, err = gocv.VideoCaptureDevice(param.(int))
 case string:
  capture, err = gocv.VideoCaptureFile(param.(string))
 default:
  return errors.New(fmt.Sprintf("%v is not supported type(%T)", param, param))
 }

 if err != nil {
  log.Panic("Can not find capture source")
  return err
 }

 log.Println("--------------------")
 log.Println("Frame count:", capture.Get(gocv.VideoCaptureFrameCount))
 log.Println("Frame width:", capture.Get(gocv.VideoCaptureFrameWidth))
 log.Println("Frame height:", capture.Get(gocv.VideoCaptureFrameHeight))
 log.Println("Frame rate:", capture.Get(gocv.VideoCaptureFPS))

 return nil
}

Execute Result

$ go run chapter01-11_obtaining_frame_stream_properties.go 
2019/03/07 00:00:06 --------------------
2019/03/07 00:00:06 Frame count: 182
2019/03/07 00:00:06 Frame width: 256
2019/03/07 00:00:06 Frame height: 240
2019/03/07 00:00:06 Frame rate: 30
2019/03/07 00:00:06 --------------------
2019/03/07 00:00:06 Frame count: 0
2019/03/07 00:00:06 Frame width: 1280
2019/03/07 00:00:06 Frame height: 720

Comments

Popular posts from this blog

[OpenCV] What is gocv?

[OpenCV] Chapter01-05 Working with UI elements such as scrollbars in OpenCV window

[OpenCV] How to set up gocv