Rewritten Blob tracking tests Project

Source: Internet
Author: User
Although the Blob tracking tests project officially provided by opencv has many algorithm features that can be verified by one compilation, beginners often do not know what commands to write to use this project, to help me understand this vs framework, I wrote a very simple Blob tracking tests project that can be used directly. The biggest function of this project is simple to use, simple code, and easier to read than the code of the original project. However, the function is much less, which may cause memory leakage, however, it can help beginners get started quickly with the vs framework. Press f5. In use, you only need to replace the main function and runblobtrackingauto function with the following function.
Static int myrunblobtrackingauto (cvcapture * pcap, cvblobtrackerauto * ptracker, char * fgaviname = NULL, char * btaviname = NULL) {int nframenum = 0; iplimage * pimg = NULL; iplimage * pmask = NULL; iplimage * PFG = NULL; int key = 0; For (nframenum = 0; pcap & (Key = cvwaitkey (2 )! = 27); nframenum ++) {pimg = cvqueryframe (pcap); If (! Pimg) break; cvshowimage ("frame", pimg); ptracker-> process (pimg, pmask); PFG = ptracker-> getfgmask (); cvshowimage ("PFG ", pfG); cvshowimage ("Mask", pmask); // cvreleaseimage (& pimg); // cvreleaseimage (& pmask);} return 0;} int main (INT argc, char * argv) {cvcapture * capture = NULL; cvblobtrackerautoparam1 Param = {0}; cvblobtrackerauto * ptracker = NULL; // framework class defmodule_fgdetector * pfgmodule = NULL; // This is defined in the first file. This structure contains the optional * pbdmodule = NULL; optional * pbtmodule = NULL; optional * pbtpostprocmodule = NULL; optional * pbtgenmodule = NULL; defmodule_blobtrackanalysis * pbtanalysismodule = NULL; // nick_name; char * fgname = NULL; char * fgaviname = NULL; char * btaviname = NULL; char * bdname = NULL; char * btname = NULL; char * btgenname = NULL; char * Avina Me = NULL; // Save the path file name. Char * trackname = NULL; // File Name of the trajectory analysis. Char * btaname = NULL; char * fgtrainframes = NULL; # ifndef win32cvinitsystem (argc, argv); # endif // initialize the string. Fgname = "myfg"; fgaviname = "fgaviname. avi "; // aviname =" video. avi "; trackname =" track.csv "; btaname =" bta.csv "; // initialize the camera. // Capture = cvcreatecaputeif (aviname) Capture = cvcapturefromfile (aviname); elsecapture = cvcreatecameracapture (-1); pfgmodule = & found [0]; // directly assign values. Pbdmodule = & Platform [0]; pbtmodule = & blobtracker_modules [0]; pbtpostprocmodule = & Platform [0]; pbtgenmodule = & blobtrackgen_modules [0]; pbtanalysismodule = & Platform [0]; param. fgtrainframes = fgtrainframes? Atoi (fgtrainframes): 0; // defines the number of frames to be counted. Param. PFG = pfgmodule-> Create (); If (! Param. PfG) // creation failed .. {Puts ("An error occurred while creating the foreground background! The program will exit "); return 1;} Param. PFG-> setnickname (pfgmodule-> nickname); Param. PFG-> paramupdate (); // is there a problem. Param. PBD = pbdmodule-> Create (); If (! Param. PBD) STD: cout <"An error occurred while creating a new block detector! "<STD: Endl; Param. PBD-> setnickname (pbdmodule-> nickname); Param. PBD-> paramupdate (); Param. PBT = pbtmodule-> Create (); If (! Param. PBT) STD: cout <"failed to create target tracking module" <STD: Endl; Param. pBT-> setnickname (pbtmodule-> nickname); Param. pBT-> paramupdate (); // If the pbtmodule is not empty, the file name of the storage track is not empty, the create function pointer of this module is not empty. If (pbtgenmodule & trackname & pbtgenmodule-> Create) {Param. pbtgen = pbtgenmodule-> Create (); Param. pbtgen-> setfilename (trackname);} If (Param. pbtgen) // if the previous execution is successful, and the Creation is successful. {Param. pbtgen-> setnickname (pbtgenmodule-> nickname); Param. pbtgen-> paramupdate ();} // post-processing Param for identifying trajectory. pbtpp = NULL; If (pbtpostprocmodule & pbtpostprocmodule-> Create) // you must first determine the non-null {Param. pbtpp = pbtpostprocmodule-> Create ();} If (Param. pbtpp) {Param. pbtpp-> setnickname (pbtpostprocmodule-> nickname); Param. pbtpp-> paramupdate ();} Param. useppdata = 0; // do not understand what this means. // Track analysis. This module is unavailable in official documents. Param. pbta = NULL; If (pbtanalysismodule & pbtanalysismodule-> Create) {Param. pbta = pbtanalysismodule-> Create (); Param. pbta-> setfilename (btaname);} If (Param. pbta) {Param. pbta-> setnickname (pbtanalysismodule-> nickname); Param. pbta-> paramupdate ();} ptracker = cvcreateblobtrackerauto1 (MB); If (! Ptracker) // It is not created successfully and must be exited. {STD: cout <"ptracker creation error! "<STD: Endl; Return-1;} myrunblobtrackingauto (capture, ptracker); If (capture) cvreleasecapture (& capture); Return 0;} // main

The effect is as follows: The image is collected from the camera on the left and the foreground mask on the right. :

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.