Home > Software engineering >  Multiple target tracking Camshift combined Kalman opencv to learn
Multiple target tracking Camshift combined Kalman opencv to learn

Time:09-22

As title, studying automatic tracking multiple targets

CodePudding user response:

This was a little difficult,,,

CodePudding user response:

Are studying, but they still can't,,,

CodePudding user response:

refer to the second floor Z960007696 response:
is working, but they still won't,,,
, I also in opencv, learn communication

CodePudding user response:

Hello, do?

CodePudding user response:

Fyi:
 # - encoding=GBK - * - * - 

# TODO
# in the web site http://answers.opencv.org/question/86188/kcf-tracker-in-python/
# search MultiTracker

# multiple target tracking
# multiple target tracking using the MultiTracker,
# if MultiTracker myTracker (KCF)
# note two points, add a target with its member function myTracker. Add (Mat SRC, Rect2d ROI),
# for tracking results using myTracker. Update (Mat SRC, vector the targets), tracking the results of the serial number is the serial number of the vector,

The import numpy as np
The import cv2
The import sys
"'
If len (sys. Argv)!=2:
Print (' Input video name is missing ')
The exit ()
"'
A=2
Print (' Select 3 tracking the targets')

Cv2. NamedWindow (" tracking ")

VFN="are. Mp4"
Video=cv2. VideoCapture (VFN)

The tracker=cv2. MultiTracker_create ()
Init_once=False

Ok, frame=video. The read ()
If not ok:
Print (' Failed to read video ')
The exit ()

Frame=cv2. Resize (frame, (0, 0), fx=1/A, fy=1/A)
Bbox1=cv2. SelectROI (' tracking 'frame)
Bbox2=cv2. SelectROI (' tracking 'frame)
Bbox3=cv2. SelectROI (' tracking 'frame)

While video. IsOpened () :
Ok, frame=video. The read ()
If not ok:
Print (' no frame to read ')
Break

Frame=cv2. Resize (frame, (0, 0), fx=1/A, fy=1/A)
If not init_once:
Ok=tracker. The add (cv2. TrackerKCF_create (), frame, bbox1)
Ok=tracker. The add (cv2. TrackerKCF_create (), frame, bbox2)
Ok=tracker. The add (cv2. TrackerKCF_create (), frame, bbox3)
Init_once=True

Ok, boxes=tracker. Update (frame)
Print (ok, boxes)
If ok:
For newbox in boxes:
P1=(int (newbox [0]), int (newbox [1]))
P2=(int (newbox newbox [0] + [2]), int (newbox newbox [1] + [3]))
Cv2. A rectangle (frame, p1, p2, (0, 255), 2)

Cv2. Imshow (' tracking 'frame)
K=cv2. WaitKey (1)
The else:
For newbox in boxes:
P1=(int (newbox [0]), int (newbox [1]))
P2=(int (newbox newbox [0] + [2]), int (newbox newbox [1] + [3]))
Cv2. A rectangle (frame, p1, p2,,0,255 (0), (2)

Cv2. Imshow (' tracking 'frame)
K=cv2. WaitKey (0)
If k==27: break # esc pressed

Cv2. DestroyAllWindows ()

  • Related