Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

questions about PredictNextPosition #2

Closed
FieldsYeh opened this issue Jun 6, 2021 · 5 comments · Fixed by #3
Closed

questions about PredictNextPosition #2

FieldsYeh opened this issue Jun 6, 2021 · 5 comments · Fixed by #3
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested

Comments

@FieldsYeh
Copy link

first question regard variable prev and current, seems current is prev, prev is current
prev := len((*b).Track) - 1
current := prev - 1

second question in below loop
for i := 1; i < int(account); i++ {
deltaX += (((*b).Track)[current].X - ((*b).Track)[prev].X) * i
......
the value ((*b).Track)[current].X - ((*b).Track)[prev].X seems can compute before the loop

@FieldsYeh
Copy link
Author

I've found a c++ version, seem more correct, see below URL
https://github.com/MicrocontrollersAndMore/OpenCV_3_Car_Counting_Cpp/blob/master/Blob.cpp

@LdDl
Copy link
Owner

LdDl commented Jun 7, 2021

first question regard variable prev and current, seems current is prev, prev is current
prev := len((*b).Track) - 1
current := prev - 1

second question in below loop
for i := 1; i < int(account); i++ {
deltaX += (((*b).Track)[current].X - ((*b).Track)[prev].X) * i
......
the value ((*b).Track)[current].X - ((*b).Track)[prev].X seems can compute before the loop

  1. Well, notations is not obvious at all. I'll work on it.
  2. Is delta really needed to be computed on initial step (i = 0 leads to the same) ? What do you think?

@LdDl
Copy link
Owner

LdDl commented Jun 7, 2021

I've found a c++ version, seem more correct, see below URL
https://github.com/MicrocontrollersAndMore/OpenCV_3_Car_Counting_Cpp/blob/master/Blob.cpp

I've used to use this code in early implementations, but I don't like hardcoded if/else statements at all.

@LdDl LdDl self-assigned this Jun 7, 2021
@LdDl LdDl added the question Further information is requested label Jun 7, 2021
@FieldsYeh
Copy link
Author

FieldsYeh commented Jun 7, 2021

below is my modified code.

func (b *KalmanBlobie) PredictNextPosition(n int) {
	account := min(n, len((*b).Track))
	current := len((*b).Track) - 1
	prev := current - 1
	var deltaX, deltaY, sum = 0, 0, 0
	for i := 1; i < int(account); i++ {
		deltaX += (((*b).Track)[current].X - ((*b).Track)[prev].X) * (account - i)
		deltaY += (((*b).Track)[current].Y - ((*b).Track)[prev].Y) * (account - i)
		sum += i
		current = prev
		prev = current - 1
	}
	if sum > 0 {
		deltaX /= sum
		deltaY /= sum
	}
	(*b).PredictedNextPosition.X = (*b).Track[len((*b).Track)-1].X + deltaX
	(*b).PredictedNextPosition.Y = (*b).Track[len((*b).Track)-1].Y + deltaY
}

@LdDl
Copy link
Owner

LdDl commented Jun 7, 2021

I've just updated your message for proper Go-code formatting if you don't mind.

So how does it perform against current implementation?

I need take a deeper look on this code. I think it is good idea to do tests with some drawing (for proof of conpect you know).... Something like this one https://github.com/LdDl/kalman-filter#usage but for two arrays of data: current position object and predicted (do not confuse 'predicted' with 'filtered').

@LdDl LdDl added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Jun 7, 2021
@LdDl LdDl mentioned this issue Aug 14, 2021
@LdDl LdDl linked a pull request Aug 14, 2021 that will close this issue
@LdDl LdDl closed this as completed in #3 Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants