Showing preview only (1,023K chars total). Download the full file or copy to clipboard to get everything.
Repository: oylz/DS
Branch: master
Commit: b26320abcfe1
Files: 49
Total size: 11.7 MB
Directory structure:
gitextract_zv8h4xpo/
├── LICENSE
├── Main.cpp
├── NT.cpp
├── NT.h
├── NTN.h
├── README.md
├── StrCommon.h
├── data/
│ └── tt1.pb
├── deepsort/
│ ├── Detection.h
│ ├── FeatureGetter/
│ │ ├── CaffeShuffeNetFeatureGetter.cpp
│ │ ├── FaceNetFeatureGetter.cpp
│ │ ├── FeatureGetter.cpp
│ │ ├── FeatureGetter.h
│ │ ├── MobileNetFeatureGetter.cpp
│ │ └── make.sh
│ ├── HungarianOper.h
│ ├── KalmanTracker.h
│ ├── iou_matching.h
│ ├── kalman_filter.h
│ ├── linear_assignment.h
│ ├── munkres/
│ │ ├── adapters/
│ │ │ ├── adapter.cpp
│ │ │ ├── adapter.h
│ │ │ ├── boostmatrixadapter.cpp
│ │ │ └── boostmatrixadapter.h
│ │ ├── matrix.cpp
│ │ ├── matrix.h
│ │ ├── munkres.cpp
│ │ └── munkres.h
│ ├── nn_matching.h
│ └── tracker.h
├── fdsst/
│ ├── SSE2NEON.h
│ ├── fdssttracker.cpp
│ ├── fdssttracker.hpp
│ ├── ffttools.hpp
│ ├── fhog.cpp
│ ├── fhog.h
│ ├── fhogbk/
│ │ ├── fhog.cpp
│ │ └── fhog.h
│ ├── labdata.hpp
│ ├── recttools.hpp
│ ├── sse.hpp
│ └── tracker.h
├── lmake.sh
├── log.txt
├── logn10.txt
├── logn15.txt
├── logn20.txt
├── make.sh
└── t.sh
================================================
FILE CONTENTS
================================================
================================================
FILE: LICENSE
================================================
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
================================================
FILE: Main.cpp
================================================
#include <opencv2/opencv.hpp>
#include "NT.h"
#include "StrCommon.h"
NT *_tt = NULL;
void DrawData(cv::Mat mm, cv::Mat frame, const std::map<int, DSResult> &map,
const std::vector<cv::Rect> &outRcs,
bool detect){
std::map<int, DSResult>::const_iterator it;
for(it = map.begin(); it != map.end(); ++it){
CvScalar clr = cvScalar(0, 255, 0);
cv::Rect rc = it->second.rc_;
cv::rectangle(frame, rc, clr);
std::string disp = toStr(it->first);
cv::putText(frame,
disp,
cvPoint(rc.x, rc.y),
CV_FONT_HERSHEY_SIMPLEX,
0.6,
cv::Scalar(0, 0, 255));
}
//
CvScalar clr = cvScalar(0, 0, 255);
for(cv::Rect rc:outRcs){
cv::rectangle(mm, rc, clr);
if(detect){
std::string disp = "detect";
cv::putText(frame,
disp,
cvPoint(100, 100),
CV_FONT_HERSHEY_SIMPLEX,
1,
cv::Scalar(0, 0, 255));
}
}
}
void ReadFileContent(const std::string &file, std::string &content){
FILE *fl = fopen(file.c_str(), "rb");
if(fl == NULL){
return;
}
fseek(fl, 0, SEEK_END);
int len = ftell(fl);
if(len <= 0){
return;
}
fseek(fl, 0, SEEK_SET);
char *buf = new char[len+1];
memset(buf, 0, len+1);
fread(buf, 1, len, fl);
content = std::string(buf);
delete []buf;
fclose(fl);
}
std::map<int, std::vector<cv::Rect>> _rcMap;
void ReadRcFileTotal(const std::string &file) {
std::string content = "";
ReadFileContent(file, content);
std::vector<std::string> lines;
splitStr(content, "\n", lines);
std::vector<cv::Rect> rcs;
int num = -1;
int tmpNum = -1;
for (int i = 0; i < lines.size(); i++) {
std::vector<std::string> cols;
splitStr(lines[i], ",", cols);
if (cols.size() < 6) {
continue;
}
tmpNum = toInt(trim(cols[0]));
if (num!=-1 && tmpNum!=num) {
_rcMap.insert(std::make_pair(num, rcs));
rcs.clear();
num = tmpNum;
}
if (num == -1) {
num = tmpNum;
}
cv::Rect rc;
rc.x = toInt(trim(cols[2]));
rc.y = toInt(trim(cols[3]));
rc.width = toInt(trim(cols[4]));
rc.height = toInt(trim(cols[5]));
rcs.push_back(rc);
}
if (!rcs.empty()) {
_rcMap.insert(std::make_pair(tmpNum, rcs));
}
}
std::string _rcFile = "";
std::string _imgDir;
cv::VideoWriter *_vw = NULL;
bool _isShow = false;
int _imgCount = 0;
void CB(cv::Mat &frame, int num){
if (_vw == NULL) {
_vw = new cv::VideoWriter("out.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25.0, cv::Size(frame.cols, frame.rows));
}
if (_rcMap.empty()) {
ReadRcFileTotal(_rcFile);
}
std::vector<cv::Rect> rcs;
std::map<int, std::vector<cv::Rect>>::iterator it = _rcMap.find(num);
if (it != _rcMap.end()) {
rcs = it->second;
}
std::vector<cv::Rect> outRcs;
int64_t tm0 = gtm();
std::map<int, DSResult> map = _tt->UpdateAndGet(frame, rcs, num, outRcs);
int64_t tm1 = gtm();
Mat mm = frame.clone();
bool detect = (!rcs.empty());
DrawData(mm, frame, map, outRcs, detect);
printf("finish %d frame, updatecasttime:%ld\n", num, tm1-tm0);
//(*_vw) << frame;
if(_isShow){
std::string disp = "frame";
cv::resize(mm, mm, cv::Size(mm.cols/2, mm.rows/2));
cv::resize(frame, frame, cv::Size(frame.cols/2, frame.rows/2));
cv::imshow("mm", mm);
cv::imshow(disp, frame);
cv::waitKey(1);
}
}
void Go() {
std::string root = _imgDir;
for (int i = 1; i < _imgCount; i++) {
std::string path = root;
path += to6dStr(i);
path += ".jpg";
cv::Mat mat = cv::imread(path);
CB(mat, i);
}
}
int main(int argc, char **argv){
if (argc < 2) {
printf("usage:\n./tt showornot(0/1)\n");
return 0;
}
_isShow = toInt(argv[1]);
_tt = new NT();
if(!_tt->Init()){
return 0;
}
//_imgDir = "e:/code/deep_sort-master/MOT16/tt/xyz/img1/";
//_rcFile = "e:/code/deep_sort-master/MOT16/tt/xyz/det/det.txt";
_imgDir = "/home/xyz/code1/xyz/img1/";
_rcFile = "/home/xyz/code1/xyz/det/det.txt";
//_rcFile = "/home/xyz/code/test/pp/FaceNumGetter/out/102.txt";
//_imgDir = "/home/xyz/code1/GEP/FrameBuffer/imglog/img1/";
//_rcFile = "/home/xyz/code1/GEP/FrameBuffer/imglog/det/det.txt";
_imgCount = 650;// 2001;// 750;// 680;
Go();
return 0;
}
================================================
FILE: NT.cpp
================================================
#include "NT.h"
//#define UDL
#ifdef UDL
//#define UBC
#include "deepsort/FeatureGetter/FeatureGetter.h"
#endif
#include "./deepsort/tracker.h"
#include "StrCommon.h"
#include "fdsst/fdssttracker.hpp"
#include "fdsst/fhog.h"
#include <boost/thread/mutex.hpp>
boost::shared_ptr<NearestNeighborDistanceMetric> NearestNeighborDistanceMetric::self_;
boost::shared_ptr<KF> KF::self_;
#define UHOG
void ExtractFeatureHog(const cv::Mat &in,
const std::vector<cv::Rect> &rcsin,
std::vector<FEATURE> &fts){
cv::Mat frame;
cvtColor(in, frame, cv::COLOR_RGB2GRAY);
for(int i = 0; i < rcsin.size(); i++){
Mat nnn = frame(rcsin[i]);
resize(nnn, nnn, Size(32, 32));
int len = 0;
float *hog = HOGXYZ(nnn, len);
if(hog==NULL || len!=128){
printf("hog(%d) is null or len(%d)!=128,exit!\n", hog==NULL, len);
exit(0);
}
FEATURE ft;
for(int j = 0; j < len; j++){
ft(j) = hog[j];
}
delete []hog;
fts.push_back(ft);
}
}
#ifdef UDL
void ExtractFeature(const cv::Mat &in,
const std::vector<cv::Rect> &rcsin,
std::vector<FEATURE> &fts) {
int maxw = 0;
int maxh = 0;
int count = rcsin.size();
#ifdef UBC
int BC = 1;
if(count < BC)count=BC;
#endif
std::vector<cv::Mat> faces;
cv::Rect lr;
for (int i = 0; i < count; i++) {
cv::Rect rc;
if(i < rcsin.size()){
rc = rcsin[i];
lr = rc;
}
else{
rc = lr;
}
faces.push_back(in(rc).clone());
int w = rc.width;
int h = rc.height;
if (w > maxw) {
maxw = w;
}
if (h > maxh) {
maxh = h;
}
}
maxw += 10;
maxh += 10;
cv::Mat frame(maxh, maxw*count, CV_8UC3);
std::vector<cv::Rect> rcs;
for (int i = 0; i < count; i++) {
cv::Mat &face = faces[i];
cv::Rect rc = cv::Rect(i*maxw + 5, 5, face.cols, face.rows);
rcs.push_back(rc);
cv::Mat tmp = frame(rc);
face.copyTo(tmp);
}
std::vector<FEATURE> newfts;
FeatureGetter::Instance()->Get(frame, rcs, newfts);
for(int i = 0; i < rcsin.size(); i++){
fts.push_back(newfts[i]);
}
}
#endif
NT::NT(){
tt_ = TTrackerP(new TTracker(0.7, 30, 1));
}
NT::~NT(){
}
bool NT::Init(){
#ifdef UDL
if(!FeatureGetter::Instance()->Init()){
return false;
}
#endif
if(0){// just a test
Mat frame = cv::imread("/home/xyz/code1/xyz/img1/000001.jpg");
Mat nnn;
cvtColor(frame, nnn, cv::COLOR_RGB2GRAY);
resize(nnn, nnn, Size(32, 32));
Mat a = fhog(nnn, 4, 9, 0.2f, false);
std::cout << "a:cols:" << a.cols << "a:rows:" << a.rows << "\njust a test, exit\n";
exit(0);
}
KF::Instance()->Init();
#ifdef UDL
#ifdef UBC
Mat frame = cv::imread("/home/xyz/code1/xyz/img1/000001.jpg");
std::vector<Detection> dets;
std::vector<FEATURE> fts;
std::vector<cv::Rect> rcs;
srand((unsigned)time(NULL));
int width = frame.cols;
int height = frame.rows;
//for(int i = 0; i < 30; i++){
int x = rand()%width;
int y = rand()%height;
int w = 100;
int h = 100;
//std::cout << x << "," << y << "," << w << "," << h << "\n";
if(x+w > width){
w = width - x;
}
if(y+h > height){
h = height - y;
}
cv::Rect rc(x, y, w, h);
rcs.push_back(rc);
//}
ExtractFeature(frame, rcs, fts);
#endif
#endif
NearestNeighborDistanceMetric::Instance()->Init(0.2, 100);
return true;
}
NewAndDelete NT::UpdateDS(const cv::Mat &frame, const std::vector<cv::Rect> &rcs, int num, const std::vector<int> &oriPos){
int64_t tm1 = gtm();
std::vector<Detection> dets;
std::vector<FEATURE> fts;
if(rcs.size() > 0){
#ifdef UHOG
ExtractFeatureHog(frame, rcs, fts);
#else
ExtractFeature(frame, rcs, fts);
#endif
}
int64_t tm2 = gtm();
for (int i = 0; i < rcs.size(); i++){
DSBOX box;
cv::Rect rc = rcs[i];
box(0) = rc.x;
box(1) = rc.y;
box(2) = rc.width;
box(3) = rc.height;
Detection det(box, 1, fts[i]);
//printf("oriPos.size():%d\n", oriPos.size());
if(i < (int)oriPos.size()-1){
det.oriPos_ = oriPos[i];
}
dets.push_back(det);
}
NewAndDelete nad = tt_->update(dets);
int64_t tm3 = gtm();
std::string tail = "";
if(tm3-tm1 > 30000){
tail = "****";
}
std::cout << num << "----rcs.size():" << rcs.size() << "[tm1:" << tm1 << ",tm2:" << tm2 << "("<< (tm2 - tm1) << ")"<< ",tm3:"
<< tm3 << "(" << (tm3-tm1) << ")]" << tail.c_str() << "\n";
return nad;
}
struct RRS{
void Push(const cv::Rect &rc){
boost::mutex::scoped_lock lock(mutex_);
rcs_.push_back(rc);
}
void Get(std::vector<cv::Rect> &rcs){
rcs = rcs_;
}
private:
std::vector<cv::Rect> rcs_;
boost::mutex mutex_;
};
struct FFS{
public:
void Push(int id, const FDSSTTrackerP &ff){
boost::mutex::scoped_lock lock(mutex_);
ffs_.push_back(std::make_pair(id, ff));
}
void Get(std::vector<std::pair<int, FDSSTTrackerP> > &ffs){
ffs = ffs_;
}
private:
std::vector<std::pair<int, FDSSTTrackerP > > ffs_;
boost::mutex mutex_;
};
// for framebuffer
void NT::UpdateFDSST(const Mat &frame, std::vector<cv::Rect> &rcs){
std::map<int, FDSSTTrackerP>::iterator it;
std::vector<int> lostIds;
RRS rrs;
std::vector<FDSSTTrackerP> ffs;
for(it = fdssts_.begin(); it != fdssts_.end(); ++it){
FDSSTTrackerP fdsst = it->second;
ffs.push_back(fdsst);
}
#pragma omp parallel for
for(int i = 0; i < ffs.size(); i++){
cv::Rect rc = ffs[i]->update(frame);
rrs.Push(rc);
}
//
std::vector<cv::Rect> rrcs;
rrs.Get(rrcs);
for(int i = 0; i < rrcs.size(); i++){
cv::Rect rc = rrcs[i];
int ww = frame.cols;
int hh = frame.rows;
int min = 8;
if(rc.x<0 || rc.y<0 ||
(rc.x+rc.width)>ww ||
(rc.y+rc.height)>hh ||
rc.width<=min || rc.height<=min){
lostIds.push_back(it->first);
continue;
}
rcs.push_back(ToOriRect(rc));
}
// remove
for(int id:lostIds){
fdssts_.erase(id);
}
}
std::map<int, DSResult> NT::UpdateAndGet(const cv::Mat &frame,
const std::vector<cv::Rect> &rcsin,
int num,
std::vector<cv::Rect> &outRcs,
const std::vector<int> &oriPos){
std::vector<cv::Rect> rcs = rcsin;
//{
Mat ffMat;
cvtColor(frame, ffMat, cv::COLOR_RGB2GRAY);
resize(ffMat, ffMat, Size(ffMat.cols*scale_, ffMat.rows*scale_));
std::cout << "NT::UpdateAndGet1\n";
//}
if(!rcsin.empty()){
fdssts_.clear();
}
else{
UpdateFDSST(ffMat, rcs);
}
std::cout << "NT::UpdateAndGet1.5\n";
outRcs = rcs;
NewAndDelete nad = UpdateDS(frame, rcs, num, oriPos);
std::map<int, DSResult> map;
std::vector<KalmanTracker> &kalmanTrackers =
tt_->kalmanTrackers_;
std::cout << "NT::UpdateAndGet2\n";
std::vector<std::pair<int, cv::Rect> > idrcs;
for (const auto& track : kalmanTrackers){
int id = (int)track->track_id;
printf("trackid:%d, is_confirmed:%d, time_since_update:%d\n", id, track->is_confirmed(), track->time_since_update_);
//if (!track->is_confirmed() || track->time_since_update_ > 0) {
// continue;
//}
if(track->time_since_update_ > 0){
continue;
}
DSBOX box = track->to_tlwh();
cv::Rect rc;
rc.x = box(0);
rc.y = box(1);
rc.width = box(2);
rc.height = box(3);
int oriPos= track->oriPos_;
DSResult tr;
tr.rc_ = rc;
tr.oriPos_ = oriPos;
if(!rcsin.empty()){
idrcs.push_back(std::make_pair(id, rc));
printf("id:%d, rc:(%d, %d, %d, %d), oriPos:%d, rcsin.size():%d, rcs.size():%d\n",
id, rc.x, rc.y, rc.width, rc.height,
oriPos, rcsin.size(), rcs.size());
}
if (!track->is_confirmed() || track->time_since_update_ > 0) {
continue;
}
map.insert(std::make_pair(id, tr));
}
std::cout << "NT::UpdateAndGet3\n";
FFS ffs;
#pragma omp parallel for
for(int i = 0; i < idrcs.size(); i++){
std::pair<int, cv::Rect> pa = idrcs[i];
int id = pa.first;
cv::Rect rc = pa.second;
printf("id:%d, rc:(%d, %d, %d, %d)\n",
id, rc.x, rc.y, rc.width, rc.height);
FDSSTTrackerP fdsst(new FDSSTTracker());
fdsst->init(ToScaleRect(rc), ffMat);
ffs.Push(id, fdsst);
}
std::cout << "NT::UpdateAndGet4\n";
std::vector<std::pair<int, FDSSTTrackerP> > pps;
ffs.Get(pps);
for(int i = 0; i < pps.size(); i++){
std::pair<int, FDSSTTrackerP> pa = pps[i];
fdssts_.insert(pa);
}
return map;
}
================================================
FILE: NT.h
================================================
#ifndef _NTH_
#define _NTH_
#include <opencv2/opencv.hpp>
#include <boost/shared_ptr.hpp>
#include "NTN.h"
using namespace cv;
struct DSResult{
cv::Rect rc_;
int oriPos_;
DSResult(){
rc_ = cv::Rect(0, 0, 0, 0);
oriPos_ = -1;
}
};
class TTracker;
typedef boost::shared_ptr<TTracker> TTrackerP;
class FDSSTTracker;
typedef boost::shared_ptr<FDSSTTracker> FDSSTTrackerP;
class NT{
public:
NT();
~NT();
bool Init();
// for framebuffer
std::map<int, DSResult> UpdateAndGet(const cv::Mat &frame,
const std::vector<cv::Rect> &rcs,
int num,
std::vector<cv::Rect> &outRcs,
const std::vector<int> &oriPos=std::vector<int>(0));
private:
void UpdateFDSST(const Mat &frame, std::vector<cv::Rect> &rcs);
NewAndDelete UpdateDS(const cv::Mat &frame,
const std::vector<cv::Rect> &rcs,
int num,
const std::vector<int> &oriPos);
private:
cv::Rect ToOriRect(const cv::Rect &rc){
cv::Rect re;
float x = ((float)rc.x)/scale_;
float y = ((float)rc.y)/scale_;
float w = ((float)rc.width)/scale_;
float h = ((float)rc.height)/scale_;
re.x = x;
re.y = y;
re.width = w;
re.height = h;
return re;
}
cv::Rect ToScaleRect(const cv::Rect &rc){
cv::Rect re;
float x = ((float)rc.x)*scale_;
float y = ((float)rc.y)*scale_;
float w = ((float)rc.width)*scale_;
float h = ((float)rc.height)*scale_;
re.x = x;
re.y = y;
re.width = w;
re.height = h;
return re;
}
private:
TTrackerP tt_;
std::map<int, FDSSTTrackerP> fdssts_;
float scale_ = 0.25;
};
#endif
================================================
FILE: NTN.h
================================================
#ifndef _NTNH_
#define _NTNH_
struct NewAndDelete{
std::map<int, int> news_;// id, pos
std::vector<int> deletes_;
};
#endif
================================================
FILE: README.md
================================================
**DS**(~~deepsort cpp version~~)
C++ implementation of Simple Online Realtime Tracking with a Deep Association Metric
# 1. dependencies
component|version
-|-
eigen|3.3
opencv|-
boost|-
tensorflow|1.4
# 2. build
./make.sh
# 3. prepare data
change the var values at [lines160-162 in Main.cpp](https://github.com/oylz/DS/blob/master/Main.cpp#L160TL162):
```
_imgDir = "/home/xyz/code1/xyz/img1/"; // MOT format
_rcFile = "/home/xyz/code1/xyz/det/det.txt"; // MOT format
_imgCount = 680; // frames count
```
# 4. run
./r.sh
# 5.tips
tensorflow build:
```
(1) ./configure
(2) bazel build -c opt --copt=-mavx --copt=-mavx2 --copt=-mfma --copt=-mfpmath=both --copt=-msse4.2 --config=cuda tensorflow:libtensorflow_cc.so
```
================================================
FILE: StrCommon.h
================================================
#ifndef _STRCOMMONH_
#define _STRCOMMONH_
#include <string>
#include <vector>
#ifdef WIN32
#include <winsock2.h>
#include <windows.h>
#include <time.h>
static int gettimeofday(struct timeval *tp, void *tzp)
{
time_t clock;
struct tm tm;
SYSTEMTIME wtm;
GetLocalTime(&wtm);
tm.tm_year = wtm.wYear - 1900;
tm.tm_mon = wtm.wMonth - 1;
tm.tm_mday = wtm.wDay;
tm.tm_hour = wtm.wHour;
tm.tm_min = wtm.wMinute;
tm.tm_sec = wtm.wSecond;
tm.tm_isdst = -1;
clock = mktime(&tm);
tp->tv_sec = clock;
tp->tv_usec = wtm.wMilliseconds * 1000;
return (0);
}
static void usleep(int64_t us) {
int64_t s = us / 1000;
Sleep(s);
}
#else
#include <sys/time.h>
#endif
using namespace cv;
static int64_t gtm() {
struct timeval tm;
gettimeofday(&tm, 0);
int64_t re = ((int64_t)tm.tv_sec) * 1000 * 1000 + tm.tv_usec;
return re;
}
static void splitStr(const std::string& inputStr, const std::string &key, std::vector<std::string>& outStrVec) {
if (inputStr == "") {
return;
}
int pos = inputStr.find(key);
int oldpos = 0;
if (pos > 0) {
std::string tmp = inputStr.substr(0, pos);
outStrVec.push_back(tmp);
}
while (1) {
if (pos < 0) {
break;
}
oldpos = pos;
int newpos = inputStr.find(key, pos + key.length());
std::string tmp = inputStr.substr(pos + key.length(), newpos - pos - key.length());
outStrVec.push_back(tmp);
pos = newpos;
}
int tmplen = 0;
if (outStrVec.size() > 0) {
tmplen = outStrVec.at(outStrVec.size() - 1).length();
}
if (oldpos + tmplen < inputStr.length() - 1) {
std::string tmp = inputStr.substr(oldpos + key.length());
outStrVec.push_back(tmp);
}
}
static std::string trim(std::string &s) {
if (s.empty()) {
return s;
}
s.erase(0, s.find_first_not_of(" "));
s.erase(s.find_last_not_of(" ") + 1);
return s;
}
static int toInt(const std::string &in){
int re = 0;
sscanf(in.c_str(), "%d", &re);
return re;
}
static float toFloat(const std::string &in) {
float re = 0;
sscanf(in.c_str(), "%f", &re);
return re;
}
static std::string toStr(float in) {
char chr[20] = { 0 };
sprintf(chr, "%f", in);
std::string re(chr);
return re;
}
static std::string toStr(int in){
char chr[20] = {0};
sprintf(chr, "%d", in);
std::string re(chr);
return re;
}
static std::string to4dStr(int in){
char chr[20] = {0};
sprintf(chr, "%04d", in);
std::string re(chr);
return re;
}
static std::string to5dStr(int in){
char chr[20] = {0};
sprintf(chr, "%05d", in);
std::string re(chr);
return re;
}
static std::string to6dStr(int in){
char chr[20] = {0};
sprintf(chr, "%06d", in);
std::string re(chr);
return re;
}
#endif
================================================
FILE: data/tt1.pb
================================================
[File too large to display: 10.7 MB]
================================================
FILE: deepsort/Detection.h
================================================
#ifndef _DETECTIONH_
#define _DETECTIONH_
#include <vector>
#include <Eigen>
typedef Eigen::Matrix<float, 1, 4, Eigen::RowMajor> DSBOX;
typedef Eigen::Matrix<float, -1, 4, Eigen::RowMajor> DSBOXS;
typedef Eigen::Matrix<float, 1, 128, Eigen::RowMajor> FEATURE;
typedef Eigen::Matrix<float, -1, 128, Eigen::RowMajor> FEATURESS;
typedef std::vector<int> IDS;
typedef Eigen::Matrix<float, 1, 2, Eigen::RowMajor> PT2;
typedef Eigen::Matrix<float, -1, -1, Eigen::RowMajor> DYNAMICM;
typedef Eigen::Matrix<float, 1, 8, Eigen::RowMajor> MEAN;
typedef Eigen::Matrix<float, 8, 8, Eigen::RowMajor> VAR;
typedef Eigen::Matrix<float, 1, 4, Eigen::RowMajor> NMEAN;
typedef Eigen::Matrix<float, 4, 4, Eigen::RowMajor> NVAR;
struct Detection {
DSBOX tlwh_;
float confidence_;
FEATURE feature_;
int oriPos_ = -1;
Detection(const DSBOX &tlwh, float confidence, const FEATURE &feature) {
tlwh_ = tlwh;
confidence_ = confidence;
//std::cout << feature;
feature_ = feature;
}
DSBOX to_tlbr() const{
DSBOX ret = tlwh_;
ret(0, 2) += ret(0, 0);
ret(0, 3) += ret(0, 1);
return ret;
}
DSBOX to_xyah() const{
DSBOX ret = tlwh_;
ret(0, 0) += ret(0, 2) / 2;
ret(0, 1) += ret(0, 3) / 2;
ret(0, 2) /= ret(0, 3);
return ret;
}
};
#endif
================================================
FILE: deepsort/FeatureGetter/CaffeShuffeNetFeatureGetter.cpp
================================================
#include "FeatureGetter.h"
#include <caffe/net.hpp>
#include <fstream>
#include <iostream>
#include <opencv2/opencv.hpp>
#include <sys/time.h>
#include <map>
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/thread/mutex.hpp>
static int64_t fgtm() {
struct timeval tm;
gettimeofday(&tm, 0);
int64_t re = ((int64_t)tm.tv_sec) * 1000 * 1000 + tm.tv_usec;
return re;
}
boost::shared_ptr<FeatureGetter> FeatureGetter::self_;
typedef unsigned char uint8;
typedef boost::shared_ptr<caffe::Net<float> > XNET;
typedef caffe::Blob<float>* XINPUT;
#ifdef OONE
static const int XCOUNT = 1;
#else
static const int XCOUNT = 10;
#endif
std::map<int, XNET> _xnets;
std::map<int, XINPUT> _xinputs;
int _iw = -1;
int _ih = -1;
int _outLayer = -1;
static const std::string _outLayerName = "fc1000";
static const std::string rootp = "/home/xyz/code1/ShuffleNet-Model/";
static const std::string modelp = rootp + "incode.prototxt";//"ssd_shufflenet_21_test.prototxt";
//static const std::string modelp = rootp + "ssd_shufflenet_21_test.prototxt";
static const std::string weightp = rootp + "shufflenet_1x_g3.caffemodel";
void to_buffer(const cv::Mat &img, float *buf){
if (img.isContinuous()) {
memcpy(buf, img.ptr<float>(0),
static_cast<size_t>(img.total()) * sizeof(float));
}
else {
for (int i = 0; i < img.rows; i++) {
memcpy(buf, img.ptr<float>(i),
static_cast<size_t>(img.cols) * sizeof(float));
buf += img.cols;
}
}
}
bool FeatureGetter::Init() {
caffe::Caffe::set_mode(caffe::Caffe::GPU);
caffe::Caffe::SetDevice(0);
for(int i = 0; i < XCOUNT; i++){
caffe::Net<float> *net = new caffe::Net<float>(modelp, caffe::TEST);
net->CopyTrainedLayersFrom(weightp);
XNET xnet;
xnet.reset(net);
//
xnet->ForwardFrom(0);
_xnets.insert(std::make_pair(i, xnet));
auto &blobs = xnet->input_blobs();
XINPUT xinput = blobs[0];
_xinputs.insert(std::make_pair(i, xinput));
if(i == 0){
auto shape = blobs[0]->shape();
//////shape[0] = 1;
//////blobs[0]->Reshape(shape);
_iw = (int)shape[2];
_ih = (int)shape[3];
printf("_iw:%d, _ih:%d\n", _iw, _ih);
int index = 0;
for (auto const &layer : xnet->layers()) {
auto const ¶m = layer->layer_param();
for (auto const &top_name : param.top()) {
if (top_name == _outLayerName) {
_outLayer = index;
break;
}
}
index++;
}
std::cout << "_outLayer:" << _outLayer << "\n";
}
}
return true;
}
// -----------------------------------------
bool GetCore(const XNET &xnet, const XINPUT &xinput, const cv::Mat &imgin, FFEATURE &ft) {
auto dst_data = xinput->mutable_cpu_data();
cv::Mat mm;
cv::resize(imgin, mm, cv::Size(_iw, _ih));
cv::Mat img;
mm.convertTo(img, CV_32FC3, 1, 0);
std::vector<cv::Mat> channels;
cv::split(img, channels);
for (size_t j = 0; j < channels.size(); j++) {
channels[j] += (-175);
to_buffer(channels[j], dst_data);
dst_data += _iw*_ih;
}
// go
xnet->ForwardFrom(0);
xnet->ForwardTo(_outLayer);
// get
std::map<std::string, std::pair<const float *, size_t>> output_data;
auto output_blob = xnet->blob_by_name(_outLayerName);
if (output_blob->count() == 0) {
//throw std::runtime_error(name + " blob is empty");
printf("blob is empty");
return false;
}
auto tmp1 = output_blob->cpu_data();
auto len = output_blob->count();
std::cout << "begin tmp1:\n" << tmp1 <<
"\nend tmp1\nbegin len:\n"
<< len << "\nend len\n";
for(int i = 0; i < len; i++){
if(i>=128){
continue;
}
ft(i) = tmp1[i];
}
return true;
}
struct XFTS{
public:
void Push(int id, const FFEATURE &ff){
boost::mutex::scoped_lock lock(mutex_);
ffs_.push_back(std::make_pair(id, ff));
}
void Get(std::vector<std::pair<int, FFEATURE> > &ffs){
ffs = ffs_;
}
private:
std::vector<std::pair<int, FFEATURE > > ffs_;
boost::mutex mutex_;
};
bool FeatureGetter::Get(const cv::Mat &img, const std::vector<cv::Rect> &rcs,
std::vector<FFEATURE> &fts) {
int64_t ftm1 = fgtm();
XFTS xfts;
#ifndef OONE
#pragma omp parallel for
#endif
for(int i = 0; i < rcs.size(); i++){
cv::Mat tmp = img(rcs[i]);
FFEATURE ft;
int64_t ftm11 = fgtm();
#ifndef OONE
XNET &xnet = _xnets[i];
XINPUT &xinput = _xinputs[i];
#else
XNET &xnet = _xnets[0];
XINPUT &xinput = _xinputs[0];
#endif
bool re = GetCore(xnet, xinput, tmp, ft);
int64_t ftm12 = fgtm();
std::cout << "\t----ftm12-ftm11:" << (ftm12-ftm11) << "\n";
if(!re){
printf("error!\n");
exit(0);
}
xfts.Push(i, ft);
fts.push_back(ft);
}
//
fts.resize(rcs.size());
std::vector<std::pair<int, FFEATURE> > pairs;
xfts.Get(pairs);
for(int i = 0; i < pairs.size(); i++){
std::pair<int, FFEATURE> pa = pairs[i];
fts[pa.first] = pa.second;
}
int64_t ftm2 = fgtm();
std::cout << "caffe.forward--shufflenet--rcs.size():" << rcs.size()
<< ", ftm2-ftm1:" << (ftm2-ftm1) << "\n";
}
================================================
FILE: deepsort/FeatureGetter/FaceNetFeatureGetter.cpp
================================================
#include "FeatureGetter.h"
#include <tensorflow/core/public/session.h>
#include <fstream>
#include <iostream>
#include <tensorflow/cc/saved_model/loader.h>
#include <tensorflow/core/graph/default_device.h>
#include <tensorflow/core/platform/env.h>
#include <tensorflow/core/protobuf/config.pb.h>
#include <tensorflow/c/checkpoint_reader.h>
#include <tensorflow/c/c_api_internal.h>
#include <opencv2/opencv.hpp>
#include <tensorflow/cc/ops/math_ops.h>
namespace tf = tensorflow;
#include <sys/time.h>
static int64_t fgtm() {
struct timeval tm;
gettimeofday(&tm, 0);
int64_t re = ((int64_t)tm.tv_sec) * 1000 * 1000 + tm.tv_usec;
return re;
}
boost::shared_ptr<FeatureGetter> FeatureGetter::self_;
typedef float uint8;
std::unique_ptr<tf::Session> session;
void tobuffer(const std::vector<cv::Mat> &imgs, uint8 *buf) {
int pos = 0;
for (cv::Mat img : imgs) {
int LLL = img.cols*img.rows * 3;
int nr = img.rows;
int nc = img.cols;
if (img.isContinuous())
{
nr = 1;
nc = LLL;
}
for (int i = 0; i < nr; i++)
{
const uchar* inData = img.ptr<uchar>(i);
for (int j = 0; j < nc; j++)
{
buf[pos] = *inData++;
pos++;
}
}
}
}
void tobufferA(const std::vector<cv::Mat> &imgs, float *buf){
int pos = 0;
for (cv::Mat img : imgs) {
if (img.isContinuous()) {
memcpy(buf+pos, img.ptr<float>(0),
static_cast<size_t>(img.total()) * sizeof(float));
pos += static_cast<size_t>(img.total()) * sizeof(float);
}
else {
printf("error\n");
exit(0);
}
}
}
typedef std::vector<double> DSR;
typedef std::vector<DSR> DSRS;
typedef std::vector<int> IDSR;
typedef std::vector<IDSR> IDSRS;
bool FeatureGetter::Init() {
tf::Session* session_ptr;
auto status = NewSession(tf::SessionOptions(), &session_ptr);
if (!status.ok()) {
std::cout << status.ToString() << "\n";
return false;
}
session.reset(session_ptr);
//------------------
tf::GraphDef graph_def;
auto status1 = ReadBinaryProto(tf::Env::Default(), "./data/facenet.pb", &graph_def);
if (!status1.ok()) {
printf("ReadBinaryProto failed: %s\n", status1.ToString().c_str());
return false;
}
status = session->Create(graph_def);
if (!status.ok()) {
printf("create graph in session failed: %s\n", status.ToString().c_str());
return false;
}
std::vector<std::string> node_names;
for (const auto &node : graph_def.node()) {
printf("node name:%s\n", node.name().c_str());
node_names.push_back(node.name());
}
return true;
}
bool FeatureGetter::Get(const cv::Mat &img, const std::vector<cv::Rect> &rcs,
std::vector<FFEATURE> &fts) {
std::vector<cv::Mat> mats;
for(cv::Rect rc:rcs){
cv::Mat mat1 = img(rc).clone();
cv::resize(mat1, mat1, cv::Size(160, 160));
/*auto face_mat = face.get_face_image()
.resize(input_width, input_height)
.convert_to(CV_32FC3)
.get_cv_mat();*/
/* cv::Mat face_mat;
//模型希望是rgb顺序
cv::cvtColor(mat1, face_mat, CV_BGR2RGB);
face_mat = face_mat.reshape(1);
// whitten
cv::Scalar means;
cv::Scalar stds;
cv::meanStdDev(face_mat, means, stds);
stds[0] =
std::max(float(stds[0]), 1.0f / sqrtf(160 * 160 * 3));
face_mat -= means[0];
face_mat /= stds[0];
cv::Mat tmp = face_mat.clone();
mats.push_back(tmp);
*/
mats.push_back(mat1);
}
int count = mats.size();
tensorflow::Tensor input_tensor0(tensorflow::DT_FLOAT, { count, 160, 160, 3 });
tobuffer(mats, input_tensor0.flat<uint8>().data());
std::vector<tensorflow::Tensor> output_tensors;
std::vector<std::pair<std::string, tensorflow::Tensor>> ins;
std::pair<std::string, tensorflow::Tensor> pa;
pa.first = "input";
pa.second = input_tensor0;
ins.push_back(pa);
{
std::pair<std::string, tensorflow::Tensor> pa1;
pa1.first ="phase_train";
tf::Tensor phase_train(tf::DT_BOOL, tf::TensorShape());
phase_train.scalar<bool>()() = false;
pa1.second = phase_train;
ins.push_back(pa1);
}
std::vector<std::string> outnames;
outnames.push_back("embeddings");
std::vector<std::string> ts;
int64_t ftm1 = fgtm();
auto status = session->Run(
ins,
outnames,
ts,
&output_tensors);
int64_t ftm2 = fgtm();
std::cout << "session.run----rcs.size():" << rcs.size() << ", ftm2-ftm1:" << (ftm2-ftm1) << "\n";
if (!status.ok()) {
printf("error 3%s \n", status.ToString().c_str());
return false;
}
float *tensor_buffer =
output_tensors[0].flat<float>().data();
int len = output_tensors[0].flat<float>().size() / count;
for (int i = 0; i < count; i++) {
//printf("begin====\n");
FFEATURE ft;
for (int j = 0; j < len; j++) {
ft(j) = tensor_buffer[i*len + j];
//printf(",%f", tensor_buffer[i*len+j]);
}
fts.push_back(ft);
//printf("\nend====\n");
}
return true;
}
================================================
FILE: deepsort/FeatureGetter/FeatureGetter.cpp
================================================
#ifdef USE_FACE_NET
#include "FaceNetFeatureGetter.cpp"
#else
#ifdef USE_MOBILE_NET
#include "MobileNetFeatureGetter.cpp"
#else
#ifdef USE_CAFFE_SHUFFE_NET
#include "CaffeShuffeNetFeatureGetter.cpp"
#else
#include "FeatureGetter.h"
#include <tensorflow/core/public/session.h>
#include <fstream>
#include <iostream>
#include <tensorflow/cc/saved_model/loader.h>
#include <tensorflow/core/graph/default_device.h>
#include <tensorflow/core/platform/env.h>
#include <tensorflow/core/protobuf/config.pb.h>
#include <tensorflow/c/checkpoint_reader.h>
#include <tensorflow/c/c_api_internal.h>
#include <opencv2/opencv.hpp>
#include <tensorflow/cc/ops/math_ops.h>
namespace tf = tensorflow;
#include <sys/time.h>
static int64_t fgtm() {
struct timeval tm;
gettimeofday(&tm, 0);
int64_t re = ((int64_t)tm.tv_sec) * 1000 * 1000 + tm.tv_usec;
return re;
}
boost::shared_ptr<FeatureGetter> FeatureGetter::self_;
typedef unsigned char uint8;
std::unique_ptr<tf::Session> session;
void tobuffer(const std::vector<cv::Mat> &imgs, uint8 *buf) {
int pos = 0;
for (cv::Mat img : imgs) {
int LLL = img.cols*img.rows * 3;
int nr = img.rows;
int nc = img.cols;
if (img.isContinuous())
{
nr = 1;
nc = LLL;
}
for (int i = 0; i < nr; i++)
{
const uchar* inData = img.ptr<uchar>(i);
for (int j = 0; j < nc; j++)
{
buf[pos] = *inData++;
pos++;
}
}
}
}
typedef std::vector<double> DSR;
typedef std::vector<DSR> DSRS;
typedef std::vector<int> IDSR;
typedef std::vector<IDSR> IDSRS;
bool FeatureGetter::Init() {
tf::Session* session_ptr;
auto status = NewSession(tf::SessionOptions(), &session_ptr);
if (!status.ok()) {
std::cout << status.ToString() << "\n";
return false;
}
session.reset(session_ptr);
//------------------
tf::GraphDef graph_def;
auto status1 = ReadBinaryProto(tf::Env::Default(), "./data/tt1.pb", &graph_def);
if (!status1.ok()) {
printf("ReadBinaryProto failed: %s\n", status1.ToString().c_str());
return false;
}
status = session->Create(graph_def);
if (!status.ok()) {
printf("create graph in session failed: %s\n", status.ToString().c_str());
return false;
}
std::vector<std::string> node_names;
for (const auto &node : graph_def.node()) {
printf("node name:%s\n", node.name().c_str());
node_names.push_back(node.name());
}
return true;
}
bool FeatureGetter::Get(const cv::Mat &img, const std::vector<cv::Rect> &rcs,
std::vector<FFEATURE> &fts) {
std::vector<cv::Mat> mats;
for(cv::Rect rc:rcs){
cv::Mat mat1 = img(rc).clone();
cv::resize(mat1, mat1, cv::Size(64, 128));
mats.push_back(mat1);
}
int count = mats.size();
tensorflow::Tensor input_tensor0(tensorflow::DT_UINT8, { count, 128, 64, 3 });
tobuffer(mats, input_tensor0.flat<uint8>().data());
std::vector<tensorflow::Tensor> output_tensors;
std::vector<std::pair<std::string, tensorflow::Tensor>> ins;
std::pair<std::string, tensorflow::Tensor> pa;
pa.first = "Placeholder";
pa.second = input_tensor0;
ins.push_back(pa);
std::vector<std::string> outnames;
outnames.push_back("truediv");
std::vector<std::string> ts;
int64_t ftm1 = fgtm();
auto status = session->Run(
ins,
outnames,
ts,
&output_tensors);
int64_t ftm2 = fgtm();
std::cout << "session.run----rcs.size():" << rcs.size() << ", ftm2-ftm1:" << (ftm2-ftm1) << "\n";
if (!status.ok()) {
printf("error 3%s \n", status.ToString().c_str());
return false;
}
float *tensor_buffer =
output_tensors[0].flat<float>().data();
int len = output_tensors[0].flat<float>().size() / count;
for (int i = 0; i < count; i++) {
//printf("begin====\n");
FFEATURE ft;
for (int j = 0; j < len; j++) {
ft(j) = tensor_buffer[i*len + j];
//printf(",%f", tensor_buffer[i*len+j]);
}
fts.push_back(ft);
//printf("\nend====\n");
}
return true;
}
#endif
#endif
#endif
================================================
FILE: deepsort/FeatureGetter/FeatureGetter.h
================================================
#ifndef _FEATUREGETTERH_
#define _FEATUREGETTERH_
#include <boost/shared_ptr.hpp>
#include <opencv2/opencv.hpp>
#include <Eigen>
typedef Eigen::Matrix<float, 1, 128, Eigen::RowMajor> FFEATURE;
class FeatureGetter {
private:
static boost::shared_ptr<FeatureGetter> self_;
public:
static boost::shared_ptr<FeatureGetter> Instance() {
if (self_.get() == NULL) {
self_.reset(new FeatureGetter());
}
return self_;
}
bool Init();
bool Get(const cv::Mat &img, const std::vector<cv::Rect> &rcs,
std::vector<FFEATURE> &fts);
public:
~FeatureGetter() {
}
};
#endif
================================================
FILE: deepsort/FeatureGetter/MobileNetFeatureGetter.cpp
================================================
#include "FeatureGetter.h"
#include <tensorflow/core/public/session.h>
#include <fstream>
#include <iostream>
#include <tensorflow/cc/saved_model/loader.h>
#include <tensorflow/core/graph/default_device.h>
#include <tensorflow/core/platform/env.h>
#include <tensorflow/core/protobuf/config.pb.h>
#include <tensorflow/c/checkpoint_reader.h>
#include <tensorflow/c/c_api_internal.h>
#include <opencv2/opencv.hpp>
#include <tensorflow/cc/ops/math_ops.h>
namespace tf = tensorflow;
#include <sys/time.h>
static int64_t fgtm() {
struct timeval tm;
gettimeofday(&tm, 0);
int64_t re = ((int64_t)tm.tv_sec) * 1000 * 1000 + tm.tv_usec;
return re;
}
boost::shared_ptr<FeatureGetter> FeatureGetter::self_;
typedef float uint8;
std::unique_ptr<tf::Session> session;
void tobuffer(const std::vector<cv::Mat> &imgs, uint8 *buf) {
int pos = 0;
for (cv::Mat img : imgs) {
int LLL = img.cols*img.rows * 3;
int nr = img.rows;
int nc = img.cols;
if (img.isContinuous())
{
nr = 1;
nc = LLL;
}
for (int i = 0; i < nr; i++)
{
const uchar* inData = img.ptr<uchar>(i);
for (int j = 0; j < nc; j++)
{
buf[pos] = *inData++;
pos++;
}
}
}
}
void tobufferA(const std::vector<cv::Mat> &imgs, float *buf){
int pos = 0;
for (cv::Mat img : imgs) {
if (img.isContinuous()) {
memcpy(buf+pos, img.ptr<float>(0),
static_cast<size_t>(img.total()) * sizeof(float));
pos += static_cast<size_t>(img.total()) * sizeof(float);
}
else {
printf("error\n");
exit(0);
}
}
}
typedef std::vector<double> DSR;
typedef std::vector<DSR> DSRS;
typedef std::vector<int> IDSR;
typedef std::vector<IDSR> IDSRS;
bool FeatureGetter::Init() {
tf::Session* session_ptr;
auto status = NewSession(tf::SessionOptions(), &session_ptr);
if (!status.ok()) {
std::cout << status.ToString() << "\n";
return false;
}
session.reset(session_ptr);
//------------------
tf::GraphDef graph_def;
auto status1 = ReadBinaryProto(tf::Env::Default(), "./data/mobilenet.pb", &graph_def);
if (!status1.ok()) {
printf("ReadBinaryProto failed: %s\n", status1.ToString().c_str());
return false;
}
status = session->Create(graph_def);
if (!status.ok()) {
printf("create graph in session failed: %s\n", status.ToString().c_str());
return false;
}
std::vector<std::string> node_names;
for (const auto &node : graph_def.node()) {
printf("node name:%s\n", node.name().c_str());
node_names.push_back(node.name());
}
return true;
}
bool FeatureGetter::Get(const cv::Mat &img, const std::vector<cv::Rect> &rcs,
std::vector<FFEATURE> &fts) {
std::vector<cv::Mat> mats;
for(cv::Rect rc:rcs){
cv::Mat mat1 = img(rc).clone();
cv::resize(mat1, mat1, cv::Size(224, 224));
mats.push_back(mat1);
}
int count = mats.size();
tensorflow::Tensor input_tensor0(tensorflow::DT_FLOAT, { count, 224, 224, 3 });
tobuffer(mats, input_tensor0.flat<uint8>().data());
std::vector<tensorflow::Tensor> output_tensors;
std::vector<std::pair<std::string, tensorflow::Tensor>> ins;
std::pair<std::string, tensorflow::Tensor> pa;
pa.first = "input";
pa.second = input_tensor0;
ins.push_back(pa);
std::vector<std::string> outnames;
outnames.push_back("MobilenetV1/Predictions/Reshape_1");
std::vector<std::string> ts;
int64_t ftm1 = fgtm();
auto status = session->Run(
ins,
outnames,
ts,
&output_tensors);
int64_t ftm2 = fgtm();
std::cout << "session.run--mobilenet--rcs.size():" << rcs.size() << ", ftm2-ftm1:" << (ftm2-ftm1) << "\n";
if (!status.ok()) {
printf("error 3%s \n", status.ToString().c_str());
return false;
}
float *tensor_buffer =
output_tensors[0].flat<float>().data();
int len = output_tensors[0].flat<float>().size() / count;
for (int i = 0; i < count; i++) {
//printf("begin====\n");
FFEATURE ft;
for (int j = 0; j < len; j++) {
if(j>=128){
continue;
}
ft(j) = tensor_buffer[i*len + j];
//printf(",%f", tensor_buffer[i*len+j]);
}
fts.push_back(ft);
//printf("\nend====\n");
}
return true;
}
================================================
FILE: deepsort/FeatureGetter/make.sh
================================================
#!/bin/bash
function getbazel(){
LINE=`readlink -f /home/$USER/code1/tensorflow-1.4.0-rc0/bazel-bin/`
POS1="_bazel_$USER/"
STR=${LINE##*$POS1}
BAZEL=${STR:0:32}
echo $BAZEL
}
BAZEL=`getbazel`
function TF(){
IINCLUDE="-I/home/$USER/code/test/pp/opencvlib/include -I/usr/local/include -I/home/$USER/.cache/bazel/_bazel_$USER/$BAZEL/external/eigen_archive/Eigen -I/home/$USER/.cache/bazel/_bazel_$USER/$BAZEL/external/eigen_archive -I/home/$USER/code1/tensorflow-1.4.0-rc0 -I/home/$USER/code1/tensorflow-1.4.0-rc0/bazel-genfiles -I/home/$USER/.cache/bazel/_bazel_$USER/$BAZEL/external/nsync/public"
LLIBPATH="-L/home/$USER/code/test/pp/opencvlib/lib -L/usr/local/lib -L/home/$USER/code1/tensorflow-1.4.0-rc0/bazel-bin/tensorflow"
LLIBS="-lopencv_corexyz -lopencv_imgprocxyz -lopencv_highguixyz -ltensorflow_cc -ltensorflow_framework"
rm libFeatureGetter.so -rf
g++ --std=c++14 -O3 -fopenmp -fPIC -shared -o libFeatureGetter.so $IINCLUDE $LLIBPATH FeatureGetter.cpp $LLIBS
}
#CAFFEROOT="/home/xyz/code/py-faster-rcnn/caffe-fast-rcnn"
CAFFEROOT="/home/$USER/code1/caffe-master"
#CAFFEROOT="/home/$USER/code1/caffe-ssd"
function CAFFE(){
IINCLUDE="-I/home/$USER/code/test/pp/opencvlib/include -I/usr/local/include -I/home/$USER/.cache/bazel/_bazel_$USER/$BAZEL/external/eigen_archive/Eigen -I/home/$USER/.cache/bazel/_bazel_$USER/$BAZEL/external/eigen_archive -I$CAFFEROOT/include -I/usr/local/cuda-8.0-cudnn5.0.5/include -I$CAFFEROOT/build/src"
LLIBPATH="-L/home/$USER/code/test/pp/opencvlib/lib -L$CAFFEROOT/distribute/lib"
LLIBS="-lopencv_corexyz -lopencv_imgprocxyz -lopencv_highguixyz -lcaffe"
rm libFeatureGetter.so -rf
g++ --std=c++14 -O3 -fopenmp -DOONE -DUSE_CAFFE_SHUFFE_NET -fPIC -shared -o libFeatureGetter.so $IINCLUDE $LLIBPATH FeatureGetter.cpp $LLIBS
#g++ --std=c++14 -O3 -fopenmp -DUSE_CAFFE_SHUFFE_NET -fPIC -shared -o libFeatureGetter.so $IINCLUDE $LLIBPATH FeatureGetter.cpp $LLIBS
}
#CAFFE
TF
================================================
FILE: deepsort/HungarianOper.h
================================================
#ifndef _HUNGARIANOPERH_
#define _HUNGARIANOPERH_
#include "munkres/munkres.h"
#include "munkres/adapters/boostmatrixadapter.h"
#include "Detection.h"
class HungarianOper {
public:
static Eigen::Matrix<float, -1, 2> Solve(const DYNAMICM &cost_matrix) {
int rows = cost_matrix.rows();
int cols = cost_matrix.cols();
Matrix<double> matrix(rows, cols);
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
matrix(row, col) = cost_matrix(row, col);
}
}
//
Munkres<double> m;
m.solve(matrix);
//
std::vector<std::pair<int, int>> pairs;
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
int tmp = (int)matrix(row, col);
if (tmp == 0) {
std::pair<int, int> pa;
pa.first = row;
pa.second = col;
pairs.push_back(pa);
}
}
}
//
int count = pairs.size();
Eigen::Matrix<float, -1, 2> re(count, 2);
for (int i = 0; i < count; i++) {
std::pair<int, int> &pa = pairs[i];
re(i, 0) = pa.first;
re(i, 1) = pa.second;
}
return re;
}
};
#endif
================================================
FILE: deepsort/KalmanTracker.h
================================================
#ifndef _KALMANTRACKERH_
#define _KALMANTRACKERH_
#include "FeatureGetter/FeatureGetter.h"
#include "kalman_filter.h"
#include <boost/shared_ptr.hpp>
enum TrackState{
TS_NONE = 0,
Tentative,
Confirmed,
Deleted
};
class KalmanTrackerN;
typedef boost::shared_ptr<KalmanTrackerN> KalmanTracker;
class KalmanTrackerN{
public:
int time_since_update_ = 0;
MEAN mean_;
VAR covariance_;
int track_id = 0;
std::vector<FEATURE> features_;
int oriPos_;
private:
int hits_ = 0;
int age_ = 0;
TrackState state_ = TS_NONE;
int _n_init_;
int _max_age_;
public:
KalmanTrackerN(const MEAN &mean,
const VAR &covariance,
int tid,
int n_init,
int max_age,
const FEATURE &feature, bool featureFull, int oriPos){
mean_ = mean;
covariance_ = covariance;
this->track_id = tid;
hits_ = 1;
age_ = 1;
time_since_update_ = 0;
state_ = Tentative;
if (featureFull) {
features_.push_back(feature);
}
_n_init_ = n_init;
_max_age_ = max_age;
oriPos_ = oriPos;
}
DSBOX to_tlwh() const{
DSBOX ret;
ret(0) = mean_(0);
ret(1) = mean_(1);
ret(2) = mean_(2);
ret(3) = mean_(3);
ret(2) *= ret(3);
ret(0) -= ret(2) / 2;
ret(1) -= ret(3) / 2;
return ret;
}
DSBOX to_tlbr(){
DSBOX ret = to_tlwh();
ret(2) = ret(0) + ret(2);
ret(3) = ret(1) + ret(3);
return ret;
}
void predict(const KF &kalmanFilter, bool only=false){
std::pair<MEAN, VAR> pa = kalmanFilter.predict(mean_, covariance_);
mean_ = pa.first;
covariance_ = pa.second;
if(only){// 2017.10.18
return;
}
age_ += 1;
time_since_update_ += 1;
}
void update(const KF &kalmanFilter, const Detection &detection){
DSBOX box = detection.to_xyah();
std::pair<MEAN, VAR> pa = kalmanFilter.update(
mean_, covariance_, box);
mean_ = pa.first;
covariance_ = pa.second;
features_.push_back(detection.feature_);
hits_ += 1;
time_since_update_ = 0;
if (state_ == Tentative && hits_ >= _n_init_) {
state_ = Confirmed;
}
}
void mark_missed(){
if(state_ == Tentative){
state_ = Deleted;
}
else if(time_since_update_ > _max_age_){
state_ = Deleted;
}
}
bool is_tentative(){
return state_ == Tentative;
}
bool is_confirmed()const {
return state_ == Confirmed;
}
bool is_deleted(){
return state_ == Deleted;
}
};
#endif
================================================
FILE: deepsort/iou_matching.h
================================================
#ifndef _IOUMH_
#define _IOUMH_
#include <vector>
#include "Detection.h"
#include <Eigen>
#include "linear_assignment.h"
#include <iterator>
class iou_matching{
private:
static Eigen::VectorXf _iouFun(const DSBOX &bbox, const DSBOXS &candidates){
Eigen::VectorXf area_candidates(candidates.rows());
//
PT2 bbox_tl; bbox_tl(0, 0) = bbox[0]; bbox_tl(0, 1) = bbox[1];
PT2 bbox_br; bbox_br(0, 0) = (bbox[0] + bbox[2]); bbox_br(0, 1) = (bbox[1] + bbox[3]);
DYNAMICM ctl(candidates.rows(), 2);
DYNAMICM cbr(candidates.rows(), 2);
for(int i = 0; i < candidates.rows(); i++){
DSBOX candidate = candidates.row(i);
PT2 candidates_tl;
candidates_tl(0, 0) = candidate[0]; candidates_tl(0, 1) = candidate[1];
ctl.row(i) = candidates_tl;
PT2 candidates_br;
candidates_br(0, 0) = (candidate[0] + candidate[2]);
candidates_br(0, 1) = (candidate[1] + candidate[3]);
cbr.row(i) = candidates_br;
{
area_candidates(i) = candidate[2] * candidate[3];
}
}
//std::cout << "ctl-b:\n" << ctl << "ctl-e\n" << std::endl;
//std::cout << "cbr-b:\n" << cbr << "cbr-e\n" << std::endl;
DYNAMICM tl(candidates.rows(), 2);
float btl0 = bbox_tl(0, 0);
float btl1 = bbox_tl(0, 1);
for (int i = 0; i < tl.rows(); i++) {
//DYNAMICM row = tl.row(i);
float m = cv::max(btl0, ctl(i, 0));
tl(i, 0) = m;
m = cv::max(btl1, ctl(i, 1));
tl(i, 1) = m;
//std::cout << "tl-b:\n" << tl << "tl-e\n" << std::endl;
}
//std::cout << "tl-b:\n" << tl << "tl-e\n" << std::endl;
DYNAMICM br(candidates.rows(), 2);
float bbr0 = bbox_br(0, 0);
float bbr1 = bbox_br(0, 1);
for (int i = 0; i < br.rows(); i++) {
//DYNAMICM row = br.row(i);
br(i, 0) = cv::min(bbr0, cbr(i, 0));
br(i, 1) = cv::min(bbr1, cbr(i, 1));
}
//std::cout << "br-b:\n" << br << "br-e\n" << std::endl;
DYNAMICM wh(candidates.rows(), 2);
Eigen::VectorXf area_intersection(candidates.rows());
for (int i = 0; i < wh.rows(); i++) {
for (int j = 0; j < wh.cols(); j++) {
float tmp = br(i, j) - tl(i, j);
wh(i, j) = tmp>0?tmp:0;
}
area_intersection(i) = wh(i, 0)*wh(i, 1);
}
//std::cout << "wh-b:\n" << wh << "wh-e\n" << std::endl;
float area_bbox = bbox(0, 2)*bbox(0, 3);
Eigen::VectorXf re(candidates.rows());
for (int i = 0; i < re.rows(); i++) {
re(i) = area_intersection(i) / (area_bbox +
area_candidates(i) -
area_intersection(i));
}
return re;
}
public:
static DYNAMICM getCostMatrixByIOU(const std::vector<KalmanTracker> &tracks,
const std::vector<Detection> &detections,
IDS *track_indicesi=NULL,
IDS *detection_indicesi=NULL){
IDS track_indices;
if (track_indicesi == NULL) {
for (int i = 0; i < tracks.size(); i++) {
track_indices.push_back(i);
}
}
else {
track_indices = *track_indicesi;
}
IDS detection_indices;
if (detection_indicesi == NULL) {
for (int i = 0; i < detections.size(); i++) {
detection_indices.push_back(i);
}
}
else {
detection_indices = *detection_indicesi;
}
DYNAMICM cost_matrix(track_indices.size(), detection_indices.size());
for (int row = 0; row < track_indices.size(); row++) {
int track_idx = track_indices[row];
if (tracks[track_idx]->time_since_update_ > 1) {
for (int c = 0; c < cost_matrix.cols(); c++) {
cost_matrix(row, c) = INFTY_COST;
}
continue;
}
DSBOX bbox = tracks[track_idx]->to_tlwh();
DSBOXS candidates(detection_indices.size(), 4);
for (int k = 0; k < detection_indices.size(); k++) {
DSBOX tmp = detections[detection_indices[k]].tlwh_;
candidates.row(k) = tmp;
}
//std::cout << "mmm" << candidates << "vvvv" << std::endl;
Eigen::VectorXf tmpm = _iouFun(bbox, candidates);
//std::cout << "tmpm--b" << tmpm << "tmpm--e" << std::endl;
auto tmp1 = tmpm.array();
auto tmp2 = -(tmp1 - 1);
cost_matrix.row(row) = tmp2.matrix();
//std::cout << "nnnnn" << cost_matrix << "uuuu" << std::endl;
}
return cost_matrix;
}
};
#endif
================================================
FILE: deepsort/kalman_filter.h
================================================
#ifndef PYKF
#ifndef _KKALMANFILTERH_
#define _KKALMANFILTERH_
#include <boost/shared_ptr.hpp>
typedef Eigen::Matrix<float, 4, 8, Eigen::RowMajor> UPM;
class KF{
private:
static boost::shared_ptr<KF> self_;
VAR _motion_mat_;
UPM _update_mat_;
double _std_weight_position_;
double _std_weight_velocity_;
public:
static boost::shared_ptr<KF> Instance() {
if (self_.get() == NULL) {
self_.reset(new KF());
}
return self_;
}
bool Init(){
return true;
}
private:
KF(){
int ndim = 4;
double dt = 1.;
_motion_mat_ = Eigen::MatrixXf::Identity(8, 8);
for(int i = 0; i < ndim; i++){
_motion_mat_(i, ndim + i) = dt;
}
_update_mat_ = Eigen::MatrixXf::Identity(4, 8);
_std_weight_position_ = 1. / 20;
_std_weight_velocity_ = 1. / 160;
}
VAR Diag(const MEAN &mean) const{
VAR var;
for(int i = 0; i < var.rows(); i++){
for(int j = 0; j < var.cols(); j++){
if(i == j){
var(i, j) = mean(i);
}
else{
var(i, j) = 0;
}
}
}
return var;
}
NVAR NDiag(const NMEAN &mean) const{
NVAR var;
for(int i = 0; i < var.rows(); i++){
for(int j = 0; j < var.cols(); j++){
if(i == j){
var(i, j) = mean(i);
}
else{
var(i, j) = 0;
}
}
}
return var;
}
public:
std::pair<MEAN, VAR> initiate(const DSBOX &measurement) const{
DSBOX mean_pos = measurement;
DSBOX mean_val;
for(int i = 0; i < 4; i++){
mean_val(i) = 0;
}
MEAN mean;
for(int i = 0; i < 8; i++){
if(i < 4){
mean(i) = mean_pos(i);
continue;
}
mean(i) = mean_val(i - 4);
}
MEAN std;
std(0) = 2 * _std_weight_position_ * measurement[3];
std(1) = 2 * _std_weight_position_ * measurement[3];
std(2) = 1e-2;
std(3) = 2 * _std_weight_position_ * measurement[3];
std(4) = 10 * _std_weight_velocity_ * measurement[3];
std(5) = 10 * _std_weight_velocity_ * measurement[3];
std(6) = 1e-5;
std(7) = 10 * _std_weight_velocity_ * measurement[3];
MEAN tmp = std.array().square();
VAR var = Diag(tmp);
#ifdef KLOG
std::cout << "[-4--]begin mean:\n" << mean << "\n[-4--]end mean\n";
std::cout << "[-4--]begin covariance:\n" << var << "\n[-4--]end covariance\n";
#endif
std::pair<MEAN, VAR> pa;
pa.first = mean;
pa.second = var;
return pa;
}
std::pair<MEAN, VAR> predict(const MEAN &mean, const VAR &covariance) const{
DSBOX std_pos;
std_pos <<
_std_weight_position_ * mean(3),
_std_weight_position_ * mean(3),
1e-2,
_std_weight_position_ * mean(3);
DSBOX std_vel;
std_vel <<
_std_weight_velocity_ * mean(3),
_std_weight_velocity_ * mean(3),
1e-5,
_std_weight_velocity_ * mean(3);
MEAN mtmp;
for(int i = 0; i < 8; i++){
if(i < 4){
mtmp(i) = std_pos(i);
continue;
}
mtmp(i) = std_vel(i - 4);
}
MEAN tmp = mtmp.array().square();
VAR motion_cov = Diag(tmp);
#ifdef KLOG
std::cout << "[-3--]begin square\n";
std::cout << tmp << "\n";
std::cout << "[-3--]end square\n";
#endif
//
MEAN mean1 = _motion_mat_ * mean.transpose();
#ifdef KLOG
std::cout << "[-3--]begin self._motion_mat_\n";
std::cout << _motion_mat_ << "\n";
std::cout << "[-3--]end self._motion_mat_\n";
std::cout << "[-3--]begin covariance\n";
std::cout << covariance << "\n";
std::cout << "[-3--]end covariance\n";
std::cout << "[-3--]begin motion_cov:\n";
std::cout << motion_cov << "\n";
std::cout << "[-3--]end motion_cov:\n";
#endif
VAR var = _motion_mat_ * covariance * (_motion_mat_.transpose());
VAR var1 = var + motion_cov;
#ifdef KLOG
std::cout << "[-3--]begin covariance result\n";
std::cout << var1 << "\n";
std::cout << "[-3--]end covariance result\n";
#endif
std::pair<MEAN, VAR> pa;
pa.first = mean1;
pa.second = var1;
return pa;
}
std::pair<MEAN, VAR> update(const MEAN &mean, const VAR &covariance, const DSBOX &measurement) const{
std::pair<NMEAN, NVAR> pa1 = _project(mean, covariance);
NMEAN projected_mean = pa1.first;
NVAR projected_cov = pa1.second;
auto ddd = covariance * (_update_mat_.transpose());
Eigen::Matrix<float, -1, 4> kalman_gain = projected_cov.llt().solve(ddd.transpose()).transpose(); // eg.8x4
Eigen::Matrix<float, 1, 4> innovation = measurement - projected_mean; //eg.1x4
#ifdef KLOG
std::cout << "[-1--]bbegin ddd\n";
std::cout << ddd << "\n";
std::cout << "[-1--]bend ddd\n";
std::cout << "[-1--]bbegin kalman_gain\n";
std::cout << kalman_gain << "\n";
std::cout << "[-1--]bend kalman_gain\n";
std::cout << "[-1--]begin measurement\n";
std::cout << measurement << "\n";
std::cout << "[-1--]end measurement\n";
std::cout << "[-1--]begin projected_mean\n";
std::cout << projected_mean << "\n";
std::cout << "[-1--]end projectd_mean\n";
std::cout << "[-1--]begin innovation\n";
std::cout << innovation << "\n";
std::cout << "[-1--]end innovation\n";
std::cout << "[-1--]begin projected_cov\n";
std::cout << projected_cov << "\n";
std::cout << "[-1--]end projectd_cov\n";
#endif
auto tmp = innovation*(kalman_gain.transpose());
MEAN new_mean = (mean.array() + tmp.array()).matrix();
VAR new_covariance = covariance - kalman_gain*projected_cov*(kalman_gain.transpose());
std::pair<MEAN, VAR> pa2;
pa2.first = new_mean;
pa2.second = new_covariance;
return pa2;
}
Eigen::Matrix<float, 1, -1> gating_distance(const MEAN &meani, const VAR &covariance,
const DSBOXS &measurements,
bool only_position=false) const{
MEAN mean = meani;
#ifdef KLOG
std::cout << "[-2--]begin mean\n";
std::cout << mean << "\n";
std::cout << "[-2--]end mean\n";
std::cout << "[-2--]begin covariance\n";
std::cout << covariance << "\n";
std::cout << "[-2--]end covariance\n";
std::cout << "[-2--]begin measurements\n";
std::cout << measurements << "\n";
std::cout << "[-2--]end measurements\n";
#endif
std::pair<NMEAN, NVAR> pa1 = _project(mean, covariance);
if(only_position){
printf("not implement!!!exit\n");
exit(0);
}
NMEAN mean1 = pa1.first;
NVAR var1 = pa1.second;
#ifdef KLOG
std::cout << "[-2--]begin mean1\n";
std::cout << mean1 << "\n";
std::cout << "[-2--]end mean1\n";
std::cout << "[-2--]begin covariance1\n";
std::cout << var1 << "\n";
std::cout << "[-2--]end covariance1\n";
#endif
int count = measurements.rows();
DSBOXS d(count, 4);
for(int i = 0; i < count; i++){
d.row(i) = measurements.row(i) - mean1;
}
#ifdef KLOG
std::cout << "[-2--]bbegin d\n";
std::cout << d << "\n";
std::cout << "[-2--]bend d\n";
#endif
Eigen::Matrix<float, -1, -1, Eigen::RowMajor> factor = var1.llt().matrixL();
Eigen::Matrix<float, -1, -1> z = factor.triangularView<Eigen::Lower>().solve<Eigen::OnTheRight>(d).transpose();
#ifdef KLOG
std::cout << "[-2--]begin z\n";
std::cout << z << "\n";
std::cout << "[-2--]end z\n";
#endif
#if 1
auto zz = ((z.array())*(z.array())).matrix();
auto squared_maha = zz.colwise().sum();
#else
Eigen::Matrix<float, 1, -1> squared_maha = z.colwise().sum();
#endif
#ifdef KLOG
std::cout << "[-2--]begin squared_maha\n";
std::cout << squared_maha << "\n";
std::cout << "[-2--]end squared_maha\n";
#endif
return squared_maha;
}
std::pair<NMEAN, NVAR> _project(const MEAN &mean, const VAR &covariance) const{
NMEAN std;
std <<
_std_weight_position_ * mean[3],
_std_weight_position_ * mean[3],
1e-1,
_std_weight_position_ * mean[3];
NMEAN mtmp = std.array().square();
#ifdef KLOG
std::cout << "[-0--]begin mtmp\n";
std::cout << mtmp << "\n";
std::cout << "[-0--]end mtmp\n";
#endif
NVAR innovation_cov = NDiag(mtmp);
NMEAN mean1 = _update_mat_*mean.transpose();
#ifdef KLOG
std::cout << "[-0--]begin innovation_cov\n";
std::cout << innovation_cov << "\n";
std::cout << "[-0--]end innovation_cov\n";
std::cout << "[-0--]begin var\n";
std::cout << covariance << "\n";
std::cout << "[-0--]end var\n";
std::cout << "[-0--]begin _update_mat_\n";
std::cout << _update_mat_ << "\n";
std::cout << "[-0--]end _update_mat_\n";
#endif
NVAR var = _update_mat_ * covariance * (_update_mat_.transpose());
NVAR var1 = var + innovation_cov;
#ifdef KLOG
std::cout << "[-0--]begin var1\n";
std::cout << var << "\n";
std::cout << "[-0--]end var1\n";
#endif
std::pair<NMEAN, NVAR> pa;
pa.first = mean1;
pa.second = var1;
return pa;
}
};
#endif
#endif
================================================
FILE: deepsort/linear_assignment.h
================================================
#ifndef _LASMH_
#define _LASMH_
#include <vector>
#include "Detection.h"
#include <Eigen>
#include "KalmanTracker.h"
#include "FeatureGetter/FeatureGetter.h"
#include "HungarianOper.h"
#include <sys/time.h>
static int64_t line_gtm() {
struct timeval tm;
gettimeofday(&tm, 0);
int64_t re = ((int64_t)tm.tv_sec) * 1000 * 1000 + tm.tv_usec;
return re;
}
const static int INFTY_COST = 1e+5;
struct RR {
std::vector<std::pair<int, int> > matches;
IDS unmatched_detections;
IDS unmatched_tracks;
};
typedef DYNAMICM (*GetCostMarixFun)(const std::vector<KalmanTracker> &tracks,
const std::vector<Detection> &detections,
IDS *track_indices,
IDS *detection_indices);
double chi2inv95[10] = {
0,
3.8415,
5.9915,
7.8147,
9.4877,
11.070,
12.592,
14.067,
15.507,
16.919 };
class linear_assignment{
public:
static RR min_cost_matching(
const GetCostMarixFun &getCostMarixFun, float max_distance,
const std::vector<KalmanTracker> &tracks,
const std::vector<Detection> &detections,
IDS *track_indicesi=NULL,
IDS *detection_indicesi=NULL){
int64_t mintm1 = line_gtm();
IDS track_indices;
IDS detection_indices;
if (track_indicesi == NULL) {
for (int i = 0; i < tracks.size(); i++) {
track_indices.push_back(i);
}
}
else {
track_indices = *track_indicesi;
}
if (detection_indicesi == NULL) {
for (int i = 0; i < detections.size(); i++) {
detection_indices.push_back(i);
}
}
else {
detection_indices = *detection_indicesi;
}
if (detection_indices.empty() || track_indices.empty()) {
RR rr;
rr.unmatched_tracks = track_indices;
rr.unmatched_detections = detection_indices;
return rr;
}
int64_t mintm2 = line_gtm();
// 5x5
DYNAMICM cost_matrix = getCostMarixFun(
tracks, detections, &track_indices, &detection_indices);
//std::cout << "\n----mmmmm----\n" << cost_matrix << "\n----vvvvv-----\n" << std::endl;
for (int i = 0; i < cost_matrix.rows(); i++) {
for (int j = 0; j < cost_matrix.cols(); j++) {
float tmp = cost_matrix(i, j);
if (tmp > max_distance) {
cost_matrix(i, j) = max_distance + 1e-5;
}
}
}
int64_t mintm3 = line_gtm();
//std::cout << "\n----222mmmmm----\n" << cost_matrix << "\n----222vvvvv-----\n" << std::endl;
//Eigen::Matrix<float, -1, 2> indices = KF::Instance()->LinearAssignmentForCpp(cost_matrix);
Eigen::Matrix<float, -1, 2> indices =
HungarianOper::Solve(cost_matrix);
int64_t mintm4 = line_gtm();
//std::cout << "indices:\n" << indices << std::endl;
//xyztodo: indices = linear_assignment(cost_matrix)
// (-1, 2)
RR rr;
// Ƿڵ2
for (int col = 0; col < detection_indices.size(); col++) {
// check if col is in indecis[:,1]
bool isIn = false;
for (int i = 0; i < indices.rows(); i++) {
int iid = indices(i, 1);
if (col == iid) {
isIn = true;
break;
}
}
if (!isIn) {
int detection_idx = detection_indices[col];
rr.unmatched_detections.push_back(detection_idx);
}
}
// Ƿڵ1
for (int row = 0; row < track_indices.size(); row++) {
// check of row is in indecis[:,0]
bool isIn = false;
for (int i = 0; i < indices.rows(); i++) {
int iid = indices(i, 0);
if (row == iid) {
isIn = true;
break;
}
}
if (!isIn) {
int track_idx = track_indices[row];
rr.unmatched_tracks.push_back(track_idx);
}
}
for (int i = 0; i < indices.rows(); i++) {
int row = indices(i, 0);
int col = indices(i, 1);
//for (int j = 0; j < indices.cols(); j++) {
// int row = i;
// int col = j;
int track_idx = track_indices[row];
int detection_idx = detection_indices[col];
if (cost_matrix(row, col) > max_distance) {
rr.unmatched_tracks.push_back(track_idx);
rr.unmatched_detections.push_back(detection_idx);
}
else {
rr.matches.push_back(std::make_pair(track_idx, detection_idx));
}
//}
}
int64_t mintm5 = line_gtm();
std::cout << "min_cost_matching----mintm2-mintm1:" << (mintm2-mintm1) <<
", mintm3-mintm1:" << (mintm3-mintm1) <<
", mintm4-mintm1:" << (mintm4-mintm1) <<
", mintm5-mintm1:" << (mintm5-mintm1) << "\n";
return rr;
}
static RR matching_cascade(
const GetCostMarixFun &getCostMarixFun, float max_distance,
int cascade_depth,
const std::vector<KalmanTracker> &tracks,
const std::vector<Detection> &detections,
IDS *track_indicesi = NULL,
IDS *detection_indicesi = NULL){
int64_t ctm0 = line_gtm();
IDS track_indices;
IDS detection_indices;
if(track_indicesi == NULL) {
for (int i = 0; i < tracks.size(); i++) {
track_indices.push_back(i);
}
}
else {
track_indices = *track_indicesi;
}
if (detection_indicesi == NULL) {
for (int i = 0; i < detections.size(); i++) {
detection_indices.push_back(i);
}
}
else {
detection_indices = *detection_indicesi;
}
RR re;
std::map<int, int> tmpMap;
IDS unmatched_detections = detection_indices;
for (int level = 0; level < cascade_depth; level++) {
int64_t ctm1 = line_gtm();
if (unmatched_detections.empty()) {
break;
}
IDS track_indices_l;
for (int k = 0; k < track_indices.size(); k++) {
if (tracks[k]->time_since_update_ == level + 1) {
track_indices_l.push_back(track_indices[k]);
}
}
if (track_indices_l.empty()) {
continue;
}
RR rr = min_cost_matching(
getCostMarixFun, max_distance, tracks, detections,
&track_indices_l, &unmatched_detections);
unmatched_detections = rr.unmatched_detections;
for (int i = 0; i < rr.matches.size(); i++) {
std::pair<int, int> pa = rr.matches[i];
re.matches.push_back(pa);
tmpMap.insert(pa);
}
int64_t ctm2 = line_gtm();
std::cout << "cascade("<< level << ")----ctm2-ctm1:" << (ctm2-ctm1) << "\n";
}
re.unmatched_detections = unmatched_detections;
for (int i = 0; i < track_indices.size(); i++) {
int tid = track_indices[i];
std::map<int, int>::iterator it = tmpMap.find(tid);
if (it == tmpMap.end()) {
re.unmatched_tracks.push_back(tid);
}
}
int64_t ctm4 = line_gtm();
std::cout << "cascade----ctm4-ctm0:" << (ctm4-ctm0) << "\n";
return re;
}
static DYNAMICM gate_cost_matrix(
const KF &kalmanFilter,
DYNAMICM &cost_matrix,
const std::vector<KalmanTracker> &tracks,
const std::vector<Detection> &detections,
IDS track_indices,
IDS detection_indices,
int gated_cost=INFTY_COST,
bool only_position=false){
int gating_dim = only_position ? 2 : 4;
float gating_threshold = chi2inv95[gating_dim];
DSBOXS measurements(detection_indices.size(), 4);
for (int i = 0; i < detection_indices.size(); i++) {
int pos = detection_indices[i];
DSBOX tmp = detections[pos].to_xyah();
measurements.row(i) = tmp;
}
for (int row = 0; row < track_indices.size(); row++) {
int track_idx = track_indices[row];
KalmanTracker track = tracks[track_idx];
// gating_distance is a vector
Eigen::Matrix<float, 1, -1> gating_distance = kalmanFilter.gating_distance(
track->mean_, track->covariance_, measurements, only_position);
for (int i = 0; i < gating_distance.cols(); i++) {
if (gating_distance(0, i) > gating_threshold) {
cost_matrix(row, i) = gated_cost;
}
}
//std::cout << "\nb--ggg\n" << cost_matrix << "\e--ggg\n";
}
return cost_matrix;
}
};
#endif
================================================
FILE: deepsort/munkres/adapters/adapter.cpp
================================================
/*
* Copyright (c) 2015 Miroslav Krajicek
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "adapter.h"
================================================
FILE: deepsort/munkres/adapters/adapter.h
================================================
/*
* Copyright (c) 2015 Miroslav Krajicek
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _ADAPTER_H_
#define _ADAPTER_H_
#include "../matrix.h"
#include "../munkres.h"
template<typename Data, class Container > class Adapter
{
public:
virtual Matrix<Data> convertToMatrix(const Container &con) const = 0;
virtual void convertFromMatrix(Container &con, const Matrix<Data> &matrix) const = 0;
virtual void solve(Container &con)
{
auto matrix = convertToMatrix(con);
m_munkres.solve(matrix);
convertFromMatrix(con, matrix);
}
protected:
Munkres<Data> m_munkres;
};
#endif /* _ADAPTER_H_ */
================================================
FILE: deepsort/munkres/adapters/boostmatrixadapter.cpp
================================================
/*
* Copyright (c) 2015 Miroslav Krajicek
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "boostmatrixadapter.h"
template class BoostMatrixAdapter<double>;
template class BoostMatrixAdapter<float>;
template class BoostMatrixAdapter<int>;
================================================
FILE: deepsort/munkres/adapters/boostmatrixadapter.h
================================================
/*
* Copyright (c) 2015 Miroslav Krajicek
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _BOOSTMATRIXADAPTER_H_
#define _BOOSTMATRIXADAPTER_H_
#include "adapter.h"
#ifndef WIN32
#include <boost/serialization/array_wrapper.hpp>
#endif
#include <boost/numeric/ublas/matrix.hpp>
template<typename Data> class BoostMatrixAdapter : public Adapter<Data,boost::numeric::ublas::matrix<Data> >
{
public:
virtual Matrix<Data> convertToMatrix(const boost::numeric::ublas::matrix<Data> &boost_matrix) const override
{
const auto rows = boost_matrix.size1 ();
const auto columns = boost_matrix.size2 ();
Matrix <Data> matrix (rows, columns);
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < columns; ++j) {
matrix (i, j) = boost_matrix (i, j);
}
}
return matrix;
}
virtual void convertFromMatrix(boost::numeric::ublas::matrix<Data> &boost_matrix,const Matrix<Data> &matrix) const override
{
const auto rows = matrix.rows();
const auto columns = matrix.columns();
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < columns; ++j) {
boost_matrix (i, j) = matrix (i, j);
}
}
}
};
#endif /* _BOOSTMATRIXADAPTER_H_ */
================================================
FILE: deepsort/munkres/matrix.cpp
================================================
/*
* Copyright (c) 2007 John Weaver
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "matrix.h"
#include <cassert>
#include <cstdlib>
#include <algorithm>
/*export*/ template <class T>
Matrix<T>::Matrix() {
m_rows = 0;
m_columns = 0;
m_matrix = nullptr;
}
/*export*/ template <class T>
Matrix<T>::Matrix(const std::initializer_list<std::initializer_list<T>> init) {
m_matrix = nullptr;
m_rows = init.size();
if ( m_rows == 0 ) {
m_columns = 0;
} else {
m_columns = init.begin()->size();
if ( m_columns > 0 ) {
resize(m_rows, m_columns);
}
}
size_t i = 0, j;
for ( auto row = init.begin() ; row != init.end() ; ++row, ++i ) {
assert ( row->size() == m_columns && "All rows must have the same number of columns." );
j = 0;
for ( auto value = row->begin() ; value != row->end() ; ++value, ++j ) {
m_matrix[i][j] = *value;
}
}
}
/*export*/ template <class T>
Matrix<T>::Matrix(const Matrix<T> &other) {
if ( other.m_matrix != nullptr ) {
// copy arrays
m_matrix = nullptr;
resize(other.m_rows, other.m_columns);
for ( size_t i = 0 ; i < m_rows ; i++ ) {
for ( size_t j = 0 ; j < m_columns ; j++ ) {
m_matrix[i][j] = other.m_matrix[i][j];
}
}
} else {
m_matrix = nullptr;
m_rows = 0;
m_columns = 0;
}
}
/*export*/ template <class T>
Matrix<T>::Matrix(const size_t rows, const size_t columns) {
m_matrix = nullptr;
resize(rows, columns);
}
/*export*/ template <class T>
Matrix<T> &
Matrix<T>::operator= (const Matrix<T> &other) {
if ( other.m_matrix != nullptr ) {
// copy arrays
resize(other.m_rows, other.m_columns);
for ( size_t i = 0 ; i < m_rows ; i++ ) {
for ( size_t j = 0 ; j < m_columns ; j++ ) {
m_matrix[i][j] = other.m_matrix[i][j];
}
}
} else {
// free arrays
for ( size_t i = 0 ; i < m_columns ; i++ ) {
delete [] m_matrix[i];
}
delete [] m_matrix;
m_matrix = nullptr;
m_rows = 0;
m_columns = 0;
}
return *this;
}
/*export*/ template <class T>
Matrix<T>::~Matrix() {
if ( m_matrix != nullptr ) {
// free arrays
for ( size_t i = 0 ; i < m_rows ; i++ ) {
delete [] m_matrix[i];
}
delete [] m_matrix;
}
m_matrix = nullptr;
}
/*export*/ template <class T>
void
Matrix<T>::resize(const size_t rows, const size_t columns, const T default_value) {
assert ( rows > 0 && columns > 0 && "Columns and rows must exist." );
if ( m_matrix == nullptr ) {
// alloc arrays
m_matrix = new T*[rows]; // rows
for ( size_t i = 0 ; i < rows ; i++ ) {
m_matrix[i] = new T[columns]; // columns
}
m_rows = rows;
m_columns = columns;
clear();
} else {
// save array pointer
T **new_matrix;
// alloc new arrays
new_matrix = new T*[rows]; // rows
for ( size_t i = 0 ; i < rows ; i++ ) {
new_matrix[i] = new T[columns]; // columns
for ( size_t j = 0 ; j < columns ; j++ ) {
new_matrix[i][j] = default_value;
}
}
// copy data from saved pointer to new arrays
size_t minrows = XYZMIN(rows, m_rows);
size_t mincols = XYZMIN(columns, m_columns);
for ( size_t x = 0 ; x < minrows ; x++ ) {
for ( size_t y = 0 ; y < mincols ; y++ ) {
new_matrix[x][y] = m_matrix[x][y];
}
}
// delete old arrays
if ( m_matrix != nullptr ) {
for ( size_t i = 0 ; i < m_rows ; i++ ) {
delete [] m_matrix[i];
}
delete [] m_matrix;
}
m_matrix = new_matrix;
}
m_rows = rows;
m_columns = columns;
}
/*export*/ template <class T>
void
Matrix<T>::clear() {
assert( m_matrix != nullptr );
for ( size_t i = 0 ; i < m_rows ; i++ ) {
for ( size_t j = 0 ; j < m_columns ; j++ ) {
m_matrix[i][j] = 0;
}
}
}
/*export*/ template <class T>
inline T&
Matrix<T>::operator ()(const size_t x, const size_t y) {
assert ( x < m_rows );
assert ( y < m_columns );
assert ( m_matrix != nullptr );
return m_matrix[x][y];
}
/*export*/ template <class T>
inline const T&
Matrix<T>::operator ()(const size_t x, const size_t y) const {
assert ( x < m_rows );
assert ( y < m_columns );
assert ( m_matrix != nullptr );
return m_matrix[x][y];
}
/*export*/ template <class T>
const T
Matrix<T>::mmin() const {
assert( m_matrix != nullptr );
assert ( m_rows > 0 );
assert ( m_columns > 0 );
T min = m_matrix[0][0];
for ( size_t i = 0 ; i < m_rows ; i++ ) {
for ( size_t j = 0 ; j < m_columns ; j++ ) {
min = std::min<T>(min, m_matrix[i][j]);
}
}
return min;
}
/*export*/ template <class T>
const T
Matrix<T>::mmax() const {
assert( m_matrix != nullptr );
assert ( m_rows > 0 );
assert ( m_columns > 0 );
T max = m_matrix[0][0];
for ( size_t i = 0 ; i < m_rows ; i++ ) {
for ( size_t j = 0 ; j < m_columns ; j++ ) {
max = std::max<T>(max, m_matrix[i][j]);
}
}
return max;
}
================================================
FILE: deepsort/munkres/matrix.h
================================================
/*
* Copyright (c) 2007 John Weaver
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _MATRIX_H_
#define _MATRIX_H_
#include <initializer_list>
#include <cstdlib>
#include <ostream>
#define XYZMIN(x, y) (x)<(y)?(x):(y)
#define XYZMAX(x, y) (x)>(y)?(x):(y)
template <class T>
class Matrix {
public:
Matrix();
Matrix(const size_t rows, const size_t columns);
Matrix(const std::initializer_list<std::initializer_list<T>> init);
Matrix(const Matrix<T> &other);
Matrix<T> & operator= (const Matrix<T> &other);
~Matrix();
// all operations modify the matrix in-place.
void resize(const size_t rows, const size_t columns, const T default_value = 0);
void clear();
T& operator () (const size_t x, const size_t y);
const T& operator () (const size_t x, const size_t y) const;
const T mmin() const;
const T mmax() const;
inline size_t minsize() { return ((m_rows < m_columns) ? m_rows : m_columns); }
inline size_t columns() const { return m_columns;}
inline size_t rows() const { return m_rows;}
friend std::ostream& operator<<(std::ostream& os, const Matrix &matrix)
{
os << "Matrix:" << std::endl;
for (size_t row = 0 ; row < matrix.rows() ; row++ )
{
for (size_t col = 0 ; col < matrix.columns() ; col++ )
{
os.width(8);
os << matrix(row, col) << ",";
}
os << std::endl;
}
return os;
}
private:
T **m_matrix;
size_t m_rows;
size_t m_columns;
};
#ifndef USE_EXPORT_KEYWORD
#include "matrix.cpp"
//#define export /*export*/
#endif
#endif /* !defined(_MATRIX_H_) */
================================================
FILE: deepsort/munkres/munkres.cpp
================================================
/*
* Copyright (c) 2007 John Weaver
* Copyright (c) 2015 Miroslav Krajicek
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "munkres.h"
template class Munkres<double>;
template class Munkres<float>;
template class Munkres<int>;
================================================
FILE: deepsort/munkres/munkres.h
================================================
/*
* Copyright (c) 2007 John Weaver
* Copyright (c) 2015 Miroslav Krajicek
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#if !defined(_MUNKRES_H_)
#define _MUNKRES_H_
#include "matrix.h"
#include <list>
#include <utility>
#include <iostream>
#include <cmath>
#include <limits>
template<typename Data> class Munkres
{
static constexpr int NORMAL = 0;
static constexpr int STAR = 1;
static constexpr int PRIME = 2;
public:
/*
*
* Linear assignment problem solution
* [modifies matrix in-place.]
* matrix(row,col): row major format assumed.
*
* Assignments are remaining 0 values
* (extra 0 values are replaced with -1)
*
*/
void solve(Matrix<Data> &m) {
const size_t rows = m.rows(),
columns = m.columns(),
size = XYZMAX(rows, columns);
#ifdef DEBUG
std::cout << "Munkres input: " << m << std::endl;
#endif
// Copy input matrix
this->matrix = m;
if ( rows != columns ) {
// If the input matrix isn't square, make it square
// and fill the empty values with the largest value present
// in the matrix.
matrix.resize(size, size, matrix.mmax());
}
// STAR == 1 == starred, PRIME == 2 == primed
mask_matrix.resize(size, size);
row_mask = new bool[size];
col_mask = new bool[size];
for ( size_t i = 0 ; i < size ; i++ ) {
row_mask[i] = false;
}
for ( size_t i = 0 ; i < size ; i++ ) {
col_mask[i] = false;
}
// Prepare the matrix values...
// If there were any infinities, replace them with a value greater
// than the maximum value in the matrix.
replace_infinites(matrix);
minimize_along_direction(matrix, rows >= columns);
minimize_along_direction(matrix, rows < columns);
// Follow the steps
int step = 1;
while ( step ) {
switch ( step ) {
case 1:
step = step1();
// step is always 2
break;
case 2:
step = step2();
// step is always either 0 or 3
break;
case 3:
step = step3();
// step in [3, 4, 5]
break;
case 4:
step = step4();
// step is always 2
break;
case 5:
step = step5();
// step is always 3
break;
}
}
// Store results
for ( size_t row = 0 ; row < size ; row++ ) {
for ( size_t col = 0 ; col < size ; col++ ) {
if ( mask_matrix(row, col) == STAR ) {
matrix(row, col) = 0;
} else {
matrix(row, col) = -1;
}
}
}
#ifdef DEBUG
std::cout << "Munkres output: " << matrix << std::endl;
#endif
// Remove the excess rows or columns that we added to fit the
// input to a square matrix.
matrix.resize(rows, columns);
m = matrix;
delete [] row_mask;
delete [] col_mask;
}
static void replace_infinites(Matrix<Data> &matrix) {
const size_t rows = matrix.rows(),
columns = matrix.columns();
//assert( rows > 0 && columns > 0 );
double max = matrix(0, 0);
constexpr auto infinity = std::numeric_limits<double>::infinity();
// Find the greatest value in the matrix that isn't infinity.
for ( size_t row = 0 ; row < rows ; row++ ) {
for ( size_t col = 0 ; col < columns ; col++ ) {
if ( matrix(row, col) != infinity ) {
if ( max == infinity ) {
max = matrix(row, col);
} else {
max = XYZMAX(max, matrix(row, col));
}
}
}
}
// a value higher than the maximum value present in the matrix.
if ( max == infinity ) {
// This case only occurs when all values are infinite.
max = 0;
} else {
max++;
}
for ( size_t row = 0 ; row < rows ; row++ ) {
for ( size_t col = 0 ; col < columns ; col++ ) {
if ( matrix(row, col) == infinity ) {
matrix(row, col) = max;
}
}
}
}
static void minimize_along_direction(Matrix<Data> &matrix, const bool over_columns) {
const size_t outer_size = over_columns ? matrix.columns() : matrix.rows(),
inner_size = over_columns ? matrix.rows() : matrix.columns();
// Look for a minimum value to subtract from all values along
// the "outer" direction.
for ( size_t i = 0 ; i < outer_size ; i++ ) {
double min = over_columns ? matrix(0, i) : matrix(i, 0);
// As long as the current minimum is greater than zero,
// keep looking for the minimum.
// Start at one because we already have the 0th value in min.
for ( size_t j = 1 ; j < inner_size && min > 0 ; j++ ) {
min = XYZMIN(
min,
over_columns ? matrix(j, i) : matrix(i, j));
}
if ( min > 0 ) {
for ( size_t j = 0 ; j < inner_size ; j++ ) {
if ( over_columns ) {
matrix(j, i) -= min;
} else {
matrix(i, j) -= min;
}
}
}
}
}
private:
inline bool find_uncovered_in_matrix(const double item, size_t &row, size_t &col) const {
const size_t rows = matrix.rows(),
columns = matrix.columns();
for ( row = 0 ; row < rows ; row++ ) {
if ( !row_mask[row] ) {
for ( col = 0 ; col < columns ; col++ ) {
if ( !col_mask[col] ) {
if ( matrix(row,col) == item ) {
return true;
}
}
}
}
}
return false;
}
bool pair_in_list(const std::pair<size_t,size_t> &needle, const std::list<std::pair<size_t,size_t> > &haystack) {
for ( std::list<std::pair<size_t,size_t> >::const_iterator i = haystack.begin() ; i != haystack.end() ; i++ ) {
if ( needle == *i ) {
return true;
}
}
return false;
}
int step1() {
const size_t rows = matrix.rows(),
columns = matrix.columns();
for ( size_t row = 0 ; row < rows ; row++ ) {
for ( size_t col = 0 ; col < columns ; col++ ) {
if ( 0 == matrix(row, col) ) {
for ( size_t nrow = 0 ; nrow < row ; nrow++ )
if ( STAR == mask_matrix(nrow,col) )
goto next_column;
mask_matrix(row,col) = STAR;
goto next_row;
}
next_column:;
}
next_row:;
}
return 2;
}
int step2() {
const size_t rows = matrix.rows(),
columns = matrix.columns();
size_t covercount = 0;
for ( size_t row = 0 ; row < rows ; row++ )
for ( size_t col = 0 ; col < columns ; col++ )
if ( STAR == mask_matrix(row, col) ) {
col_mask[col] = true;
covercount++;
}
if ( covercount >= matrix.minsize() ) {
#ifdef DEBUG
std::cout << "Final cover count: " << covercount << std::endl;
#endif
return 0;
}
#ifdef DEBUG
std::cout << "Munkres matrix has " << covercount << " of " << matrix.minsize() << " Columns covered:" << std::endl;
std::cout << matrix << std::endl;
#endif
return 3;
}
int step3() {
/*
Main Zero Search
1. Find an uncovered Z in the distance matrix and prime it. If no such zero exists, go to Step 5
2. If No Z* exists in the row of the Z', go to Step 4.
3. If a Z* exists, cover this row and uncover the column of the Z*. Return to Step 3.1 to find a new Z
*/
if ( find_uncovered_in_matrix(0, saverow, savecol) ) {
mask_matrix(saverow,savecol) = PRIME; // prime it.
} else {
return 5;
}
for ( size_t ncol = 0 ; ncol < matrix.columns() ; ncol++ ) {
if ( mask_matrix(saverow,ncol) == STAR ) {
row_mask[saverow] = true; //cover this row and
col_mask[ncol] = false; // uncover the column containing the starred zero
return 3; // repeat
}
}
return 4; // no starred zero in the row containing this primed zero
}
int step4() {
const size_t rows = matrix.rows(),
columns = matrix.columns();
// seq contains pairs of row/column values where we have found
// either a star or a prime that is part of the ``alternating sequence``.
std::list<std::pair<size_t,size_t> > seq;
// use saverow, savecol from step 3.
std::pair<size_t,size_t> z0(saverow, savecol);
seq.insert(seq.end(), z0);
// We have to find these two pairs:
std::pair<size_t,size_t> z1(-1, -1);
std::pair<size_t,size_t> z2n(-1, -1);
size_t row, col = savecol;
/*
Increment Set of Starred Zeros
1. Construct the ``alternating sequence'' of primed and starred zeros:
Z0 : Unpaired Z' from Step 4.2
Z1 : The Z* in the column of Z0
Z[2N] : The Z' in the row of Z[2N-1], if such a zero exists
Z[2N+1] : The Z* in the column of Z[2N]
The sequence eventually terminates with an unpaired Z' = Z[2N] for some N.
*/
bool madepair;
do {
madepair = false;
for ( row = 0 ; row < rows ; row++ ) {
if ( mask_matrix(row,col) == STAR ) {
z1.first = row;
z1.second = col;
if ( pair_in_list(z1, seq) ) {
continue;
}
madepair = true;
seq.insert(seq.end(), z1);
break;
}
}
if ( !madepair )
break;
madepair = false;
for ( col = 0 ; col < columns ; col++ ) {
if ( mask_matrix(row, col) == PRIME ) {
z2n.first = row;
z2n.second = col;
if ( pair_in_list(z2n, seq) ) {
continue;
}
madepair = true;
seq.insert(seq.end(), z2n);
break;
}
}
} while ( madepair );
for ( std::list<std::pair<size_t,size_t> >::iterator i = seq.begin() ;
i != seq.end() ;
i++ ) {
// 2. Unstar each starred zero of the sequence.
if ( mask_matrix(i->first,i->second) == STAR )
mask_matrix(i->first,i->second) = NORMAL;
// 3. Star each primed zero of the sequence,
// thus increasing the number of starred zeros by one.
if ( mask_matrix(i->first,i->second) == PRIME )
mask_matrix(i->first,i->second) = STAR;
}
// 4. Erase all primes, uncover all columns and rows,
for ( size_t row = 0 ; row < mask_matrix.rows() ; row++ ) {
for ( size_t col = 0 ; col < mask_matrix.columns() ; col++ ) {
if ( mask_matrix(row,col) == PRIME ) {
mask_matrix(row,col) = NORMAL;
}
}
}
for ( size_t i = 0 ; i < rows ; i++ ) {
row_mask[i] = false;
}
for ( size_t i = 0 ; i < columns ; i++ ) {
col_mask[i] = false;
}
// and return to Step 2.
return 2;
}
int step5() {
const size_t rows = matrix.rows(),
columns = matrix.columns();
/*
New Zero Manufactures
1. Let h be the smallest uncovered entry in the (modified) distance matrix.
2. Add h to all covered rows.
3. Subtract h from all uncovered columns
4. Return to Step 3, without altering stars, primes, or covers.
*/
double h = 100000;//xyzoylz std::numeric_limits<double>::max();
for ( size_t row = 0 ; row < rows ; row++ ) {
if ( !row_mask[row] ) {
for ( size_t col = 0 ; col < columns ; col++ ) {
if ( !col_mask[col] ) {
if ( h > matrix(row, col) && matrix(row, col) != 0 ) {
h = matrix(row, col);
}
}
}
}
}
for ( size_t row = 0 ; row < rows ; row++ ) {
if ( row_mask[row] ) {
for ( size_t col = 0 ; col < columns ; col++ ) {
matrix(row, col) += h;
}
}
}
for ( size_t col = 0 ; col < columns ; col++ ) {
if ( !col_mask[col] ) {
for ( size_t row = 0 ; row < rows ; row++ ) {
matrix(row, col) -= h;
}
}
}
return 3;
}
Matrix<int> mask_matrix;
Matrix<Data> matrix;
bool *row_mask;
bool *col_mask;
size_t saverow = 0, savecol = 0;
};
#endif /* !defined(_MUNKRES_H_) */
================================================
FILE: deepsort/nn_matching.h
================================================
#ifndef _NNMATCHINGH_
#define _NNMATCHINGH_
#include <vector>
#include "Detection.h"
#include <Eigen>
#include <map>
#include <sys/time.h>
#ifdef USETBB
#include <tbb.h>
#endif
#include <map>
#include <boost/shared_ptr.hpp>
#include <boost/thread/mutex.hpp>
static int64_t nn_gtm() {
struct timeval tm;
gettimeofday(&tm, 0);
int64_t re = ((int64_t)tm.tv_sec) * 1000 * 1000 + tm.tv_usec;
return re;
}
Eigen::VectorXf _nn_cosine_distance(const FEATURESS &x,
const FEATURESS &y){
int64_t nntm1 = nn_gtm();
FEATURESS a = x;
FEATURESS b = y;
//std::cout << "a---b\n" << a << "\na----e\n" << std::endl;
//std::cout << "b---b\n" << b << "\nb----e\n" << std::endl;
for (int row = 0; row < a.rows(); row++) {
auto t = a.row(row);
t = t / t.norm();
a.row(row) = t;
}
for (int row = 0; row < b.rows(); row++) {
auto t = b.row(row);
t = t / t.norm();
b.row(row) = t;
}
//std::cout << "a---b\n" << a << "\na----e\n" << std::endl;
//std::cout << "b---b\n" << b << "\nb----e\n" << std::endl;
auto tmp = a*b.transpose();
auto tmp1 = tmp.array();
auto tmp2 = -(tmp1 - 1);
DYNAMICM distances = tmp2.matrix();
Eigen::VectorXf re(distances.cols());
#ifdef WIN32
auto rea = re.array();
for (int col = 0; col < distances.cols(); col++) {
auto cc = distances.col(col);
float min = cc.minCoeff();
rea.row(col) = min;
}
re = rea.matrix();
#else
for (int col = 0; col < distances.cols(); col++) {
auto cc = distances.col(col);
float min = cc.minCoeff();
re(col) = min;
}
#endif
int64_t nntm2 = nn_gtm();
std::cout << "_nn_cosine_distance(" << x.rows() << "," << y.rows() << ")----nntm2-nntm1:" << (nntm2-nntm1) << "\n";
//std::cout << "re---b\n" << re << "\nre----e\n" << std::endl;
return re;
}
class NearestNeighborDistanceMetric{
private:
static boost::shared_ptr<NearestNeighborDistanceMetric> self_;
float matching_threshold_ = 0;
int budget_ = 0;
std::map<int, std::vector<FEATURE> > samples_;
public:
float matching_threshold() {
return matching_threshold_;
}
static boost::shared_ptr<NearestNeighborDistanceMetric> Instance(){
if(self_.get() == NULL){
self_.reset(new NearestNeighborDistanceMetric());
}
return self_;
}
void Init(float matching_threshold, int budget){
matching_threshold_ = matching_threshold;
budget_ = budget;
}
void partial_fit(const FEATURESS &features,
const IDS &ids,
const IDS &active_ids){
//samples_.clear();
for(int i = 0; i < features.rows(); i++){
FEATURE feature = features.row(i);
int iid = ids[i];
//
{
bool isIn = false;
for(int k = 0; k < active_ids.size(); k++){
if(iid == active_ids[k]){
isIn = true;
break;
}
}
if(!isIn){
continue;
}
}
//
std::map<int, std::vector<FEATURE>>::iterator it = samples_.find(iid);
if(it == samples_.end()){
std::vector<FEATURE> tmps;
samples_.insert(std::make_pair(iid, tmps));
it = samples_.find(iid);
}
it->second.push_back(feature);
#if 1
std::vector<FEATURE>::iterator ii = it->second.begin();
if(it->second.size() > budget_){
it->second.erase(ii);
}
#else
/*if(samples_.size() > budget_){
samples_.erase(samples_.begin());
}*/
#endif
}
}
struct DDS{
public:
void Push(int pos, const Eigen::VectorXf &dd){
boost::mutex::scoped_lock lock(mutex_);
dds_.push_back(
std::make_pair(pos, dd)
);
}
void Get(std::vector<std::pair<int, Eigen::VectorXf> > &dds){
dds = dds_;
}
private:
std::vector<std::pair<int, Eigen::VectorXf> > dds_;
boost::mutex mutex_;
};
DYNAMICM distance(const FEATURESS &features, const IDS &ids){
#ifdef USETBB
static DYNAMICM cost_matrix;
cost_matrix = DYNAMICM(ids.size(), features.rows());
int64_t dtm0 = nn_gtm();
using namespace tbb;
parallel_for( blocked_range<size_t>(0,ids.size()),
[=](const blocked_range<size_t> &r){
for(int i = r.begin(); i != r.end(); ++i){
int iid = ids[i];
std::vector<FEATURE> &ftsvec = samples_[iid];
FEATURESS fts(ftsvec.size(), 128);
for (int k = 0; k < ftsvec.size(); k++) {
fts.row(k) = ftsvec[k];
}
int64_t dtm1 = nn_gtm();
cost_matrix.row(i) = _nn_cosine_distance(fts, features);
int64_t dtm2 = nn_gtm();
std::cout << "distance(" << iid<< ")----dtm2-dtm1:" << (dtm2-dtm1) << "\n";
}
}
);
#else
static DYNAMICM cost_matrix;
cost_matrix = DYNAMICM(ids.size(), features.rows());
int64_t dtm0 = nn_gtm();
DDS dds;
#pragma omp parallel for
for(int i = 0; i < ids.size(); i++){
int iid = ids[i];
std::vector<FEATURE> &ftsvec = samples_[iid];
FEATURESS fts(ftsvec.size(), 128);
for (int k = 0; k < ftsvec.size(); k++) {
fts.row(k) = ftsvec[k];
}
int64_t dtm1 = nn_gtm();
//cost_matrix.row(i) = _nn_cosine_distance(fts, features);
Eigen::VectorXf dd = _nn_cosine_distance(fts, features);
dds.Push(i, dd);
int64_t dtm2 = nn_gtm();
std::cout << "distance(" << iid<< ")----dtm2-dtm1:" << (dtm2-dtm1) << "\n";
}
std::vector<std::pair<int, Eigen::VectorXf>> vec;
dds.Get(vec);
for(int i = 0; i < vec.size(); i++){
std::pair<int, Eigen::VectorXf> pa = vec[i];
cost_matrix.row(pa.first) = pa.second;
}
#endif
int64_t dtm4 = nn_gtm();
std::cout << "distance----dtm4-dtm0:" << (dtm4-dtm0) << "\n";
//std::cout << "\nb-haha\n" << cost_matrix << "\ne-haha\n";
return cost_matrix;
}
};
#endif
================================================
FILE: deepsort/tracker.h
================================================
#ifndef _TTH_
#define _TTH_
#include "nn_matching.h"
#include "linear_assignment.h"
#include <algorithm>
#include <vector>
#include <iterator>
#include "iou_matching.h"
#include "FeatureGetter/FeatureGetter.h"
#include "../NTN.h"
DYNAMICM getCostMatrixByNND(const std::vector<KalmanTracker> &kalmanTrackers,
const std::vector<Detection> &dets,
IDS *track_indices,
IDS *detection_indices);
class TTracker *p;
class TTracker{
public:
std::vector<KalmanTracker> kalmanTrackers_;
private:
float max_iou_distance_ = 0;
int max_age_ = 0;
int n_init_ = 0;
int _next_id_ = 0;
public:
TTracker(float max_iou_distance=0.7, int max_age=30, int n_init=3){
max_iou_distance_ = max_iou_distance;
max_age_ = max_age;
n_init_ = n_init;
_next_id_ = 1;
p = this;
}
NewAndDelete update(const std::vector<Detection> &detections){
NewAndDelete re;
int64_t uptm1 = line_gtm();
for(KalmanTracker kalmanTrack : kalmanTrackers_){
kalmanTrack->predict(*KF::Instance());
}
int64_t uptm2 = line_gtm();
//# Run matching cascade.
RR rr = this->_match(detections);
int64_t uptm3 = line_gtm();
//# Update track set.
//# -matches
for(int i = 0; i < rr.matches.size(); i++){
std::pair<int, int> pa = rr.matches[i];
int track_idx = pa.first;
int detection_idx = pa.second;
kalmanTrackers_[track_idx]->update(*KF::Instance(),
detections[detection_idx]);
}
//# -unmatches(track)
for(int i = 0; i < rr.unmatched_tracks.size(); i++){
int track_idx = rr.unmatched_tracks[i];
kalmanTrackers_[track_idx]->mark_missed();
}
//# -unmatches(detect)
for(int i = 0; i < rr.unmatched_detections.size(); i++){
int detection_idx = rr.unmatched_detections[i];
int id = this->_NewTrack(detections[detection_idx]);
re.news_.insert(std::make_pair(id, detections[detection_idx].oriPos_));
}
int64_t uptm4 = line_gtm();
std::vector<KalmanTracker>::iterator it;
while (1) {
bool cn = false;
for (it = kalmanTrackers_.begin(); it != kalmanTrackers_.end(); ++it) {
KalmanTracker p = *it;
if (p->is_deleted()) {
re.deletes_.push_back(p->track_id);
kalmanTrackers_.erase(it);
//delete p;
cn = true;
break;
}
}
if (cn) {
continue;
}
break;
}
//# Update distance nearestNeighborDistanceMetric.
IDS active_ids;
for(KalmanTracker t : kalmanTrackers_){
if(t->is_confirmed()){
active_ids.push_back(t->track_id);
}
}
int64_t uptm5 = line_gtm();
int featureCount = 0;
IDS ids;
for(KalmanTracker t : kalmanTrackers_){
if(!t->is_confirmed()){
continue;
}
std::vector<FEATURE> &fts = t->features_;
featureCount += fts.size();
//ids += [kalmanTrack.track_id_ for _ in kalmanTrack.features_]
// ˼
for (int kk = 0; kk < fts.size(); kk++) {
ids.push_back(t->track_id);
}
}
FEATURESS features(featureCount, 128);
int pos = 0;
for (KalmanTracker t : kalmanTrackers_) {
if (!t->is_confirmed()) {
continue;
}
std::vector<FEATURE> &fts = t->features_;
for (int i = 0; i < fts.size(); i++) {
FEATURE tt = fts.at(i);
features.row(pos++) = tt;
}
t->features_.clear();
}
int64_t uptm6 = line_gtm();
NearestNeighborDistanceMetric::Instance()->partial_fit(
features, ids, active_ids);
int64_t uptm7 = line_gtm();
std::cout << "up----uptm2-uptm1:" << (uptm2-uptm1) <<
", uptm3-uptm1:" << uptm3-uptm1 <<
", uptm4-uptm1:" << (uptm4-uptm1) <<
", uptm5-uptm1:" << (uptm5-uptm1) <<
", uptm6-uptm1:" << (uptm6-uptm1) << "\n";
return re;
}
private:
RR _match(const std::vector<Detection> &detections){
int64_t mtm1 = line_gtm();
//Split track set into confirmed and unconfirmed kalmanTrackers.
IDS confirmed_trackIds;
IDS unconfirmed_trackIds;
for(int i = 0; i < kalmanTrackers_.size(); i++){
KalmanTracker t = kalmanTrackers_[i];
if(t->is_confirmed()){
confirmed_trackIds.push_back(i);
}
else{
unconfirmed_trackIds.push_back(i);
}
}
//# Associate confirmed kalmanTrackers using appearance features.
RR rr = linear_assignment::matching_cascade(
getCostMatrixByNND,
NearestNeighborDistanceMetric::Instance()->matching_threshold(),
max_age_,
kalmanTrackers_,
detections,
&confirmed_trackIds);
std::vector<std::pair<int, int> > matches_a = rr.matches;
IDS unmatched_tracks_a = rr.unmatched_tracks;
IDS unmatched_detections = rr.unmatched_detections;
int64_t mtm2 = line_gtm();
//# Associate remaining kalmanTrackers together with unconfirmed kalmanTrackers using IOU.
IDS iou_track_candidateIds, tmp;
std::copy(unconfirmed_trackIds.begin(),
unconfirmed_trackIds.end(),
std::back_inserter(iou_track_candidateIds));
for(int k = 0; k < unmatched_tracks_a.size(); k++){
int id = unmatched_tracks_a[k];
if(kalmanTrackers_[id]->time_since_update_ == 1){
iou_track_candidateIds.push_back(id);
}
else{
tmp.push_back(id);
}
}
unmatched_tracks_a.clear();
unmatched_tracks_a = tmp;
int64_t mtm3 = line_gtm();
//
RR rr1 = linear_assignment::min_cost_matching(
iou_matching::getCostMatrixByIOU,
max_iou_distance_,
kalmanTrackers_,
detections,
&iou_track_candidateIds,
&unmatched_detections);
std::vector<std::pair<int, int> > matches_b = rr1.matches;
IDS unmatched_tracks_b = rr1.unmatched_tracks;
unmatched_detections = rr1.unmatched_detections;
int64_t mtm4 = line_gtm();
// all
RR re;
re.matches = matches_a;
std::copy(matches_b.begin(), matches_b.end(),
std::back_inserter(re.matches));
re.unmatched_detections = unmatched_detections;
re.unmatched_tracks = unmatched_tracks_a;
std::copy(unmatched_tracks_b.begin(),
unmatched_tracks_b.end(),
std::back_inserter(re.unmatched_tracks));
int64_t mtm5 = line_gtm();
std::cout << "match----mtm2-mtm1:" << (mtm2-mtm1) <<
", mtm3-mtm1:" << (mtm3-mtm1) <<
", mtm4-mtm1:" << (mtm4-mtm1) <<
", mtm5-mtm1:" << (mtm5-mtm1) << "\n";
return re;
}
int _NewTrack(const Detection &detection){
int id = _next_id_;
std::pair<MEAN, VAR> pa =
KF::Instance()->initiate(detection.to_xyah());
KalmanTracker newt(new KalmanTrackerN(
pa.first, pa.second, _next_id_, n_init_, max_age_,
detection.feature_, true, detection.oriPos_));
kalmanTrackers_.push_back(newt);/*new KalmanTracker(
pa.first, pa.second, _next_id_, n_init_, max_age_,
detection.feature_, true, detection.oriPos_));*/
_next_id_ += 1;
return id;
}
};
DYNAMICM getCostMatrixByNND(const std::vector<KalmanTracker> &kalmanTrackers,
const std::vector<Detection> &dets,
IDS *track_indicesi,
IDS *detection_indicesi) {
int64_t gtm1 = line_gtm();
IDS track_indices = *track_indicesi;
IDS detection_indices = *detection_indicesi;
FEATURESS features(detection_indices.size(), 128);
for (int i = 0; i < detection_indices.size(); i++) {
int pos = detection_indices[i];
features.row(i) = dets[pos].feature_;
}
IDS ids;
for (int i = 0; i < track_indices.size(); i++) {
int pos = track_indices[i];
ids.push_back(p->kalmanTrackers_[pos]->track_id);
}
DYNAMICM cost_matrix =
NearestNeighborDistanceMetric::Instance()->distance(features, ids);
int64_t gtm2 = line_gtm();
cost_matrix = linear_assignment::gate_cost_matrix(
*KF::Instance(), cost_matrix, kalmanTrackers, dets, track_indices,
detection_indices);
int64_t gtm3 = line_gtm();
std::cout << "getCostMatrixByNND----gtm2-gtm1:" << (gtm2-gtm1) <<
", gtm3-gtm1:" << (gtm3-gtm1) << "\n";
return cost_matrix;
}
#endif
================================================
FILE: fdsst/SSE2NEON.h
================================================
#ifndef SSE2NEON_H
#define SSE2NEON_H
// This header file provides a simple API translation layer
// between SSE intrinsics to their corresponding ARM NEON versions
//
// This header file does not (yet) translate *all* of the SSE intrinsics.
// Since this is in support of a specific porting effort, I have only
// included the intrinsics I needed to get my port to work.
//
// Questions/Comments/Feedback send to: jratcliffscarab@gmail.com
//
// If you want to improve or add to this project, send me an
// email and I will probably approve your access to the depot.
//
// Project is located here:
//
// https://github.com/jratcliff63367/sse2neon
//
// TipJar: 1PzgWDSyq4pmdAXRH8SPUtta4SWGrt4B1p : https://blockchain.info/address/1PzgWDSyq4pmdAXRH8SPUtta4SWGrt4B1p
//
//
// Contributors to this project are:
//
// John W. Ratcliff : jratcliffscarab@gmail.com
// Brandon Rowlett : browlett@nvidia.com
// Ken Fast : kfast@gdeb.com
#define GCC 1
#define ENABLE_CPP_VERSION 0
#if GCC
#define FORCE_INLINE inline __attribute__((always_inline))
#else
#define FORCE_INLINE inline
#endif
#include "arm_neon.h"
/*******************************************************/
/* MACRO for shuffle parameter for _mm_shuffle_ps(). */
/* Argument fp3 is a digit[0123] that represents the fp*/
/* from argument "b" of mm_shuffle_ps that will be */
/* placed in fp3 of result. fp2 is the same for fp2 in */
/* result. fp1 is a digit[0123] that represents the fp */
/* from argument "a" of mm_shuffle_ps that will be */
/* places in fp1 of result. fp0 is the same for fp0 of */
/* result */
/*******************************************************/
#define _MM_SHUFFLE(fp3,fp2,fp1,fp0) (((fp3) << 6) | ((fp2) << 4) | \
((fp1) << 2) | ((fp0)))
typedef float32x4_t __m128;
typedef int32x4_t __m128i;
// ******************************************
// Set/get methods
// ******************************************
// Sets the 128-bit value to zero https://msdn.microsoft.com/en-us/library/vstudio/ys7dw0kh(v=vs.100).aspx
FORCE_INLINE __m128i _mm_setzero_si128()
{
return vdupq_n_s32(0);
}
// Clears the four single-precision, floating-point values. https://msdn.microsoft.com/en-us/library/vstudio/tk1t2tbz(v=vs.100).aspx
FORCE_INLINE __m128 _mm_setzero_ps(void)
{
return vdupq_n_f32(0);
}
// Sets the four single-precision, floating-point values to w. https://msdn.microsoft.com/en-us/library/vstudio/2x1se8ha(v=vs.100).aspx
FORCE_INLINE __m128 _mm_set1_ps(float _w)
{
return vdupq_n_f32(_w);
}
// Sets the four single-precision, floating-point values to w. https://msdn.microsoft.com/en-us/library/vstudio/2x1se8ha(v=vs.100).aspx
FORCE_INLINE __m128 _mm_set_ps1(float _w)
{
return vdupq_n_f32(_w);
}
// Sets the four single-precision, floating-point values to the four inputs. https://msdn.microsoft.com/en-us/library/vstudio/afh0zf75(v=vs.100).aspx
FORCE_INLINE __m128 _mm_set_ps(float w, float z, float y, float x)
{
float __attribute__((aligned(16))) data[4] = { x, y, z, w };
return vld1q_f32(data);
}
// Sets the four single-precision, floating-point values to the four inputs in reverse order. https://msdn.microsoft.com/en-us/library/vstudio/d2172ct3(v=vs.100).aspx
FORCE_INLINE __m128 _mm_setr_ps(float w, float z , float y , float x )
{
float __attribute__ ((aligned (16))) data[4] = { w, z, y, x };
return vld1q_f32(data);
}
// Sets the 4 signed 32-bit integer values to i. https://msdn.microsoft.com/en-us/library/vstudio/h4xscxat(v=vs.100).aspx
FORCE_INLINE __m128i _mm_set1_epi32(int _i)
{
return vdupq_n_s32(_i);
}
// Sets the 4 signed 32-bit integer values. https://msdn.microsoft.com/en-us/library/vstudio/019beekt(v=vs.100).aspx
FORCE_INLINE __m128i _mm_set_epi32(int i3, int i2, int i1, int i0)
{
int32_t __attribute__((aligned(16))) data[4] = { i0, i1, i2, i3 };
return vld1q_s32(data);
}
// Stores four single-precision, floating-point values. https://msdn.microsoft.com/en-us/library/vstudio/s3h4ay6y(v=vs.100).aspx
FORCE_INLINE void _mm_store_ps(float *p, __m128 a)
{
vst1q_f32(p, a);
}
// Stores four single-precision, floating-point values. https://msdn.microsoft.com/en-us/library/44e30x22(v=vs.100).aspx
FORCE_INLINE void _mm_storeu_ps(float *p, __m128 a)
{
vst1q_f32(p, a);
}
// Stores four 32-bit integer values as (as a __m128i value) at the address p. https://msdn.microsoft.com/en-us/library/vstudio/edk11s13(v=vs.100).aspx
FORCE_INLINE void _mm_store_si128(__m128i *p, __m128i a )
{
vst1q_s32((int32_t*) p,a);
}
// Stores the lower single - precision, floating - point value. https://msdn.microsoft.com/en-us/library/tzz10fbx(v=vs.100).aspx
FORCE_INLINE void _mm_store_ss(float *p, __m128 a)
{
vst1q_lane_f32(p, a, 0);
}
// Reads the lower 64 bits of b and stores them into the lower 64 bits of a. https://msdn.microsoft.com/en-us/library/hhwf428f%28v=vs.90%29.aspx
FORCE_INLINE void _mm_storel_epi64(__m128i* a, __m128i b)
{
*a = (__m128i)vsetq_lane_s64((int64_t)vget_low_s32(b), *(int64x2_t*)a, 0);
}
// Loads a single single-precision, floating-point value, copying it into all four words https://msdn.microsoft.com/en-us/library/vstudio/5cdkf716(v=vs.100).aspx
FORCE_INLINE __m128 _mm_load1_ps(const float * p)
{
return vld1q_dup_f32(p);
}
// Loads four single-precision, floating-point values. https://msdn.microsoft.com/en-us/library/vstudio/zzd50xxt(v=vs.100).aspx
FORCE_INLINE __m128 _mm_load_ps(const float * p)
{
return vld1q_f32(p);
}
// Loads four single-precision, floating-point values. https://msdn.microsoft.com/en-us/library/x1b16s7z%28v=vs.90%29.aspx
FORCE_INLINE __m128 _mm_loadu_ps(const float * p)
{
// for neon, alignment doesn't matter, so _mm_load_ps and _mm_loadu_ps are equivalent for neon
return vld1q_f32(p);
}
// Loads an single - precision, floating - point value into the low word and clears the upper three words. https://msdn.microsoft.com/en-us/library/548bb9h4%28v=vs.90%29.aspx
FORCE_INLINE __m128 _mm_load_ss(const float * p)
{
__m128 result = vdupq_n_f32(0);
return vsetq_lane_f32(*p, result, 0);
}
// ******************************************
// Logic/Binary operations
// ******************************************
// Compares for inequality. https://msdn.microsoft.com/en-us/library/sf44thbx(v=vs.100).aspx
FORCE_INLINE __m128 _mm_cmpneq_ps(__m128 a, __m128 b)
{
return (__m128)vmvnq_s32((__m128i)vceqq_f32(a, b));
}
// Computes the bitwise AND-NOT of the four single-precision, floating-point values of a and b. https://msdn.microsoft.com/en-us/library/vstudio/68h7wd02(v=vs.100).aspx
FORCE_INLINE __m128 _mm_andnot_ps(__m128 a, __m128 b)
{
return (__m128)vbicq_s32((__m128i)b, (__m128i)a); // *NOTE* argument swap
}
// Computes the bitwise AND of the 128-bit value in b and the bitwise NOT of the 128-bit value in a. https://msdn.microsoft.com/en-us/library/vstudio/1beaceh8(v=vs.100).aspx
FORCE_INLINE __m128i _mm_andnot_si128(__m128i a, __m128i b)
{
return (__m128i)vbicq_s32(b, a); // *NOTE* argument swap
}
// Computes the bitwise AND of the 128-bit value in a and the 128-bit value in b. https://msdn.microsoft.com/en-us/library/vstudio/6d1txsa8(v=vs.100).aspx
FORCE_INLINE __m128i _mm_and_si128(__m128i a, __m128i b)
{
return (__m128i)vandq_s32(a, b);
}
// Computes the bitwise AND of the four single-precision, floating-point values of a and b. https://msdn.microsoft.com/en-us/library/vstudio/73ck1xc5(v=vs.100).aspx
FORCE_INLINE __m128 _mm_and_ps(__m128 a, __m128 b)
{
return (__m128)vandq_s32((__m128i)a, (__m128i)b);
}
// Computes the bitwise OR of the four single-precision, floating-point values of a and b. https://msdn.microsoft.com/en-us/library/vstudio/7ctdsyy0(v=vs.100).aspx
FORCE_INLINE __m128 _mm_or_ps(__m128 a, __m128 b)
{
return (__m128)vorrq_s32((__m128i)a, (__m128i)b);
}
// Computes bitwise EXOR (exclusive-or) of the four single-precision, floating-point values of a and b. https://msdn.microsoft.com/en-us/library/ss6k3wk8(v=vs.100).aspx
FORCE_INLINE __m128 _mm_xor_ps(__m128 a, __m128 b)
{
return (__m128)veorq_s32((__m128i)a, (__m128i)b);
}
// Computes the bitwise OR of the 128-bit value in a and the 128-bit value in b. https://msdn.microsoft.com/en-us/library/vstudio/ew8ty0db(v=vs.100).aspx
FORCE_INLINE __m128i _mm_or_si128(__m128i a, __m128i b)
{
return (__m128i)vorrq_s32(a, b);
}
// Computes the bitwise XOR of the 128-bit value in a and the 128-bit value in b. https://msdn.microsoft.com/en-us/library/fzt08www(v=vs.100).aspx
FORCE_INLINE __m128i _mm_xor_si128(__m128i a, __m128i b)
{
return veorq_s32(a, b);
}
// NEON does not provide this method
// Creates a 4-bit mask from the most significant bits of the four single-precision, floating-point values. https://msdn.microsoft.com/en-us/library/vstudio/4490ys29(v=vs.100).aspx
FORCE_INLINE int _mm_movemask_ps(__m128 a)
{
#if ENABLE_CPP_VERSION // I am not yet convinced that the NEON version is faster than the C version of this
uint32x4_t &ia = *(uint32x4_t *)&a;
return (ia[0] >> 31) | ((ia[1] >> 30) & 2) | ((ia[2] >> 29) & 4) | ((ia[3] >> 28) & 8);
#else
static const uint32x4_t movemask = { 1, 2, 4, 8 };
static const uint32x4_t highbit = { 0x80000000, 0x80000000, 0x80000000, 0x80000000 };
uint32x4_t t0 = vreinterpretq_u32_f32(a);
uint32x4_t t1 = vtstq_u32(t0, highbit);
uint32x4_t t2 = vandq_u32(t1, movemask);
uint32x2_t t3 = vorr_u32(vget_low_u32(t2), vget_high_u32(t2));
return vget_lane_u32(t3, 0) | vget_lane_u32(t3, 1);
#endif
}
// Takes the upper 64 bits of a and places it in the low end of the result
// Takes the lower 64 bits of b and places it into the high end of the result.
FORCE_INLINE __m128 _mm_shuffle_ps_1032(__m128 a, __m128 b)
{
return vcombine_f32(vget_high_f32(a), vget_low_f32(b));
}
// takes the lower two 32-bit values from a and swaps them and places in high end of result
// takes the higher two 32 bit values from b and swaps them and places in low end of result.
FORCE_INLINE __m128 _mm_shuffle_ps_2301(__m128 a, __m128 b)
{
return vcombine_f32(vrev64_f32(vget_low_f32(a)), vrev64_f32(vget_high_f32(b)));
}
// keeps the low 64 bits of b in the low and puts the high 64 bits of a in the high
FORCE_INLINE __m128 _mm_shuffle_ps_3210(__m128 a, __m128 b)
{
return vcombine_f32(vget_low_f32(a), vget_high_f32(b));
}
FORCE_INLINE __m128 _mm_shuffle_ps_0011(__m128 a, __m128 b)
{
return vcombine_f32(vdup_n_f32(vgetq_lane_f32(a, 1)), vdup_n_f32(vgetq_lane_f32(b, 0)));
}
FORCE_INLINE __m128 _mm_shuffle_ps_0022(__m128 a, __m128 b)
{
return vcombine_f32(vdup_n_f32(vgetq_lane_f32(a, 2)), vdup_n_f32(vgetq_lane_f32(b, 0)));
}
FORCE_INLINE __m128 _mm_shuffle_ps_2200(__m128 a, __m128 b)
{
return vcombine_f32(vdup_n_f32(vgetq_lane_f32(a, 0)), vdup_n_f32(vgetq_lane_f32(b, 2)));
}
FORCE_INLINE __m128 _mm_shuffle_ps_3202(__m128 a, __m128 b)
{
float32_t a0 = vgetq_lane_f32(a, 0);
float32_t a2 = vgetq_lane_f32(a, 2);
float32x2_t aVal = vdup_n_f32(a2);
aVal = vset_lane_f32(a0, aVal, 1);
return vcombine_f32(aVal, vget_high_f32(b));
}
FORCE_INLINE __m128 _mm_shuffle_ps_1133(__m128 a, __m128 b)
{
return vcombine_f32(vdup_n_f32(vgetq_lane_f32(a, 3)), vdup_n_f32(vgetq_lane_f32(b, 1)));
}
FORCE_INLINE __m128 _mm_shuffle_ps_2010(__m128 a, __m128 b)
{
float32_t b0 = vgetq_lane_f32(b, 0);
float32_t b2 = vgetq_lane_f32(b, 2);
float32x2_t bVal = vdup_n_f32(b0);
bVal = vset_lane_f32(b2, bVal, 1);
return vcombine_f32(vget_low_f32(a), bVal);
}
FORCE_INLINE __m128 _mm_shuffle_ps_2001(__m128 a, __m128 b)
{
float32_t b0 = vgetq_lane_f32(b, 0);
float32_t b2 = vgetq_lane_f32(b, 2);
float32x2_t bVal = vdup_n_f32(b0);
bVal = vset_lane_f32(b2, bVal, 1);
return vcombine_f32(vrev64_f32(vget_low_f32(a)), bVal);
}
FORCE_INLINE __m128 _mm_shuffle_ps_2032(__m128 a, __m128 b)
{
float32_t b0 = vgetq_lane_f32(b, 0);
float32_t b2 = vgetq_lane_f32(b, 2);
float32x2_t bVal = vdup_n_f32(b0);
bVal = vset_lane_f32(b2, bVal, 1);
return vcombine_f32(vget_high_f32(a), bVal);
}
// NEON does not support a general purpose permute intrinsic
// Currently I am not sure whether the C implementation is faster or slower than the NEON version.
// Note, this has to be expanded as a template because the shuffle value must be an immediate value.
// The same is true on SSE as well.
// Selects four specific single-precision, floating-point values from a and b, based on the mask i. https://msdn.microsoft.com/en-us/library/vstudio/5f0858x0(v=vs.100).aspx
template <int i>
FORCE_INLINE __m128 _mm_shuffle_ps_default(__m128 a, __m128 b)
{
#if ENABLE_CPP_VERSION // I am not convinced that the NEON version is faster than the C version yet.
__m128 ret;
ret[0] = a[i & 0x3];
ret[1] = a[(i >> 2) & 0x3];
ret[2] = b[(i >> 4) & 0x03];
ret[3] = b[(i >> 6) & 0x03];
return ret;
#else
__m128 ret = vmovq_n_f32(vgetq_lane_f32(a, i & 0x3));
ret = vsetq_lane_f32(vgetq_lane_f32(a, (i >> 2) & 0x3), ret, 1);
ret = vsetq_lane_f32(vgetq_lane_f32(b, (i >> 4) & 0x3), ret, 2);
ret = vsetq_lane_f32(vgetq_lane_f32(b, (i >> 6) & 0x3), ret, 3);
return ret;
#endif
}
template <int i >
FORCE_INLINE __m128 _mm_shuffle_ps_function(__m128 a, __m128 b)
{
switch (i)
{
case _MM_SHUFFLE(1, 0, 3, 2): return _mm_shuffle_ps_1032(a, b); break;
case _MM_SHUFFLE(2, 3, 0, 1): return _mm_shuffle_ps_2301(a, b); break;
case _MM_SHUFFLE(3, 2, 1, 0): return _mm_shuffle_ps_3210(a, b); break;
case _MM_SHUFFLE(0, 0, 1, 1): return _mm_shuffle_ps_0011(a, b); break;
case _MM_SHUFFLE(0, 0, 2, 2): return _mm_shuffle_ps_0022(a, b); break;
case _MM_SHUFFLE(2, 2, 0, 0): return _mm_shuffle_ps_2200(a, b); break;
case _MM_SHUFFLE(3, 2, 0, 2): return _mm_shuffle_ps_3202(a, b); break;
case _MM_SHUFFLE(1, 1, 3, 3): return _mm_shuffle_ps_1133(a, b); break;
case _MM_SHUFFLE(2, 0, 1, 0): return _mm_shuffle_ps_2010(a, b); break;
case _MM_SHUFFLE(2, 0, 0, 1): return _mm_shuffle_ps_2001(a, b); break;
case _MM_SHUFFLE(2, 0, 3, 2): return _mm_shuffle_ps_2032(a, b); break;
default: _mm_shuffle_ps_default<i>(a, b);
}
}
#define _mm_shuffle_ps(a,b,i) _mm_shuffle_ps_function<i>(a,b)
// Takes the upper 64 bits of a and places it in the low end of the result
// Takes the lower 64 bits of b and places it into the high end of the result.
FORCE_INLINE __m128i _mm_shuffle_epi_1032(__m128i a, __m128i b)
{
return vcombine_s32(vget_high_s32(a), vget_low_s32(b));
}
// takes the lower two 32-bit values from a and swaps them and places in low end of result
// takes the higher two 32 bit values from b and swaps them and places in high end of result.
FORCE_INLINE __m128i _mm_shuffle_epi_2301(__m128i a, __m128i b)
{
return vcombine_s32(vrev64_s32(vget_low_s32(a)), vrev64_s32(vget_high_s32(b)));
}
// shift a right by 32 bits, and put the lower 32 bits of a into the upper 32 bits of b
// when a and b are the same, rotates the least significant 32 bits into the most signficant 32 bits, and shifts the rest down
FORCE_INLINE __m128i _mm_shuffle_epi_0321(__m128i a, __m128i b)
{
return vextq_s32(a, b, 1);
}
// shift a left by 32 bits, and put the upper 32 bits of b into the lower 32 bits of a
// when a and b are the same, rotates the most significant 32 bits into the least signficant 32 bits, and shifts the rest up
FORCE_INLINE __m128i _mm_shuffle_epi_2103(__m128i a, __m128i b)
{
return vextq_s32(a, b, 3);
}
// gets the lower 64 bits of a, and places it in the upper 64 bits
// gets the lower 64 bits of b and places it in the lower 64 bits
FORCE_INLINE __m128i _mm_shuffle_epi_1010(__m128i a, __m128i b)
{
return vcombine_s32(vget_low_s32(a), vget_low_s32(a));
}
// gets the lower 64 bits of a, and places it in the upper 64 bits
// gets the lower 64 bits of b, swaps the 0 and 1 elements, and places it in the lower 64 bits
FORCE_INLINE __m128i _mm_shuffle_epi_1001(__m128i a, __m128i b)
{
return vcombine_s32(vrev64_s32(vget_low_s32(a)), vget_low_s32(b));
}
// gets the lower 64 bits of a, swaps the 0 and 1 elements and places it in the upper 64 bits
// gets the lower 64 bits of b, swaps the 0 and 1 elements, and places it in the lower 64 bits
FORCE_INLINE __m128i _mm_shuffle_epi_0101(__m128i a, __m128i b)
{
return vcombine_s32(vrev64_s32(vget_low_s32(a)), vrev64_s32(vget_low_s32(b)));
}
FORCE_INLINE __m128i _mm_shuffle_epi_2211(__m128i a, __m128i b)
{
return vcombine_s32(vdup_n_s32(vgetq_lane_s32(a, 1)), vdup_n_s32(vgetq_lane_s32(b, 2)));
}
FORCE_INLINE __m128i _mm_shuffle_epi_0122(__m128i a, __m128i b)
{
return vcombine_s32(vdup_n_s32(vgetq_lane_s32(a, 2)), vrev64_s32(vget_low_s32(b)));
}
FORCE_INLINE __m128i _mm_shuffle_epi_3332(__m128i a, __m128i b)
{
return vcombine_s32(vget_high_s32(a), vdup_n_s32(vgetq_lane_s32(b, 3)));
}
template <int i >
FORCE_INLINE __m128i _mm_shuffle_epi32_default(__m128i a, __m128i b)
{
#if ENABLE_CPP_VERSION
__m128i ret;
ret[0] = a[i & 0x3];
ret[1] = a[(i >> 2) & 0x3];
ret[2] = b[(i >> 4) & 0x03];
ret[3] = b[(i >> 6) & 0x03];
return ret;
#else
__m128i ret = vmovq_n_s32(vgetq_lane_s32(a, i & 0x3));
ret = vsetq_lane_s32(vgetq_lane_s32(a, (i >> 2) & 0x3), ret, 1);
ret = vsetq_lane_s32(vgetq_lane_s32(b, (i >> 4) & 0x3), ret, 2);
ret = vsetq_lane_s32(vgetq_lane_s32(b, (i >> 6) & 0x3), ret, 3);
return ret;
#endif
}
template <int i >
FORCE_INLINE __m128i _mm_shuffle_epi32_function(__m128i a, __m128i b)
{
switch (i)
{
case _MM_SHUFFLE(1, 0, 3, 2): return _mm_shuffle_epi_1032(a, b); break;
case _MM_SHUFFLE(2, 3, 0, 1): return _mm_shuffle_epi_2301(a, b); break;
case _MM_SHUFFLE(0, 3, 2, 1): return _mm_shuffle_epi_0321(a, b); break;
case _MM_SHUFFLE(2, 1, 0, 3): return _mm_shuffle_epi_2103(a, b); break;
case _MM_SHUFFLE(1, 0, 1, 0): return _mm_shuffle_epi_1010(a, b); break;
case _MM_SHUFFLE(1, 0, 0, 1): return _mm_shuffle_epi_1001(a, b); break;
case _MM_SHUFFLE(0, 1, 0, 1): return _mm_shuffle_epi_0101(a, b); break;
case _MM_SHUFFLE(2, 2, 1, 1): return _mm_shuffle_epi_2211(a, b); break;
case _MM_SHUFFLE(0, 1, 2, 2): return _mm_shuffle_epi_0122(a, b); break;
case _MM_SHUFFLE(3, 3, 3, 2): return _mm_shuffle_epi_3332(a, b); break;
default: return _mm_shuffle_epi32_default<i>(a, b);
}
}
template <int i >
FORCE_INLINE __m128i _mm_shuffle_epi32_splat(__m128i a)
{
return vdupq_n_s32(vgetq_lane_s32(a, i));
}
template <int i>
FORCE_INLINE __m128i _mm_shuffle_epi32_single(__m128i a)
{
switch (i)
{
case _MM_SHUFFLE(0, 0, 0, 0): return _mm_shuffle_epi32_splat<0>(a); break;
case _MM_SHUFFLE(1, 1, 1, 1): return _mm_shuffle_epi32_splat<1>(a); break;
case _MM_SHUFFLE(2, 2, 2, 2): return _mm_shuffle_epi32_splat<2>(a); break;
case _MM_SHUFFLE(3, 3, 3, 3): return _mm_shuffle_epi32_splat<3>(a); break;
default: return _mm_shuffle_epi32_function<i>(a, a);
}
}
// Shuffles the 4 signed or unsigned 32-bit integers in a as specified by imm. https://msdn.microsoft.com/en-us/library/56f67xbk%28v=vs.90%29.aspx
#define _mm_shuffle_epi32(a,i) _mm_shuffle_epi32_single<i>(a)
template <int i>
FORCE_INLINE __m128i _mm_shufflehi_epi16_function(__m128i a)
{
int16x8_t ret = (int16x8_t)a;
int16x4_t highBits = vget_high_s16(ret);
ret = vsetq_lane_s16(vget_lane_s16(highBits, i & 0x3), ret, 4);
ret = vsetq_lane_s16(vget_lane_s16(highBits, (i >> 2) & 0x3), ret, 5);
ret = vsetq_lane_s16(vget_lane_s16(highBits, (i >> 4) & 0x3), ret, 6);
ret = vsetq_lane_s16(vget_lane_s16(highBits, (i >> 6) & 0x3), ret, 7);
return (__m128i)ret;
}
// Shuffles the upper 4 signed or unsigned 16 - bit integers in a as specified by imm. https://msdn.microsoft.com/en-us/library/13ywktbs(v=vs.100).aspx
#define _mm_shufflehi_epi16(a,i) _mm_shufflehi_epi16_function<i>(a)
// Shifts the 4 signed or unsigned 32-bit integers in a left by count bits while shifting in zeros. : https://msdn.microsoft.com/en-us/library/z2k3bbtb%28v=vs.90%29.aspx
#define _mm_slli_epi32(a, imm) (__m128i)vshlq_n_s32(a,imm)
//Shifts the 4 signed or unsigned 32-bit integers in a right by count bits while shifting in zeros. https://msdn.microsoft.com/en-us/library/w486zcfa(v=vs.100).aspx
#define _mm_srli_epi32( a, imm ) (__m128i)vshrq_n_u32((uint32x4_t)a, imm)
// Shifts the 4 signed 32 - bit integers in a right by count bits while shifting in the sign bit. https://msdn.microsoft.com/en-us/library/z1939387(v=vs.100).aspx
#define _mm_srai_epi32( a, imm ) vshrq_n_s32(a, imm)
// Shifts the 128 - bit value in a right by imm bytes while shifting in zeros.imm must be an immediate. https://msdn.microsoft.com/en-us/library/305w28yz(v=vs.100).aspx
//#define _mm_srli_si128( a, imm ) (__m128i)vmaxq_s8((int8x16_t)a, vextq_s8((int8x16_t)a, vdupq_n_s8(0), imm))
#define _mm_srli_si128( a, imm ) (__m128i)vextq_s8((int8x16_t)a, vdupq_n_s8(0), (imm))
// Shifts the 128-bit value in a left by imm bytes while shifting in zeros. imm must be an immediate. https://msdn.microsoft.com/en-us/library/34d3k2kt(v=vs.100).aspx
#define _mm_slli_si128( a, imm ) (__m128i)vextq_s8(vdupq_n_s8(0), (int8x16_t)a, 16 - (imm))
// NEON does not provide a version of this function, here is an article about some ways to repro the results.
// http://stackoverflow.com/questions/11870910/sse-mm-movemask-epi8-equivalent-method-for-arm-neon
// Creates a 16-bit mask from the most significant bits of the 16 signed or unsigned 8-bit integers in a and zero extends the upper bits. https://msdn.microsoft.com/en-us/library/vstudio/s090c8fk(v=vs.100).aspx
FORCE_INLINE int _mm_movemask_epi8(__m128i _a)
{
uint8x16_t input = (uint8x16_t)_a;
const int8_t __attribute__((aligned(16))) xr[8] = { -7, -6, -5, -4, -3, -2, -1, 0 };
uint8x8_t mask_and = vdup_n_u8(0x80);
int8x8_t mask_shift = vld1_s8(xr);
uint8x8_t lo = vget_low_u8(input);
uint8x8_t hi = vget_high_u8(input);
lo = vand_u8(lo, mask_and);
lo = vshl_u8(lo, mask_shift);
hi = vand_u8(hi, mask_and);
hi = vshl_u8(hi, mask_shift);
lo = vpadd_u8(lo, lo);
lo = vpadd_u8(lo, lo);
lo = vpadd_u8(lo, lo);
hi = vpadd_u8(hi, hi);
hi = vpadd_u8(hi, hi);
hi = vpadd_u8(hi, hi);
return ((hi[0] << 8) | (lo[0] & 0xFF));
}
// ******************************************
// Math operations
// ******************************************
// Subtracts the four single-precision, floating-point values of a and b. https://msdn.microsoft.com/en-us/library/vstudio/1zad2k61(v=vs.100).aspx
FORCE_INLINE __m128 _mm_sub_ps(__m128 a, __m128 b)
{
return vsubq_f32(a, b);
}
// Subtracts the 4 signed or unsigned 32-bit integers of b from the 4 signed or unsigned 32-bit integers of a. https://msdn.microsoft.com/en-us/library/vstudio/fhh866h0(v=vs.100).aspx
FORCE_INLINE __m128i _mm_sub_epi32(__m128i a, __m128i b)
{
return vsubq_s32(a, b);
}
// Adds the four single-precision, floating-point values of a and b. https://msdn.microsoft.com/en-us/library/vstudio/c9848chc(v=vs.100).aspx
FORCE_INLINE __m128 _mm_add_ps(__m128 a, __m128 b)
{
return vaddq_f32(a, b);
}
// Adds the 4 signed or unsigned 32-bit integers in a to the 4 signed or unsigned 32-bit integers in b. https://msdn.microsoft.com/en-us/library/vstudio/09xs4fkk(v=vs.100).aspx
FORCE_INLINE __m128i _mm_add_epi32(__m128i a, __m128i b)
{
return vaddq_s32(a, b);
}
// Adds the 8 signed or unsigned 16-bit integers in a to the 8 signed or unsigned 16-bit integers in b. https://msdn.microsoft.com/en-us/library/fceha5k4(v=vs.100).aspx
FORCE_INLINE __m128i _mm_add_epi16(__m128i a, __m128i b)
{
return (__m128i)vaddq_s16((int16x8_t)a, (int16x8_t)b);
}
// Multiplies the 8 signed or unsigned 16-bit integers from a by the 8 signed or unsigned 16-bit integers from b. https://msdn.microsoft.com/en-us/library/vstudio/9ks1472s(v=vs.100).aspx
FORCE_INLINE __m128i _mm_mullo_epi16(__m128i a, __m128i b)
{
return (__m128i)vmulq_s16((int16x8_t)a, (int16x8_t)b);
}
// Multiplies the 4 signed or unsigned 32-bit integers from a by the 4 signed or unsigned 32-bit integers from b. https://msdn.microsoft.com/en-us/library/vstudio/bb531409(v=vs.100).aspx
FORCE_INLINE __m128i _mm_mullo_epi32 (__m128i a, __m128i b)
{
return (__m128i)vmulq_s32((int32x4_t)a,(int32x4_t)b);
}
// Multiplies the four single-precision, floating-point values of a and b. https://msdn.microsoft.com/en-us/library/vstudio/22kbk6t9(v=vs.100).aspx
FORCE_INLINE __m128 _mm_mul_ps(__m128 a, __m128 b)
{
return vmulq_f32(a, b);
}
// This version does additional iterations to improve accuracy. Between 1 and 4 recommended.
// Computes the approximations of reciprocals of the four single-precision, floating-point values of a. https://msdn.microsoft.com/en-us/library/vstudio/796k1tty(v=vs.100).aspx
FORCE_INLINE __m128 recipq_newton(__m128 in, int n)
{
__m128 recip = vrecpeq_f32(in);
for (int i = 0; i<n; ++i)
{
recip = vmulq_f32(recip, vrecpsq_f32(recip, in));
}
return recip;
}
// Computes the approximations of reciprocals of the four single-precision, floating-point values of a. https://msdn.microsoft.com/en-us/library/vstudio/796k1tty(v=vs.100).aspx
FORCE_INLINE __m128 _mm_rcp_ps(__m128 in)
{
__m128 recip = vrecpeq_f32(in);
recip = vmulq_f32(recip, vrecpsq_f32(recip, in));
return recip;
}
// Computes the approximations of square roots of the four single-precision, floating-point values of a. First computes reciprocal square roots and then reciprocals of the four values. https://msdn.microsoft.com/en-us/library/vstudio/8z67bwwk(v=vs.100).aspx
FORCE_INLINE __m128 _mm_sqrt_ps(__m128 in)
{
__m128 recipsq = vrsqrteq_f32(in);
__m128 sq = vrecpeq_f32(recipsq);
// ??? use step versions of both sqrt and recip for better accuracy?
return sq;
}
// Computes the maximums of the four single-precision, floating-point values of a and b. https://msdn.microsoft.com/en-us/library/vstudio/ff5d607a(v=vs.100).aspx
FORCE_INLINE __m128 _mm_max_ps(__m128 a, __m128 b)
{
return vmaxq_f32(a, b);
}
// Computes the minima of the four single-precision, floating-point values of a and b. https://msdn.microsoft.com/en-us/library/vstudio/wh13kadz(v=vs.100).aspx
FORCE_INLINE __m128 _mm_min_ps(__m128 a, __m128 b)
{
return vminq_f32(a, b);
}
// Computes the pairwise minima of the 8 signed 16-bit integers from a and the 8 signed 16-bit integers from b. https://msdn.microsoft.com/en-us/library/vstudio/6te997ew(v=vs.100).aspx
FORCE_INLINE __m128i _mm_min_epi16(__m128i a, __m128i b)
{
return (__m128i)vminq_s16((int16x8_t)a, (int16x8_t)b);
}
// epi versions of min/max
// Computes the pariwise maximums of the four signed 32-bit integer values of a and b. https://msdn.microsoft.com/en-us/library/vstudio/bb514055(v=vs.100).aspx
FORCE_INLINE __m128i _mm_max_epi32(__m128i a, __m128i b )
{
return vmaxq_s32(a,b);
}
// Computes the pariwise minima of the four signed 32-bit integer values of a and b. https://msdn.microsoft.com/en-us/library/vstudio/bb531476(v=vs.100).aspx
FORCE_INLINE __m128i _mm_min_epi32(__m128i a, __m128i b )
{
return vminq_s32(a,b);
}
// Multiplies the 8 signed 16-bit integers from a by the 8 signed 16-bit integers from b. https://msdn.microsoft.com/en-us/library/vstudio/59hddw1d(v=vs.100).aspx
FORCE_INLINE __m128i _mm_mulhi_epi16(__m128i a, __m128i b)
{
int16x8_t ret = vqdmulhq_s16((int16x8_t)a, (int16x8_t)b);
ret = vshrq_n_s16(ret, 1);
return (__m128i)ret;
}
// Computes pairwise add of each argument as single-precision, floating-point values a and b.
//https://msdn.microsoft.com/en-us/library/yd9wecaa.aspx
FORCE_INLINE __m128 _mm_hadd_ps(__m128 a, __m128 b )
{
// This does not work, no vpaddq...
// return (__m128) vpaddq_f32(a,b);
//
// get two f32x2_t values from a
// do vpadd
// put result in low half of f32x4 result
//
// get two f32x2_t values from b
// do vpadd
// put result in high half of f32x4 result
//
// combine
return vcombine_f32( vpadd_f32( vget_low_f32(a), vget_high_f32(a) ), vpadd_f32( vget_low_f32(b), vget_high_f32(b) ) );
}
// ******************************************
// Compare operations
// ******************************************
// Compares for less than https://msdn.microsoft.com/en-us/library/vstudio/f330yhc8(v=vs.100).aspx
FORCE_INLINE __m128 _mm_cmplt_ps(__m128 a, __m128 b)
{
return (__m128)vcltq_f32(a, b);
}
// Compares for greater than. https://msdn.microsoft.com/en-us/library/vstudio/11dy102s(v=vs.100).aspx
FORCE_INLINE __m128 _mm_cmpgt_ps(__m128 a, __m128 b)
{
return (__m128)vcgtq_f32(a, b);
}
// Compares for greater than or equal. https://msdn.microsoft.com/en-us/library/vstudio/fs813y2t(v=vs.100).aspx
FORCE_INLINE __m128 _mm_cmpge_ps(__m128 a, __m128 b)
{
return (__m128)vcgeq_f32(a, b);
}
// Compares for less than or equal. https://msdn.microsoft.com/en-us/library/vstudio/1s75w83z(v=vs.100).aspx
FORCE_INLINE __m128 _mm_cmple_ps(__m128 a, __m128 b)
{
return (__m128)vcleq_f32(a, b);
}
// Compares for equality. https://msdn.microsoft.com/en-us/library/vstudio/36aectz5(v=vs.100).aspx
FORCE_INLINE __m128 _mm_cmpeq_ps(__m128 a, __m128 b)
{
return (__m128)vceqq_f32(a, b);
}
// Compares the 4 signed 32-bit integers in a and the 4 signed 32-bit integers in b for less than. https://msdn.microsoft.com/en-us/library/vstudio/4ak0bf5d(v=vs.100).aspx
FORCE_INLINE __m128i _mm_cmplt_epi32(__m128i a, __m128i b)
{
return (__m128i)vcltq_s32(a, b);
}
// Compares the 4 signed 32-bit integers in a and the 4 signed 32-bit integers in b for greater than. https://msdn.microsoft.com/en-us/library/vstudio/1s9f2z0y(v=vs.100).aspx
FORCE_INLINE __m128i _mm_cmpgt_epi32(__m128i a, __m128i b)
{
return (__m128i)vcgtq_s32(a, b);
}
// Compares the four 32-bit floats in a and b to check if any values are NaN. Ordered compare between each value returns true for "orderable" and false for "not orderable" (NaN). https://msdn.microsoft.com/en-us/library/vstudio/0h9w00fx(v=vs.100).aspx
// see also:
// http://stackoverflow.com/questions/8627331/what-does-ordered-unordered-comparison-mean
// http://stackoverflow.com/questions/29349621/neon-isnanval-intrinsics
FORCE_INLINE __m128 _mm_cmpord_ps(__m128 a, __m128 b )
{
// Note: NEON does not have ordered compare builtin
// Need to compare a eq a and b eq b to check for NaN
// Do AND of results to get final
return (__m128) vreinterpretq_f32_u32( vandq_u32( vceqq_f32(a,a), vceqq_f32(b,b) ) );
}
// ******************************************
// Conversions
// ******************************************
// Converts the four single-precision, floating-point values of a to signed 32-bit integer values using truncate. https://msdn.microsoft.com/en-us/library/vstudio/1h005y6x(v=vs.100).aspx
FORCE_INLINE __m128i _mm_cvttps_epi32(__m128 a)
{
return vcvtq_s32_f32(a);
}
// Converts the four signed 32-bit integer values of a to single-precision, floating-point values https://msdn.microsoft.com/en-us/library/vstudio/36bwxcx5(v=vs.100).aspx
FORCE_INLINE __m128 _mm_cvtepi32_ps(__m128i a)
{
return vcvtq_f32_s32(a);
}
// Converts the four single-precision, floating-point values of a to signed 32-bit integer values. https://msdn.microsoft.com/en-us/library/vstudio/xdc42k5e(v=vs.100).aspx
FORCE_INLINE __m128i _mm_cvtps_epi32(__m128 a)
{
#if __aarch64__
return vcvtaq_s32_f32(a);
#else
__m128 half = vdupq_n_f32(0.5f);
const __m128 sign = vcvtq_f32_u32((vshrq_n_u32(vreinterpretq_u32_f32(a), 31)));
const __m128 aPlusHalf = vaddq_f32(a, half);
const __m128 aRound = vsubq_f32(aPlusHalf, sign);
return vcvtq_s32_f32(aRound);
#endif
}
// Moves the least significant 32 bits of a to a 32-bit integer. https://msdn.microsoft.com/en-us/library/5z7a9642%28v=vs.90%29.aspx
FORCE_INLINE int _mm_cvtsi128_si32(__m128i a)
{
return vgetq_lane_s32(a, 0);
}
// Moves 32-bit integer a to the least significant 32 bits of an __m128 object, zero extending the upper bits. https://msdn.microsoft.com/en-us/library/ct3539ha%28v=vs.90%29.aspx
FORCE_INLINE __m128i _mm_cvtsi32_si128(int a)
{
__m128i result = vdupq_n_s32(0);
return vsetq_lane_s32(a, result, 0);
}
// Applies a type cast to reinterpret four 32-bit floating point values passed in as a 128-bit parameter as packed 32-bit integers. https://msdn.microsoft.com/en-us/library/bb514099.aspx
FORCE_INLINE __m128i _mm_castps_si128(__m128 a)
{
return *(const __m128i *)&a;
}
// Applies a type cast to reinterpret four 32-bit integers passed in as a 128-bit parameter as packed 32-bit floating point values. https://msdn.microsoft.com/en-us/library/bb514029.aspx
FORCE_INLINE __m128 _mm_castsi128_ps(__m128i a)
{
return *(const __m128 *)&a;
}
// Loads 128-bit value. : https://msdn.microsoft.com/en-us/library/atzzad1h(v=vs.80).aspx
FORCE_INLINE __m128i _mm_load_si128(const __m128i *p)
{
return vld1q_s32((int32_t *)p);
}
// ******************************************
// Miscellaneous Operations
// ******************************************
// Packs the 16 signed 16-bit integers from a and b into 8-bit integers and saturates. https://msdn.microsoft.com/en-us/library/k4y4f7w5%28v=vs.90%29.aspx
FORCE_INLINE __m128i _mm_packs_epi16(__m128i a, __m128i b)
{
return (__m128i)vcombine_s8(vqmovn_s16((int16x8_t)a), vqmovn_s16((int16x8_t)b));
}
// Packs the 16 signed 16 - bit integers from a and b into 8 - bit unsigned integers and saturates. https://msdn.microsoft.com/en-us/library/07ad1wx4(v=vs.100).aspx
FORCE_INLINE __m128i _mm_packus_epi16(const __m128i a, const __m128i b)
{
return (__m128i)vcombine_u8(vqmovun_s16((int16x8_t)a), vqmovun_s16((int16x8_t)b));
}
// Packs the 8 signed 32-bit integers from a and b into signed 16-bit integers and saturates. https://msdn.microsoft.com/en-us/library/393t56f9%28v=vs.90%29.aspx
FORCE_INLINE __m128i _mm_packs_epi32(__m128i a, __m128i b)
{
return (__m128i)vcombine_s16(vqmovn_s32(a), vqmovn_s32(b));
}
// Interleaves the lower 8 signed or unsigned 8-bit integers in a with the lower 8 signed or unsigned 8-bit integers in b. https://msdn.microsoft.com/en-us/library/xf7k860c%28v=vs.90%29.aspx
FORCE_INLINE __m128i _mm_unpacklo_epi8(__m128i a, __m128i b)
{
int8x8_t a1 = (int8x8_t)vget_low_s16((int16x8_t)a);
int8x8_t b1 = (int8x8_t)vget_low_s16((int16x8_t)b);
int8x8x2_t result = vzip_s8(a1, b1);
return (__m128i)vcombine_s8(result.val[0], result.val[1]);
}
// Interleaves the lower 4 signed or unsigned 16-bit integers in a with the lower 4 signed or unsigned 16-bit integers in b. https://msdn.microsoft.com/en-us/library/btxb17bw%28v=vs.90%29.aspx
FORCE_INLINE __m128i _mm_unpacklo_epi16(__m128i a, __m128i b)
{
int16x4_t a1 = vget_low_s16((int16x8_t)a);
int16x4_t b1 = vget_low_s16((int16x8_t)b);
int16x4x2_t result = vzip_s16(a1, b1);
return (__m128i)vcombine_s16(result.val[0], result.val[1]);
}
// Interleaves the lower 2 signed or unsigned 32 - bit integers in a with the lower 2 signed or unsigned 32 - bit integers in b. https://msdn.microsoft.com/en-us/library/x8atst9d(v=vs.100).aspx
FORCE_INLINE __m128i _mm_unpacklo_epi32(__m128i a, __m128i b)
{
int32x2_t a1 = vget_low_s32(a);
int32x2_t b1 = vget_low_s32(b);
int32x2x2_t result = vzip_s32(a1, b1);
return vcombine_s32(result.val[0], result.val[1]);
}
// Selects and interleaves the lower two single-precision, floating-point values from a and b. https://msdn.microsoft.com/en-us/library/25st103b%28v=vs.90%29.aspx
FORCE_INLINE __m128 _mm_unpacklo_ps(__m128 a, __m128 b)
{
float32x2x2_t result = vzip_f32(vget_low_f32(a), vget_low_f32(b));
return vcombine_f32(result.val[0], result.val[1]);
}
// Selects and interleaves the upper two single-precision, floating-point values from a and b. https://msdn.microsoft.com/en-us/library/skccxx7d%28v=vs.90%29.aspx
FORCE_INLINE __m128 _mm_unpackhi_ps(__m128 a, __m128 b)
{
float32x2x2_t result = vzip_f32(vget_high_f32(a), vget_high_f32(b));
return vcombine_f32(result.val[0], result.val[1]);
}
// Interleaves the upper 2 signed or unsigned 32-bit integers in a with the upper 2 signed or unsigned 32-bit integers in b. https://msdn.microsoft.com/en-us/library/65sa7cbs(v=vs.100).aspx
FORCE_INLINE __m128i _mm_unpackhi_epi32(__m128i a, __m128i b)
{
int32x2_t a1 = vget_high_s32(a);
int32x2_t b1 = vget_high_s32(b);
int32x2x2_t result = vzip_s32(a1, b1);
return vcombine_s32(result.val[0], result.val[1]);
}
// Extracts the selected signed or unsigned 16-bit integer from a and zero extends. https://msdn.microsoft.com/en-us/library/6dceta0c(v=vs.100).aspx
#define _mm_extract_epi16( a, imm ) vgetq_lane_s16((int16x8_t)a, imm)
// ******************************************
// Streaming Extensions
// ******************************************
// Guarantees that every preceding store is globally visible before any subsequent store. https://msdn.microsoft.com/en-us/library/5h2w73d1%28v=vs.90%29.aspx
FORCE_INLINE void _mm_sfence(void)
{
__sync_synchronize();
}
// Stores the data in a to the address p without polluting the caches. If the cache line containing address p is already in the cache, the cache will be updated.Address p must be 16 - byte aligned. https://msdn.microsoft.com/en-us/library/ba08y07y%28v=vs.90%29.aspx
FORCE_INLINE void _mm_stream_si128(__m128i *p, __m128i a)
{
*p = a;
}
// Cache line containing p is flushed and invalidated from all caches in the coherency domain.
FORCE_INLINE void _mm_clflush(void const*p) {
// no corollary for Neon?
}
#endif
================================================
FILE: fdsst/fdssttracker.cpp
================================================
/*
Tracker based on Kernelized Correlation Filter (KCF) [1] and Circulant Structure with Kernels (CSK) [2].
CSK is implemented by using raw gray level features, since it is a single-channel filter.
KCF is implemented by using HOG features (the default), since it extends CSK to multiple channels.
[1] J. F. Henriques, R. Caseiro, P. Martins, J. Batista,
"High-Speed Tracking with Kernelized Correlation Filters", TPAMI 2015.
[2] J. F. Henriques, R. Caseiro, P. Martins, J. Batista,
"Exploiting the Circulant Structure of Tracking-by-detection with Kernels", ECCV 2012.
Authors: Joao Faro, Christian Bailer, Joao F. Henriques
Contacts: joaopfaro@gmail.com, Christian.Bailer@dfki.de, henriques@isr.uc.pt
Institute of Systems and Robotics - University of Coimbra / Department Augmented Vision DFKI
Constructor parameters, all boolean:
hog: use HOG features (default), otherwise use raw pixels
fixed_window: fix window size (default), otherwise use ROI size (slower but more accurate)
multiscale: use multi-scale tracking (default; cannot be used with fixed_window = true)
Default values are set for all properties of the tracker depending on the above choices.
Their values can be customized further before calling init():
interp_factor: linear interpolation factor for adaptation
sigma: gaussian kernel bandwidth
lambda: regularization
cell_size: HOG cell size
padding: area surrounding the target, relative to its size
output_sigma_factor: bandwidth of gaussian target
template_size: template size in pixels, 0 to use ROI size
scale_step: scale step for multi-scale estimation, 1 to disable it
scale_weight: to downweight detection scores of other scales for added stability
For speed, the value (template_size/cell_size) should be a power of 2 or a product of small prime numbers.
Inputs to init():
image is the initial frame.
roi is a cv::Rect with the target positions in the initial frame
Inputs to update():
image is the current frame.
Outputs of update():
cv::Rect with target positions for the current frame
By downloading, copying, installing or using the software you agree to this license.
If you do not agree to this license, do not download, install,
copy or use the software.
License Agreement
For Open Source Computer Vision Library
(3-clause BSD License)
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the names of the copyright holders nor the names of the contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
This software is provided by the copyright holders and contributors "as is" and
any express or implied warranties, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose are disclaimed.
In no event shall copyright holders or contributors be liable for any direct,
indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services;
loss of use, data, or profits; or business interruption) however caused
and on any theory of liability, whether in contract, strict liability,
or tort (including negligence or otherwise) arising in any way out of
the use of this software, even if advised of the possibility of such damage.
*/
#if 1
#include <time.h>
#include "fdssttracker.hpp"
#include "ffttools.hpp"
#include "recttools.hpp"
#include "fhog.h"
#include "labdata.hpp"
#include <glog/logging.h>
// #define PFS_DEBUG
static double t_start, t_end;
template <typename T>
cv::Mat rangeToColVector(int begin, int end, int n)
{
cv::Mat_<T> colVec(1, n);
for (int i = begin, j = 0; i <= end; ++i, j++)
colVec.template at<T>(0, j) = static_cast<T>(i);
return colVec;
}
template <typename BT, typename ET>
cv::Mat pow(BT base_, const cv::Mat_<ET>& exponent)
{
cv::Mat dst = cv::Mat(exponent.rows, exponent.cols, exponent.type());
int widthChannels = exponent.cols * exponent.channels();
int height = exponent.rows;
// http://docs.opencv.org/doc/tutorials/core/how_to_scan_images/how_to_scan_images.html#the-efficient-way
if (exponent.isContinuous())
{
widthChannels *= height;
height = 1;
}
int row = 0, col = 0;
const ET* exponentd = 0;
ET* dstd = 0;
for (row = 0; row < height; ++row)
{
exponentd = exponent.template ptr<ET>(row);
dstd = dst.template ptr<ET>(row);
for (col = 0; col < widthChannels; ++col)
{
dstd[col] = std::pow(base_, exponentd[col]);
}
}
return dst;
}
void shift(const cv::Mat& src, cv::Mat& dst, cv::Point2f delta, int fill, cv::Scalar value = cv::Scalar(0, 0, 0, 0)) {
// error checking
CV_Assert(fabs(delta.x) < src.cols && fabs(delta.y) < src.rows);
// split the shift into integer and subpixel components
cv::Point2i deltai(static_cast<int>(ceil(delta.x)), static_cast<int>(ceil(delta.y)));
cv::Point2f deltasub(fabs(delta.x - deltai.x), fabs(delta.y - deltai.y));
// INTEGER SHIFT
// first create a border around the parts of the Mat that will be exposed
int t = 0, b = 0, l = 0, r = 0;
if (deltai.x > 0) l = deltai.x;
if (deltai.x < 0) r = -deltai.x;
if (deltai.y > 0) t = deltai.y;
if (deltai.y < 0) b = -deltai.y;
cv::Mat padded;
cv::copyMakeBorder(src, padded, t, b, l, r, fill, value);
// SUBPIXEL SHIFT
float eps = std::numeric_limits<float>::epsilon();
if (deltasub.x > eps || deltasub.y > eps) {
switch (src.depth()) {
case CV_32F:
{
cv::Matx<float, 1, 2> dx(1 - deltasub.x, deltasub.x);
cv::Matx<float, 2, 1> dy(1 - deltasub.y, deltasub.y);
sepFilter2D(padded, padded, -1, dx, dy, cv::Point(0, 0), 0, cv::BORDER_CONSTANT);
break;
}
case CV_64F:
{
cv::Matx<double, 1, 2> dx(1 - deltasub.x, deltasub.x);
cv::Matx<double, 2, 1> dy(1 - deltasub.y, deltasub.y);
sepFilter2D(padded, padded, -1, dx, dy, cv::Point(0, 0), 0, cv::BORDER_CONSTANT);
break;
}
default:
{
cv::Matx<float, 1, 2> dx(1 - deltasub.x, deltasub.x);
cv::Matx<float, 2, 1> dy(1 - deltasub.y, deltasub.y);
padded.convertTo(padded, CV_32F);
sepFilter2D(padded, padded, CV_32F, dx, dy, cv::Point(0, 0), 0, cv::BORDER_CONSTANT);
break;
}
}
}
// construct the region of interest around the new matrix
cv::Rect roi = cv::Rect(std::max(-deltai.x, 0), std::max(-deltai.y, 0), 0, 0) + src.size();
//xyz2017.06.17 cv::Rect roi = cv::Rect(max(-deltai.x, 0), max(-deltai.y, 0), 0, 0) + src.size();
dst = padded(roi);
}
// Constructor
FDSSTTracker::FDSSTTracker(bool hog, bool fixed_window, bool multiscale, bool lab)
{
Reset();
// Parameters equal in all cases
lambda = 0.0001;
padding = 2.5;
//output_sigma_factor = 0.1;
output_sigma_factor = 0.125;
if (hog) { // HOG
// VOT
interp_factor = 0.015;
sigma = 0.6;
// TPAMI
//interp_factor = 0.02;
//sigma = 0.5;
cell_size = 4;
_hogfeatures = true;
num_compressed_dim = 13;
if (lab) {
interp_factor = 0.005;
sigma = 0.4;
//output_sigma_factor = 0.025;
output_sigma_factor = 0.1;
_labfeatures = true;
_labCentroids = cv::Mat(nClusters, 3, CV_32FC1, &data);
cell_sizeQ = cell_size*cell_size;
}
else{
_labfeatures = false;
}
}
else { // RAW
interp_factor = 0.075;
sigma = 0.2;
cell_size = 1;
_hogfeatures = false;
if (lab) {
LOG(ERROR) << "Lab features are only used with HOG features.\n";
_labfeatures = false;
}
}
if (multiscale) { // multiscale
template_size = 96;
//scale parameters initial
scale_padding = 1.0;
scale_step = 1.05;
scale_sigma_factor = 1.0 / 16;
n_scales = 9;
n_interp_scales = 33;
scale_lr = 0.025;
scale_max_area = 512;
currentScaleFactor = 1;
scale_lambda = 0.01;
if (!fixed_window) {
fixed_window = true;
}
}
else if (fixed_window) { // fit correction without multiscale
template_size = 96;
//template_size = 100;
scale_step = 1;
// begin xyz add ==================
template_size = 64;
currentScaleFactor = 1;
n_scales = 3;
n_interp_scales = 1;
scale_max_area = 256;
cell_size = 8;
// end xyz add ==================
}
else {
template_size = 1;
scale_step = 1;
}
success_ = true;
}
// Initialize tracker
// Initialize tracker
void FDSSTTracker::init(const cv::Rect &roi, cv::Mat image)
{
_roi = roi;
assert(roi.width >= 0 && roi.height >= 0);
_tmpl = getFeatures(image, 1);
if(!success_){
return;
}
_prob = createGaussianPeak(size_patch[0], size_patch[1]);
_alphaf = cv::Mat(size_patch[0], size_patch[1], CV_32FC2, float(0));
dsstInit(roi, image);
//_num = cv::Mat(size_patch[0], size_patch[1], CV_32FC2, float(0));
//_den = cv::Mat(size_patch[0], size_patch[1], CV_32FC2, float(0));
train(_tmpl, 1.0); // train with initial frame
}
// Update position based on the new frame
cv::Rect FDSSTTracker::update(cv::Mat image)
{
if(!success_){
return cv::Rect(0, 0, 0, 0);
}
if (_roi.x + _roi.width <= 0) _roi.x = -_roi.width + 1;
if (_roi.y + _roi.height <= 0) _roi.y = -_roi.height + 1;
if (_roi.x >= image.cols - 1) _roi.x = image.cols - 2;
if (_roi.y >= image.rows - 1) _roi.y = image.rows - 2;
float cx = _roi.x + _roi.width / 2.0f;
float cy = _roi.y + _roi.height / 2.0f;
float peak_value;
#ifdef PFS_DEBUG
t_start = clock();
#endif
cv::Point2f res = detect(getFeatures(image, 0, 1.0f), peak_value);
if(!success_){
return cv::Rect(0, 0, 0, 0);
}
#ifdef PFS_DEBUG
t_end = clock();
std::cout << "translation detction duration: " << (t_end - t_start) / CLOCKS_PER_SEC << "\n";
#endif
// Adjust by cell size and _scale
_roi.x = cx - _roi.width / 2.0f + ((float) res.x * cell_size * _scale * currentScaleFactor);
_roi.y = cy - _roi.height / 2.0f + ((float) res.y * cell_size * _scale * currentScaleFactor);
if (_roi.x >= image.cols - 1) _roi.x = image.cols - 1;
if (_roi.y >= image.rows - 1) _roi.y = image.rows - 1;
if (_roi.x + _roi.width <= 0) _roi.x = -_roi.width + 2;
if (_roi.y + _roi.height <= 0) _roi.y = -_roi.height + 2;
// Update scale
#ifdef PFS_DEBUG
t_start = clock();
#endif
cv::Point2i scale_pi = detect_scale(image);
if(!success_){
return cv::Rect(0, 0, 0, 0);
}
#ifdef PFS_DEBUG
t_end = clock();
std::cout << "scale detction duration: " << (t_end - t_start) / CLOCKS_PER_SEC << "\n";
#endif
currentScaleFactor = currentScaleFactor * interp_scaleFactors[scale_pi.x];
// std::cout << currentScaleFactor<<"\n";
if(currentScaleFactor < min_scale_factor)
currentScaleFactor = min_scale_factor;
// else if(currentScaleFactor > max_scale_factor)
// currentScaleFactor = max_scale_factor;
update_roi();
train_scale(image);
if (_roi.x >= image.cols - 1) _roi.x = image.cols - 1;
if (_roi.y >= image.rows - 1) _roi.y = image.rows - 1;
if (_roi.x + _roi.width <= 0) _roi.x = -_roi.width + 2;
if (_roi.y + _roi.height <= 0) _roi.y = -_roi.height + 2;
assert(_roi.width >= 0 && _roi.height >= 0);
cv::Mat x = getFeatures(image, 0);
if(!success_){
return cv::Rect(0, 0, 0, 0);
}
train(x, interp_factor);
return _roi;
}
// Detect the new scaling rate
cv::Point2i FDSSTTracker::detect_scale(cv::Mat image)
{
cv::Mat xsf = FDSSTTracker::get_scale_sample(image);
if(!success_){
return cv::Point2i(0, 0);
}
// Compute AZ in the paper
cv::Mat add_temp;
cv::reduce(FFTTools::complexMultiplication(sf_num, xsf), add_temp, 0, CV_REDUCE_SUM);
// compute the final y
cv::Mat scale_responsef = FFTTools::complexDivisionReal(add_temp, (sf_den + scale_lambda));
cv::Mat interp_scale_responsef = resizeDFT(scale_responsef, n_interp_scales);
cv::Mat interp_scale_response;
cv::idft(interp_scale_responsef, interp_scale_response);
interp_scale_response = FFTTools::real(interp_scale_response);
// Get the max point as the final scaling rate
cv::Point2i pi;
double pv;
cv::minMaxLoc(interp_scale_response, NULL, &pv, NULL, &pi);
return pi;
}
// Detect object in the current frame.
cv::Point2f FDSSTTracker::detect(cv::Mat x, float &peak_value)
{
if(x.empty()){
return cv::Point2f(0, 0);
}
using namespace FFTTools;
x = features_projection(x);
cv::Mat z = features_projection(_tmpl);
#ifdef PFS_DEBUG
double t_start1 = clock();
#endif
cv::Mat k = gaussianCorrelation(x, z);
#ifdef PFS_DEBUG
t_end = clock();
std::cout << "**************gaussianCorrelation duration: " << (t_end - t_start1) / CLOCKS_PER_SEC << "\n";
#endif
#ifdef PFS_DEBUG
t_start = clock();
#endif
cv::Mat res = (real(fftd(complexMultiplication(_alphaf, fftd(k)), true)));
#ifdef PFS_DEBUG
t_end = clock();
std::cout << "complexMultiplication *******************: " << (t_end - t_start) / CLOCKS_PER_SEC << "\n";
#endif
//minMaxLoc only accepts doubles for the peak, and integer points for the coordinates
cv::Point2i pi;
double pv;
cv::minMaxLoc(res, NULL, &pv, NULL, &pi);
peak_value = (float)pv;
//subpixel peak estimation, coordinates will be non-integer
cv::Point2f p((float)pi.x, (float)pi.y);
if (pi.x > 0 && pi.x < res.cols - 1) {
p.x += subPixelPeak(res.at<float>(pi.y, pi.x - 1), peak_value, res.at<float>(pi.y, pi.x + 1));
}
if (pi.y > 0 && pi.y < res.rows - 1) {
p.y += subPixelPeak(res.at<float>(pi.y - 1, pi.x), peak_value, res.at<float>(pi.y + 1, pi.x));
}
p.x -= (res.cols) / 2;
p.y -= (res.rows) / 2;
return p;
}
// train tracker with a single image
void FDSSTTracker::train(cv::Mat x, float train_interp_factor)
{
using namespace FFTTools;
_tmpl = (1 - train_interp_factor) * _tmpl + (train_interp_factor)* x;
cv::Mat W, U, VT, X, out;
X = _tmpl * _tmpl.t();
cv::SVD::compute(X, W, U, VT);
VT.rowRange(0, num_compressed_dim).copyTo(proj_matrix);
x = features_projection(x);
cv::Mat k = gaussianCorrelation(x, x);
cv::Mat alphaf = complexDivision(_prob, (fftd(k) + lambda));
_alphaf = (1 - train_interp_factor) * _alphaf + (train_interp_factor)* alphaf;
}
// Evaluates a Gaussian kernel with bandwidth SIGMA for all relative shifts between input images X and Y, which must both be MxN. They must also be periodic (ie., pre-processed with a cosine window).
cv::Mat FDSSTTracker::gaussianCorrelation(cv::Mat x1, cv::Mat x2)
{
using namespace FFTTools;
#ifdef PFS_DEBUG
double t_start1 = clock();
#endif
cv::Mat c = cv::Mat( cv::Size(size_patch[1], size_patch[0]), CV_32F, cv::Scalar(0) );
// HOG features
if (_hogfeatures) {
cv::Mat caux;
cv::Mat x1aux;
cv::Mat x2aux;
for (int i = 0; i < size_patch[2]; i++) {
x1aux = x1.row(i); // Procedure do deal with cv::Mat multichannel bug
x1aux = x1aux.reshape(1, size_patch[0]);
x2aux = x2.row(i).reshape(1, size_pa
gitextract_zv8h4xpo/ ├── LICENSE ├── Main.cpp ├── NT.cpp ├── NT.h ├── NTN.h ├── README.md ├── StrCommon.h ├── data/ │ └── tt1.pb ├── deepsort/ │ ├── Detection.h │ ├── FeatureGetter/ │ │ ├── CaffeShuffeNetFeatureGetter.cpp │ │ ├── FaceNetFeatureGetter.cpp │ │ ├── FeatureGetter.cpp │ │ ├── FeatureGetter.h │ │ ├── MobileNetFeatureGetter.cpp │ │ └── make.sh │ ├── HungarianOper.h │ ├── KalmanTracker.h │ ├── iou_matching.h │ ├── kalman_filter.h │ ├── linear_assignment.h │ ├── munkres/ │ │ ├── adapters/ │ │ │ ├── adapter.cpp │ │ │ ├── adapter.h │ │ │ ├── boostmatrixadapter.cpp │ │ │ └── boostmatrixadapter.h │ │ ├── matrix.cpp │ │ ├── matrix.h │ │ ├── munkres.cpp │ │ └── munkres.h │ ├── nn_matching.h │ └── tracker.h ├── fdsst/ │ ├── SSE2NEON.h │ ├── fdssttracker.cpp │ ├── fdssttracker.hpp │ ├── ffttools.hpp │ ├── fhog.cpp │ ├── fhog.h │ ├── fhogbk/ │ │ ├── fhog.cpp │ │ └── fhog.h │ ├── labdata.hpp │ ├── recttools.hpp │ ├── sse.hpp │ └── tracker.h ├── lmake.sh ├── log.txt ├── logn10.txt ├── logn15.txt ├── logn20.txt ├── make.sh └── t.sh
SYMBOL INDEX (314 symbols across 34 files)
FILE: Main.cpp
function DrawData (line 8) | void DrawData(cv::Mat mm, cv::Mat frame, const std::map<int, DSResult> &...
function ReadFileContent (line 41) | void ReadFileContent(const std::string &file, std::string &content){
function ReadRcFileTotal (line 61) | void ReadRcFileTotal(const std::string &file) {
function CB (line 103) | void CB(cv::Mat &frame, int num){
function Go (line 135) | void Go() {
function main (line 147) | int main(int argc, char **argv){
FILE: NT.cpp
function ExtractFeatureHog (line 22) | void ExtractFeatureHog(const cv::Mat &in,
function ExtractFeature (line 45) | void ExtractFeature(const cv::Mat &in,
function NewAndDelete (line 150) | NewAndDelete NT::UpdateDS(const cv::Mat &frame, const std::vector<cv::Re...
type RRS (line 189) | struct RRS{
method Push (line 190) | void Push(const cv::Rect &rc){
method Get (line 194) | void Get(std::vector<cv::Rect> &rcs){
type FFS (line 201) | struct FFS{
method Push (line 203) | void Push(int id, const FDSSTTrackerP &ff){
method Get (line 207) | void Get(std::vector<std::pair<int, FDSSTTrackerP> > &ffs){
FILE: NT.h
type DSResult (line 8) | struct DSResult{
type boost (line 18) | typedef boost::shared_ptr<TTracker> TTrackerP;
type boost (line 21) | typedef boost::shared_ptr<FDSSTTracker> FDSSTTrackerP;
function class (line 24) | class NT{
FILE: NTN.h
type NewAndDelete (line 4) | struct NewAndDelete{
FILE: StrCommon.h
function gettimeofday (line 10) | static int gettimeofday(struct timeval *tp, void *tzp)
function usleep (line 30) | static void usleep(int64_t us) {
function gtm (line 41) | static int64_t gtm() {
function splitStr (line 48) | static void splitStr(const std::string& inputStr, const std::string &key...
function std (line 78) | static std::string trim(std::string &s) {
function toInt (line 88) | static int toInt(const std::string &in){
function toFloat (line 93) | static float toFloat(const std::string &in) {
function std (line 98) | static std::string toStr(float in) {
function std (line 104) | static std::string toStr(int in){
function std (line 110) | static std::string to4dStr(int in){
function std (line 116) | static std::string to5dStr(int in){
function std (line 122) | static std::string to6dStr(int in){
FILE: deepsort/Detection.h
type Eigen (line 6) | typedef Eigen::Matrix<float, 1, 4, Eigen::RowMajor> DSBOX;
type Eigen (line 8) | typedef Eigen::Matrix<float, 1, 128, Eigen::RowMajor> FEATURE;
type std (line 10) | typedef std::vector<int> IDS;
type Eigen (line 11) | typedef Eigen::Matrix<float, 1, 2, Eigen::RowMajor> PT2;
type Eigen (line 13) | typedef Eigen::Matrix<float, 1, 8, Eigen::RowMajor> MEAN;
type Eigen (line 14) | typedef Eigen::Matrix<float, 8, 8, Eigen::RowMajor> VAR;
type Eigen (line 15) | typedef Eigen::Matrix<float, 1, 4, Eigen::RowMajor> NMEAN;
type Eigen (line 16) | typedef Eigen::Matrix<float, 4, 4, Eigen::RowMajor> NVAR;
type Detection (line 18) | struct Detection {
FILE: deepsort/FeatureGetter/CaffeShuffeNetFeatureGetter.cpp
function fgtm (line 16) | static int64_t fgtm() {
function to_buffer (line 48) | void to_buffer(const cv::Mat &img, float *buf){
function GetCore (line 104) | bool GetCore(const XNET &xnet, const XINPUT &xinput, const cv::Mat &imgi...
type XFTS (line 142) | struct XFTS{
method Push (line 144) | void Push(int id, const FFEATURE &ff){
method Get (line 148) | void Get(std::vector<std::pair<int, FFEATURE> > &ffs){
FILE: deepsort/FeatureGetter/FaceNetFeatureGetter.cpp
function fgtm (line 22) | static int64_t fgtm() {
function tobuffer (line 36) | void tobuffer(const std::vector<cv::Mat> &imgs, uint8 *buf) {
function tobufferA (line 59) | void tobufferA(const std::vector<cv::Mat> &imgs, float *buf){
FILE: deepsort/FeatureGetter/FeatureGetter.cpp
function fgtm (line 33) | static int64_t fgtm() {
function tobuffer (line 47) | void tobuffer(const std::vector<cv::Mat> &imgs, uint8 *buf) {
FILE: deepsort/FeatureGetter/FeatureGetter.h
type Eigen (line 7) | typedef Eigen::Matrix<float, 1, 128, Eigen::RowMajor> FFEATURE;
function class (line 13) | class FeatureGetter {
FILE: deepsort/FeatureGetter/MobileNetFeatureGetter.cpp
function fgtm (line 22) | static int64_t fgtm() {
function tobuffer (line 36) | void tobuffer(const std::vector<cv::Mat> &imgs, uint8 *buf) {
function tobufferA (line 59) | void tobufferA(const std::vector<cv::Mat> &imgs, float *buf){
FILE: deepsort/HungarianOper.h
function class (line 7) | class HungarianOper {
FILE: deepsort/KalmanTracker.h
type TrackState (line 7) | enum TrackState{
type boost (line 14) | typedef boost::shared_ptr<KalmanTrackerN> KalmanTracker;
FILE: deepsort/iou_matching.h
function class (line 9) | class iou_matching{
FILE: deepsort/kalman_filter.h
type Eigen (line 6) | typedef Eigen::Matrix<float, 4, 8, Eigen::RowMajor> UPM;
function class (line 8) | class KF{
FILE: deepsort/linear_assignment.h
function line_gtm (line 12) | static int64_t line_gtm() {
type RR (line 19) | struct RR {
type DYNAMICM (line 25) | typedef DYNAMICM (*GetCostMarixFun)(const std::vector<KalmanTracker> &tr...
function class (line 42) | class linear_assignment{
FILE: deepsort/munkres/adapters/boostmatrixadapter.cpp
class BoostMatrixAdapter<double> (line 21) | class BoostMatrixAdapter<double>
class BoostMatrixAdapter<float> (line 22) | class BoostMatrixAdapter<float>
class BoostMatrixAdapter<int> (line 23) | class BoostMatrixAdapter<int>
FILE: deepsort/munkres/adapters/boostmatrixadapter.h
function virtual (line 44) | virtual void convertFromMatrix(boost::numeric::ublas::matrix<Data> &boos...
FILE: deepsort/munkres/matrix.cpp
function T (line 185) | inline T&
function T (line 195) | inline const T&
function T (line 205) | const T
function T (line 223) | const T
FILE: deepsort/munkres/matrix.h
function T (line 42) | const T& operator () (const size_t x, const size_t y) const;
FILE: deepsort/munkres/munkres.cpp
class Munkres<double> (line 22) | class Munkres<double>
class Munkres<float> (line 23) | class Munkres<float>
class Munkres<int> (line 24) | class Munkres<int>
FILE: deepsort/munkres/munkres.h
function replace_infinites (line 142) | static void replace_infinites(Matrix<Data> &matrix) {
function minimize_along_direction (line 179) | static void minimize_along_direction(Matrix<Data> &matrix, const bool ov...
function pair_in_list (line 230) | bool pair_in_list(const std::pair<size_t,size_t> &needle, const std::lis...
function step1 (line 240) | int step1() {
function step2 (line 262) | int step2() {
function step3 (line 290) | int step3() {
function step4 (line 315) | int step4() {
function step5 (line 413) | int step5() {
FILE: deepsort/nn_matching.h
function nn_gtm (line 17) | static int64_t nn_gtm() {
function class (line 69) | class NearestNeighborDistanceMetric{
function DYNAMICM (line 146) | DYNAMICM distance(const FEATURESS &features, const IDS &ids){
FILE: deepsort/tracker.h
function class (line 18) | class TTracker{
function NewAndDelete (line 37) | NewAndDelete update(const std::vector<Detection> &detections){
function _NewTrack (line 220) | int _NewTrack(const Detection &detection){
function DYNAMICM (line 235) | DYNAMICM getCostMatrixByNND(const std::vector<KalmanTracker> &kalmanTrac...
FILE: fdsst/SSE2NEON.h
type float32x4_t (line 52) | typedef float32x4_t __m128;
type int32x4_t (line 53) | typedef int32x4_t __m128i;
function FORCE_INLINE (line 60) | FORCE_INLINE __m128i _mm_setzero_si128()
function FORCE_INLINE (line 66) | FORCE_INLINE __m128 _mm_setzero_ps(void)
function FORCE_INLINE (line 72) | FORCE_INLINE __m128 _mm_set1_ps(float _w)
function FORCE_INLINE (line 78) | FORCE_INLINE __m128 _mm_set_ps1(float _w)
function FORCE_INLINE (line 84) | FORCE_INLINE __m128 _mm_set_ps(float w, float z, float y, float x)
function FORCE_INLINE (line 91) | FORCE_INLINE __m128 _mm_setr_ps(float w, float z , float y , float x )
function FORCE_INLINE (line 98) | FORCE_INLINE __m128i _mm_set1_epi32(int _i)
function FORCE_INLINE (line 104) | FORCE_INLINE __m128i _mm_set_epi32(int i3, int i2, int i1, int i0)
function FORCE_INLINE (line 111) | FORCE_INLINE void _mm_store_ps(float *p, __m128 a)
function FORCE_INLINE (line 117) | FORCE_INLINE void _mm_storeu_ps(float *p, __m128 a)
function FORCE_INLINE (line 123) | FORCE_INLINE void _mm_store_si128(__m128i *p, __m128i a )
function FORCE_INLINE (line 129) | FORCE_INLINE void _mm_store_ss(float *p, __m128 a)
function FORCE_INLINE (line 135) | FORCE_INLINE void _mm_storel_epi64(__m128i* a, __m128i b)
function FORCE_INLINE (line 141) | FORCE_INLINE __m128 _mm_load1_ps(const float * p)
function FORCE_INLINE (line 147) | FORCE_INLINE __m128 _mm_load_ps(const float * p)
function FORCE_INLINE (line 153) | FORCE_INLINE __m128 _mm_loadu_ps(const float * p)
function FORCE_INLINE (line 160) | FORCE_INLINE __m128 _mm_load_ss(const float * p)
function FORCE_INLINE (line 172) | FORCE_INLINE __m128 _mm_cmpneq_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 178) | FORCE_INLINE __m128 _mm_andnot_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 184) | FORCE_INLINE __m128i _mm_andnot_si128(__m128i a, __m128i b)
function FORCE_INLINE (line 190) | FORCE_INLINE __m128i _mm_and_si128(__m128i a, __m128i b)
function FORCE_INLINE (line 196) | FORCE_INLINE __m128 _mm_and_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 202) | FORCE_INLINE __m128 _mm_or_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 208) | FORCE_INLINE __m128 _mm_xor_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 214) | FORCE_INLINE __m128i _mm_or_si128(__m128i a, __m128i b)
function FORCE_INLINE (line 220) | FORCE_INLINE __m128i _mm_xor_si128(__m128i a, __m128i b)
function FORCE_INLINE (line 227) | FORCE_INLINE int _mm_movemask_ps(__m128 a)
function FORCE_INLINE (line 245) | FORCE_INLINE __m128 _mm_shuffle_ps_1032(__m128 a, __m128 b)
function FORCE_INLINE (line 252) | FORCE_INLINE __m128 _mm_shuffle_ps_2301(__m128 a, __m128 b)
function FORCE_INLINE (line 258) | FORCE_INLINE __m128 _mm_shuffle_ps_3210(__m128 a, __m128 b)
function FORCE_INLINE (line 263) | FORCE_INLINE __m128 _mm_shuffle_ps_0011(__m128 a, __m128 b)
function FORCE_INLINE (line 268) | FORCE_INLINE __m128 _mm_shuffle_ps_0022(__m128 a, __m128 b)
function FORCE_INLINE (line 273) | FORCE_INLINE __m128 _mm_shuffle_ps_2200(__m128 a, __m128 b)
function FORCE_INLINE (line 278) | FORCE_INLINE __m128 _mm_shuffle_ps_3202(__m128 a, __m128 b)
function FORCE_INLINE (line 287) | FORCE_INLINE __m128 _mm_shuffle_ps_1133(__m128 a, __m128 b)
function FORCE_INLINE (line 292) | FORCE_INLINE __m128 _mm_shuffle_ps_2010(__m128 a, __m128 b)
function FORCE_INLINE (line 301) | FORCE_INLINE __m128 _mm_shuffle_ps_2001(__m128 a, __m128 b)
function FORCE_INLINE (line 310) | FORCE_INLINE __m128 _mm_shuffle_ps_2032(__m128 a, __m128 b)
function __m128 (line 326) | __m128 _mm_shuffle_ps_default(__m128 a, __m128 b)
function __m128 (line 345) | __m128 _mm_shuffle_ps_function(__m128 a, __m128 b)
function FORCE_INLINE (line 368) | FORCE_INLINE __m128i _mm_shuffle_epi_1032(__m128i a, __m128i b)
function FORCE_INLINE (line 375) | FORCE_INLINE __m128i _mm_shuffle_epi_2301(__m128i a, __m128i b)
function FORCE_INLINE (line 382) | FORCE_INLINE __m128i _mm_shuffle_epi_0321(__m128i a, __m128i b)
function FORCE_INLINE (line 389) | FORCE_INLINE __m128i _mm_shuffle_epi_2103(__m128i a, __m128i b)
function FORCE_INLINE (line 396) | FORCE_INLINE __m128i _mm_shuffle_epi_1010(__m128i a, __m128i b)
function FORCE_INLINE (line 403) | FORCE_INLINE __m128i _mm_shuffle_epi_1001(__m128i a, __m128i b)
function FORCE_INLINE (line 410) | FORCE_INLINE __m128i _mm_shuffle_epi_0101(__m128i a, __m128i b)
function FORCE_INLINE (line 415) | FORCE_INLINE __m128i _mm_shuffle_epi_2211(__m128i a, __m128i b)
function FORCE_INLINE (line 420) | FORCE_INLINE __m128i _mm_shuffle_epi_0122(__m128i a, __m128i b)
function FORCE_INLINE (line 425) | FORCE_INLINE __m128i _mm_shuffle_epi_3332(__m128i a, __m128i b)
function __m128i (line 431) | __m128i _mm_shuffle_epi32_default(__m128i a, __m128i b)
function __m128i (line 450) | __m128i _mm_shuffle_epi32_function(__m128i a, __m128i b)
function __m128i (line 469) | __m128i _mm_shuffle_epi32_splat(__m128i a)
function __m128i (line 475) | __m128i _mm_shuffle_epi32_single(__m128i a)
function __m128i (line 491) | __m128i _mm_shufflehi_epi16_function(__m128i a)
function FORCE_INLINE (line 524) | FORCE_INLINE int _mm_movemask_epi8(__m128i _a)
function FORCE_INLINE (line 557) | FORCE_INLINE __m128 _mm_sub_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 563) | FORCE_INLINE __m128i _mm_sub_epi32(__m128i a, __m128i b)
function FORCE_INLINE (line 569) | FORCE_INLINE __m128 _mm_add_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 575) | FORCE_INLINE __m128i _mm_add_epi32(__m128i a, __m128i b)
function FORCE_INLINE (line 581) | FORCE_INLINE __m128i _mm_add_epi16(__m128i a, __m128i b)
function FORCE_INLINE (line 587) | FORCE_INLINE __m128i _mm_mullo_epi16(__m128i a, __m128i b)
function FORCE_INLINE (line 593) | FORCE_INLINE __m128i _mm_mullo_epi32 (__m128i a, __m128i b)
function FORCE_INLINE (line 599) | FORCE_INLINE __m128 _mm_mul_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 606) | FORCE_INLINE __m128 recipq_newton(__m128 in, int n)
function FORCE_INLINE (line 617) | FORCE_INLINE __m128 _mm_rcp_ps(__m128 in)
function FORCE_INLINE (line 626) | FORCE_INLINE __m128 _mm_sqrt_ps(__m128 in)
function FORCE_INLINE (line 636) | FORCE_INLINE __m128 _mm_max_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 642) | FORCE_INLINE __m128 _mm_min_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 648) | FORCE_INLINE __m128i _mm_min_epi16(__m128i a, __m128i b)
function FORCE_INLINE (line 655) | FORCE_INLINE __m128i _mm_max_epi32(__m128i a, __m128i b )
function FORCE_INLINE (line 661) | FORCE_INLINE __m128i _mm_min_epi32(__m128i a, __m128i b )
function FORCE_INLINE (line 667) | FORCE_INLINE __m128i _mm_mulhi_epi16(__m128i a, __m128i b)
function FORCE_INLINE (line 676) | FORCE_INLINE __m128 _mm_hadd_ps(__m128 a, __m128 b )
function FORCE_INLINE (line 698) | FORCE_INLINE __m128 _mm_cmplt_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 704) | FORCE_INLINE __m128 _mm_cmpgt_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 710) | FORCE_INLINE __m128 _mm_cmpge_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 716) | FORCE_INLINE __m128 _mm_cmple_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 722) | FORCE_INLINE __m128 _mm_cmpeq_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 728) | FORCE_INLINE __m128i _mm_cmplt_epi32(__m128i a, __m128i b)
function FORCE_INLINE (line 734) | FORCE_INLINE __m128i _mm_cmpgt_epi32(__m128i a, __m128i b)
function FORCE_INLINE (line 743) | FORCE_INLINE __m128 _mm_cmpord_ps(__m128 a, __m128 b )
function FORCE_INLINE (line 756) | FORCE_INLINE __m128i _mm_cvttps_epi32(__m128 a)
function FORCE_INLINE (line 762) | FORCE_INLINE __m128 _mm_cvtepi32_ps(__m128i a)
function FORCE_INLINE (line 768) | FORCE_INLINE __m128i _mm_cvtps_epi32(__m128 a)
function FORCE_INLINE (line 782) | FORCE_INLINE int _mm_cvtsi128_si32(__m128i a)
function FORCE_INLINE (line 788) | FORCE_INLINE __m128i _mm_cvtsi32_si128(int a)
function FORCE_INLINE (line 796) | FORCE_INLINE __m128i _mm_castps_si128(__m128 a)
function FORCE_INLINE (line 802) | FORCE_INLINE __m128 _mm_castsi128_ps(__m128i a)
function FORCE_INLINE (line 808) | FORCE_INLINE __m128i _mm_load_si128(const __m128i *p)
function FORCE_INLINE (line 818) | FORCE_INLINE __m128i _mm_packs_epi16(__m128i a, __m128i b)
function FORCE_INLINE (line 824) | FORCE_INLINE __m128i _mm_packus_epi16(const __m128i a, const __m128i b)
function FORCE_INLINE (line 830) | FORCE_INLINE __m128i _mm_packs_epi32(__m128i a, __m128i b)
function FORCE_INLINE (line 836) | FORCE_INLINE __m128i _mm_unpacklo_epi8(__m128i a, __m128i b)
function FORCE_INLINE (line 847) | FORCE_INLINE __m128i _mm_unpacklo_epi16(__m128i a, __m128i b)
function FORCE_INLINE (line 858) | FORCE_INLINE __m128i _mm_unpacklo_epi32(__m128i a, __m128i b)
function FORCE_INLINE (line 869) | FORCE_INLINE __m128 _mm_unpacklo_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 876) | FORCE_INLINE __m128 _mm_unpackhi_ps(__m128 a, __m128 b)
function FORCE_INLINE (line 883) | FORCE_INLINE __m128i _mm_unpackhi_epi32(__m128i a, __m128i b)
function FORCE_INLINE (line 901) | FORCE_INLINE void _mm_sfence(void)
function FORCE_INLINE (line 907) | FORCE_INLINE void _mm_stream_si128(__m128i *p, __m128i a)
function FORCE_INLINE (line 913) | FORCE_INLINE void _mm_clflush(void const*p) {
FILE: fdsst/fdssttracker.cpp
function rangeToColVector (line 102) | cv::Mat rangeToColVector(int begin, int end, int n)
function pow (line 114) | cv::Mat pow(BT base_, const cv::Mat_<ET>& exponent)
function shift (line 145) | void shift(const cv::Mat& src, cv::Mat& dst, cv::Point2f delta, int fill...
FILE: fdsst/fdssttracker.hpp
class FDSSTTracker (line 90) | class FDSSTTracker {
method FDSSTTracker (line 92) | FDSSTTracker(bool hog = true, bool fixed_window = true, bool multiscal...
method init (line 97) | virtual void init(const cv::Rect &roi, cv::Mat image) {
method update (line 102) | virtual cv::Rect update(cv::Mat image) {
method Reset (line 159) | void Reset() {
class FDSSTTracker (line 111) | class FDSSTTracker : public Tracker
method FDSSTTracker (line 92) | FDSSTTracker(bool hog = true, bool fixed_window = true, bool multiscal...
method init (line 97) | virtual void init(const cv::Rect &roi, cv::Mat image) {
method update (line 102) | virtual cv::Rect update(cv::Mat image) {
method Reset (line 159) | void Reset() {
FILE: fdsst/ffttools.hpp
type FFTTools (line 48) | namespace FFTTools
function fftd (line 53) | cv::Mat fftd(cv::Mat img, bool backwards = false, bool byRow = false)
function real (line 73) | cv::Mat real(cv::Mat img)
function imag (line 80) | cv::Mat imag(cv::Mat img)
function magnitude (line 87) | cv::Mat magnitude(cv::Mat img)
function complexMultiplication (line 98) | cv::Mat complexMultiplication(cv::Mat a, cv::Mat b, bool conj = false)
function complexDivisionReal (line 118) | cv::Mat complexDivisionReal(cv::Mat a, cv::Mat b)
function complexDivision (line 135) | cv::Mat complexDivision(cv::Mat a, cv::Mat b)
function rearrange (line 154) | void rearrange(cv::Mat &img)
function normalizedLogTransform (line 196) | void normalizedLogTransform(cv::Mat &img)
function ComplexMats (line 206) | ComplexMats MultiChannelsDFT(const cv::Mat &img, int flags = 0)
function ComplexMats (line 222) | ComplexMats ComplexMatsMultiMat(const ComplexMats &A, cv::Mat b)
function ComplexMats (line 235) | ComplexMats ComplexMatsMultiComplexMats(const ComplexMats &A, const Co...
function ComplexMats (line 248) | ComplexMats MCComplexConjMultiplication(const ComplexMats &A)
function MCMulti (line 262) | cv::Mat MCMulti(cv::Mat a, cv::Mat b)
function MCSum (line 280) | cv::Mat MCSum(const ComplexMats &a)
function MCSum (line 293) | cv::Mat MCSum(const cv::Mat &a)
FILE: fdsst/fhog.cpp
function alFree (line 34) | void alFree(void* aligned) {
function grad1 (line 49) | void grad1( float *I, float *Gx, float *Gy, int h, int w, int x ) {
function grad2 (line 74) | void grad2( float *I, float *Gx, float *Gy, int h, int w, int d ) {
function hoglog (line 82) | void hoglog(){
function gradMag (line 103) | void gradMag( float *I, float *M, float *O, int h, int w, int d, bool fu...
function gradMagNorm (line 157) | void gradMagNorm( float *M, float *S, int h, int w, float norm ) {
function gradQuantize (line 166) | void gradQuantize( float *O, float *M, int *O0, int *O1, float *M0, floa...
function gradHist (line 202) | void gradHist( float *M, float *O, float *H, int h, int w,
function hogChannels (line 313) | void hogChannels( float *H, const float *R, const float *N,
function hog (line 340) | void hog( float *M, float *O, float *H, int h, int w, int binSize,
function fhog (line 356) | bool fhog( float *M, float *O, float *H, int h, int w, int binSize,
function mxArray (line 387) | mxArray* mxCreateMatrix3( int h, int w, int d, mxClassID id, bool c, voi...
function checkArgs (line 399) | void checkArgs( int nl, mxArray *pl[], int nr, const mxArray *pr[], int ...
function mGrad2 (line 412) | void mGrad2( int nl, mxArray *pl[], int nr, const mxArray *pr[] ) {
function mGradMag (line 422) | void mGradMag( int nl, mxArray *pl[], int nr, const mxArray *pr[] ) {
function mGradMagNorm (line 434) | void mGradMagNorm( int nl, mxArray *pl[], int nr, const mxArray *pr[] ) {
function mGradHist (line 444) | void mGradHist( int nl, mxArray *pl[], int nr, const mxArray *pr[] ) {
function mexFunction (line 471) | void mexFunction( int nl, mxArray *pl[], int nr, const mxArray *pr[] ) {
function change_format (line 524) | void change_format(float *des,float *source,int height,int width,int cha...
function fhog (line 571) | cv::Mat fhog(const cv::Mat& input, int binSize, int nOrients, float clip...
FILE: fdsst/fhog.h
function wrError (line 50) | inline void wrError(const char *errormsg) { throw errormsg; }
function wrFree (line 72) | inline void wrFree( void * ptr ) {
FILE: fdsst/fhogbk/fhog.cpp
function grad1 (line 37) | void grad1( float *I, float *Gx, float *Gy, int h, int w, int x ) {
function grad2 (line 62) | void grad2( float *I, float *Gx, float *Gy, int h, int w, int d ) {
function hoglog (line 70) | void hoglog(){
function gradMag (line 91) | void gradMag( float *I, float *M, float *O, int h, int w, int d, bool fu...
function gradMagNorm (line 148) | void gradMagNorm( float *M, float *S, int h, int w, float norm ) {
function gradQuantize (line 157) | void gradQuantize( float *O, float *M, int *O0, int *O1, float *M0, floa...
function gradHist (line 193) | void gradHist( float *M, float *O, float *H, int h, int w,
function hogChannels (line 312) | void hogChannels( float *H, const float *R, const float *N,
function hog (line 339) | void hog( float *M, float *O, float *H, int h, int w, int binSize,
function fhog (line 355) | bool fhog( float *M, float *O, float *H, int h, int w, int binSize,
function mxArray (line 386) | mxArray* mxCreateMatrix3( int h, int w, int d, mxClassID id, bool c, voi...
function checkArgs (line 398) | void checkArgs( int nl, mxArray *pl[], int nr, const mxArray *pr[], int ...
function mGrad2 (line 411) | void mGrad2( int nl, mxArray *pl[], int nr, const mxArray *pr[] ) {
function mGradMag (line 421) | void mGradMag( int nl, mxArray *pl[], int nr, const mxArray *pr[] ) {
function mGradMagNorm (line 433) | void mGradMagNorm( int nl, mxArray *pl[], int nr, const mxArray *pr[] ) {
function mGradHist (line 443) | void mGradHist( int nl, mxArray *pl[], int nr, const mxArray *pr[] ) {
function mexFunction (line 470) | void mexFunction( int nl, mxArray *pl[], int nr, const mxArray *pr[] ) {
function change_format (line 523) | void change_format(float *des,float *source,int height,int width,int cha...
function fhog (line 570) | cv::Mat fhog(const cv::Mat& input, int binSize, int nOrients, float clip...
FILE: fdsst/recttools.hpp
type RectTools (line 44) | namespace RectTools
function center (line 48) | inline cv::Vec<t, 2 > center(const cv::Rect_<t> &rect)
function t (line 54) | inline t x2(const cv::Rect_<t> &rect)
function t (line 60) | inline t y2(const cv::Rect_<t> &rect)
function resize (line 66) | inline void resize(cv::Rect_<t> &rect, float scalex, float scaley = 0)
function limit (line 78) | inline void limit(cv::Rect_<t> &rect, cv::Rect_<t> limit)
function limit (line 97) | inline void limit(cv::Rect_<t> &rect, t width, t height, t x = 0, t y ...
function getBorder (line 103) | inline cv::Rect getBorder(const cv::Rect_<t > &original, cv::Rect_<t >...
function subwindow (line 114) | inline cv::Mat subwindow(const cv::Mat &in, const cv::Rect & window, i...
function cutOutsize (line 130) | inline void cutOutsize(float &num, int limit)
function extractImage (line 138) | inline cv::Mat extractImage(const cv::Mat &in, float cx, float cy, flo...
function getGrayImage (line 165) | inline cv::Mat getGrayImage(cv::Mat img)
FILE: fdsst/sse.hpp
type sse (line 9) | namespace sse{
function RETf (line 16) | RETf SET( const float &x ) { return _mm_set1_ps(x); }
function RETf (line 17) | RETf SET( float x, float y, float z, float w ) { return _mm_set_ps(x,y...
function RETi (line 18) | RETi SET( const int &x ) { return _mm_set1_epi32(x); }
function RETf (line 19) | RETf LD( const float &x ) { return _mm_load_ps(&x); }
function RETf (line 20) | RETf LDu( const float &x ) { return _mm_loadu_ps(&x); }
function RETf (line 21) | RETf STR( float &x, const __m128 y ) { _mm_store_ps(&x,y); return y; }
function RETf (line 22) | RETf STR1( float &x, const __m128 y ) { _mm_store_ss(&x,y); return y; }
function RETf (line 23) | RETf STRu( float &x, const __m128 y ) { _mm_storeu_ps(&x,y); return y; }
function RETf (line 24) | RETf STR( float &x, const float y ) { return STR(x,SET(y)); }
function RETi (line 27) | RETi ADD( const __m128i x, const __m128i y ) { return _mm_add_epi32(x,...
function RETf (line 28) | RETf ADD( const __m128 x, const __m128 y ) { return _mm_add_ps(x,y); }
function RETf (line 29) | RETf ADD( const __m128 x, const __m128 y, const __m128 z ) {
function RETf (line 31) | RETf ADD( const __m128 a, const __m128 b, const __m128 c, const __m128...
function RETf (line 33) | RETf SUB( const __m128 x, const __m128 y ) { return _mm_sub_ps(x,y); }
function RETf (line 34) | RETf MUL( const __m128 x, const __m128 y ) { return _mm_mul_ps(x,y); }
function RETf (line 35) | RETf MUL( const __m128 x, const float y ) { return MUL(x,SET(y)); }
function RETf (line 36) | RETf MUL( const float x, const __m128 y ) { return MUL(SET(x),y); }
function RETf (line 37) | RETf INC( __m128 &x, const __m128 y ) { return x = ADD(x,y); }
function RETf (line 38) | RETf INC( float &x, const __m128 y ) { __m128 t=ADD(LD(x),y); return S...
function RETf (line 39) | RETf DEC( __m128 &x, const __m128 y ) { return x = SUB(x,y); }
function RETf (line 40) | RETf DEC( float &x, const __m128 y ) { __m128 t=SUB(LD(x),y); return S...
function RETf (line 41) | RETf MIN( const __m128 x, const __m128 y ) { return _mm_min_ps(x,y); }
function RETf (line 42) | RETf RCP( const __m128 x ) { return _mm_rcp_ps(x); }
function RETf (line 43) | RETf RCPSQRT( const __m128 x ) { return _mm_rsqrt_ps(x); }
function RETf (line 46) | RETf AND( const __m128 x, const __m128 y ) { return _mm_and_ps(x,y); }
function RETi (line 47) | RETi AND( const __m128i x, const __m128i y ) { return _mm_and_si128(x,...
function RETf (line 48) | RETf ANDNOT( const __m128 x, const __m128 y ) { return _mm_andnot_ps(x...
function RETf (line 49) | RETf OR( const __m128 x, const __m128 y ) { return _mm_or_ps(x,y); }
function RETf (line 50) | RETf XOR( const __m128 x, const __m128 y ) { return _mm_xor_ps(x,y); }
function RETf (line 53) | RETf CMPGT( const __m128 x, const __m128 y ) { return _mm_cmpgt_ps(x,y...
function RETf (line 54) | RETf CMPLT( const __m128 x, const __m128 y ) { return _mm_cmplt_ps(x,y...
function RETi (line 55) | RETi CMPGT( const __m128i x, const __m128i y ) { return _mm_cmpgt_epi3...
function RETi (line 56) | RETi CMPLT( const __m128i x, const __m128i y ) { return _mm_cmplt_epi3...
function RETf (line 59) | RETf CVT( const __m128i x ) { return _mm_cvtepi32_ps(x); }
function RETi (line 60) | RETi CVT( const __m128 x ) { return _mm_cvttps_epi32(x); }
FILE: fdsst/tracker.h
function class (line 23) | class Tracker
Condensed preview — 49 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,042K chars).
[
{
"path": "LICENSE",
"chars": 35147,
"preview": " GNU GENERAL PUBLIC LICENSE\n Version 3, 29 June 2007\n\n Copyright (C) 2007 Free "
},
{
"path": "Main.cpp",
"chars": 4021,
"preview": "#include <opencv2/opencv.hpp>\n#include \"NT.h\"\n#include \"StrCommon.h\"\n\nNT *_tt = NULL;\n\n\nvoid DrawData(cv::Mat mm, cv::Ma"
},
{
"path": "NT.cpp",
"chars": 8081,
"preview": "#include \"NT.h\"\n\n//#define UDL\n#ifdef UDL\n\t//#define UBC\n\t#include \"deepsort/FeatureGetter/FeatureGetter.h\"\n#endif\n\n#inc"
},
{
"path": "NT.h",
"chars": 1508,
"preview": "#ifndef _NTH_\n#define _NTH_\n#include <opencv2/opencv.hpp>\n#include <boost/shared_ptr.hpp>\n#include \"NTN.h\"\nusing namespa"
},
{
"path": "NTN.h",
"chars": 128,
"preview": "#ifndef _NTNH_\n#define _NTNH_\n\nstruct NewAndDelete{\n\tstd::map<int, int> news_;// id, pos\n\tstd::vector<int> deletes_;\n};\n"
},
{
"path": "README.md",
"chars": 738,
"preview": "**DS**(~~deepsort cpp version~~)\n\nC++ implementation of Simple Online Realtime Tracking with a Deep Association Metric\n\n"
},
{
"path": "StrCommon.h",
"chars": 2595,
"preview": "#ifndef _STRCOMMONH_\n#define _STRCOMMONH_\n#include <string>\n#include <vector>\n#ifdef WIN32\n#include <winsock2.h>\n#includ"
},
{
"path": "deepsort/Detection.h",
"chars": 1243,
"preview": "#ifndef _DETECTIONH_\n#define _DETECTIONH_\n#include <vector>\n#include <Eigen>\n\ntypedef Eigen::Matrix<float, 1, 4, Eigen::"
},
{
"path": "deepsort/FeatureGetter/CaffeShuffeNetFeatureGetter.cpp",
"chars": 5151,
"preview": "\n#include \"FeatureGetter.h\"\n\n#include <caffe/net.hpp>\n\n#include <fstream>\n#include <iostream>\n#include <opencv2/opencv.h"
},
{
"path": "deepsort/FeatureGetter/FaceNetFeatureGetter.cpp",
"chars": 5463,
"preview": "\n#include \"FeatureGetter.h\"\n\n\n#include <tensorflow/core/public/session.h>\n#include <fstream>\n#include <iostream>\n\n#inclu"
},
{
"path": "deepsort/FeatureGetter/FeatureGetter.cpp",
"chars": 4351,
"preview": "\n#ifdef USE_FACE_NET\n#include \"FaceNetFeatureGetter.cpp\"\n\n#else\n\t#ifdef USE_MOBILE_NET\n\t\t#include \"MobileNetFeatureGette"
},
{
"path": "deepsort/FeatureGetter/FeatureGetter.h",
"chars": 583,
"preview": "#ifndef _FEATUREGETTERH_\n#define _FEATUREGETTERH_\n\n#include <boost/shared_ptr.hpp>\n#include <opencv2/opencv.hpp>\n#includ"
},
{
"path": "deepsort/FeatureGetter/MobileNetFeatureGetter.cpp",
"chars": 4544,
"preview": "\n#include \"FeatureGetter.h\"\n\n\n#include <tensorflow/core/public/session.h>\n#include <fstream>\n#include <iostream>\n\n#inclu"
},
{
"path": "deepsort/FeatureGetter/make.sh",
"chars": 1943,
"preview": "#!/bin/bash\nfunction getbazel(){\n\tLINE=`readlink -f /home/$USER/code1/tensorflow-1.4.0-rc0/bazel-bin/`\n\n\tPOS1=\"_bazel_$U"
},
{
"path": "deepsort/HungarianOper.h",
"chars": 1074,
"preview": "#ifndef _HUNGARIANOPERH_\n#define _HUNGARIANOPERH_\n#include \"munkres/munkres.h\"\n#include \"munkres/adapters/boostmatrixada"
},
{
"path": "deepsort/KalmanTracker.h",
"chars": 2407,
"preview": "#ifndef _KALMANTRACKERH_\n#define _KALMANTRACKERH_\n#include \"FeatureGetter/FeatureGetter.h\"\n#include \"kalman_filter.h\"\n#i"
},
{
"path": "deepsort/iou_matching.h",
"chars": 4047,
"preview": "#ifndef _IOUMH_\n#define _IOUMH_\n#include <vector>\n#include \"Detection.h\"\n#include <Eigen>\n#include \"linear_assignment.h\""
},
{
"path": "deepsort/kalman_filter.h",
"chars": 9978,
"preview": "#ifndef PYKF\n#ifndef _KKALMANFILTERH_\n#define _KKALMANFILTERH_\n#include <boost/shared_ptr.hpp>\n\ntypedef Eigen::Matrix<fl"
},
{
"path": "deepsort/linear_assignment.h",
"chars": 8451,
"preview": "#ifndef _LASMH_\n#define _LASMH_\n#include <vector>\n#include \"Detection.h\"\n#include <Eigen>\n\n#include \"KalmanTracker.h\"\n#i"
},
{
"path": "deepsort/munkres/adapters/adapter.cpp",
"chars": 808,
"preview": "/*\n * Copyright (c) 2015 Miroslav Krajicek\n *\n * This program is free software; you can redistribute it and/or modif"
},
{
"path": "deepsort/munkres/adapters/adapter.h",
"chars": 1343,
"preview": "/*\n * Copyright (c) 2015 Miroslav Krajicek\n *\n * This program is free software; you can redistribute it and/or modif"
},
{
"path": "deepsort/munkres/adapters/boostmatrixadapter.cpp",
"chars": 945,
"preview": "/*\n * Copyright (c) 2015 Miroslav Krajicek\n *\n * This program is free software; you can redistribute it and/or modif"
},
{
"path": "deepsort/munkres/adapters/boostmatrixadapter.h",
"chars": 2011,
"preview": "/*\n * Copyright (c) 2015 Miroslav Krajicek\n *\n * This program is free software; you can redistribute it and/or modif"
},
{
"path": "deepsort/munkres/matrix.cpp",
"chars": 5639,
"preview": "/*\n * Copyright (c) 2007 John Weaver\n *\n * This program is free software; you can redistribute it and/or modify\n * "
},
{
"path": "deepsort/munkres/matrix.h",
"chars": 2310,
"preview": "/*\n * Copyright (c) 2007 John Weaver\n *\n * This program is free software; you can redistribute it and/or modify\n * "
},
{
"path": "deepsort/munkres/munkres.cpp",
"chars": 938,
"preview": "/*\n * Copyright (c) 2007 John Weaver\n * Copyright (c) 2015 Miroslav Krajicek\n *\n * This program is free software; "
},
{
"path": "deepsort/munkres/munkres.h",
"chars": 13205,
"preview": "/*\n * Copyright (c) 2007 John Weaver\n * Copyright (c) 2015 Miroslav Krajicek\n *\n * This program is free software; "
},
{
"path": "deepsort/nn_matching.h",
"chars": 5891,
"preview": "#ifndef _NNMATCHINGH_\n#define _NNMATCHINGH_\n#include <vector>\n#include \"Detection.h\"\n#include <Eigen>\n#include <map>\n#in"
},
{
"path": "deepsort/tracker.h",
"chars": 8594,
"preview": "#ifndef _TTH_\n#define _TTH_\n#include \"nn_matching.h\"\n#include \"linear_assignment.h\"\n#include <algorithm>\n#include <vecto"
},
{
"path": "fdsst/SSE2NEON.h",
"chars": 37001,
"preview": "#ifndef SSE2NEON_H\n#define SSE2NEON_H\n\n// This header file provides a simple API translation layer\n// between SSE intrin"
},
{
"path": "fdsst/fdssttracker.cpp",
"chars": 28242,
"preview": "/*\n\nTracker based on Kernelized Correlation Filter (KCF) [1] and Circulant Structure with Kernels (CSK) [2].\nCSK is impl"
},
{
"path": "fdsst/fdssttracker.hpp",
"chars": 8642,
"preview": "/*\n\nTracker based on Kernelized Correlation Filter (KCF) [1] and Circulant Structure with Kernels (CSK) [2].\nCSK is impl"
},
{
"path": "fdsst/ffttools.hpp",
"chars": 7449,
"preview": "/*\nAuthor: Christian Bailer\nContact address: Christian.Bailer@dfki.de\nDepartment Augmented Vision DFKI\n\n "
},
{
"path": "fdsst/fhog.cpp",
"chars": 24754,
"preview": "#include <cstring>\n#include <iostream>\n\nusing namespace std;\n\n#include \"fhog.h\"\n#undef MIN\n#ifdef WIN32\n//{\n#ifndef _CRT"
},
{
"path": "fdsst/fhog.h",
"chars": 2653,
"preview": "#ifndef FHOG_H\n#define FHOG_H\n#include <opencv2/core/core.hpp>\n#include <boost/thread/mutex.hpp>\n#ifdef WIN32\n#ifndef _C"
},
{
"path": "fdsst/fhogbk/fhog.cpp",
"chars": 24532,
"preview": "#include <cstring>\n#include <iostream>\n\nusing namespace std;\n\n#include \"fhog.h\"\n#undef MIN\n#define GLOG_NO_ABBREVIATED_S"
},
{
"path": "fdsst/fhogbk/fhog.h",
"chars": 1210,
"preview": "#ifndef FHOG_H\n#define FHOG_H\n#include <opencv2/core/core.hpp>\n#include <boost/thread/mutex.hpp>\n//#include <cstdlib>\n#i"
},
{
"path": "fdsst/labdata.hpp",
"chars": 617,
"preview": "const int nClusters = 15;\nfloat data[nClusters][3] = {\n{161.317504, 127.223401, 128.609333},\n{142.922425, 128.666965, 12"
},
{
"path": "fdsst/recttools.hpp",
"chars": 5324,
"preview": "/*\nAuthor: Christian Bailer\nContact address: Christian.Bailer@dfki.de\nDepartment Augmented Vision DFKI\n\n "
},
{
"path": "fdsst/sse.hpp",
"chars": 3155,
"preview": "/*******************************************************************************\n* Piotr's Computer Vision Matlab Toolbo"
},
{
"path": "fdsst/tracker.h",
"chars": 1326,
"preview": "/*\n * File: BasicTracker.h\n * Author: Joao F. Henriques, Joao Faro, Christian Bailer\n * Contact address: henriques@isr"
},
{
"path": "lmake.sh",
"chars": 1796,
"preview": "#!/bin/bash\n\nfunction getbazel(){\n\tLINE=`readlink -f /home/$USER/code1/tensorflow-1.4.0-rc0/bazel-bin/`\n\n\tPOS1=\"_bazel_$"
},
{
"path": "log.txt",
"chars": 178996,
"preview": "hahahah0\nhahahah1\nhahahah2\nprocess image cost time:2\n_create_network\nbatch_norm_fn\nbatch_norm_fn\n('feature dimensionalit"
},
{
"path": "logn10.txt",
"chars": 180632,
"preview": "hahahah0\nhahahah1\nhahahah2\nprocess image cost time:2\n_create_network\nbatch_norm_fn\nbatch_norm_fn\n('feature dimensionalit"
},
{
"path": "logn15.txt",
"chars": 180869,
"preview": "hahahah0\nhahahah1\nhahahah2\nprocess image cost time:2\n_create_network\nbatch_norm_fn\nbatch_norm_fn\n('feature dimensionalit"
},
{
"path": "logn20.txt",
"chars": 183074,
"preview": "hahahah0\nhahahah1\nhahahah2\nprocess image cost time:1\n_create_network\nbatch_norm_fn\nbatch_norm_fn\n('feature dimensionalit"
},
{
"path": "make.sh",
"chars": 1751,
"preview": "#!/bin/bash\n\nfunction getbazel(){\n\tLINE=`readlink -f /home/$USER/code1/tensorflow-1.4.0-rc0/bazel-bin/`\n\n\tPOS1=\"_bazel_$"
},
{
"path": "t.sh",
"chars": 92,
"preview": "#!/bin/bash\n\n\nps aux | grep DS | grep -v grep | awk '{print $2}' | xargs -i -t kill -9 {}\n\n"
}
]
// ... and 1 more files (download for full content)
About this extraction
This page contains the full source code of the oylz/DS GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 49 files (11.7 MB), approximately 405.5k tokens, and a symbol index with 314 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.