Answer the question
In order to leave comments, you need to log in
How to superimpose an image on another image (in the center)?
Hey!
There was a task to superimpose one image on the second using gocv.
The difficulty is that you need to calculate the center "background" of the image.
What am I doing now:
bgImg := gocv.IMRead("bg.jpg", gocv.IMReadColor)
inputImg := gocv.IMRead("input.jpg", gocv.IMReadColor)
bgHalfWidth := bgImg.Cols() / 2
bgHalfHeight := bgImg.Rows() / 2
imgHalfWidth := inputImg.Cols() / 2
imgHalfHeight := inputImg.Rows() / 2
minX := bgHalfWidth - imgHalfWidth
minY := bgHalfHeight - imgHalfHeight
maxX := bgHalfWidth + imgHalfWidth
maxY := bgHalfHeight + imgHalfHeight
rect := image.Rect(minX, minY, maxX, maxY)
roi := bgImg.Region(rect)
gocv.AddWeighted(roi, 0.0, bgImg, 1.0, 0.0, &roi)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question