admin 管理员组

文章数量: 1086019


2024年1月14日发(作者:怎样学好一门编程语言)

cout << "Could not read video file" << endl; return 1;

}

// Read first frame Mat frame; bool ok = (frame);

// Define initial boundibg box Rect2d bbox(287, 23, 86, 320);

// Uncomment the line below to select a different bounding box bbox = selectROI(frame, false);

// Display bounding box. rectangle(frame, bbox, Scalar( 255, 0, 0 ), 2, 1 ); imshow("Tracking", frame);

tracker->init(frame, bbox);

while((frame)) {

// Start timer double timer = (double)getTickCount();

// Update the tracking result bool ok = tracker->update(frame, bbox);

// Calculate Frames per second (FPS) float fps = getTickFrequency() / ((double)getTickCount() - timer);

if (ok) { // Tracking success : Draw the tracked object rectangle(frame, bbox, Scalar( 255, 0, 0 ), 2, 1 ); } else { // Tracking failure detected. putText(frame, "Tracking failure detected", Point(100,80), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(0,0,255),2); }

// Display tracker type on frame putText(frame, trackerType + " Tracker", Point(100,20), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(50,170,50),2);

// Display FPS on frame putText(frame, "FPS : " + SSTR(int(fps)), Point(100,50), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(50,170,50), 2);

// Display frame. imshow("Tracking", frame);

// Exit if ESC pressed. int k = waitKey(1); if(k == 27) { break; }

}}Python

import cv2import sys

(major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')

if __name__ == '__main__' :

# Set up tracker. # Instead of MIL, you can also use

tracker_types = ['BOOSTING', 'MIL','KCF', 'TLD', 'MEDIANFLOW', 'GOTURN'] tracker_type = tracker_types[2]

if int(minor_ver) < 3: tracker = r_create(tracker_type) else: if tracker_type == 'BOOSTING': tracker = rBoosting_create() if tracker_type == 'MIL': tracker = rMIL_create() if tracker_type == 'KCF': tracker = rKCF_create() if tracker_type == 'TLD': tracker = rTLD_create() if tracker_type == 'MEDIANFLOW': tracker = rMedianFlow_create() if tracker_type == 'GOTURN': tracker = rGOTURN_create()

# Read video video = apture("videos/4")

# Exit if video not opened. if not ed(): print "Could not open video" ()

# Read first frame. ok, frame = () if not ok: print 'Cannot read video file' ()

# Define an initial bounding box bbox = (287, 23, 86, 320)

# Uncomment the line below to select a different bounding box bbox = ROI(frame, False)

# Initialize tracker with first frame and bounding box ok = (frame, bbox)

while True: # Read a new frame ok, frame = () if not ok: break

# Start timer timer = kCount()

# Update tracker ok, bbox = (frame)


本文标签: 学好 编程语言 作者