func (capture *Capture) GetProperty(property_id int) float64 {
	rv := C.cvGetCaptureProperty((*C.CvCapture)(capture),
		C.int(property_id),
	)
	return float64(rv)
}
/* retrieve or set capture properties
package opencv
import "C"
import (
	"runtime"
	"unsafe"
)
func initSystem(args []string) int {
	argc := C.int(len(args))
	argv := make([]*C.char, len(args))
	for i := 0; i < len(args); i++ {
		argv[i] = C.CString(args[i])
	}
	rv := C.cvInitSystem(argc, (**C.char)(unsafe.Pointer(&argv)))
	return int(rv)
}
func StartWindowThread() int {
	return int(C.cvStartWindowThread())
}
func WaitKey(delay int) int {
	key := C.cvWaitKey(C.int(delay))
	return int(key)
}
type MouseFunc interface{}
type MouseFuncA func(event, x, y, flags int)
type MouseFuncB func(event, x, y, flags int, param ...interface{})
type TrackbarFunc interface{}
type TrackbarFuncA func(pos int)
type TrackbarFuncB func(pos int, param ...interface{})
type Window struct {
	name   string
	name_c *C.char
	flags  C.int
	mouseHandle MouseFunc
	param       []interface{}
	trackbarHandle map[string]TrackbarFunc
	trackbarMax    map[string]int
	trackbarVal    map[string]int
	trackbarName   map[string](*C.char)
	trackbarParam  map[string]([]interface{})
	image    *IplImage
	refCount int
}
var allWindows = make(map[string]*Window, 1000)
const (
	CV_WINDOW_AUTOSIZE = C.CV_WINDOW_AUTOSIZE
)
func NewWindow(name string, flags ...int) *Window {
	win_flags := C.int(CV_WINDOW_AUTOSIZE)
	if len(flags) > 0 {
		win_flags = C.int(flags[0])
	}
	win := &Window{
		name:   name,
		name_c: C.CString(name),
		flags:  win_flags,
		trackbarHandle: make(map[string]TrackbarFunc, 50),
		trackbarMax:    make(map[string]int, 50),
		trackbarVal:    make(map[string]int, 50),
		trackbarName:   make(map[string](*C.char), 50),
		trackbarParam:  make(map[string]([]interface{}), 50),
	}
	C.cvNamedWindow(win.name_c, win.flags)
	C.GoOpenCV_SetMouseCallback(win.name_c)
	allWindows[win.name] = win
	return win
}
func (win *Window) ShowImage(image *IplImage) {
	win.image = image
	C.cvShowImage(win.name_c, unsafe.Pointer(image))
}
func (win *Window) Resize(width, height int) {
	C.cvResizeWindow(win.name_c, C.int(width), C.int(height))
}
func (win *Window) Move(x, y int) {
	C.cvMoveWindow(win.name_c, C.int(x), C.int(y))
}
func (win *Window) GetHandle() unsafe.Pointer {
	p := C.cvGetWindowHandle(win.name_c)
	return unsafe.Pointer(p)
}
func (win *Window) GetWindowName() string {
	return win.name
}
func (win *Window) CreateTrackbar(name string,
	value, count int,
	on_changed TrackbarFunc, param ...interface{}) bool {
	bar_name := C.CString(name)
	switch f := on_changed.(type) {
	case TrackbarFuncA:
		win.trackbarHandle[name] = TrackbarFunc(f)
	case TrackbarFuncB:
		win.trackbarHandle[name] = TrackbarFunc(f)
	case func(pos int):
		win.trackbarHandle[name] = TrackbarFunc(f)
	case func(pos int, param ...interface{}):
		win.trackbarHandle[name] = TrackbarFunc(f)
	default:
		panic("unknow func type!")
	}
	win.trackbarVal[name] = value
	win.trackbarMax[name] = count
	win.trackbarName[name] = bar_name
	if len(param) > 0 {
		win.trackbarParam[name] = param
	} else {
		win.trackbarParam[name] = nil
	}
	rv := C.GoOpenCV_CreateTrackbar(bar_name, win.name_c,
		C.int(value), C.int(count))
	return bool(rv != 0)
}
func destroyTrackbar(barName_, winName_ *C.char) {
	C.GoOpenCV_DestroyTrackbar(barName_, winName_)
}
func goTrackbarCallback(barName_, winName_ *C.char, pos C.int) {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()
	winName := C.GoString(winName_)
	barName := C.GoString(barName_)
	win, ok := allWindows[winName]
	if !ok {
		return
	}
	trackbarHandle, ok := win.trackbarHandle[barName]
	if !ok {
		return
	}
	if trackbarHandle == nil {
		return
	}
	if fa, ok := trackbarHandle.(func(pos int)); ok {
		fa(int(pos))
	} else if fb, ok := trackbarHandle.(func(pos int, param ...interface{})); ok {
		param := win.trackbarParam[barName]
		if param != nil {
			fb(int(pos), param...)
		} else {
			fb(int(pos))
		}
	}
}
func (win *Window) GetTrackbarPos(name string) (value, max int) {
	rv := C.cvGetTrackbarPos(win.trackbarName[name], win.name_c)
	return int(rv), win.trackbarMax[name]
}
func (win *Window) SetTrackbarPos(name string, pos int) {
	C.cvSetTrackbarPos(win.trackbarName[name], win.name_c, C.int(pos))
}
const (
	CV_EVENT_MOUSEMOVE     = int(C.CV_EVENT_MOUSEMOVE)
	CV_EVENT_LBUTTONDOWN   = int(C.CV_EVENT_LBUTTONDOWN)
	CV_EVENT_RBUTTONDOWN   = int(C.CV_EVENT_RBUTTONDOWN)
	CV_EVENT_MBUTTONDOWN   = int(C.CV_EVENT_MBUTTONDOWN)
	CV_EVENT_LBUTTONUP     = int(C.CV_EVENT_LBUTTONUP)
	CV_EVENT_RBUTTONUP     = int(C.CV_EVENT_RBUTTONUP)
	CV_EVENT_MBUTTONUP     = int(C.CV_EVENT_MBUTTONUP)
	CV_EVENT_LBUTTONDBLCLK = int(C.CV_EVENT_LBUTTONDBLCLK)
	CV_EVENT_RBUTTONDBLCLK = int(C.CV_EVENT_RBUTTONDBLCLK)
	CV_EVENT_MBUTTONDBLCLK = int(C.CV_EVENT_MBUTTONDBLCLK)
	CV_EVENT_FLAG_LBUTTON  = int(C.CV_EVENT_FLAG_LBUTTON)
	CV_EVENT_FLAG_RBUTTON  = int(C.CV_EVENT_FLAG_RBUTTON)
	CV_EVENT_FLAG_MBUTTON  = int(C.CV_EVENT_FLAG_MBUTTON)
	CV_EVENT_FLAG_CTRLKEY  = int(C.CV_EVENT_FLAG_CTRLKEY)
	CV_EVENT_FLAG_SHIFTKEY = int(C.CV_EVENT_FLAG_SHIFTKEY)
	CV_EVENT_FLAG_ALTKEY   = int(C.CV_EVENT_FLAG_ALTKEY)
)
func (win *Window) SetMouseCallback(on_mouse MouseFunc, param ...interface{}) {
	switch f := on_mouse.(type) {
	case MouseFuncA:
		win.mouseHandle = MouseFunc(f)
	case MouseFuncB:
		win.mouseHandle = MouseFunc(f)
	case func(event, x, y, flags int):
		win.mouseHandle = MouseFunc(f)
	case func(event, x, y, flags int, param ...interface{}):
		win.mouseHandle = MouseFunc(f)
	default:
		panic("unknow func type!")
	}
	if len(param) > 0 {
		win.param = param
	} else {
		win.param = nil
	}
}
func goMouseCallback(name *C.char, event, x, y, flags C.int) {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()
	winName := C.GoString(name)
	win, ok := allWindows[winName]
	if !ok {
		return
	}
	if win.mouseHandle == nil {
		return
	}
	if fa, ok := win.mouseHandle.(func(event, x, y, flags int)); ok {
		fa(int(event), int(x), int(y), int(flags))
		return
	}
	if fb, ok := win.mouseHandle.(func(event, x, y, flags int, param ...interface{})); ok {
		if win.param != nil {
			fb(int(event), int(x), int(y), int(flags), win.param...)
		} else {
			fb(int(event), int(x), int(y), int(flags))
		}
		return
	}
}
func (win *Window) Destroy() {
	C.cvDestroyWindow(win.name_c)
	delete(allWindows, win.name)
	for _, bar_name := range win.trackbarName {
		C.GoOpenCV_DestroyTrackbar(bar_name, win.name_c)
		C.free(unsafe.Pointer(bar_name))
	}
	C.free(unsafe.Pointer(win.name_c))
	win.name_c = nil
}
func DestroyAllWindows() {
	for _, win := range allWindows {
		win.Destroy()
	}
}
const (
	CV_LOAD_IMAGE_UNCHANGED = int(C.CV_LOAD_IMAGE_UNCHANGED)
	CV_LOAD_IMAGE_GRAYSCALE = int(C.CV_LOAD_IMAGE_GRAYSCALE)
	CV_LOAD_IMAGE_COLOR = int(C.CV_LOAD_IMAGE_COLOR)
	CV_LOAD_IMAGE_ANYDEPTH = int(C.CV_LOAD_IMAGE_ANYDEPTH)
	CV_LOAD_IMAGE_ANYCOLOR = int(C.CV_LOAD_IMAGE_ANYCOLOR)
)
func LoadImage(filename string, iscolor_ ...int) *IplImage {
	iscolor := CV_LOAD_IMAGE_COLOR
	if len(iscolor_) > 0 {
		iscolor = iscolor_[0]
	}
	name_c := C.CString(filename)
	defer C.free(unsafe.Pointer(name_c))
	rv := C.cvLoadImage(name_c, C.int(iscolor))
	return (*IplImage)(rv)
}
func LoadImageM(filename string, iscolor int) *Mat {
	name_c := C.CString(filename)
	defer C.free(unsafe.Pointer(name_c))
	rv := C.cvLoadImageM(name_c, C.int(iscolor))
	return (*Mat)(rv)
}
func SaveImage(filename string, image *IplImage) int {
	name_c := C.CString(filename)
	defer C.free(unsafe.Pointer(name_c))
	rv := C.cvSaveImage(name_c, unsafe.Pointer(image))
	return int(rv)
}
const (
	CV_CVTIMG_FLIP    = int(C.CV_CVTIMG_FLIP)
	CV_CVTIMG_SWAP_RB = int(C.CV_CVTIMG_SWAP_RB)
)
func ConvertImage(src, dst unsafe.Pointer, flags int) {
	C.cvConvertImage(src, dst, C.int(flags))
}
type Capture C.CvCapture
func NewFileCapture(filename string) *Capture {
	filename_c := C.CString(filename)
	defer C.free(unsafe.Pointer(filename_c))
	cap := C.cvCreateFileCapture(filename_c)
	return (*Capture)(cap)
}
const (
	CV_CAP_ANY = int(C.CV_CAP_ANY)  
	CV_CAP_MIL = int(C.CV_CAP_MIL)  
	CV_CAP_VFW  = int(C.CV_CAP_VFW)  
	CV_CAP_V4L  = int(C.CV_CAP_V4L)
	CV_CAP_V4L2 = int(C.CV_CAP_V4L2)
	CV_CAP_FIREWARE = int(C.CV_CAP_FIREWARE)  
	CV_CAP_FIREWIRE = int(C.CV_CAP_FIREWIRE)
	CV_CAP_IEEE1394 = int(C.CV_CAP_IEEE1394)
	CV_CAP_DC1394   = int(C.CV_CAP_DC1394)
	CV_CAP_CMU1394  = int(C.CV_CAP_CMU1394)
	CV_CAP_STEREO = int(C.CV_CAP_STEREO)  
	CV_CAP_TYZX   = int(C.CV_CAP_TYZX)
	CV_TYZX_LEFT  = int(C.CV_TYZX_LEFT)
	CV_TYZX_RIGHT = int(C.CV_TYZX_RIGHT)
	CV_TYZX_COLOR = int(C.CV_TYZX_COLOR)
	CV_TYZX_Z     = int(C.CV_TYZX_Z)
	CV_CAP_QT = int(C.CV_CAP_QT)  
	CV_CAP_UNICAP = int(C.CV_CAP_UNICAP)  
	CV_CAP_DSHOW = int(C.CV_CAP_DSHOW)  
)
func NewCameraCapture(index int) *Capture {
	cap := C.cvCreateCameraCapture(C.int(index))
	return (*Capture)(cap)
}
func (capture *Capture) GrabFrame() bool {
	rv := C.cvGrabFrame((*C.CvCapture)(capture))
	return (rv != C.int(0))
}
func (capture *Capture) RetrieveFrame() *IplImage {
	rv := C.cvRetrieveFrame((*C.CvCapture)(capture))
	return (*IplImage)(rv)
}
func (capture *Capture) QueryFrame() *IplImage {
	rv := C.cvQueryFrame((*C.CvCapture)(capture))
	return (*IplImage)(rv)
}
func (capture *Capture) Release() {
	cap_c := (*C.CvCapture)(capture)
	C.cvReleaseCapture(&cap_c)
}
const (
	CV_CAP_PROP_POS_MSEC      = int(C.CV_CAP_PROP_POS_MSEC)
	CV_CAP_PROP_POS_FRAMES    = int(C.CV_CAP_PROP_POS_FRAMES)
	CV_CAP_PROP_POS_AVI_RATIO = int(C.CV_CAP_PROP_POS_AVI_RATIO)
	CV_CAP_PROP_FRAME_WIDTH   = int(C.CV_CAP_PROP_FRAME_WIDTH)
	CV_CAP_PROP_FRAME_HEIGHT  = int(C.CV_CAP_PROP_FRAME_HEIGHT)
	CV_CAP_PROP_FPS           = int(C.CV_CAP_PROP_FPS)
	CV_CAP_PROP_FOURCC        = int(C.CV_CAP_PROP_FOURCC)
	CV_CAP_PROP_FRAME_COUNT   = int(C.CV_CAP_PROP_FRAME_COUNT)
	CV_CAP_PROP_FORMAT        = int(C.CV_CAP_PROP_FORMAT)
	CV_CAP_PROP_MODE          = int(C.CV_CAP_PROP_MODE)
	CV_CAP_PROP_BRIGHTNESS    = int(C.CV_CAP_PROP_BRIGHTNESS)
	CV_CAP_PROP_CONTRAST      = int(C.CV_CAP_PROP_CONTRAST)
	CV_CAP_PROP_SATURATION    = int(C.CV_CAP_PROP_SATURATION)
	CV_CAP_PROP_HUE           = int(C.CV_CAP_PROP_HUE)
	CV_CAP_PROP_GAIN          = int(C.CV_CAP_PROP_GAIN)
	CV_CAP_PROP_EXPOSURE      = int(C.CV_CAP_PROP_EXPOSURE)
	CV_CAP_PROP_CONVERT_RGB   = int(C.CV_CAP_PROP_CONVERT_RGB)
	CV_CAP_PROP_RECTIFICATION = int(C.CV_CAP_PROP_RECTIFICATION)
)