Commit 59e9a9ae authored by berak's avatar berak

add Tracker and MultiTracker python bindings

parent bf0c8712
set(the_description "Tracking API")
ocv_define_module(tracking opencv_imgproc opencv_core opencv_video opencv_highgui opencv_datasets)
ocv_define_module(tracking opencv_imgproc opencv_core opencv_video opencv_highgui opencv_datasets WRAP python)
......@@ -58,7 +58,7 @@ namespace cv
class ClfOnlineStump;
class ClfMilBoost
class CV_EXPORTS ClfMilBoost
{
public:
struct CV_EXPORTS Params
......
import numpy as np
import cv2
cv2.namedWindow("tracking")
camera = cv2.VideoCapture("E:/code/opencv/samples/data/768x576.avi")
tracker = cv2.MultiTracker("MIL")
bbox1 = (638.0,230.0,56.0,101.0)
bbox2 = (240.0,210.0,60.0,104.0)
bbox3 = (486.0,149.0,54.0,83.0)
init_once = False
while camera.isOpened():
ok, image=camera.read()
if not ok:
print 'no image read'
break
if not init_once:
# add a list of boxes:
ok = tracker.add(image, (bbox1,bbox2))
# or add single box:
ok = tracker.add(image, bbox3)
init_once = True
ok, boxes = tracker.update(image)
print ok, boxes
for newbox in boxes:
p1 = (int(newbox[0]), int(newbox[1]))
p2 = (int(newbox[0] + newbox[2]), int(newbox[1] + newbox[3]))
cv2.rectangle(image, p1, p2, (200,0,0))
cv2.imshow("tracking", image)
k = cv2.waitKey(1) & 0xff
if k == 27 : break # esc pressed
import numpy as np
import cv2
cv2.namedWindow("tracking")
camera = cv2.VideoCapture("E:/code/opencv/samples/data/768x576.avi")
bbox = (638.0,230.0,56.0,101.0)
tracker = cv2.Tracker_create("MIL")
init_once = False
while camera.isOpened():
ok, image=camera.read()
if not ok:
print 'no image read'
break
if not init_once:
ok = tracker.init(image, bbox)
init_once = True
ok, newbox = tracker.update(image)
print ok, newbox
if ok:
p1 = (int(newbox[0]), int(newbox[1]))
p2 = (int(newbox[0] + newbox[2]), int(newbox[1] + newbox[3]))
cv2.rectangle(image, p1, p2, (200,0,0))
cv2.imshow("tracking", image)
k = cv2.waitKey(1) & 0xff
if k == 27 : break # esc pressed
\ No newline at end of file
......@@ -91,7 +91,7 @@ namespace cv {
return select("ROI selector", img, fromCenter);
}
Rect2d ROISelector::select(const std::string& windowName, Mat img, bool showCrossair, bool fromCenter){
Rect2d ROISelector::select(const cv::String& windowName, Mat img, bool showCrossair, bool fromCenter){
key=0;
......@@ -149,7 +149,7 @@ namespace cv {
return selectorParams.box;
}
void ROISelector::select(const std::string& windowName, Mat img, std::vector<Rect2d> & boundingBox, bool fromCenter){
void ROISelector::select(const cv::String& windowName, Mat img, std::vector<Rect2d> & boundingBox, bool fromCenter){
std::vector<Rect2d> box;
Rect2d temp;
key=0;
......@@ -172,12 +172,12 @@ namespace cv {
return _selector.select("ROI selector", img, true, fromCenter);
};
Rect2d selectROI(const std::string& windowName, Mat img, bool showCrossair, bool fromCenter){
Rect2d selectROI(const cv::String& windowName, Mat img, bool showCrossair, bool fromCenter){
printf("Select an object to track and then press SPACE or ENTER button!\n" );
return _selector.select(windowName,img, showCrossair, fromCenter);
};
void selectROI(const std::string& windowName, Mat img, std::vector<Rect2d> & boundingBox, bool fromCenter){
void selectROI(const cv::String& windowName, Mat img, std::vector<Rect2d> & boundingBox, bool fromCenter){
return _selector.select(windowName, img, boundingBox, fromCenter);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment