Add cvResize binding.
This commit is contained in:
parent
487ef183fd
commit
cc0a3e06c2
1 changed files with 37 additions and 0 deletions
37
opencv/imgproc.go
Normal file
37
opencv/imgproc.go
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
// Copyright 2013 jrweizhang AT gmail.com. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package opencv
|
||||||
|
|
||||||
|
//#include "opencv.h"
|
||||||
|
//#cgo linux pkg-config: opencv
|
||||||
|
//#cgo darwin pkg-config: opencv
|
||||||
|
//#cgo windows LDFLAGS: -lopencv_core242.dll -lopencv_imgproc242.dll -lopencv_photo242.dll -lopencv_highgui242.dll -lstdc++
|
||||||
|
import "C"
|
||||||
|
import (
|
||||||
|
//"errors"
|
||||||
|
"log"
|
||||||
|
"unsafe"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Resize(src *IplImage, width, height, interpolation int) *IplImage {
|
||||||
|
if width == 0 && height == 0 {
|
||||||
|
panic("Width and Height cannot be 0 at the same time")
|
||||||
|
}
|
||||||
|
if width == 0 {
|
||||||
|
ratio := float64(height / src.Height())
|
||||||
|
width = int(float64(src.Width()) * ratio)
|
||||||
|
log.Println(ratio)
|
||||||
|
log.Println(width)
|
||||||
|
} else if height == 0 {
|
||||||
|
ratio := float64(width / src.Width())
|
||||||
|
height = int(float64(src.Height()) * ratio)
|
||||||
|
log.Println(ratio)
|
||||||
|
log.Println(height)
|
||||||
|
}
|
||||||
|
|
||||||
|
dst := CreateImage(width, height, src.Depth(), src.Channels())
|
||||||
|
C.cvResize(unsafe.Pointer(src), unsafe.Pointer(dst), C.int(interpolation))
|
||||||
|
return dst
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue