package producer

import (
	"github.com/sirupsen/logrus"
	"gocv.io/x/gocv"
)

// 分景后再做配准
func (r *ImgProc) RegisterScenes(pan, mss *Scene) error {
	proc := NewImgProc(DownSampled)
	proc.PanImage = pan.Mat[0]
	proc.MssImages = [4]gocv.Mat{mss.Mat[0], mss.Mat[1], mss.Mat[2], mss.Mat[3]}
	proc.MssHeight = mss.Height
	proc.MssWidth = mss.Width
	proc.PanHeight = pan.Height
	proc.PanWidth = pan.Width

	err := proc.DoPhaseCorrelation(false)
	if err != nil {
		logrus.Error("register scene failed: ", err)
		return err
	}

	pan.Height = proc.PanHeight
	pan.Width = proc.PanWidth
	pan.Mat[0] = proc.PanImage

	mss.Height = proc.MssHeight
	mss.Width = proc.MssWidth
	for i := 0; i < 4; i++ {
		mss.Mat[i].Close()
		mss.Mat[i] = proc.registeredMssImages[i]
	}

	return nil
}
