Comments (2)
Hey Gianluca.
Well, in order not to have to create an interface of some sort asking me what object I want to track in my program, I set the initial [x,y] of the histogram to be equal to [240,320] (this point was purely empirical based on my camera, screen, etc).
So it will start tracking the object at this point (it will compute the histogram for it at the start of the program).
In order to make this more interactive, we could implement a way of clicking in the screen to define the first point to be tracked, which i think is quite easy.
I also commented some of the functions within the code, I hope things are clearer. If not, keep asking!
Cheers,
Eric
from cbpt.
Good morning, sir,
I tried to use your particle filter code by defining by a screenshot, (from the mouse) my reference box to apply the particle filter, but it doesn't work so far. I'm attaching the code I wrote.
I'd like to have an article with it doing my job. Please help me. I'll quote your article in my publication.
best regars
import cv2
import numpy as np
from matplotlib import pyplot as plt
from particle_filter import ParticleFilter
objet=0
nbr_classes=180
seuil=30
term_criteria=(cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1.0)
def click(event, x, y, flags, param):
global roi_x, roi_y, roi_w, roi_h, roi_hist, frame, objet
if event==cv2.EVENT_LBUTTONDBLCLK:
roi_x, roi_y, roi_w, roi_h=cv2.selectROI('ROI', frame, False, False)
roi=frame[roi_y: roi_y + roi_h, roi_x: roi_x + roi_w]
hsv_roi=cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
roi_hist=cv2.calcHist([hsv_roi], [0], None, [nbr_classes], [0, nbr_classes])
cv2.normalize(roi_hist, roi_hist, 0, 255, cv2.NORM_MINMAX)
cv2.destroyWindow('ROI')
plt.clf()
plt.plot(roi_hist)
plt.show(block=False)
plt.pause(0.01)
objet=1
video=cv2.VideoCapture('vtest.avi')
cv2.namedWindow('Camera')
cv2.setMouseCallback('Camera', click)
alpha = 0.5
while True:
ret, frame=video.read()
orig = np.array(frame)
img=frame
if objet:
frame = cv2.resize(frame, (572, 572))
#hsv=cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# mask=cv2.calcBackProject([hsv], [0], roi_hist, [0, nbr_classes], 1)
# _, mask=cv2.threshold(mask, seuil, 255, cv2.THRESH_BINARY)
#mask=cv2.erode(mask, None, iterations=3)
#mask=cv2.dilate(mask, None, iterations=3)
pf = ParticleFilter(roi_x,roi_y,frame,n_particles=500,square_size=50,
dt=0.20)
x,y,sq_size,distrib,distrib_control = pf.next_state(frame)
p1 = (int(y - sq_size), int(x - sq_size))
p2 = (int(y + sq_size), int(x + sq_size))
# before resampling
for (x2, y2, scale2) in distrib_control:
x2 = int(x2)
y2 = int(y2)
cv2.circle(img, (y2, x2), 1, (255, 0, 0), thickness=10)
# after resampling
for (x1, y1, scale1) in distrib:
x1 = int(x1)
y1 = int(y1)
cv2.circle(img, (y1, x1), 1, (0, 0, 255), thickness=10)
cv2.rectangle(img, p1, p2, (0, 0, 255), thickness=5)
cv2.addWeighted(orig, alpha, img, 1 - alpha, 0, img)
cv2.imshow("video", img)
key = cv2.waitKey(10) & 0xFF
if key == ord('q'):
quit()
if key == ord('p'):
seuil = min(250, seuil + 1)
if key == ord('m'):
seuil = max(1, seuil - 1)
video.release()
cv2.destroyAllWindows()
from cbpt.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cbpt.