Odd duplication issue in goroutine loop

I’ve got a function that should be pretty simple to implement, but I’ve been having fits with it. The function has an input channel, a loop, and an output channel. I should also mention that I have a custom type that contains a gocv mat broken down with some metadata added on, like the percent of pixels that change vs a comparison frame. When the function starts up, a variable called compFrm gets initialized out of the channel, then the loop begins. Each time a frame comes down the channel, it gets compared against the compFrm to detect motion. If it’s been more than 5 seconds, compFrm gets updated. The frames get sent down the output channel and the cycle begins anew.

For whatever reason, compFrm and procFrm are the exact same every time the loop comes back around. It’s like compFrm becomes procFrm every single round, even though it’s only supposed to copy after five seconds. I’ve completely removed the timer update bit, but it’s still getting copied for whatever reason. Below is a highly simplified version that still has the issue.

I’m sure it’s something simple, but still, I can’t seem to get it.


func manageUserCamMotion(input chan okoframe.Frame, output chan okoframe.Frame, colorThresh int) {

	var compFrm okoframe.Frame = <-input //Prime the comparison
	var err error

	compTime := time.Now()

	for procFrm := range input {

		procFrm.MotionPercentChange, err = getDiffPerc(procFrm, compFrm, colorThresh)

		if err != nil {
			fmt.Println("Error in manageUserCamMotion:", err)
		}

		//I've tried removing this to see if I was having some kind of malfunction with copying.
		if time.Since(compTime) > 5*time.Second {
			compFrm = procFrm
			compTime = time.Now()
			fmt.Println("Switched")
		}

		output <- procFrm
	}
}