Skip to content

Latest commit

 

History

History
67 lines (51 loc) · 1.64 KB

object-tracking.org

File metadata and controls

67 lines (51 loc) · 1.64 KB

Object tracking

Background subtraction

Trivial background subtraction

$$B = F - F_\text{prior}$$

frame_binary = frame_gray.clone();
threshold(frame_gray, frame_binary, 128.0, 255.0, THRESH_BINARY);
frame_old_binary = frame_old.clone();
threshold(frame_old, frame_old_binary, 128.0, 255.0, THRESH_BINARY);
frame_sub = frame_binary - frame_old_binary;

Mixture of Gaussians

BackgroundSubtractorMOG2 backsub;

// and for each frame:
fgmask = frame.clone();
backsub(frame, fgmask, 0.1);
backsub.getBackgroundImage(bg);

Finding bounding boxes

…by finding contours, then bounding boxes

vector<Rect> boxes;
vector<vector<Point> > contours;
Mat fgmask_contours = fgmask.clone();
findContours(fgmask_contours, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
vector<vector<Point> >::const_iterator it = contours.begin();
while(it != contours.end()) {
    Rect box = boundingRect(Mat(*it));
    if(box.width > 5 && box.height > 5) {
        boxes.push_back(box);
    }
    ++it;
}
// visualize the contours
drawContours(frame, contours, -1, Scalar(255), 1);

Connecting detections over time

Kalman filter?