TLD single target tracking

Source: Internet
Author: User
Tags abs tld

#include <opencv2/core.hpp> #include <opencv2/highgui.hpp> #include <opencv2/imgproc.hpp> #include <opencv2/tracking/tracker.hpp> #include <opencv2/core/utility.hpp> #include <opencv2/tracking.hpp
> #include <opencv2/videoio.hpp> #include <iostream> #include <vector> using namespace CV; Move the mouse to select a rectangular box void Mouseclickcallback (int event, int x, int y, int flags, void* UserData) {//Rectangle data Return CV::RECT2D * pRe
	ct = reinterpret_cast<cv::rect2d*> (userdata); Mouse Down action if (event = = Cv::event_lbuttondown) {std::cout << "Lbuttondown (" << x << "," <&lt ;
		Y << ")" << Std::endl;
		Gets the x, y coordinates prect->x = x;
	Prect->y = y; }//Mouse up action else if (event = = Cv::event_lbuttonup) {std::cout << "lbuttonup (" << x << "," &L
		t;< y << ")" << Std::endl;
		Get rectangle width High prect->width = Std::abs (x-prect->x); Prect->height = Std::abs (y-prect->y);
	}} int main (int argc, char** argv) {//Read video stream cv::videocapture cap ("... 
	\\images\\car.avi ");
		if (!cap.isopened ()) {std::cout << "on data!" << Std::endl;
	return-1;
	} cap.set (Cv_cap_prop_pos_msec, 2*1000);
	Cv::mat frame;
	Initializes the TLD tracker cv::rect2d *rect (new cv::rect2d);
	CV::P tr<cv::trackertld> tracker = Cv::trackertld::createtracker (); 
	Read First frame initialize rectangle box cap >> frame;
	Cv::resize (frame, frame, cv::size (), 0.25,0.25);
	Cv::imshow ("Trackertld", frame);
	Mouse movement gets the rectangular area cv::setmousecallback ("Trackertld", Mouseclickcallback, reinterpret_cast<void*> (rect));
	Cv::waitkey ();
	if (rect->area () = = 0.0) return-1;
	Tracker initial Tracker->init (frame, *rect);
	Double fps = 1.0;
		while (true) {cap >> frame;
		Cv::resize (frame, frame, cv::size (), 0.25,0.25);
		if (Frame.empty ()) break; Tracker Update if (Tracker->update (frame, *rect))//Draw trace results Cv::rectangle (frame, *rect, cv::scalar (255, 0, 0),
		2, 1); Cv::imshow ("TrackerTLD ", frame);
		char C = cv::waitkey (10);
	if (= = c) break;
	} cap.release ();
return 0;

 }




Reprint: http://blog.csdn.net/zhuwei1988

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.