1: add CV_INTER_* const values.
2: add imgproc_test.go
This commit is contained in:
parent
1f95ef5787
commit
ecf8d35122
2 changed files with 67 additions and 11 deletions
|
|
@ -16,6 +16,14 @@ import (
|
|||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
CV_INTER_NN = int(C.CV_INTER_NN)
|
||||
CV_INTER_LINEAR = int(C.CV_INTER_LINEAR)
|
||||
CV_INTER_CUBIC = int(C.CV_INTER_CUBIC)
|
||||
CV_INTER_AREA = int(C.CV_INTER_AREA)
|
||||
CV_INTER_LANCZOS4 = int(C.CV_INTER_LANCZOS4)
|
||||
)
|
||||
|
||||
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")
|
||||
|
|
@ -33,18 +41,9 @@ func Resize(src *IplImage, width, height, interpolation int) *IplImage {
|
|||
return dst
|
||||
}
|
||||
|
||||
func NewRect(x, y, width, height int) Rect {
|
||||
r := C.cvRect(
|
||||
C.int(x),
|
||||
C.int(y),
|
||||
C.int(width),
|
||||
C.int(height),
|
||||
)
|
||||
return Rect(r)
|
||||
}
|
||||
|
||||
func Crop(src *IplImage, x, y, width, height int) *IplImage {
|
||||
rect := NewRect(x, y, width, height)
|
||||
r := C.cvRect(C.int(x), C.int(y), C.int(width), C.int(height))
|
||||
rect := Rect(r)
|
||||
|
||||
src.SetROI(rect)
|
||||
dest := CreateImage(width, height, src.Depth(), src.Channels())
|
||||
|
|
|
|||
57
opencv/imgproc_test.go
Normal file
57
opencv/imgproc_test.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package opencv
|
||||
|
||||
import (
|
||||
"path"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestResize(t *testing.T) {
|
||||
_, currentfile, _, _ := runtime.Caller(0)
|
||||
filename := path.Join(path.Dir(currentfile), "../images/lena.jpg")
|
||||
|
||||
image := LoadImage(filename)
|
||||
if image == nil {
|
||||
t.Fatal("LoadImage fail")
|
||||
}
|
||||
defer image.Release()
|
||||
|
||||
rimage := Resize(image, 10, 10, CV_INTER_LINEAR)
|
||||
if rimage == nil {
|
||||
t.Fatal("Resize fail")
|
||||
}
|
||||
defer rimage.Release()
|
||||
|
||||
if rimage.Width() != 10 {
|
||||
t.Fatalf("excepted width is 10, returned %d\n", rimage.Width())
|
||||
}
|
||||
|
||||
if rimage.Height() != 10 {
|
||||
t.Fatalf("excepted width is 10, returned %d\n", rimage.Height())
|
||||
}
|
||||
}
|
||||
|
||||
func TestCrop(t *testing.T) {
|
||||
_, currentfile, _, _ := runtime.Caller(0)
|
||||
filename := path.Join(path.Dir(currentfile), "../images/lena.jpg")
|
||||
|
||||
image := LoadImage(filename)
|
||||
if image == nil {
|
||||
t.Fatal("LoadImage fail")
|
||||
}
|
||||
defer image.Release()
|
||||
|
||||
crop := Crop(image, 0, 0, 200, 200)
|
||||
if crop == nil {
|
||||
t.Fatal("Crop fail")
|
||||
}
|
||||
defer crop.Release()
|
||||
|
||||
if crop.Width() != 200 {
|
||||
t.Fatalf("excepted width is 200, returned %d\n", crop.Width())
|
||||
}
|
||||
|
||||
if crop.Height() != 200 {
|
||||
t.Fatalf("excepted width is 200, returned %d\n", crop.Height())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue