bimg icon indicating copy to clipboard operation
bimg copied to clipboard

Performance is low

Open HrachMD opened this issue 1 year ago • 0 comments

GoCV - 74.686ms Bimg - 3.292993s

Same task with Imaging (github.com/disintegration/imaging) ~300ms // with python-cv ~150ms // with python PIL ~1.5s

package main

import (
	"fmt"
	"time"

	"github.com/h2non/bimg"
	"gocv.io/x/gocv"
)

func do() {
	st := time.Now().UTC()
	newMat3 := gocv.NewMat()
	newMat2 := gocv.NewMat()
	newMat := gocv.NewMat()
	mat := gocv.IMRead("/Users/hrachdev/Desktop/hawaii.jpg", gocv.IMReadColor)
	gocv.Resize(mat, &newMat3, image.Point{0, 0}, 3, 3, gocv.InterpolationArea)
	gocv.Resize(newMat3, &newMat2, image.Point{0, 0}, 2, 2, gocv.InterpolationArea)
	gocv.Resize(newMat2, &newMat, image.Point{0, 0}, 0.05, 0.05, gocv.InterpolationArea)
	gocv.IMWrite("/Users/hrachdev/Desktop/111/haw-cv.jpg", newMat)
	fmt.Println(time.Since(st))

	st = time.Now().UTC()
	bf, _ := bimg.Read("/Users/hrachdev/Desktop/hawaii.jpg")
	imB := bimg.NewImage(bf)
	szB, _ := imB.Size()
	opt1 := bimg.Options{
		Width:        szB.Width * 3,
		Height:       szB.Height * 3,
		Quality:      95,
		Interlace:    true,
		Interpolator: bimg.Interpolator(gocv.InterpolationArea),
	}
	opt2 := bimg.Options{
		Width:        szB.Width * 6,
		Height:       szB.Height * 6,
		Quality:      95,
		Interlace:    true,
		Interpolator: bimg.Interpolator(gocv.InterpolationArea),
	}
	opt3 := bimg.Options{
		Width:        int(float32(szB.Width) * 0.3),
		Height:       int(float32(szB.Height) * 0.3),
		Quality:      95,
		Interlace:    true,
		Interpolator: bimg.Interpolator(gocv.InterpolationArea),
	}
	imB.Process(opt1)
	imB.Process(opt2)
	imNewB, _ := imB.Process(opt3)
	bimg.Write("/Users/hrachdev/Desktop/111/haw-bim.jpg", imNewB)
	fmt.Println(time.Since(st))
}

func main() {
	do()
}

HrachMD avatar Jul 14 '22 10:07 HrachMD